@picsart/ai-sdk 1.139.0 → 1.143.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/_cli.js +82 -70
- package/index.d.ts +9 -2
- package/index.js +77 -3
- package/package.json +1 -1
package/_cli.js
CHANGED
|
@@ -6270,11 +6270,19 @@ function createClient(config) {
|
|
|
6270
6270
|
const completed = await executeModel(resolved, workflow, finalPayload, options?.signal);
|
|
6271
6271
|
return parseResult(completed, resolved, contract);
|
|
6272
6272
|
},
|
|
6273
|
+
/** @deprecated Use `getCredits()` instead. */
|
|
6274
|
+
async estimate(model, params2) {
|
|
6275
|
+
if (!transport.options) return null;
|
|
6276
|
+
const resolved = resolveModel(model);
|
|
6277
|
+
const { workflow, payload } = prepareRequest(resolved, params2);
|
|
6278
|
+
return await transport.options(workflow, payload) ?? null;
|
|
6279
|
+
},
|
|
6273
6280
|
/**
|
|
6274
|
-
*
|
|
6281
|
+
* Get exact credit cost for a model with specific parameters.
|
|
6282
|
+
* Calls the backend /options endpoint for real-time pricing.
|
|
6275
6283
|
* Returns null if pricing is unavailable.
|
|
6276
6284
|
*/
|
|
6277
|
-
async
|
|
6285
|
+
async getCredits(model, params2) {
|
|
6278
6286
|
if (!transport.options) return null;
|
|
6279
6287
|
const resolved = resolveModel(model);
|
|
6280
6288
|
const { workflow, payload } = prepareRequest(resolved, params2);
|
|
@@ -6909,6 +6917,76 @@ var init_deeplink = __esm({
|
|
|
6909
6917
|
}
|
|
6910
6918
|
});
|
|
6911
6919
|
|
|
6920
|
+
// src/core/pricing.ts
|
|
6921
|
+
function resolveToolId(mapping, ctx) {
|
|
6922
|
+
if (!mapping) return void 0;
|
|
6923
|
+
if (typeof mapping === "string") return mapping;
|
|
6924
|
+
let next;
|
|
6925
|
+
switch (mapping.by) {
|
|
6926
|
+
case "audio":
|
|
6927
|
+
next = ctx.generateAudio ?? false ? mapping.on : mapping.off;
|
|
6928
|
+
break;
|
|
6929
|
+
case "resolution": {
|
|
6930
|
+
const key = ctx.resolution ?? Object.keys(mapping.map)[0];
|
|
6931
|
+
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
6932
|
+
break;
|
|
6933
|
+
}
|
|
6934
|
+
case "quality": {
|
|
6935
|
+
const key = String(ctx.quality ?? Object.keys(mapping.map)[0]);
|
|
6936
|
+
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
6937
|
+
break;
|
|
6938
|
+
}
|
|
6939
|
+
case "renderingSpeed": {
|
|
6940
|
+
const key = String(ctx.renderingSpeed ?? Object.keys(mapping.map)[0]);
|
|
6941
|
+
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
6942
|
+
break;
|
|
6943
|
+
}
|
|
6944
|
+
case "duration": {
|
|
6945
|
+
const key = String(ctx.duration ?? Object.keys(mapping.map)[0]);
|
|
6946
|
+
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
6947
|
+
break;
|
|
6948
|
+
}
|
|
6949
|
+
case "megapixel": {
|
|
6950
|
+
const mp = ctx.outputMegapixels ?? 0;
|
|
6951
|
+
const tiers = Object.keys(mapping.map).map(Number).sort((a, b) => a - b);
|
|
6952
|
+
const tier = tiers.find((t) => mp <= t) ?? tiers[tiers.length - 1];
|
|
6953
|
+
next = mapping.map[String(tier)];
|
|
6954
|
+
break;
|
|
6955
|
+
}
|
|
6956
|
+
}
|
|
6957
|
+
return resolveToolId(next, ctx);
|
|
6958
|
+
}
|
|
6959
|
+
function getAllToolIds(model) {
|
|
6960
|
+
const ids = [];
|
|
6961
|
+
const extract = (m) => {
|
|
6962
|
+
if (!m) return;
|
|
6963
|
+
if (typeof m === "string") {
|
|
6964
|
+
ids.push(m);
|
|
6965
|
+
return;
|
|
6966
|
+
}
|
|
6967
|
+
switch (m.by) {
|
|
6968
|
+
case "resolution":
|
|
6969
|
+
case "quality":
|
|
6970
|
+
case "renderingSpeed":
|
|
6971
|
+
case "duration":
|
|
6972
|
+
case "megapixel":
|
|
6973
|
+
for (const v of Object.values(m.map)) extract(v);
|
|
6974
|
+
break;
|
|
6975
|
+
case "audio":
|
|
6976
|
+
extract(m.on);
|
|
6977
|
+
extract(m.off);
|
|
6978
|
+
break;
|
|
6979
|
+
}
|
|
6980
|
+
};
|
|
6981
|
+
extract(model.toolId);
|
|
6982
|
+
extract(model.editToolId);
|
|
6983
|
+
return ids;
|
|
6984
|
+
}
|
|
6985
|
+
var init_pricing = __esm({
|
|
6986
|
+
"src/core/pricing.ts"() {
|
|
6987
|
+
}
|
|
6988
|
+
});
|
|
6989
|
+
|
|
6912
6990
|
// src/index.ts
|
|
6913
6991
|
var init_src = __esm({
|
|
6914
6992
|
"src/index.ts"() {
|
|
@@ -6920,6 +6998,7 @@ var init_src = __esm({
|
|
|
6920
6998
|
init_deeplink();
|
|
6921
6999
|
init_catalog();
|
|
6922
7000
|
init_model_registry();
|
|
7001
|
+
init_pricing();
|
|
6923
7002
|
}
|
|
6924
7003
|
});
|
|
6925
7004
|
|
|
@@ -11572,74 +11651,7 @@ Done: ${uploaded} uploaded, ${failed} failed`);
|
|
|
11572
11651
|
init_base_command();
|
|
11573
11652
|
init_src();
|
|
11574
11653
|
init_model_registry();
|
|
11575
|
-
|
|
11576
|
-
// src/core/pricing.ts
|
|
11577
|
-
function resolveToolId(mapping, ctx) {
|
|
11578
|
-
if (!mapping) return void 0;
|
|
11579
|
-
if (typeof mapping === "string") return mapping;
|
|
11580
|
-
let next;
|
|
11581
|
-
switch (mapping.by) {
|
|
11582
|
-
case "audio":
|
|
11583
|
-
next = ctx.generateAudio ?? false ? mapping.on : mapping.off;
|
|
11584
|
-
break;
|
|
11585
|
-
case "resolution": {
|
|
11586
|
-
const key = ctx.resolution ?? Object.keys(mapping.map)[0];
|
|
11587
|
-
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
11588
|
-
break;
|
|
11589
|
-
}
|
|
11590
|
-
case "quality": {
|
|
11591
|
-
const key = String(ctx.quality ?? Object.keys(mapping.map)[0]);
|
|
11592
|
-
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
11593
|
-
break;
|
|
11594
|
-
}
|
|
11595
|
-
case "renderingSpeed": {
|
|
11596
|
-
const key = String(ctx.renderingSpeed ?? Object.keys(mapping.map)[0]);
|
|
11597
|
-
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
11598
|
-
break;
|
|
11599
|
-
}
|
|
11600
|
-
case "duration": {
|
|
11601
|
-
const key = String(ctx.duration ?? Object.keys(mapping.map)[0]);
|
|
11602
|
-
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
11603
|
-
break;
|
|
11604
|
-
}
|
|
11605
|
-
case "megapixel": {
|
|
11606
|
-
const mp = ctx.outputMegapixels ?? 0;
|
|
11607
|
-
const tiers = Object.keys(mapping.map).map(Number).sort((a, b) => a - b);
|
|
11608
|
-
const tier = tiers.find((t) => mp <= t) ?? tiers[tiers.length - 1];
|
|
11609
|
-
next = mapping.map[String(tier)];
|
|
11610
|
-
break;
|
|
11611
|
-
}
|
|
11612
|
-
}
|
|
11613
|
-
return resolveToolId(next, ctx);
|
|
11614
|
-
}
|
|
11615
|
-
function getAllToolIds(model) {
|
|
11616
|
-
const ids = [];
|
|
11617
|
-
const extract = (m) => {
|
|
11618
|
-
if (!m) return;
|
|
11619
|
-
if (typeof m === "string") {
|
|
11620
|
-
ids.push(m);
|
|
11621
|
-
return;
|
|
11622
|
-
}
|
|
11623
|
-
switch (m.by) {
|
|
11624
|
-
case "resolution":
|
|
11625
|
-
case "quality":
|
|
11626
|
-
case "renderingSpeed":
|
|
11627
|
-
case "duration":
|
|
11628
|
-
case "megapixel":
|
|
11629
|
-
for (const v of Object.values(m.map)) extract(v);
|
|
11630
|
-
break;
|
|
11631
|
-
case "audio":
|
|
11632
|
-
extract(m.on);
|
|
11633
|
-
extract(m.off);
|
|
11634
|
-
break;
|
|
11635
|
-
}
|
|
11636
|
-
};
|
|
11637
|
-
extract(model.toolId);
|
|
11638
|
-
extract(model.editToolId);
|
|
11639
|
-
return ids;
|
|
11640
|
-
}
|
|
11641
|
-
|
|
11642
|
-
// _cli/src/commands/pricing.ts
|
|
11654
|
+
init_pricing();
|
|
11643
11655
|
init_usage();
|
|
11644
11656
|
init_key_value();
|
|
11645
11657
|
var Pricing = class _Pricing extends BaseCommand {
|
package/index.d.ts
CHANGED
|
@@ -940,8 +940,10 @@ interface GenerateOptions {
|
|
|
940
940
|
interface AiClient {
|
|
941
941
|
/** Generate content using a model. Params are type-checked against the model's schema. */
|
|
942
942
|
generate<M extends TypedModelId>(model: M, params: ModelInputById[M], options?: GenerateOptions): Promise<GenerateResult>;
|
|
943
|
-
/**
|
|
943
|
+
/** @deprecated Use `getCredits()` instead. */
|
|
944
944
|
estimate<M extends TypedModelId>(model: M, params: ModelInputById[M]): Promise<number | null>;
|
|
945
|
+
/** Get exact credit cost for a model with specific parameters. */
|
|
946
|
+
getCredits<M extends TypedModelId>(model: M, params: ModelInputById[M]): Promise<number | null>;
|
|
945
947
|
/** Submit a generation job and get a handle back. */
|
|
946
948
|
submit<M extends TypedModelId>(model: M, params: ModelInputById[M], options?: GenerateOptions): Promise<WorkflowJobHandle>;
|
|
947
949
|
/** Check the current status of a submitted job. */
|
|
@@ -1647,4 +1649,9 @@ declare const getModel: (id: string) => ModelDefinition | undefined;
|
|
|
1647
1649
|
/** Find a model by ID, workflow name, or display name (case-insensitive). */
|
|
1648
1650
|
declare const findModel: (ref: string) => ModelDefinition | undefined;
|
|
1649
1651
|
|
|
1650
|
-
|
|
1652
|
+
/** Resolve a ToolIdMapping to a concrete toolId for a generation context. Recursive. */
|
|
1653
|
+
declare function resolveToolId(mapping: ToolIdMapping | undefined, ctx: Partial<GenerationContext>): string | undefined;
|
|
1654
|
+
/** Return all toolIds a model can resolve to (toolId + editToolId variants). Recursive. */
|
|
1655
|
+
declare function getAllToolIds(model: ModelDefinition): string[];
|
|
1656
|
+
|
|
1657
|
+
export { ALL_MODELS, type AiClient, type AuthenticatedFetch, type AvatarOption, type BooleanDescriptor, type BooleanEntry, type ClientConfig, type DeepLinkResult, type DriveConfig, type DriveFileDetails, type DriveFolder, type DriveMediaItem, type DriveSaveResult, type EntryMeta, type EnumDescriptor, type EnumEntry, type FileDescriptor, type FileEntry, type FlatParamEntry, type GenerateOptions, type GenerateResult, type GenerateResultItem, type GenerationContext, type GenerationMode, type ListOptions, 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 ProviderInfo, type RangeDescriptor, type RangeEntry, type SaveParams, type SdkTransport, type TextDescriptor, type TextEntry, type TypedModelId, type VoiceOption, type WorkflowJobHandle, buildFilename, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, findModel, getAllToolIds, getModel, getModelsByMode, getVoiceById, inferResourceType, resolveToolId };
|
package/index.js
CHANGED
|
@@ -5545,11 +5545,19 @@ function createClient(config) {
|
|
|
5545
5545
|
const completed = await executeModel(resolved, workflow, finalPayload, options?.signal);
|
|
5546
5546
|
return parseResult(completed, resolved, contract);
|
|
5547
5547
|
},
|
|
5548
|
+
/** @deprecated Use `getCredits()` instead. */
|
|
5549
|
+
async estimate(model, params2) {
|
|
5550
|
+
if (!transport.options) return null;
|
|
5551
|
+
const resolved = resolveModel(model);
|
|
5552
|
+
const { workflow, payload } = prepareRequest(resolved, params2);
|
|
5553
|
+
return await transport.options(workflow, payload) ?? null;
|
|
5554
|
+
},
|
|
5548
5555
|
/**
|
|
5549
|
-
*
|
|
5556
|
+
* Get exact credit cost for a model with specific parameters.
|
|
5557
|
+
* Calls the backend /options endpoint for real-time pricing.
|
|
5550
5558
|
* Returns null if pricing is unavailable.
|
|
5551
5559
|
*/
|
|
5552
|
-
async
|
|
5560
|
+
async getCredits(model, params2) {
|
|
5553
5561
|
if (!transport.options) return null;
|
|
5554
5562
|
const resolved = resolveModel(model);
|
|
5555
5563
|
const { workflow, payload } = prepareRequest(resolved, params2);
|
|
@@ -6282,4 +6290,70 @@ function decodeDeepLinkPayload(encoded) {
|
|
|
6282
6290
|
return deserializePayload(encoded);
|
|
6283
6291
|
}
|
|
6284
6292
|
|
|
6285
|
-
|
|
6293
|
+
// src/core/pricing.ts
|
|
6294
|
+
function resolveToolId(mapping, ctx) {
|
|
6295
|
+
if (!mapping) return void 0;
|
|
6296
|
+
if (typeof mapping === "string") return mapping;
|
|
6297
|
+
let next;
|
|
6298
|
+
switch (mapping.by) {
|
|
6299
|
+
case "audio":
|
|
6300
|
+
next = ctx.generateAudio ?? false ? mapping.on : mapping.off;
|
|
6301
|
+
break;
|
|
6302
|
+
case "resolution": {
|
|
6303
|
+
const key = ctx.resolution ?? Object.keys(mapping.map)[0];
|
|
6304
|
+
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
6305
|
+
break;
|
|
6306
|
+
}
|
|
6307
|
+
case "quality": {
|
|
6308
|
+
const key = String(ctx.quality ?? Object.keys(mapping.map)[0]);
|
|
6309
|
+
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
6310
|
+
break;
|
|
6311
|
+
}
|
|
6312
|
+
case "renderingSpeed": {
|
|
6313
|
+
const key = String(ctx.renderingSpeed ?? Object.keys(mapping.map)[0]);
|
|
6314
|
+
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
6315
|
+
break;
|
|
6316
|
+
}
|
|
6317
|
+
case "duration": {
|
|
6318
|
+
const key = String(ctx.duration ?? Object.keys(mapping.map)[0]);
|
|
6319
|
+
next = mapping.map[key] ?? Object.values(mapping.map)[0];
|
|
6320
|
+
break;
|
|
6321
|
+
}
|
|
6322
|
+
case "megapixel": {
|
|
6323
|
+
const mp = ctx.outputMegapixels ?? 0;
|
|
6324
|
+
const tiers = Object.keys(mapping.map).map(Number).sort((a, b) => a - b);
|
|
6325
|
+
const tier = tiers.find((t) => mp <= t) ?? tiers[tiers.length - 1];
|
|
6326
|
+
next = mapping.map[String(tier)];
|
|
6327
|
+
break;
|
|
6328
|
+
}
|
|
6329
|
+
}
|
|
6330
|
+
return resolveToolId(next, ctx);
|
|
6331
|
+
}
|
|
6332
|
+
function getAllToolIds(model) {
|
|
6333
|
+
const ids = [];
|
|
6334
|
+
const extract = (m) => {
|
|
6335
|
+
if (!m) return;
|
|
6336
|
+
if (typeof m === "string") {
|
|
6337
|
+
ids.push(m);
|
|
6338
|
+
return;
|
|
6339
|
+
}
|
|
6340
|
+
switch (m.by) {
|
|
6341
|
+
case "resolution":
|
|
6342
|
+
case "quality":
|
|
6343
|
+
case "renderingSpeed":
|
|
6344
|
+
case "duration":
|
|
6345
|
+
case "megapixel":
|
|
6346
|
+
for (const v of Object.values(m.map)) extract(v);
|
|
6347
|
+
break;
|
|
6348
|
+
case "audio":
|
|
6349
|
+
extract(m.on);
|
|
6350
|
+
extract(m.off);
|
|
6351
|
+
break;
|
|
6352
|
+
}
|
|
6353
|
+
};
|
|
6354
|
+
extract(model.toolId);
|
|
6355
|
+
extract(model.editToolId);
|
|
6356
|
+
return ids;
|
|
6357
|
+
}
|
|
6358
|
+
|
|
6359
|
+
export { ALL_MODELS, Model, Models, buildFilename, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, findModel, getAllToolIds, getModel, getModelsByMode, getVoiceById, inferResourceType, resolveToolId };
|