@sogni-ai/sogni-creative-agent-skill 3.73.1 → 3.73.3

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.
@@ -3,7 +3,7 @@ name: sogni-creative-agent-skill
3
3
  description: "Generate and edit images, create Pixal3D 3D models, remove backgrounds with BiRefNet, synthesize Qwen3-TTS speech, upscale images, create video and music, animate image folders into seamless reels, and manage reusable personas with Sogni AI. Use when a Hermes user asks to draw, render, upscale, edit or restyle an image, animate an image, make a video, create music or lyrics, build a media workflow, build a playable world, apply a saved identity, or refine an earlier Sogni result."
4
4
  license: MIT
5
5
  metadata:
6
- version: "3.73.1"
6
+ version: "3.73.3"
7
7
  author: Sogni AI
8
8
  hermes:
9
9
  category: creative
@@ -64,7 +64,7 @@ Prompt-only families return the directly runnable prompt with no label,
64
64
  Markdown fence, preamble, explanation, or render offer.
65
65
 
66
66
  <!-- BEGIN GENERATED PROMPT GUIDE: image-models -->
67
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
67
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
68
68
 
69
69
  ## Per-model rules from Sogni's image prompt writer
70
70
 
@@ -124,7 +124,7 @@ LTX-2.5 text-to-video, one shot, so one sentence: "A medium shot frames a woman
124
124
  ```
125
125
 
126
126
  <!-- BEGIN GENERATED PROMPT GUIDE: ltx-2.5 -->
127
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
127
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
128
128
 
129
129
  ### Sogni's prompt rules: ltx-2.5
130
130
 
@@ -179,7 +179,7 @@ Preserve requested visual style and production value without adding new objects,
179
179
  <!-- END GENERATED PROMPT GUIDE: ltx-2.5 -->
180
180
 
181
181
  <!-- BEGIN GENERATED PROMPT GUIDE: ltx-2.3 -->
182
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
182
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
183
183
 
184
184
  ### Sogni's prompt rules: ltx-2.3
185
185
 
@@ -977,7 +977,7 @@ the exact waveform-conditioned lip-sync input. Remote audio URLs and additional
977
977
  audio references keep their existing handling.
978
978
 
979
979
  <!-- BEGIN GENERATED PROMPT GUIDE: minimax-h3 -->
980
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
980
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
981
981
 
982
982
  ### Sogni's prompt rules: minimax-h3
983
983
 
@@ -1195,7 +1195,7 @@ A low tracking shot races alongside a teal 1960s convertible down a sunlit coast
1195
1195
  ```
1196
1196
 
1197
1197
  <!-- BEGIN GENERATED PROMPT GUIDE: seedance-2.5 -->
1198
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
1198
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
1199
1199
 
1200
1200
  ### Sogni's prompt rules: seedance-2.5
1201
1201
 
@@ -1269,7 +1269,7 @@ TARGET CAPABILITIES: Seedance 2.5 uses the same director-style prompt grammar an
1269
1269
  <!-- END GENERATED PROMPT GUIDE: seedance-2.5 -->
1270
1270
 
1271
1271
  <!-- BEGIN GENERATED PROMPT GUIDE: seedance-2.0 -->
1272
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
1272
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
1273
1273
 
1274
1274
  ### Sogni's prompt rules: seedance-2.0
1275
1275
 
@@ -1378,7 +1378,7 @@ writer uses close this section.
1378
1378
  motion timing, camera path, framing, and background.
1379
1379
 
1380
1380
  <!-- BEGIN GENERATED PROMPT GUIDE: wan-2.2 -->
1381
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
1381
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
1382
1382
 
1383
1383
  ### Sogni's prompt rules: wan-2.2
1384
1384
 
@@ -1468,7 +1468,7 @@ The rules Sogni's own prompt writer uses close this section.
1468
1468
  - Prompts may run to 20,000 characters.
1469
1469
 
1470
1470
  <!-- BEGIN GENERATED PROMPT GUIDE: wan-3 -->
1471
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
1471
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
1472
1472
 
1473
1473
  ### Sogni's prompt rules: wan-3
1474
1474
 
@@ -1523,7 +1523,7 @@ audio that is always on. What it renders well and the reference limits are in
1523
1523
  [models.md § HappyHorse 1.1](./models.md#happyhorse-11-prompting-tips).
1524
1524
 
1525
1525
  <!-- BEGIN GENERATED PROMPT GUIDE: happyhorse-1.1 -->
1526
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
1526
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
1527
1527
 
1528
1528
  ### Sogni's prompt rules: happyhorse-1.1
1529
1529
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sogni-creative-agent",
3
- "version": "3.73.1",
3
+ "version": "3.73.3",
4
4
  "description": "Sogni Creative Agent: image, 3D, speech, video, and music generation via Sogni AI's decentralized GPU network. Supports personas, persistent memories, style transfer, and multi-step creative workflows.",
5
5
  "author": {
6
6
  "name": "Sogni AI",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sogni-creative-agent",
3
- "version": "3.73.1",
3
+ "version": "3.73.3",
4
4
  "description": "Create images, 3D models, speech, generative video, music, and image-folder loops with Sogni AI.",
5
5
  "author": {
6
6
  "name": "Sogni AI",
package/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [3.73.3] - 2026-11-23
2
+
3
+ - Hosts can allocate storage before saving completed renders. If a result will not fit, the CLI preserves saved files and gives commands to collect the existing render after making room.
4
+ - Optional result-download limits count decoded bytes across batches and retries. Without a configured limit or host grant protocol, downloads keep their existing behavior.
5
+
6
+ ## [3.73.2] - 2026-11-22
7
+
8
+ - If another connection takes over while a render is running, the CLI reports error 4015 immediately and prints `sogni-agent --result <project-id> --wait` for each affected project. You can collect the original render without submitting or paying for it again.
9
+ - A takeover during startup identifies the shared app ID. A takeover after the final job completes still lets the CLI finish saving the result.
10
+ - Use Sogni SDK 5.86.1 and intelligence-client 4.33.1.
11
+
1
12
  ## [3.73.1] - 2026-11-22
2
13
 
3
14
  - Media references continue to download through configured proxies across supported Node versions, with clearer failures for invalid, oversized or stalled downloads.
package/README.md CHANGED
@@ -455,6 +455,9 @@ Defaults live under `~/.config/sogni/` for credentials, last-render metadata, pe
455
455
  | `FFMPEG_PATH` | Custom `ffmpeg` binary |
456
456
  | `FFPROBE_PATH` | Custom `ffprobe` binary |
457
457
  | `SOGNI_MEDIA_DOWNLOAD_MAX_BYTES` | Largest download from one media URL (default: 536870912, 512 MiB); local files have no limit |
458
+ | `SOGNI_RESULT_DOWNLOAD_MAX_BYTES` | Optional total decoded-byte budget for result downloads in one CLI invocation. Unset keeps existing behavior. Counts all result files and retries, including discarded retry bytes; zero permits no result bytes. A refusal preserves existing output files, removes the current partial download, and reports `RESULT_DOWNLOAD_LIMIT` with collection commands. Hosts should reserve this many bytes before launching the CLI and account for retained files before releasing the reservation. This is not a quota for local media processing or other file writes |
459
+
460
+ Hosts that share storage across simultaneous writers can pass `--result-download-budget-stdio` instead of reserving the whole byte limit upfront. Before each result chunk is written, stderr emits one `SOGNI_DOWNLOAD_BUDGET_V1 {"id":1,"bytes":65536}` line. The host must atomically reserve those bytes and answer on stdin with `{"id":1,"allowed":true}` followed by a newline, or deny with `allowed:false`. Requests are serialized; each needs the matching ID and a boolean answer within 30 seconds. Denial reports `RESULT_DOWNLOAD_STORAGE_FULL`; a missing or malformed reply reports `RESULT_DOWNLOAD_BUDGET_UNAVAILABLE`. Both preserve existing outputs and include result-collection commands. The host must keep granted reservations until the CLI exits, account for retained files, then release them. The environment byte limit still applies. Without the flag, the CLI neither reads this protocol nor emits its request lines. Old CLI versions reject the flag, so a host cannot silently lose enforcement by running an older version.
458
461
 
459
462
  ---
460
463
 
package/SKILL.md CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sogni-creative-agent-skill
3
3
  description: "CLI and agent skill for personal LoRAs, image, video, and music generation using Sogni AI's decentralized GPU network. Supports Pixal3D single- and multi-view image-to-GLB, BiRefNet background removal, Qwen3-TTS speech/voice cloning/design, MiniMax Music 3, SAM 3 object selection, promptless RTX VSR image upscaling through 16K, promptless FlashVSR and RelayVSR video upscaling up to 2160p, one-click image-folder loop reels, personas (people with saved photos and voices), persistent memories, custom personality, style transfer, angle synthesis, MiniMax H3/H3 Balanced/LightX2V Turbo/FastH3 Turbo (including audio-to-video from an uploaded track)/Seedance/HappyHorse/LTX/WAN video, music/lyrics, hosted chat, durable workflows, replay records, and multi-step creative workflows. Ask the agent to \"draw\", \"generate\", \"create an image\", \"upscale an image\", \"upscale a video\", \"make a video/animate\", \"turn this image folder into a loop\", \"make music\", \"build a playable world\", \"apply a style\", or \"generate me as a superhero\"."
4
4
  metadata:
5
- version: "3.73.1"
5
+ version: "3.73.3"
6
6
  homepage: https://sogni.ai
7
7
  openclaw:
8
8
  emoji: "🎨"
@@ -2,7 +2,7 @@
2
2
  "manifest_version": "0.3",
3
3
  "name": "sogni-creative-agent",
4
4
  "display_name": "Sogni Creative Agent",
5
- "version": "3.73.1",
5
+ "version": "3.73.3",
6
6
  "description": "Generate images, video, music, and speech, and upscale images and video, on Sogni AI's decentralized GPU network — with personas, memories, and safe video editing tools.",
7
7
  "author": { "name": "Sogni AI", "url": "https://sogni.ai" },
8
8
  "homepage": "https://sogni.ai",
@@ -2,7 +2,7 @@
2
2
  "id": "sogni-creative-agent-skill",
3
3
  "name": "Sogni Creative Agent Skill — Image, Video & Music Generation",
4
4
  "description": "Agent skill and CLI for Sogni AI image, video, and music generation.",
5
- "version": "3.73.1",
5
+ "version": "3.73.3",
6
6
  "skills": [
7
7
  "."
8
8
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sogni-ai/sogni-creative-agent-skill",
3
- "version": "3.73.1",
3
+ "version": "3.73.3",
4
4
  "description": "Sogni Creative Agent Skill: agent skill and CLI for Sogni AI image, 3D, speech, video, and music generation.",
5
5
  "type": "module",
6
6
  "main": "sogni-agent.mjs",
@@ -108,7 +108,7 @@
108
108
  "progress-events.mjs"
109
109
  ],
110
110
  "dependencies": {
111
- "@sogni-ai/sogni-intelligence-client": "4.32.2",
111
+ "@sogni-ai/sogni-intelligence-client": "4.33.1",
112
112
  "execa": "^10.0.1",
113
113
  "json5": "^2.2.3",
114
114
  "sharp": "0.35.5"
@@ -64,7 +64,7 @@ Prompt-only families return the directly runnable prompt with no label,
64
64
  Markdown fence, preamble, explanation, or render offer.
65
65
 
66
66
  <!-- BEGIN GENERATED PROMPT GUIDE: image-models -->
67
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
67
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
68
68
 
69
69
  ## Per-model rules from Sogni's image prompt writer
70
70
 
@@ -124,7 +124,7 @@ LTX-2.5 text-to-video, one shot, so one sentence: "A medium shot frames a woman
124
124
  ```
125
125
 
126
126
  <!-- BEGIN GENERATED PROMPT GUIDE: ltx-2.5 -->
127
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
127
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
128
128
 
129
129
  ### Sogni's prompt rules: ltx-2.5
130
130
 
@@ -179,7 +179,7 @@ Preserve requested visual style and production value without adding new objects,
179
179
  <!-- END GENERATED PROMPT GUIDE: ltx-2.5 -->
180
180
 
181
181
  <!-- BEGIN GENERATED PROMPT GUIDE: ltx-2.3 -->
182
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
182
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
183
183
 
184
184
  ### Sogni's prompt rules: ltx-2.3
185
185
 
@@ -977,7 +977,7 @@ the exact waveform-conditioned lip-sync input. Remote audio URLs and additional
977
977
  audio references keep their existing handling.
978
978
 
979
979
  <!-- BEGIN GENERATED PROMPT GUIDE: minimax-h3 -->
980
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
980
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
981
981
 
982
982
  ### Sogni's prompt rules: minimax-h3
983
983
 
@@ -1195,7 +1195,7 @@ A low tracking shot races alongside a teal 1960s convertible down a sunlit coast
1195
1195
  ```
1196
1196
 
1197
1197
  <!-- BEGIN GENERATED PROMPT GUIDE: seedance-2.5 -->
1198
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
1198
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
1199
1199
 
1200
1200
  ### Sogni's prompt rules: seedance-2.5
1201
1201
 
@@ -1269,7 +1269,7 @@ TARGET CAPABILITIES: Seedance 2.5 uses the same director-style prompt grammar an
1269
1269
  <!-- END GENERATED PROMPT GUIDE: seedance-2.5 -->
1270
1270
 
1271
1271
  <!-- BEGIN GENERATED PROMPT GUIDE: seedance-2.0 -->
1272
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
1272
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
1273
1273
 
1274
1274
  ### Sogni's prompt rules: seedance-2.0
1275
1275
 
@@ -1378,7 +1378,7 @@ writer uses close this section.
1378
1378
  motion timing, camera path, framing, and background.
1379
1379
 
1380
1380
  <!-- BEGIN GENERATED PROMPT GUIDE: wan-2.2 -->
1381
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
1381
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
1382
1382
 
1383
1383
  ### Sogni's prompt rules: wan-2.2
1384
1384
 
@@ -1468,7 +1468,7 @@ The rules Sogni's own prompt writer uses close this section.
1468
1468
  - Prompts may run to 20,000 characters.
1469
1469
 
1470
1470
  <!-- BEGIN GENERATED PROMPT GUIDE: wan-3 -->
1471
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
1471
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
1472
1472
 
1473
1473
  ### Sogni's prompt rules: wan-3
1474
1474
 
@@ -1523,7 +1523,7 @@ audio that is always on. What it renders well and the reference limits are in
1523
1523
  [models.md § HappyHorse 1.1](./models.md#happyhorse-11-prompting-tips).
1524
1524
 
1525
1525
  <!-- BEGIN GENERATED PROMPT GUIDE: happyhorse-1.1 -->
1526
- <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.32.2; edit the rules there, not here. -->
1526
+ <!-- Generated by npm run sync:prompt-guides from @sogni-ai/sogni-intelligence-client 4.33.1; edit the rules there, not here. -->
1527
1527
 
1528
1528
  ### Sogni's prompt rules: happyhorse-1.1
1529
1529
 
@@ -3,7 +3,7 @@
3
3
  "private": true,
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "@sogni-ai/sogni-intelligence-client": "4.32.2",
6
+ "@sogni-ai/sogni-intelligence-client": "4.33.1",
7
7
  "execa": "^10.0.1",
8
8
  "json5": "^2.2.3",
9
9
  "sharp": "0.35.5"
package/sogni-agent.mjs CHANGED
@@ -14,6 +14,7 @@ import { createRequire } from 'module';
14
14
  import { readFileSync, writeFileSync, existsSync, mkdirSync, mkdtempSync, statSync, readdirSync, realpathSync, lstatSync, unlinkSync, rmdirSync, rmSync, renameSync, openSync, readSync, writeSync, closeSync } from 'fs';
15
15
  import { join, dirname, basename, extname, sep, resolve } from 'path';
16
16
  import { homedir, tmpdir } from 'os';
17
+ import { createInterface } from 'node:readline';
17
18
  import sharp from 'sharp';
18
19
  import { importAccountPersona } from './account-personas.mjs';
19
20
  import { getEnv, hasEnv } from './env.mjs';
@@ -853,12 +854,15 @@ function resolveConfiguredPath(rawPath, fallbackPath, label) {
853
854
  async function disableLiveModelAvailabilityEvents(wrapper) {
854
855
  const sdkClient = wrapper?.client;
855
856
 
857
+ const stopWatching = watchForConnectionTakeover(wrapper);
856
858
  try {
857
859
  if (typeof sdkClient?.setSocketEventSubscriptions === 'function') {
858
860
  await sdkClient.setSocketEventSubscriptions(SOCKET_EVENT_SUBSCRIPTIONS);
859
861
  }
860
862
  } catch (err) {
861
863
  // Subscription optimization is best-effort and must not block generation.
864
+ } finally {
865
+ stopWatching();
862
866
  }
863
867
  }
864
868
 
@@ -980,6 +984,10 @@ function classifyCliError(error, context = {}) {
980
984
  error = unwrapGenericProjectError(error);
981
985
  const rawMessage = cliErrorMessage(error);
982
986
 
987
+ if (error?.code === '4015') {
988
+ return { error_type: 'SWITCH_CONNECTION', category: 'connection_error', message: rawMessage, retryable: false };
989
+ }
990
+
983
991
  if (RELAXED_UNAVAILABLE_MESSAGE.test(rawMessage)) {
984
992
  return {
985
993
  error_type: 'MODEL_UNAVAILABLE',
@@ -1012,6 +1020,9 @@ function classifyCliError(error, context = {}) {
1012
1020
  }
1013
1021
 
1014
1022
  // The render finished; only its download failed, and `--result` (details.resultCommands) fetches it later.
1023
+ if (['RESULT_DOWNLOAD_LIMIT', 'RESULT_DOWNLOAD_STORAGE_FULL', 'RESULT_DOWNLOAD_BUDGET_UNAVAILABLE'].includes(error?.code)) {
1024
+ return { error_type: 'RESOURCE_LIMIT', category: 'resource_limit', message: rawMessage, retryable: false };
1025
+ }
1015
1026
  if (error?.code === 'RESULT_DOWNLOAD_FAILED') {
1016
1027
  return { error_type: 'PROVIDER_TIMEOUT', category: 'timeout', message: rawMessage, retryable: true };
1017
1028
  }
@@ -1289,23 +1300,55 @@ function reportFatalError(error) {
1289
1300
  process.on('uncaughtException', reportFatalError);
1290
1301
  process.on('unhandledRejection', reportFatalError);
1291
1302
 
1292
- // Connect to Sogni, mapping a rejected connection into a clean auth error
1293
- // where we can. (Detached SDK failures that never reach this await are caught
1294
- // by the global handlers above.)
1303
+ const connectionTakeovers = new WeakMap();
1304
+
1295
1305
  /** The CLI's SDK client, signed in with the API key under one app ID. */
1296
1306
  function createSkillSogniClient(creds, appId) {
1297
- return new SogniClientWrapper({
1307
+ const takeover = new AbortController();
1308
+ const client = new SogniClientWrapper({
1298
1309
  appSource: SOGNI_APP_SOURCE,
1299
1310
  appId,
1300
1311
  attribution: clientAttribution(AGENT_ATTRIBUTION),
1301
1312
  network: renderNetwork,
1302
1313
  autoConnect: false,
1314
+ onConnectionTakeover: () => takeover.abort(),
1303
1315
  apiKey: creds.SOGNI_API_KEY,
1304
1316
  authType: 'apiKey'
1305
1317
  });
1318
+ connectionTakeovers.set(client, takeover.signal);
1319
+ client.on(ClientEvent.PROJECT_CREATED, project => runProjectIds.add(project.id));
1320
+ return client;
1321
+ }
1322
+
1323
+ // A 4015 ends this socket's event stream. Keep completed downloads and other
1324
+ // REST-only work independent of it, and stop only commands relying on the socket.
1325
+ function watchForConnectionTakeover(client, projectId = options.projectLookup?.projectId) {
1326
+ const signal = connectionTakeovers.get(client);
1327
+ const report = () => {
1328
+ const projects = sdkClientOf(client)?.projects?.trackedProjects || [];
1329
+ const ids = new Set(projectId ? [projectId] : []);
1330
+ for (const project of projects) {
1331
+ if (!project.finished && runProjectIds.has(project.id)) ids.add(project.id);
1332
+ }
1333
+ const projectIds = [...ids];
1334
+ const waitCommands = projectIds.map(waitCommandFor);
1335
+ const usesFixedId = getEnv('SOGNI_APP_ID') || getEnv('SOGNI_APP_ID_PATH');
1336
+ const appIdHint = 'For parallel runs, let the CLI allocate its app IDs or give each process its own SOGNI_APP_ID.';
1337
+ fatalCliError('Another connection took over this Sogni app ID (4015).', {
1338
+ code: '4015',
1339
+ details: { projectIds, waitCommands },
1340
+ hint: waitCommands.length
1341
+ ? `${usesFixedId ? 'Clear the shared SOGNI_APP_ID or SOGNI_APP_ID_PATH before recovery. ' : ''}Recover the existing render with: ${waitCommands.join('; ')}`
1342
+ : appIdHint
1343
+ });
1344
+ };
1345
+ if (signal.aborted) report();
1346
+ signal.addEventListener('abort', report, { once: true });
1347
+ return () => signal.removeEventListener('abort', report);
1306
1348
  }
1307
1349
 
1308
1350
  async function connectSogniClient(client) {
1351
+ const stopWatching = watchForConnectionTakeover(client);
1309
1352
  try {
1310
1353
  await client.connect();
1311
1354
  } catch (error) {
@@ -1315,6 +1358,8 @@ async function connectSogniClient(client) {
1315
1358
  if (!error.code) error.code = 'INVALID_API_KEY';
1316
1359
  }
1317
1360
  throw error;
1361
+ } finally {
1362
+ stopWatching();
1318
1363
  }
1319
1364
  }
1320
1365
 
@@ -4267,6 +4312,7 @@ const args = process.argv.slice(2);
4267
4312
  const options = {
4268
4313
  prompt: null,
4269
4314
  output: null,
4315
+ resultDownloadBudgetStdio: false,
4270
4316
  model: null, // Will be set based on type
4271
4317
  width: 512,
4272
4318
  height: 512,
@@ -4623,6 +4669,8 @@ for (let i = 0; i < args.length; i++) {
4623
4669
  i++;
4624
4670
  options.output = expandHomePath(raw);
4625
4671
  cliSet.output = true;
4672
+ } else if (arg === '--result-download-budget-stdio') {
4673
+ options.resultDownloadBudgetStdio = true;
4626
4674
  } else if (arg === '-m' || arg === '--model') {
4627
4675
  const raw = requireFlagValue(args, i, arg);
4628
4676
  i++;
@@ -5992,6 +6040,7 @@ General:
5992
6040
  holds the project is not counted. The project is NOT cancelled; fetch it
5993
6041
  later with --result
5994
6042
  --cancel-on-timeout Cancel the project when --timeout runs out (the pre-3.53 behavior)
6043
+ --result-download-budget-stdio Host integration: require a storage grant over stdin before each result chunk
5995
6044
  --detach, --no-wait Submit, print the project id, and exit without waiting. The project keeps
5996
6045
  running; follow it with --result <projectId> --wait
5997
6046
  --status <projectId> Show a project's state and, while queued, why it is waiting
@@ -12908,6 +12957,16 @@ async function downloadUrlToFile(url, filePath, { projectId = null, retryOutput
12908
12957
  saved = true;
12909
12958
  return;
12910
12959
  }
12960
+ } catch (error) {
12961
+ if (['RESULT_DOWNLOAD_LIMIT', 'RESULT_DOWNLOAD_STORAGE_FULL', 'RESULT_DOWNLOAD_BUDGET_UNAVAILABLE'].includes(error?.code)) {
12962
+ const command = projectId ? `${resultCommandFor(projectId)}${retryOutput ? ` -o ${shellWord(retryOutput)}` : ''}` : null;
12963
+ error.details = {
12964
+ ...error.details,
12965
+ projectIds: projectId ? [projectId] : [],
12966
+ resultCommands: command ? [command] : [],
12967
+ };
12968
+ }
12969
+ throw error;
12911
12970
  } finally {
12912
12971
  if (!saved) {
12913
12972
  try { rmSync(tempPath, { force: true }); } catch { /* best effort */ }
@@ -12935,6 +12994,79 @@ async function downloadUrlToFile(url, filePath, { projectId = null, retryOutput
12935
12994
  throw err;
12936
12995
  }
12937
12996
 
12997
+ // One CLI invocation owns this optional budget across all result files and
12998
+ // retries. Bytes are charged before writes, including bytes a retry discards,
12999
+ // so a host can reserve this upper bound without inspecting download timing.
13000
+ let activeResultDownloadBudget;
13001
+ function resultDownloadBudget() {
13002
+ if (activeResultDownloadBudget) return activeResultDownloadBudget;
13003
+ const raw = getEnv('SOGNI_RESULT_DOWNLOAD_MAX_BYTES', { trim: true });
13004
+ const maxBytes = raw ? Number(raw) : Infinity;
13005
+ if (raw && (!Number.isSafeInteger(maxBytes) || maxBytes < 0)) {
13006
+ const error = new Error('SOGNI_RESULT_DOWNLOAD_MAX_BYTES must be a non-negative safe integer byte count.');
13007
+ error.code = 'INVALID_ARGUMENT';
13008
+ throw error;
13009
+ }
13010
+ activeResultDownloadBudget = { maxBytes, writtenBytes: 0, pending: Promise.resolve(), sequence: 0, reader: null, lines: null };
13011
+ return activeResultDownloadBudget;
13012
+ }
13013
+
13014
+ function checkResultDownloadBudget(bytes, consume = false) {
13015
+ const budget = resultDownloadBudget();
13016
+ if (bytes > budget.maxBytes - budget.writtenBytes) {
13017
+ const error = new Error(`Result downloads exceed this invocation's ${budget.maxBytes}-byte budget.`);
13018
+ error.code = 'RESULT_DOWNLOAD_LIMIT';
13019
+ error.hint = 'Do not render it again. Free storage or raise the host download budget, then collect the existing render with --result.';
13020
+ error.details = { maxBytes: budget.maxBytes, bytesWritten: budget.writtenBytes };
13021
+ throw error;
13022
+ }
13023
+ if (consume) budget.writtenBytes += bytes;
13024
+ }
13025
+
13026
+ function resultDownloadGrantError(code) {
13027
+ const error = new Error(code === 'RESULT_DOWNLOAD_STORAGE_FULL'
13028
+ ? 'The host could not reserve storage for this result download.'
13029
+ : 'The host did not provide a valid storage grant for this result download.');
13030
+ error.code = code;
13031
+ error.hint = 'Do not render it again. Check available storage and the host connection, then collect the existing render with --result.';
13032
+ return error;
13033
+ }
13034
+
13035
+ // The opt-in host protocol serializes requests, including if future callers
13036
+ // download several files at once. No bytes are written until the matching
13037
+ // grant arrives. An older CLI refuses the flag instead of ignoring a host's
13038
+ // reservation requirement. Default invocations never read stdin or emit it.
13039
+ function reserveResultDownloadBytes(bytes) {
13040
+ const budget = resultDownloadBudget();
13041
+ const work = budget.pending.then(async () => {
13042
+ checkResultDownloadBudget(bytes);
13043
+ if (options.resultDownloadBudgetStdio) {
13044
+ if (!budget.reader) {
13045
+ budget.reader = createInterface({ input: process.stdin, crlfDelay: Infinity, terminal: false });
13046
+ budget.lines = budget.reader[Symbol.asyncIterator]();
13047
+ }
13048
+ const id = ++budget.sequence;
13049
+ let timer;
13050
+ try {
13051
+ const line = budget.lines.next();
13052
+ const deadline = new Promise((_resolve, reject) => {
13053
+ timer = setTimeout(() => reject(resultDownloadGrantError('RESULT_DOWNLOAD_BUDGET_UNAVAILABLE')), 30_000);
13054
+ });
13055
+ process.stderr.write(`SOGNI_DOWNLOAD_BUDGET_V1 ${JSON.stringify({ id, bytes })}\n`);
13056
+ const answer = await Promise.race([line, deadline]);
13057
+ if (answer.done || answer.value.length > 512) throw resultDownloadGrantError('RESULT_DOWNLOAD_BUDGET_UNAVAILABLE');
13058
+ let grant;
13059
+ try { grant = JSON.parse(answer.value); } catch { throw resultDownloadGrantError('RESULT_DOWNLOAD_BUDGET_UNAVAILABLE'); }
13060
+ if (grant?.id !== id || typeof grant.allowed !== 'boolean') throw resultDownloadGrantError('RESULT_DOWNLOAD_BUDGET_UNAVAILABLE');
13061
+ if (!grant.allowed) throw resultDownloadGrantError('RESULT_DOWNLOAD_STORAGE_FULL');
13062
+ } finally { clearTimeout(timer); }
13063
+ }
13064
+ checkResultDownloadBudget(bytes, true);
13065
+ });
13066
+ budget.pending = work;
13067
+ return work;
13068
+ }
13069
+
12938
13070
  /** One GET into tempPath: fresh, or appended from state.received with a Range request. */
12939
13071
  async function downloadResultAttempt(url, tempPath, state, { stallMs, filePath, label }) {
12940
13072
  const controller = new AbortController();
@@ -12992,6 +13124,7 @@ async function downloadResultAttempt(url, tempPath, state, { stallMs, filePath,
12992
13124
  throw err;
12993
13125
  }
12994
13126
 
13127
+ if (state.total !== null) checkResultDownloadBudget(Math.max(0, state.total - state.received));
12995
13128
  if (response.body) {
12996
13129
  const reader = response.body.getReader();
12997
13130
  for (;;) {
@@ -13002,6 +13135,7 @@ async function downloadResultAttempt(url, tempPath, state, { stallMs, filePath,
13002
13135
  throw retryableDownloadError(silentFor ? `stalled with no data for ${formatDownloadDuration(silentFor)}` : downloadConnectionReason(error), error);
13003
13136
  }
13004
13137
  if (chunk.done) break;
13138
+ await reserveResultDownloadBytes(chunk.value.length);
13005
13139
  for (let offset = 0; offset < chunk.value.length;) {
13006
13140
  offset += writeSync(fd, chunk.value, offset, chunk.value.length - offset);
13007
13141
  }
@@ -14186,6 +14320,7 @@ function waitCommandFor(projectId) {
14186
14320
  * still ends a run whose submission never completes.
14187
14321
  */
14188
14322
  function createProjectWaitTracker(client, log, timeoutMs = options.timeout) {
14323
+ const stopWatching = watchForConnectionTakeover(client);
14189
14324
  const projects = new Map();
14190
14325
  const reasons = new Map();
14191
14326
  const described = new Map();
@@ -14212,6 +14347,7 @@ function createProjectWaitTracker(client, log, timeoutMs = options.timeout) {
14212
14347
  return now - startedAt - heldMs - (heldSince === null ? 0 : now - heldSince);
14213
14348
  };
14214
14349
  const cleanup = () => {
14350
+ stopWatching();
14215
14351
  clearTimeout(timer);
14216
14352
  if (typeof sdkProjects?.off === 'function') sdkProjects.off('queueChanged', onQueueChanged);
14217
14353
  };
@@ -14536,12 +14672,14 @@ async function followProjectToEnd(client, projectId, { log, creds, timeoutMs })
14536
14672
  }
14537
14673
  }
14538
14674
  const deadline = Date.now() + timeoutMs;
14539
- let tracked = await trackedProjectAfterSync(projectsApi, projectId);
14675
+ const stopWatching = watchForConnectionTakeover(client, projectId);
14540
14676
  let trackingClient = client;
14541
14677
  let sideClient = null;
14542
14678
  let claim = null;
14543
14679
  let stopProgressEvents = () => {};
14680
+ let stopWatchingSideClient;
14544
14681
  try {
14682
+ let tracked = await trackedProjectAfterSync(projectsApi, projectId);
14545
14683
  if (!tracked) {
14546
14684
  const inFlight = await projectsApi.listProjectsElsewhere();
14547
14685
  const holder = (inFlight || []).find((project) => project?.id === projectId);
@@ -14551,8 +14689,14 @@ async function followProjectToEnd(client, projectId, { log, creds, timeoutMs })
14551
14689
  log(`Taking project ${projectId} back from the run that submitted it...`);
14552
14690
  sideClient = createSkillSogniClient(creds, claim.appId);
14553
14691
  await connectSogniClient(sideClient);
14692
+ stopWatchingSideClient = watchForConnectionTakeover(sideClient, projectId);
14554
14693
  tracked = await trackedProjectAfterSync(sdkClientOf(sideClient).projects, projectId);
14555
- trackingClient = sideClient;
14694
+ if (tracked) {
14695
+ stopWatching();
14696
+ trackingClient = sideClient;
14697
+ } else {
14698
+ stopWatchingSideClient();
14699
+ }
14556
14700
  }
14557
14701
  if (!tracked) {
14558
14702
  log(claim?.heldByPid
@@ -14570,6 +14714,8 @@ async function followProjectToEnd(client, projectId, { log, creds, timeoutMs })
14570
14714
  }
14571
14715
  await settleTrackedProject(tracked, { log, deadline, timeoutMs });
14572
14716
  } finally {
14717
+ stopWatching();
14718
+ stopWatchingSideClient?.();
14573
14719
  stopProgressEvents();
14574
14720
  if (sideClient) {
14575
14721
  try { await sideClient.disconnect(); } catch { /* already closed */ }
@@ -14704,6 +14850,7 @@ async function buildProjectTimeoutError(projects, timeoutMs, label = 'Project')
14704
14850
  }
14705
14851
 
14706
14852
  async function runImageEditProjectWithEvents(client, editConfig, expectedCount, log, timeoutMs, label) {
14853
+ const stopWatching = watchForConnectionTakeover(client);
14707
14854
  const results = [];
14708
14855
  let completed = 0;
14709
14856
  let projectId = null;
@@ -14744,6 +14891,7 @@ async function runImageEditProjectWithEvents(client, editConfig, expectedCount,
14744
14891
  };
14745
14892
 
14746
14893
  const cleanup = () => {
14894
+ stopWatching();
14747
14895
  clearTimeout(timeout);
14748
14896
  removeClientListener(client, ClientEvent.JOB_COMPLETED, onCompleted);
14749
14897
  removeClientListener(client, ClientEvent.JOB_FAILED, onFailed);
@@ -15068,7 +15216,8 @@ async function runMultiAngleFlow(client, log) {
15068
15216
  if (options.autoResizeVideoAssets !== null) {
15069
15217
  clipConfig.autoResizeVideoAssets = options.autoResizeVideoAssets;
15070
15218
  }
15071
- const clipResult = await client.createVideoProject(withBillingMode(clipConfig));
15219
+ const stopWatching = watchForConnectionTakeover(client);
15220
+ const clipResult = await client.createVideoProject(withBillingMode(clipConfig)).finally(stopWatching);
15072
15221
 
15073
15222
  // Check for errors in the response (e.g., insufficient tokens)
15074
15223
  if (clipResult?.error || clipResult?.message) {
@@ -15867,15 +16016,7 @@ async function runDoctor() {
15867
16016
  if (creds?.SOGNI_API_KEY) {
15868
16017
  let doctorClient = null;
15869
16018
  try {
15870
- doctorClient = new SogniClientWrapper({
15871
- appSource: SOGNI_APP_SOURCE,
15872
- appId: getOrCreateSogniAppId(),
15873
- attribution: clientAttribution(AGENT_ATTRIBUTION),
15874
- network: renderNetwork,
15875
- autoConnect: false,
15876
- apiKey: creds.SOGNI_API_KEY,
15877
- authType: 'apiKey'
15878
- });
16019
+ doctorClient = createSkillSogniClient(creds, getOrCreateSogniAppId());
15879
16020
  const authFlow = (async () => {
15880
16021
  await connectSogniClient(doctorClient);
15881
16022
  const balance = await doctorClient.getBalance();
@@ -15962,6 +16103,7 @@ async function main() {
15962
16103
  let client = null;
15963
16104
 
15964
16105
  try {
16106
+ resultDownloadBudget();
15965
16107
  if (options.video && isWan3ModelLocal(options.model)) {
15966
16108
  await prepareWan3ReferenceMediaPlan();
15967
16109
  }
@@ -17825,7 +17967,8 @@ async function main() {
17825
17967
  // projects.create() resolves once the request is handed to the socket, before the server
17826
17968
  // has it, so exiting at once dropped every detached project (2026-10-01: none reached
17827
17969
  // the server, yet each was reported as submitted). Report only what the server answered.
17828
- const unconfirmed = await awaitServerAnswer([...activeProjects]);
17970
+ const stopWatching = watchForConnectionTakeover(client);
17971
+ const unconfirmed = await awaitServerAnswer([...activeProjects]).finally(stopWatching);
17829
17972
  const refused = [...activeProjects].find((project) => project?.status === 'failed');
17830
17973
  if (refused) throw buildProjectResultError({ error: refused.terminalError?.() ?? refused.error }, 'Sogni refused the project');
17831
17974
  if (unconfirmed.length) {
@@ -18018,20 +18161,13 @@ async function main() {
18018
18161
 
18019
18162
  // Create a new client for second clip to avoid event conflicts
18020
18163
  const creds = loadCredentials();
18021
- const client2 = new SogniClientWrapper({
18022
- appSource: SOGNI_APP_SOURCE,
18023
- appId: getOrCreateSogniAppId(),
18024
- attribution: clientAttribution(AGENT_ATTRIBUTION),
18025
- network: renderNetwork,
18026
- autoConnect: false,
18027
- apiKey: creds.SOGNI_API_KEY,
18028
- authType: 'apiKey'
18029
- });
18164
+ const client2 = createSkillSogniClient(creds, getOrCreateSogniAppId());
18030
18165
  await connectSogniClient(client2);
18031
18166
  await disableLiveModelAvailabilityEvents(client2);
18032
18167
 
18033
18168
  // Create second clip and wait for completion via events
18034
18169
  let activeClip2Project = null;
18170
+ const stopWatchingClip2 = watchForConnectionTakeover(client2);
18035
18171
  const clip2Promise = new Promise((resolve, reject) => {
18036
18172
  const timeout = setTimeout(() => {
18037
18173
  void buildProjectTimeoutError([activeClip2Project], options.timeout, 'second clip project')
@@ -18039,6 +18175,7 @@ async function main() {
18039
18175
  }, options.timeout);
18040
18176
 
18041
18177
  client2.on(ClientEvent.JOB_COMPLETED, async (data) => {
18178
+ stopWatchingClip2();
18042
18179
  try {
18043
18180
  clearTimeout(timeout);
18044
18181
  if (data.job?.isWithheld === true) {
@@ -18375,6 +18512,12 @@ async function main() {
18375
18512
  printHumanError(error, errorContext);
18376
18513
  }
18377
18514
  } finally {
18515
+ if (activeResultDownloadBudget?.reader) {
18516
+ activeResultDownloadBudget.reader.close();
18517
+ activeResultDownloadBudget.reader = null;
18518
+ activeResultDownloadBudget.lines = null;
18519
+ process.stdin.pause();
18520
+ }
18378
18521
  try {
18379
18522
  if (client?.isConnected?.()) {
18380
18523
  await Promise.race([
package/version.mjs CHANGED
@@ -1 +1 @@
1
- export const PACKAGE_VERSION = '3.73.1';
1
+ export const PACKAGE_VERSION = '3.73.3';