@picsart/ai-sdk 6.13.1 → 6.13.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.
- package/index.d.ts +268 -240
- package/index.js +90 -5
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1922,219 +1922,71 @@ type ModelInput<M extends TypedModelId> = ModelInputById[M];
|
|
|
1922
1922
|
type TextModelId = "claude-fable-5" | "claude-fable-5-1" | "claude-haiku-4-5" | "claude-opus-4-8" | "claude-opus-5" | "claude-sonnet-4-5" | "claude-sonnet-4-6" | "claude-sonnet-5" | "eleven-speech-to-text" | "gemini-2.5-flash" | "gemini-3-pro" | "gemini-3.5-flash-lite" | "gemini-3.6-flash" | "gemini-3.7-flash" | "gemini-3.8-flash" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini" | "gpt-5" | "gpt-5-mini" | "gpt-5.1" | "gpt-5.2" | "gpt-5.5" | "gpt-5.6-luna" | "gpt-5.6-sol" | "gpt-5.6-terra" | "gpt-6-astra";
|
|
1923
1923
|
type TextModelInputById = Pick<ModelInputById, TextModelId>;
|
|
1924
1924
|
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
generatedVoiceId?: string;
|
|
1936
|
-
/** URL of the generated video's last frame, when the model was asked for it
|
|
1937
|
-
* (`returnLastFrame`, seedance) — the seed for frame-chaining flows. */
|
|
1938
|
-
lastFrameUrl?: string;
|
|
1939
|
-
/** The draft a Seedance 2.5 Draft generation produced — pass it back
|
|
1940
|
-
* unchanged as `draftTask` to the matching `-draft-final` model to render
|
|
1941
|
-
* the final 1080p video (valid 7 days). Wire field names on purpose: the
|
|
1942
|
-
* worker signs it, so any change is rejected. */
|
|
1943
|
-
draftTask?: SeedanceDraftTask;
|
|
1944
|
-
}
|
|
1945
|
-
/** A Seedance 2.5 draft reference, as the worker issues it. */
|
|
1946
|
-
interface SeedanceDraftTask {
|
|
1947
|
-
id: string;
|
|
1948
|
-
video_input: boolean;
|
|
1949
|
-
signature: string;
|
|
1925
|
+
interface ParamSchema {
|
|
1926
|
+
type: 'string' | 'number' | 'boolean' | 'file';
|
|
1927
|
+
enum?: (string | number)[];
|
|
1928
|
+
default?: string | number | boolean;
|
|
1929
|
+
min?: number;
|
|
1930
|
+
max?: number;
|
|
1931
|
+
step?: number;
|
|
1932
|
+
required?: boolean;
|
|
1933
|
+
label?: string;
|
|
1934
|
+
accept?: string;
|
|
1950
1935
|
}
|
|
1936
|
+
type ModelParamSchema = Record<string, ParamSchema>;
|
|
1951
1937
|
|
|
1952
1938
|
/**
|
|
1953
|
-
*
|
|
1939
|
+
* Runtime catalogs — the standard format served by the platform
|
|
1940
|
+
* `<vendor>/v1/catalog/<voices|avatars|…>` tasks (voices, avatars, effect
|
|
1941
|
+
* templates), plus the in-memory hydration registry that lets runtime-fetched
|
|
1942
|
+
* catalogs back the descriptor system.
|
|
1954
1943
|
*
|
|
1955
|
-
*
|
|
1956
|
-
*
|
|
1944
|
+
* The wire types mirror the shared backend contract (`@picsart/pa-genai-common`);
|
|
1945
|
+
* the SDK owns its own copy so it carries no backend dependency.
|
|
1957
1946
|
*/
|
|
1958
1947
|
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
/** A folder reference in Picsart Drive. */
|
|
1962
|
-
interface DriveFolder {
|
|
1963
|
-
name: string;
|
|
1964
|
-
uid: string;
|
|
1965
|
-
}
|
|
1966
|
-
/** Drive save result, attached to GenerateResult when drive is enabled. */
|
|
1967
|
-
interface DriveSaveResult {
|
|
1968
|
-
uid: string;
|
|
1969
|
-
folder: DriveFolder;
|
|
1970
|
-
}
|
|
1971
|
-
/**
|
|
1972
|
-
* The generation input parameters, serialized into the `aiSDKPayload` attribute.
|
|
1973
|
-
* Captures every value from the generation context — the named fields below are
|
|
1974
|
-
* common ones for convenience; the index signature carries any other input param.
|
|
1975
|
-
*/
|
|
1976
|
-
interface SdkPayload {
|
|
1977
|
-
prompt: string;
|
|
1978
|
-
aspectRatio?: string;
|
|
1979
|
-
duration?: number;
|
|
1980
|
-
resolution?: string;
|
|
1981
|
-
generateAudio?: boolean;
|
|
1982
|
-
imageUrls?: string[];
|
|
1983
|
-
videoUrls?: string[];
|
|
1984
|
-
audioUrls?: string[];
|
|
1985
|
-
startFrame?: string;
|
|
1986
|
-
endFrame?: string;
|
|
1948
|
+
interface CatalogPreview {
|
|
1949
|
+
imageUrl?: string;
|
|
1987
1950
|
videoUrl?: string;
|
|
1988
1951
|
audioUrl?: string;
|
|
1989
|
-
[key: string]: unknown;
|
|
1990
|
-
}
|
|
1991
|
-
type DriveFile = {
|
|
1992
|
-
uid: string;
|
|
1993
|
-
} & Record<string, unknown>;
|
|
1994
|
-
interface DriveAttributes {
|
|
1995
|
-
model: string;
|
|
1996
|
-
/** JSON-encoded SdkPayload (all generation input params). */
|
|
1997
|
-
aiSDKPayload: string;
|
|
1998
|
-
appId?: string;
|
|
1999
|
-
appType?: AppType;
|
|
2000
|
-
}
|
|
2001
|
-
/** A saved Seedance 2.5 draft — pass `draftTask` unchanged as the final's
|
|
2002
|
-
* `draftTask` param until `draftExpiresAt`. */
|
|
2003
|
-
interface DriveDraftInfo {
|
|
2004
|
-
draftTask?: SeedanceDraftTask;
|
|
2005
|
-
/** ISO timestamp after which the vendor no longer renders a final from it. */
|
|
2006
|
-
draftExpiresAt?: string;
|
|
2007
|
-
}
|
|
2008
|
-
interface GenerationFile extends DriveDraftInfo {
|
|
2009
|
-
appId?: string;
|
|
2010
|
-
appType?: AppType;
|
|
2011
|
-
model?: string;
|
|
2012
|
-
aiSDKPayload?: SdkPayload;
|
|
2013
|
-
userReaction?: UserReaction;
|
|
2014
|
-
}
|
|
2015
|
-
interface DriveMediaItem {
|
|
2016
|
-
uid: string;
|
|
2017
|
-
url: string;
|
|
2018
|
-
name: string;
|
|
2019
|
-
type: MediaTypeFilter;
|
|
2020
|
-
previewUrl?: string;
|
|
2021
|
-
timestamp: number;
|
|
2022
|
-
}
|
|
2023
|
-
interface DriveFileDetails extends DriveMediaItem, DriveDraftInfo {
|
|
2024
|
-
createdAt?: string;
|
|
2025
|
-
model?: string;
|
|
2026
|
-
prompt?: string;
|
|
2027
|
-
service?: string;
|
|
2028
|
-
subType?: string;
|
|
2029
|
-
duration?: string;
|
|
2030
|
-
aspectRatio?: string;
|
|
2031
|
-
resolution?: string;
|
|
2032
|
-
quality?: string;
|
|
2033
|
-
userReaction?: UserReaction;
|
|
2034
|
-
referenceImageUrls?: string[];
|
|
2035
|
-
referenceVideoUrl?: string;
|
|
2036
|
-
referenceAudioUrl?: string;
|
|
2037
|
-
}
|
|
2038
|
-
interface ListOptions {
|
|
2039
|
-
folder?: DriveFolder;
|
|
2040
|
-
type?: MediaTypeFilter;
|
|
2041
|
-
}
|
|
2042
|
-
interface SaveParams {
|
|
2043
|
-
url: string;
|
|
2044
|
-
name: string;
|
|
2045
|
-
resourceType: 'PHOTO' | 'VIDEO' | 'AUDIO';
|
|
2046
|
-
attributes?: Record<string, string>;
|
|
2047
|
-
previewUrl?: string;
|
|
2048
1952
|
}
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
path?: string;
|
|
2053
|
-
/** Folder UID — overrides path when provided. */
|
|
2054
|
-
id?: string;
|
|
2055
|
-
}
|
|
2056
|
-
/** Drive save options injected into the workflow payload as `options.drive`. */
|
|
2057
|
-
interface PayloadDriveOptions {
|
|
2058
|
-
/** Filename for the saved asset. */
|
|
1953
|
+
interface CatalogItem {
|
|
1954
|
+
/** Vendor-native id, sent back verbatim on generate as the bound param's value. */
|
|
1955
|
+
id: string;
|
|
2059
1956
|
name: string;
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
1957
|
+
description?: string;
|
|
1958
|
+
/** Facets for filtering: gender, language, age, accent, tone, … */
|
|
1959
|
+
tags: string[];
|
|
1960
|
+
preview?: CatalogPreview;
|
|
1961
|
+
/** Vendor extras, e.g. `defaultVoiceId` on HeyGen avatars. */
|
|
1962
|
+
meta?: Record<string, unknown>;
|
|
2064
1963
|
}
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
ensureFolder(subfolder?: string): Promise<DriveFolder | null>;
|
|
2073
|
-
/** List the immediate subfolders of the root folder. */
|
|
2074
|
-
folders(): Promise<DriveFolder[]>;
|
|
2075
|
-
/** List all folders recursively. */
|
|
2076
|
-
allFolders(): Promise<DriveFolder[]>;
|
|
2077
|
-
/** Find a folder by name. */
|
|
2078
|
-
findFolder(name: string): Promise<DriveFolder | null>;
|
|
2079
|
-
/** List media items in a folder. */
|
|
2080
|
-
list(options?: ListOptions): Promise<DriveMediaItem[]>;
|
|
2081
|
-
/** List media items in a folder with full generation metadata. */
|
|
2082
|
-
listDetailed(options?: ListOptions): Promise<DriveFileDetails[]>;
|
|
2083
|
-
/** Read a single generation's stored attributes. */
|
|
2084
|
-
getGeneration(fileUid: string): Promise<GenerationFile | null>;
|
|
2085
|
-
/** Save an asset to Drive. */
|
|
2086
|
-
save(params: SaveParams, folder?: DriveFolder): Promise<DriveSaveResult | null>;
|
|
2087
|
-
/** Build the save params for a generation result. */
|
|
2088
|
-
buildSaveParams(url: string, modelId: string, modelName: string, mode: string, prompt?: string): SaveParams;
|
|
2089
|
-
/** Set a like/dislike reaction on a file. */
|
|
2090
|
-
addReaction(fileUid: string, reaction: UserReaction): Promise<boolean>;
|
|
2091
|
-
/** Clear the reaction on a file. */
|
|
2092
|
-
removeReaction(fileUid: string): Promise<boolean>;
|
|
1964
|
+
interface CatalogQuery {
|
|
1965
|
+
/** Worker-side filter (e.g. the seed-audio model variant on bytedance). */
|
|
1966
|
+
modelId?: string;
|
|
1967
|
+
/** Opaque cursor from a previous page. */
|
|
1968
|
+
cursor?: string;
|
|
1969
|
+
/** Page size. Every catalog task accepts up to 100. */
|
|
1970
|
+
limit?: number;
|
|
2093
1971
|
}
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
declare function parseGeneration(file: DriveFile | Record<string, unknown>): GenerationFile;
|
|
2103
|
-
|
|
2104
|
-
/** Result of `ai.apis.run()` — the API result plus optional credit usage. */
|
|
2105
|
-
type ApiResponse<R = unknown> = WorkflowResponse<R>;
|
|
2106
|
-
/**
|
|
2107
|
-
* Options for `ai.apis.run()` — execution mode, polling, abort signal, progress callbacks.
|
|
2108
|
-
* Intentionally omits the lib's `remoteSettingName` (a no-op without remote settings),
|
|
2109
|
-
* `onPartialResult`, and `notificationConfig` — these aren't part of the SDK surface.
|
|
2110
|
-
*/
|
|
2111
|
-
type ApiRunOptions = Omit<ExecutionOptions, 'remoteSettingName' | 'onPartialResult' | 'notificationConfig'>;
|
|
2112
|
-
/** Registry of known API names → their params/result types (from @picsart/workflows-types). */
|
|
2113
|
-
type ApiSchemas = WorkflowTypes;
|
|
2114
|
-
/**
|
|
2115
|
-
* The `ai.apis` surface — direct, low-level access to the Picsart model APIs.
|
|
2116
|
-
* Known API names (keys of {@link ApiSchemas}) get typed params + result;
|
|
2117
|
-
* unknown names take an open payload and return an unknown result.
|
|
2118
|
-
*
|
|
2119
|
-
* Failures arrive as {@link ApiError}, the same as the generation surface.
|
|
2120
|
-
*/
|
|
2121
|
-
interface ApisClient {
|
|
2122
|
-
/** Run an API by name (mirrors WorkflowsClient.run()). */
|
|
2123
|
-
run<W extends string = string>(api: W, payload: W extends keyof ApiSchemas ? ApiSchemas[W]['params'] : Record<string, unknown>, options?: ApiRunOptions): Promise<ApiResponse<W extends keyof ApiSchemas ? ApiSchemas[W]['result'] : unknown>>;
|
|
1972
|
+
interface CatalogResult {
|
|
1973
|
+
items: CatalogItem[];
|
|
1974
|
+
/** Crawl date or curation stamp identifying the snapshot. */
|
|
1975
|
+
version: string;
|
|
1976
|
+
/** How long the caller may cache this response. */
|
|
1977
|
+
ttlSeconds: number;
|
|
1978
|
+
/** `null` when the list is complete. */
|
|
1979
|
+
nextCursor: string | null;
|
|
2124
1980
|
}
|
|
2125
|
-
|
|
2126
|
-
interface
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
max?: number;
|
|
2132
|
-
step?: number;
|
|
2133
|
-
required?: boolean;
|
|
2134
|
-
label?: string;
|
|
2135
|
-
accept?: string;
|
|
1981
|
+
/** Binds a param's options to a platform catalog task. */
|
|
1982
|
+
interface CatalogSource {
|
|
1983
|
+
/** Catalog workflow name, e.g. `heygen/v1/catalog/voices`. */
|
|
1984
|
+
workflow: string;
|
|
1985
|
+
/** Worker-side filter passed on fetch. */
|
|
1986
|
+
modelId?: string;
|
|
2136
1987
|
}
|
|
2137
|
-
|
|
1988
|
+
declare function toVoiceOption(item: CatalogItem, provider: Provider): VoiceOption;
|
|
1989
|
+
declare function toAvatarOption(item: CatalogItem, provider: Provider): AvatarOption;
|
|
2138
1990
|
|
|
2139
1991
|
/**
|
|
2140
1992
|
* Param Descriptor types — the new, open-ended parameter definition system.
|
|
@@ -2653,6 +2505,12 @@ interface ModelDefinition {
|
|
|
2653
2505
|
/** I2V/edit payload builder when different from buildPayload. */
|
|
2654
2506
|
buildEditPayload?: PayloadBuilder;
|
|
2655
2507
|
outputSchema?: RuntimeSchema<unknown>;
|
|
2508
|
+
/**
|
|
2509
|
+
* File extension the model produces when it has no output-format param
|
|
2510
|
+
* (e.g. 'jpg'). Used to name a Drive save made before the job runs; without
|
|
2511
|
+
* it the mode default applies (png / mp4 / mp3).
|
|
2512
|
+
*/
|
|
2513
|
+
outputExtension?: string;
|
|
2656
2514
|
estimatedTime?: number | Record<string, number>;
|
|
2657
2515
|
editEstimatedTime?: number | Record<string, number>;
|
|
2658
2516
|
testTimeout?: number;
|
|
@@ -2669,57 +2527,227 @@ interface ModelDefinition {
|
|
|
2669
2527
|
}
|
|
2670
2528
|
|
|
2671
2529
|
/**
|
|
2672
|
-
*
|
|
2673
|
-
*
|
|
2674
|
-
|
|
2675
|
-
|
|
2530
|
+
* Per-item vendor metadata promoted from the response. Every key is
|
|
2531
|
+
* best-effort: present when the vendor reports it, absent otherwise.
|
|
2532
|
+
*/
|
|
2533
|
+
interface GenerateResultItemMetadata {
|
|
2534
|
+
/** Explore image id (recraft explore models) — pass back as `sourceImageId`
|
|
2535
|
+
* to iterate on this image. */
|
|
2536
|
+
exploreImageId?: string;
|
|
2537
|
+
/** Voice preview id (ElevenLabs voice design/remix) — pass to the vendor's
|
|
2538
|
+
* create-voice-from-preview step to persist the voice. */
|
|
2539
|
+
generatedVoiceId?: string;
|
|
2540
|
+
/** URL of the generated video's last frame, when the model was asked for it
|
|
2541
|
+
* (`returnLastFrame`, seedance) — the seed for frame-chaining flows. */
|
|
2542
|
+
lastFrameUrl?: string;
|
|
2543
|
+
/** The draft a Seedance 2.5 Draft generation produced — pass it back
|
|
2544
|
+
* unchanged as `draftTask` to the matching `-draft-final` model to render
|
|
2545
|
+
* the final 1080p video (valid 7 days). Wire field names on purpose: the
|
|
2546
|
+
* worker signs it, so any change is rejected. */
|
|
2547
|
+
draftTask?: SeedanceDraftTask;
|
|
2548
|
+
}
|
|
2549
|
+
/** A Seedance 2.5 draft reference, as the worker issues it. */
|
|
2550
|
+
interface SeedanceDraftTask {
|
|
2551
|
+
id: string;
|
|
2552
|
+
video_input: boolean;
|
|
2553
|
+
signature: string;
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
/**
|
|
2557
|
+
* Drive client — manages folders and file saving in Picsart Drive.
|
|
2676
2558
|
*
|
|
2677
|
-
*
|
|
2678
|
-
*
|
|
2559
|
+
* Uses the same authenticated fetch as the generation client.
|
|
2560
|
+
* Root folder is auto-created on first use and cached.
|
|
2679
2561
|
*/
|
|
2680
2562
|
|
|
2681
|
-
|
|
2682
|
-
|
|
2563
|
+
type MediaTypeFilter = 'image' | 'video' | 'audio';
|
|
2564
|
+
type UserReaction = 'like' | 'dislike';
|
|
2565
|
+
/** A folder reference in Picsart Drive. */
|
|
2566
|
+
interface DriveFolder {
|
|
2567
|
+
name: string;
|
|
2568
|
+
uid: string;
|
|
2569
|
+
}
|
|
2570
|
+
/** Drive save result, attached to GenerateResult when drive is enabled. */
|
|
2571
|
+
interface DriveSaveResult {
|
|
2572
|
+
uid: string;
|
|
2573
|
+
folder: DriveFolder;
|
|
2574
|
+
}
|
|
2575
|
+
/**
|
|
2576
|
+
* The generation input parameters, serialized into the `aiSDKPayload` attribute.
|
|
2577
|
+
* Captures every value from the generation context — the named fields below are
|
|
2578
|
+
* common ones for convenience; the index signature carries any other input param.
|
|
2579
|
+
*/
|
|
2580
|
+
interface SdkPayload {
|
|
2581
|
+
prompt: string;
|
|
2582
|
+
aspectRatio?: string;
|
|
2583
|
+
duration?: number;
|
|
2584
|
+
resolution?: string;
|
|
2585
|
+
generateAudio?: boolean;
|
|
2586
|
+
imageUrls?: string[];
|
|
2587
|
+
videoUrls?: string[];
|
|
2588
|
+
audioUrls?: string[];
|
|
2589
|
+
startFrame?: string;
|
|
2590
|
+
endFrame?: string;
|
|
2683
2591
|
videoUrl?: string;
|
|
2684
2592
|
audioUrl?: string;
|
|
2593
|
+
[key: string]: unknown;
|
|
2685
2594
|
}
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2595
|
+
type DriveFile = {
|
|
2596
|
+
uid: string;
|
|
2597
|
+
} & Record<string, unknown>;
|
|
2598
|
+
interface DriveAttributes {
|
|
2599
|
+
model: string;
|
|
2600
|
+
/** JSON-encoded SdkPayload (all generation input params). */
|
|
2601
|
+
aiSDKPayload: string;
|
|
2602
|
+
appId?: string;
|
|
2603
|
+
appType?: AppType;
|
|
2604
|
+
}
|
|
2605
|
+
/** A saved Seedance 2.5 draft — pass `draftTask` unchanged as the final's
|
|
2606
|
+
* `draftTask` param until `draftExpiresAt`. */
|
|
2607
|
+
interface DriveDraftInfo {
|
|
2608
|
+
draftTask?: SeedanceDraftTask;
|
|
2609
|
+
/** ISO timestamp after which the vendor no longer renders a final from it. */
|
|
2610
|
+
draftExpiresAt?: string;
|
|
2611
|
+
}
|
|
2612
|
+
interface GenerationFile extends DriveDraftInfo {
|
|
2613
|
+
appId?: string;
|
|
2614
|
+
appType?: AppType;
|
|
2615
|
+
model?: string;
|
|
2616
|
+
aiSDKPayload?: SdkPayload;
|
|
2617
|
+
userReaction?: UserReaction;
|
|
2618
|
+
}
|
|
2619
|
+
interface DriveMediaItem {
|
|
2620
|
+
uid: string;
|
|
2621
|
+
url: string;
|
|
2689
2622
|
name: string;
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
preview?: CatalogPreview;
|
|
2694
|
-
/** Vendor extras, e.g. `defaultVoiceId` on HeyGen avatars. */
|
|
2695
|
-
meta?: Record<string, unknown>;
|
|
2623
|
+
type: MediaTypeFilter;
|
|
2624
|
+
previewUrl?: string;
|
|
2625
|
+
timestamp: number;
|
|
2696
2626
|
}
|
|
2697
|
-
interface
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2627
|
+
interface DriveFileDetails extends DriveMediaItem, DriveDraftInfo {
|
|
2628
|
+
createdAt?: string;
|
|
2629
|
+
model?: string;
|
|
2630
|
+
prompt?: string;
|
|
2631
|
+
service?: string;
|
|
2632
|
+
subType?: string;
|
|
2633
|
+
duration?: string;
|
|
2634
|
+
aspectRatio?: string;
|
|
2635
|
+
resolution?: string;
|
|
2636
|
+
quality?: string;
|
|
2637
|
+
userReaction?: UserReaction;
|
|
2638
|
+
referenceImageUrls?: string[];
|
|
2639
|
+
referenceVideoUrl?: string;
|
|
2640
|
+
referenceAudioUrl?: string;
|
|
2704
2641
|
}
|
|
2705
|
-
interface
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
version: string;
|
|
2709
|
-
/** How long the caller may cache this response. */
|
|
2710
|
-
ttlSeconds: number;
|
|
2711
|
-
/** `null` when the list is complete. */
|
|
2712
|
-
nextCursor: string | null;
|
|
2642
|
+
interface ListOptions {
|
|
2643
|
+
folder?: DriveFolder;
|
|
2644
|
+
type?: MediaTypeFilter;
|
|
2713
2645
|
}
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2646
|
+
interface SaveParams {
|
|
2647
|
+
url: string;
|
|
2648
|
+
name: string;
|
|
2649
|
+
resourceType: 'PHOTO' | 'VIDEO' | 'AUDIO';
|
|
2650
|
+
attributes?: Record<string, string>;
|
|
2651
|
+
previewUrl?: string;
|
|
2652
|
+
}
|
|
2653
|
+
/** Target folder for backend Drive save. */
|
|
2654
|
+
interface PayloadDriveFolderOptions {
|
|
2655
|
+
/** Folder path — backend resolves it (e.g. 'AI Playground' or 'AI Playground/My Board'). */
|
|
2656
|
+
path?: string;
|
|
2657
|
+
/** Folder UID — overrides path when provided. */
|
|
2658
|
+
id?: string;
|
|
2659
|
+
}
|
|
2660
|
+
/** Drive save options injected into the workflow payload as `options.drive`. */
|
|
2661
|
+
interface PayloadDriveOptions {
|
|
2662
|
+
/** Filename for the saved asset. */
|
|
2663
|
+
name: string;
|
|
2664
|
+
/** Generation attributes attached to the file (SDK-assembled, fixed shape). */
|
|
2665
|
+
attributes?: DriveAttributes;
|
|
2666
|
+
/** Target folder in Picsart Drive. */
|
|
2667
|
+
folder?: PayloadDriveFolderOptions;
|
|
2668
|
+
}
|
|
2669
|
+
/**
|
|
2670
|
+
* Drive operations surface — returned by {@link createDriveClient} and exposed
|
|
2671
|
+
* as `ai.drive` when Drive is configured. Manages folders, listing, saving, and
|
|
2672
|
+
* reactions in Picsart Drive.
|
|
2673
|
+
*/
|
|
2674
|
+
interface DriveClient {
|
|
2675
|
+
/** Ensure a folder exists (creating it if needed) and return it. */
|
|
2676
|
+
ensureFolder(subfolder?: string): Promise<DriveFolder | null>;
|
|
2677
|
+
/** List the immediate subfolders of the root folder. */
|
|
2678
|
+
folders(): Promise<DriveFolder[]>;
|
|
2679
|
+
/** List all folders recursively. */
|
|
2680
|
+
allFolders(): Promise<DriveFolder[]>;
|
|
2681
|
+
/** Find a folder by name. */
|
|
2682
|
+
findFolder(name: string): Promise<DriveFolder | null>;
|
|
2683
|
+
/** List media items in a folder. */
|
|
2684
|
+
list(options?: ListOptions): Promise<DriveMediaItem[]>;
|
|
2685
|
+
/** List media items in a folder with full generation metadata. */
|
|
2686
|
+
listDetailed(options?: ListOptions): Promise<DriveFileDetails[]>;
|
|
2687
|
+
/** Read a single generation's stored attributes. */
|
|
2688
|
+
getGeneration(fileUid: string): Promise<GenerationFile | null>;
|
|
2689
|
+
/** Save an asset to Drive. */
|
|
2690
|
+
save(params: SaveParams, folder?: DriveFolder): Promise<DriveSaveResult | null>;
|
|
2691
|
+
/** Build the save params for a generation result. */
|
|
2692
|
+
buildSaveParams(url: string, modelId: string, modelName: string, mode: string, prompt?: string): SaveParams;
|
|
2693
|
+
/** Set a like/dislike reaction on a file. */
|
|
2694
|
+
addReaction(fileUid: string, reaction: UserReaction): Promise<boolean>;
|
|
2695
|
+
/** Clear the reaction on a file. */
|
|
2696
|
+
removeReaction(fileUid: string): Promise<boolean>;
|
|
2697
|
+
}
|
|
2698
|
+
declare function inferResourceType(mode: string): 'PHOTO' | 'VIDEO' | 'AUDIO';
|
|
2699
|
+
/** What is known about the file being named. Every field is optional; the
|
|
2700
|
+
* most reliable one present wins (see `resolveExtension`). */
|
|
2701
|
+
interface FilenameHints {
|
|
2702
|
+
/** MIME type of the produced file (e.g. `image/jpeg`). */
|
|
2703
|
+
mimeType?: string;
|
|
2704
|
+
/** URL of the produced file; its path extension is used when present. */
|
|
2705
|
+
url?: string;
|
|
2706
|
+
/** Output format requested of (or declared by) the model, e.g. `jpeg`, `mov`, `ogg_opus`. */
|
|
2707
|
+
format?: string;
|
|
2708
|
+
}
|
|
2709
|
+
/**
|
|
2710
|
+
* Pick a file extension for a generation. Most to least reliable: the result's
|
|
2711
|
+
* MIME type, the result URL's path extension, the requested output format, then
|
|
2712
|
+
* the mode default (png / mp4 / mp3).
|
|
2713
|
+
*/
|
|
2714
|
+
declare function resolveExtension(mode: string, hints?: FilenameHints): string;
|
|
2715
|
+
/**
|
|
2716
|
+
* The output format a generation will produce, known before the job runs:
|
|
2717
|
+
* an explicit format param, else that param's catalog default, else the
|
|
2718
|
+
* model's declared `outputExtension`. Undefined when nothing is known.
|
|
2719
|
+
*/
|
|
2720
|
+
declare function expectedOutputFormat(model: Pick<ModelDefinition, 'paramConfig' | 'outputExtension'>, params: Record<string, unknown>): string | undefined;
|
|
2721
|
+
declare function buildFilename(prompt: string | undefined, mode: string, hints?: FilenameHints): string;
|
|
2722
|
+
declare function buildGenerationAttributes(input: {
|
|
2723
|
+
modelId: string;
|
|
2724
|
+
params: Record<string, unknown>;
|
|
2725
|
+
/** TODO(backend-autosave): temporary — remove once the backend stamps appId/appType. */
|
|
2726
|
+
app?: AppIdentity;
|
|
2727
|
+
}): DriveAttributes;
|
|
2728
|
+
declare function parseGeneration(file: DriveFile | Record<string, unknown>): GenerationFile;
|
|
2729
|
+
|
|
2730
|
+
/** Result of `ai.apis.run()` — the API result plus optional credit usage. */
|
|
2731
|
+
type ApiResponse<R = unknown> = WorkflowResponse<R>;
|
|
2732
|
+
/**
|
|
2733
|
+
* Options for `ai.apis.run()` — execution mode, polling, abort signal, progress callbacks.
|
|
2734
|
+
* Intentionally omits the lib's `remoteSettingName` (a no-op without remote settings),
|
|
2735
|
+
* `onPartialResult`, and `notificationConfig` — these aren't part of the SDK surface.
|
|
2736
|
+
*/
|
|
2737
|
+
type ApiRunOptions = Omit<ExecutionOptions, 'remoteSettingName' | 'onPartialResult' | 'notificationConfig'>;
|
|
2738
|
+
/** Registry of known API names → their params/result types (from @picsart/workflows-types). */
|
|
2739
|
+
type ApiSchemas = WorkflowTypes;
|
|
2740
|
+
/**
|
|
2741
|
+
* The `ai.apis` surface — direct, low-level access to the Picsart model APIs.
|
|
2742
|
+
* Known API names (keys of {@link ApiSchemas}) get typed params + result;
|
|
2743
|
+
* unknown names take an open payload and return an unknown result.
|
|
2744
|
+
*
|
|
2745
|
+
* Failures arrive as {@link ApiError}, the same as the generation surface.
|
|
2746
|
+
*/
|
|
2747
|
+
interface ApisClient {
|
|
2748
|
+
/** Run an API by name (mirrors WorkflowsClient.run()). */
|
|
2749
|
+
run<W extends string = string>(api: W, payload: W extends keyof ApiSchemas ? ApiSchemas[W]['params'] : Record<string, unknown>, options?: ApiRunOptions): Promise<ApiResponse<W extends keyof ApiSchemas ? ApiSchemas[W]['result'] : unknown>>;
|
|
2720
2750
|
}
|
|
2721
|
-
declare function toVoiceOption(item: CatalogItem, provider: Provider): VoiceOption;
|
|
2722
|
-
declare function toAvatarOption(item: CatalogItem, provider: Provider): AvatarOption;
|
|
2723
2751
|
|
|
2724
2752
|
/**
|
|
2725
2753
|
* ai.catalogs — runtime access to the platform catalog tasks
|
|
@@ -3489,4 +3517,4 @@ declare const getModel: (id: string) => ModelDefinition | undefined;
|
|
|
3489
3517
|
*/
|
|
3490
3518
|
declare const findModel: (ref: string) => ModelDefinition | undefined;
|
|
3491
3519
|
|
|
3492
|
-
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, findModel, getModel, getModelsByMode, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, toAvatarOption, toVoiceOption };
|
|
3520
|
+
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 };
|
package/index.js
CHANGED
|
@@ -1119,6 +1119,7 @@ function defineModels(provider, configs) {
|
|
|
1119
1119
|
if (c.editEstimatedTime !== void 0) model.editEstimatedTime = c.editEstimatedTime;
|
|
1120
1120
|
if (c.testTimeout !== void 0) model.testTimeout = c.testTimeout;
|
|
1121
1121
|
if (c.pollOptions !== void 0) model.pollOptions = c.pollOptions;
|
|
1122
|
+
if (c.outputExtension !== void 0) model.outputExtension = c.outputExtension;
|
|
1122
1123
|
if (c.badge !== void 0) model.badge = c.badge;
|
|
1123
1124
|
if (c.addedAt !== void 0) model.addedAt = c.addedAt;
|
|
1124
1125
|
if (c.deprecated !== void 0) model.deprecated = c.deprecated;
|
|
@@ -8851,6 +8852,8 @@ var { MODELS: MODELS30 } = defineModels("picsart", [
|
|
|
8851
8852
|
workflow: "pcp/v1/sana-sprint",
|
|
8852
8853
|
syncExecute: true,
|
|
8853
8854
|
buildPayload: buildPcpSanaSprintPayload,
|
|
8855
|
+
// The worker returns JPEG and exposes no format param.
|
|
8856
|
+
outputExtension: "jpg",
|
|
8854
8857
|
estimatedTime: 3,
|
|
8855
8858
|
mode: "image",
|
|
8856
8859
|
inputType: "t2i",
|
|
@@ -11732,9 +11735,90 @@ function inferResourceType(mode) {
|
|
|
11732
11735
|
if (mode === "audio") return "AUDIO";
|
|
11733
11736
|
return "PHOTO";
|
|
11734
11737
|
}
|
|
11735
|
-
|
|
11738
|
+
var MIME_EXTENSIONS = {
|
|
11739
|
+
"image/jpeg": "jpg",
|
|
11740
|
+
"image/jpg": "jpg",
|
|
11741
|
+
"image/pjpeg": "jpg",
|
|
11742
|
+
"image/png": "png",
|
|
11743
|
+
"image/webp": "webp",
|
|
11744
|
+
"image/gif": "gif",
|
|
11745
|
+
"image/avif": "avif",
|
|
11746
|
+
"image/heic": "heic",
|
|
11747
|
+
"image/heif": "heif",
|
|
11748
|
+
"image/bmp": "bmp",
|
|
11749
|
+
"image/tiff": "tiff",
|
|
11750
|
+
"image/svg+xml": "svg",
|
|
11751
|
+
"video/mp4": "mp4",
|
|
11752
|
+
"video/quicktime": "mov",
|
|
11753
|
+
"video/webm": "webm",
|
|
11754
|
+
"video/x-matroska": "mkv",
|
|
11755
|
+
"video/x-msvideo": "avi",
|
|
11756
|
+
"video/x-m4v": "m4v",
|
|
11757
|
+
"audio/mpeg": "mp3",
|
|
11758
|
+
"audio/mp3": "mp3",
|
|
11759
|
+
"audio/wav": "wav",
|
|
11760
|
+
"audio/x-wav": "wav",
|
|
11761
|
+
"audio/wave": "wav",
|
|
11762
|
+
"audio/vnd.wave": "wav",
|
|
11763
|
+
"audio/ogg": "ogg",
|
|
11764
|
+
"audio/opus": "ogg",
|
|
11765
|
+
"audio/aac": "aac",
|
|
11766
|
+
"audio/flac": "flac",
|
|
11767
|
+
"audio/x-flac": "flac",
|
|
11768
|
+
"audio/mp4": "m4a",
|
|
11769
|
+
"audio/x-m4a": "m4a",
|
|
11770
|
+
"audio/webm": "webm"
|
|
11771
|
+
};
|
|
11772
|
+
var EXTENSION_ALIASES = {
|
|
11773
|
+
jpeg: "jpg",
|
|
11774
|
+
jpe: "jpg",
|
|
11775
|
+
tif: "tiff",
|
|
11776
|
+
mpeg4: "mp4",
|
|
11777
|
+
quicktime: "mov"
|
|
11778
|
+
};
|
|
11779
|
+
function normalizeExtension(raw) {
|
|
11780
|
+
if (!raw) return void 0;
|
|
11781
|
+
const ext = raw.trim().toLowerCase().replace(/^\./, "").split("_")[0];
|
|
11782
|
+
if (!/^[a-z0-9]{2,5}$/.test(ext)) return void 0;
|
|
11783
|
+
return EXTENSION_ALIASES[ext] ?? ext;
|
|
11784
|
+
}
|
|
11785
|
+
function extensionFromMime(mimeType) {
|
|
11786
|
+
if (!mimeType) return void 0;
|
|
11787
|
+
const base2 = mimeType.split(";")[0].trim().toLowerCase();
|
|
11788
|
+
return MIME_EXTENSIONS[base2];
|
|
11789
|
+
}
|
|
11790
|
+
function extensionFromUrl(url) {
|
|
11791
|
+
if (!url) return void 0;
|
|
11792
|
+
let path;
|
|
11793
|
+
try {
|
|
11794
|
+
path = new URL(url).pathname;
|
|
11795
|
+
} catch {
|
|
11796
|
+
path = url.split(/[?#]/)[0];
|
|
11797
|
+
}
|
|
11798
|
+
const match = /\.([A-Za-z0-9]{2,5})$/.exec(path.split("/").pop() ?? "");
|
|
11799
|
+
return normalizeExtension(match?.[1]);
|
|
11800
|
+
}
|
|
11801
|
+
function defaultExtension(mode) {
|
|
11802
|
+
return mode === "video" ? "mp4" : mode === "audio" ? "mp3" : "png";
|
|
11803
|
+
}
|
|
11804
|
+
function resolveExtension(mode, hints = {}) {
|
|
11805
|
+
return extensionFromMime(hints.mimeType) ?? extensionFromUrl(hints.url) ?? normalizeExtension(hints.format) ?? defaultExtension(mode);
|
|
11806
|
+
}
|
|
11807
|
+
var FORMAT_PARAM_KEYS = ["outputFormat", "output_format", "format"];
|
|
11808
|
+
function expectedOutputFormat(model, params2) {
|
|
11809
|
+
for (const key of FORMAT_PARAM_KEYS) {
|
|
11810
|
+
const value = params2[key];
|
|
11811
|
+
if (typeof value === "string" && value) return value;
|
|
11812
|
+
}
|
|
11813
|
+
for (const key of FORMAT_PARAM_KEYS) {
|
|
11814
|
+
const fallback = model.paramConfig?.[key]?.descriptor?.default;
|
|
11815
|
+
if (typeof fallback === "string" && fallback) return fallback;
|
|
11816
|
+
}
|
|
11817
|
+
return model.outputExtension;
|
|
11818
|
+
}
|
|
11819
|
+
function buildFilename(prompt, mode, hints) {
|
|
11736
11820
|
const shortId = String(Date.now()).slice(-6);
|
|
11737
|
-
const ext = mode
|
|
11821
|
+
const ext = resolveExtension(mode, hints);
|
|
11738
11822
|
if (!prompt) return `ai-generation-${shortId}.${ext}`;
|
|
11739
11823
|
const slug = prompt.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 50);
|
|
11740
11824
|
return `${slug}-${shortId}.${ext}`;
|
|
@@ -12181,7 +12265,7 @@ function createDriveClient(f, apiUrl, rootFolderName) {
|
|
|
12181
12265
|
buildSaveParams(url, modelId, modelName, mode, prompt) {
|
|
12182
12266
|
return {
|
|
12183
12267
|
url,
|
|
12184
|
-
name: buildFilename(prompt, mode),
|
|
12268
|
+
name: buildFilename(prompt, mode, { url }),
|
|
12185
12269
|
resourceType: inferResourceType(mode),
|
|
12186
12270
|
attributes: {
|
|
12187
12271
|
tool: "ai-sdk",
|
|
@@ -12492,7 +12576,8 @@ function createClient(config) {
|
|
|
12492
12576
|
});
|
|
12493
12577
|
const folderPath = options?.folder?.name ?? driveConfig?.folder;
|
|
12494
12578
|
return {
|
|
12495
|
-
|
|
12579
|
+
// Named before the job runs, so the requested/declared format is the best hint.
|
|
12580
|
+
name: explicit?.name ?? buildFilename(params2.prompt, model.mode, { format: expectedOutputFormat(model, params2) }),
|
|
12496
12581
|
// SDK-assembled attributes are the baseline; explicit attributes win per-key.
|
|
12497
12582
|
attributes: { ...attributes, ...explicit?.attributes ?? {} },
|
|
12498
12583
|
folder: explicit?.folder ?? (folderPath ? { path: folderPath } : void 0)
|
|
@@ -13817,4 +13902,4 @@ function decodeDeepLinkPayload(encoded) {
|
|
|
13817
13902
|
return deserializePayload(encoded);
|
|
13818
13903
|
}
|
|
13819
13904
|
|
|
13820
|
-
export { ALL_MODELS, ApiError, ExecutionMode as ApiRunMode, DEFAULT_VISIBLE_RELEASES, GenerationEventType, Model, Models, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, findModel, getModel, getModelsByMode, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, toAvatarOption, toVoiceOption };
|
|
13905
|
+
export { ALL_MODELS, ApiError, ExecutionMode as ApiRunMode, DEFAULT_VISIBLE_RELEASES, GenerationEventType, Model, Models, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, expectedOutputFormat, findModel, getModel, getModelsByMode, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, resolveExtension, toAvatarOption, toVoiceOption };
|