@picsart/ai-sdk 6.21.0 → 6.21.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.
Files changed (2) hide show
  1. package/index.js +18 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -12342,6 +12342,7 @@ function parseTextResult(completed, model) {
12342
12342
 
12343
12343
  // src/core/limits.ts
12344
12344
  var MAX_DRIVE_PROMPT_LENGTH = 18e3;
12345
+ var MAX_DRIVE_ATTRIBUTE_LENGTH = 2e4;
12345
12346
 
12346
12347
  // src/client/drive.ts
12347
12348
  var USER_REACTION_ATTR = "userReaction";
@@ -12497,7 +12498,7 @@ function parseJsonAttr(raw) {
12497
12498
  var asString = (v) => typeof v === "string" && v.trim() ? v : void 0;
12498
12499
  var asStringArray = (v) => Array.isArray(v) && v.length && v.every((x) => typeof x === "string") ? v : void 0;
12499
12500
  function toSdkPayload(params2) {
12500
- const p2 = { prompt: String(params2.prompt ?? "").slice(0, MAX_DRIVE_PROMPT_LENGTH) };
12501
+ const p2 = { prompt: cutPrompt(String(params2.prompt ?? ""), MAX_DRIVE_PROMPT_LENGTH) };
12501
12502
  for (const [key, value] of Object.entries(params2)) {
12502
12503
  if (key === "prompt") continue;
12503
12504
  if (value === void 0 || value === null || value === "") continue;
@@ -12505,10 +12506,25 @@ function toSdkPayload(params2) {
12505
12506
  }
12506
12507
  return p2;
12507
12508
  }
12509
+ function cutPrompt(prompt, max) {
12510
+ if (prompt.length <= max) return prompt;
12511
+ const code = prompt.charCodeAt(max - 1);
12512
+ return prompt.slice(0, code >= 55296 && code <= 56319 ? max - 1 : max);
12513
+ }
12514
+ function serializeSdkPayload(params2) {
12515
+ const payload = toSdkPayload(params2);
12516
+ let prompt = payload.prompt;
12517
+ for (; ; ) {
12518
+ const serialized = JSON.stringify({ ...payload, prompt });
12519
+ const excess = serialized.length - MAX_DRIVE_ATTRIBUTE_LENGTH;
12520
+ if (excess <= 0 || prompt.length === 0) return serialized;
12521
+ prompt = cutPrompt(prompt, Math.max(0, prompt.length - excess));
12522
+ }
12523
+ }
12508
12524
  function buildGenerationAttributes(input) {
12509
12525
  const attrs = {
12510
12526
  model: input.modelId,
12511
- aiSDKPayload: JSON.stringify(toSdkPayload(input.params))
12527
+ aiSDKPayload: serializeSdkPayload(input.params)
12512
12528
  };
12513
12529
  if (input.app) {
12514
12530
  attrs.appId = input.app.id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picsart/ai-sdk",
3
- "version": "6.21.0",
3
+ "version": "6.21.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",