@picsart/ai-sdk 5.16.1 → 5.17.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/index.d.ts +39 -9
- package/index.js +15 -10
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -17,12 +17,41 @@ interface WorkflowProgress {
|
|
|
17
17
|
percent?: number;
|
|
18
18
|
estimatedSecondsLeft?: number;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Per-tool credit usage entry inside {@link CreditUsage.details}
|
|
22
|
+
* (mirrors `ToolUsage` from `pa-pluggable-api-adapter`).
|
|
23
|
+
*/
|
|
24
|
+
interface ToolUsage {
|
|
25
|
+
operationId?: string;
|
|
26
|
+
toolId: string;
|
|
27
|
+
price: number;
|
|
28
|
+
amount: number;
|
|
29
|
+
credits: number;
|
|
30
|
+
failed?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Credit usage reported on a completed task, as returned by the pluggable
|
|
34
|
+
* APIs platform on every task response (mirrors the adapter's public
|
|
35
|
+
* `CreditUsage` from `pa-pluggable-api-adapter`).
|
|
36
|
+
*/
|
|
37
|
+
interface CreditUsage {
|
|
38
|
+
/** The tool identifier. Set to "total_credits" when subtask usage is present. */
|
|
39
|
+
toolId?: string;
|
|
40
|
+
/** Per-tool credit usage breakdown. */
|
|
41
|
+
details?: ToolUsage[];
|
|
42
|
+
/** The amount of credits charged. */
|
|
43
|
+
credits: number;
|
|
44
|
+
/** The remaining balance. */
|
|
45
|
+
balance?: number;
|
|
46
|
+
}
|
|
20
47
|
interface WorkflowStatusResult<TResult = unknown> {
|
|
21
48
|
handle: WorkflowJobHandle;
|
|
22
49
|
status: WorkflowStatus;
|
|
23
50
|
result?: TResult;
|
|
24
51
|
error?: string;
|
|
25
52
|
progress?: WorkflowProgress;
|
|
53
|
+
/** Credit usage reported by the platform, when present on the response. */
|
|
54
|
+
usage?: CreditUsage;
|
|
26
55
|
raw: unknown;
|
|
27
56
|
}
|
|
28
57
|
/**
|
|
@@ -1043,25 +1072,25 @@ type ModelInputById = {
|
|
|
1043
1072
|
};
|
|
1044
1073
|
"recraftv4_styles": {
|
|
1045
1074
|
prompt: string;
|
|
1046
|
-
|
|
1075
|
+
imageUrls: [string, ...string[]];
|
|
1047
1076
|
aspectRatio?: "1:1" | "4:3" | "3:4" | "3:2" | "2:3" | "16:9" | "9:16" | "2:1" | "1:2";
|
|
1048
1077
|
count?: 1 | 2 | 4 | 6;
|
|
1049
1078
|
};
|
|
1050
1079
|
"recraftv4_styles_pro": {
|
|
1051
1080
|
prompt: string;
|
|
1052
|
-
|
|
1081
|
+
imageUrls: [string, ...string[]];
|
|
1053
1082
|
aspectRatio?: "1:1" | "4:3" | "3:4" | "3:2" | "2:3" | "16:9" | "9:16" | "2:1" | "1:2";
|
|
1054
1083
|
count?: 1 | 2 | 4 | 6;
|
|
1055
1084
|
};
|
|
1056
1085
|
"recraftv4_styles_pro_vector": {
|
|
1057
1086
|
prompt: string;
|
|
1058
|
-
|
|
1087
|
+
imageUrls: [string, ...string[]];
|
|
1059
1088
|
aspectRatio?: "1:1" | "4:3" | "3:4" | "3:2" | "2:3" | "16:9" | "9:16" | "2:1" | "1:2";
|
|
1060
1089
|
count?: 1 | 2 | 4 | 6;
|
|
1061
1090
|
};
|
|
1062
1091
|
"recraftv4_styles_vector": {
|
|
1063
1092
|
prompt: string;
|
|
1064
|
-
|
|
1093
|
+
imageUrls: [string, ...string[]];
|
|
1065
1094
|
aspectRatio?: "1:1" | "4:3" | "3:4" | "3:2" | "2:3" | "16:9" | "9:16" | "2:1" | "1:2";
|
|
1066
1095
|
count?: 1 | 2 | 4 | 6;
|
|
1067
1096
|
};
|
|
@@ -1993,9 +2022,6 @@ interface GenerationContext {
|
|
|
1993
2022
|
language?: string;
|
|
1994
2023
|
accent?: string;
|
|
1995
2024
|
style?: string;
|
|
1996
|
-
/** Recraft V4 Styles — style-reference image URLs (max 5, t2i only).
|
|
1997
|
-
* Required: the V4 Styles API rejects requests without a style. */
|
|
1998
|
-
styleReferenceUrls?: string[];
|
|
1999
2025
|
/**
|
|
2000
2026
|
* Effect template id — a catalog-served content preset id (e.g. a Kling effect
|
|
2001
2027
|
* scene from `kling/v1/catalog/templates`). Free string; the live catalog is
|
|
@@ -2307,6 +2333,8 @@ interface GenerateResult {
|
|
|
2307
2333
|
handle: WorkflowJobHandle;
|
|
2308
2334
|
/** Raw parsed output for advanced consumers. */
|
|
2309
2335
|
raw: unknown;
|
|
2336
|
+
/** Credit usage reported by the platform — same structure as the pluggable APIs' GenAITaskResponse. */
|
|
2337
|
+
usage?: CreditUsage;
|
|
2310
2338
|
/** Present when Drive is enabled and the file was saved. */
|
|
2311
2339
|
drive?: DriveSaveResult;
|
|
2312
2340
|
}
|
|
@@ -2318,8 +2346,10 @@ interface GenerateTextResult {
|
|
|
2318
2346
|
model: string;
|
|
2319
2347
|
/** Job handle for status tracking. */
|
|
2320
2348
|
handle: WorkflowJobHandle;
|
|
2321
|
-
/** Raw parsed output — carries usage, finish reason, thinking trace, etc. */
|
|
2349
|
+
/** Raw parsed output — carries vendor token usage, finish reason, thinking trace, etc. */
|
|
2322
2350
|
raw: unknown;
|
|
2351
|
+
/** Credit usage reported by the platform — same structure as the pluggable APIs' GenAITaskResponse. */
|
|
2352
|
+
usage?: CreditUsage;
|
|
2323
2353
|
}
|
|
2324
2354
|
/** Options for individual generate() / submit() calls. */
|
|
2325
2355
|
interface GenerateOptions {
|
|
@@ -2762,4 +2792,4 @@ declare const findModel: (ref: string) => ModelDefinition | undefined;
|
|
|
2762
2792
|
*/
|
|
2763
2793
|
declare const KLING_DUAL_IMAGE_EFFECTS: ReadonlySet<string>;
|
|
2764
2794
|
|
|
2765
|
-
export { ALL_MODELS, type AiClient, 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 CatalogKind, type CatalogPage, type CatalogPageOptions, type CatalogPreview, type CatalogQuery, type CatalogResult, type CatalogSource, type CatalogsClient, type CatalogsOptions, type ClientConfig, type CreditRange, type CreditRangeContext, type CreditTier, DEFAULT_VISIBLE_RELEASES, type DeepLinkResult, type DriveAttributes, type DriveClient, type DriveConfig, 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 GenerateTextResult, type GenerationContext, type GenerationFile, type GenerationMode, KLING_DUAL_IMAGE_EFFECTS, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelDefinition, type ModelDescriptor, type ModelFilter$1 as 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 PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, type SaveParams, type SdkPayload, type SdkTransport, type TextDescriptor, type TextEntry, type TextModelId, type TextModelInputById, type TypedModelId, type UserReaction, type ValidationResult$1 as ValidationResult, type VoiceOption, type WorkflowJobHandle, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, findModel, getModel, getModelsByMode, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, toAvatarOption, toVoiceOption };
|
|
2795
|
+
export { ALL_MODELS, type AiClient, 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 CatalogKind, 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 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 GenerateTextResult, type GenerationContext, type GenerationFile, type GenerationMode, KLING_DUAL_IMAGE_EFFECTS, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelDefinition, type ModelDescriptor, type ModelFilter$1 as 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 PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, type SaveParams, type SdkPayload, type SdkTransport, type TextDescriptor, type TextEntry, type TextModelId, type TextModelInputById, type ToolUsage, type TypedModelId, type UserReaction, type ValidationResult$1 as ValidationResult, type VoiceOption, type WorkflowJobHandle, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, findModel, getModel, getModelsByMode, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, toAvatarOption, toVoiceOption };
|
package/index.js
CHANGED
|
@@ -474,6 +474,8 @@ function parseWorkflowStatus(handle, raw) {
|
|
|
474
474
|
const statusRaw = pickFirst(raw, [["response", "status"], ["status"]]);
|
|
475
475
|
const status = normalizeStatus(statusRaw);
|
|
476
476
|
const result = pickFirst(raw, [["response", "result"], ["result"]]);
|
|
477
|
+
const usageRaw = pickFirst(raw, [["response", "usage"], ["usage"]]);
|
|
478
|
+
const usage = usageRaw && typeof usageRaw === "object" && (typeof usageRaw.credits === "number" || Array.isArray(usageRaw.details)) ? usageRaw : void 0;
|
|
477
479
|
const errorRaw = pickFirst(raw, [["response", "error"], ["error"], ["message"], ["reason"]]);
|
|
478
480
|
const progressRaw = pickFirst(raw, [["response", "progress"], ["progress"]]);
|
|
479
481
|
const progress = progressRaw && typeof progressRaw === "object" ? {
|
|
@@ -486,6 +488,7 @@ function parseWorkflowStatus(handle, raw) {
|
|
|
486
488
|
result,
|
|
487
489
|
error: typeof errorRaw === "string" ? errorRaw : void 0,
|
|
488
490
|
progress,
|
|
491
|
+
usage,
|
|
489
492
|
raw
|
|
490
493
|
};
|
|
491
494
|
}
|
|
@@ -6712,15 +6715,15 @@ var buildRecraftUtilityPayload = (includePrompt) => (ctx) => ({
|
|
|
6712
6715
|
...includePrompt && ctx.prompt ? { prompt: ctx.prompt } : {}
|
|
6713
6716
|
});
|
|
6714
6717
|
var buildRecraftV4StylesPayload = (apiModel) => (ctx) => {
|
|
6715
|
-
if (!ctx.
|
|
6716
|
-
throw new Error("V4 Styles models require
|
|
6718
|
+
if (!ctx.imageUrls?.length) {
|
|
6719
|
+
throw new Error("V4 Styles models require style-reference images");
|
|
6717
6720
|
}
|
|
6718
6721
|
return {
|
|
6719
6722
|
prompt: ctx.prompt,
|
|
6720
6723
|
model: apiModel,
|
|
6721
6724
|
n: ctx.count ?? 1,
|
|
6722
6725
|
...ctx.aspectRatio ? { size: ctx.aspectRatio } : {},
|
|
6723
|
-
style_reference_urls: ctx.
|
|
6726
|
+
style_reference_urls: ctx.imageUrls
|
|
6724
6727
|
};
|
|
6725
6728
|
};
|
|
6726
6729
|
var buildRecraftV4VariantPayload = (apiModel) => (ctx) => ({
|
|
@@ -6739,7 +6742,7 @@ var buildRecraftExploreSimilarPayload = (ctx) => ({
|
|
|
6739
6742
|
similarity: ctx.similarity ?? 3,
|
|
6740
6743
|
...ctx.aspectRatio ? { size: ctx.aspectRatio } : {}
|
|
6741
6744
|
});
|
|
6742
|
-
var v4StylesParams = p.file("
|
|
6745
|
+
var v4StylesParams = p.file("imageUrls", "image", {
|
|
6743
6746
|
label: "Style References",
|
|
6744
6747
|
required: true,
|
|
6745
6748
|
array: { min: 1, max: 5 },
|
|
@@ -8552,12 +8555,13 @@ var extractAllResults = (result) => {
|
|
|
8552
8555
|
}
|
|
8553
8556
|
return void 0;
|
|
8554
8557
|
};
|
|
8555
|
-
function toCompletedStatus(handle, result, raw) {
|
|
8558
|
+
function toCompletedStatus(handle, result, raw, usage) {
|
|
8556
8559
|
return {
|
|
8557
8560
|
handle,
|
|
8558
8561
|
status: "COMPLETED",
|
|
8559
8562
|
result,
|
|
8560
|
-
raw
|
|
8563
|
+
raw,
|
|
8564
|
+
usage
|
|
8561
8565
|
};
|
|
8562
8566
|
}
|
|
8563
8567
|
|
|
@@ -8710,13 +8714,13 @@ function parseResult(completed, model, contract) {
|
|
|
8710
8714
|
url: item.url,
|
|
8711
8715
|
metadata: item.exploreImageId ? { exploreImageId: item.exploreImageId } : void 0
|
|
8712
8716
|
}));
|
|
8713
|
-
return { url: results[0].url, results, model: model.id, handle: completed.handle, raw: parsed };
|
|
8717
|
+
return { url: results[0].url, results, model: model.id, handle: completed.handle, raw: parsed, usage: completed.usage };
|
|
8714
8718
|
}
|
|
8715
8719
|
const url = extractUrl(parsed);
|
|
8716
8720
|
if (!url) {
|
|
8717
8721
|
throw new Error(`${model.name}: unexpected response \u2014 no result URL`);
|
|
8718
8722
|
}
|
|
8719
|
-
return { url, results: [{ url }], model: model.id, handle: completed.handle, raw: parsed };
|
|
8723
|
+
return { url, results: [{ url }], model: model.id, handle: completed.handle, raw: parsed, usage: completed.usage };
|
|
8720
8724
|
}
|
|
8721
8725
|
function parseTextResult(completed, model) {
|
|
8722
8726
|
if (completed.status === "FAILED") {
|
|
@@ -8731,7 +8735,7 @@ function parseTextResult(completed, model) {
|
|
|
8731
8735
|
if (text == null) {
|
|
8732
8736
|
throw new Error(`${model.name}: unexpected response \u2014 no text`);
|
|
8733
8737
|
}
|
|
8734
|
-
return { text, model: model.id, handle: completed.handle, raw: completed.raw ?? completed.result };
|
|
8738
|
+
return { text, model: model.id, handle: completed.handle, raw: completed.raw ?? completed.result, usage: completed.usage };
|
|
8735
8739
|
}
|
|
8736
8740
|
|
|
8737
8741
|
// src/core/limits.ts
|
|
@@ -9807,7 +9811,8 @@ function createClient(config) {
|
|
|
9807
9811
|
return toCompletedStatus(
|
|
9808
9812
|
syncResponse.handle,
|
|
9809
9813
|
extractSyncResult(syncResponse.raw),
|
|
9810
|
-
syncResponse.raw
|
|
9814
|
+
syncResponse.raw,
|
|
9815
|
+
syncResponse.usage
|
|
9811
9816
|
);
|
|
9812
9817
|
}
|
|
9813
9818
|
return client.run({ workflow, payload, signal });
|