@sogni-ai/sogni-creative-agent-skill 3.54.2 → 3.54.4
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/.agents/skills/sogni-creative-agent-skill/SKILL.md +4 -4
- package/.agents/skills/sogni-creative-agent-skill/references/hosted-api.md +4 -2
- package/.agents/skills/sogni-creative-agent-skill/references/interactive-worlds.md +3 -0
- package/.agents/skills/sogni-creative-agent-skill/references/long-jobs-and-queues.md +22 -5
- package/.agents/skills/sogni-creative-agent-skill/references/loop-maker.md +13 -2
- package/.agents/skills/sogni-creative-agent-skill/references/models.md +67 -36
- package/.agents/skills/sogni-creative-agent-skill/references/personal-loras.md +1 -1
- package/.agents/skills/sogni-creative-agent-skill/references/video-prompting.md +35 -15
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +24 -0
- package/README.md +22 -17
- package/SKILL.md +10 -10
- package/desktop-extension/manifest.json +1 -1
- package/desktop-extension/server/tools.mjs +14 -8
- package/generated/creative-agent-runtime.mjs +4 -4
- package/llm.txt +1 -1
- package/openclaw.plugin.json +3 -3
- package/package.json +4 -2
- package/plugin-skills/sogni-creative-agent/SKILL.md +2 -2
- package/references/hosted-api.md +4 -2
- package/references/interactive-worlds.md +3 -0
- package/references/long-jobs-and-queues.md +22 -5
- package/references/loop-maker.md +13 -2
- package/references/models.md +67 -36
- package/references/openclaw-config.md +2 -2
- package/references/personal-loras.md +1 -1
- package/references/video-prompting.md +35 -15
- package/skill-package.json +1 -1
- package/skills/composition_planning.md +2 -2
- package/skills/video_editing.md +1 -1
- package/skills/video_generation.md +1 -1
- package/sogni-agent.mjs +401 -117
- package/sogni-app-id.mjs +50 -0
- package/version.mjs +1 -1
package/sogni-agent.mjs
CHANGED
|
@@ -17,7 +17,7 @@ import { join, dirname, basename, extname, sep, resolve } from 'path';
|
|
|
17
17
|
import { homedir, tmpdir } from 'os';
|
|
18
18
|
import sharp from 'sharp';
|
|
19
19
|
import { getEnv, hasEnv } from './env.mjs';
|
|
20
|
-
import { getOrCreateSogniAppId } from './sogni-app-id.mjs';
|
|
20
|
+
import { claimSogniAppIdSlot, getOrCreateSogniAppId } from './sogni-app-id.mjs';
|
|
21
21
|
import { PACKAGE_VERSION } from './version.mjs';
|
|
22
22
|
import {
|
|
23
23
|
SOGNI_APP_SOURCE,
|
|
@@ -316,6 +316,15 @@ const DEFAULT_PERSONALITY_PATH = join(homedir(), '.config', 'sogni', 'personalit
|
|
|
316
316
|
const DEFAULT_PERSONAS_DIR = join(homedir(), '.config', 'sogni', 'personas');
|
|
317
317
|
const DEFAULT_PERSONAS_INDEX_PATH = join(homedir(), '.config', 'sogni', 'personas', 'index.json');
|
|
318
318
|
const DEFAULT_API_MEDIA_REFERENCE_MAX_BYTES = 100 * 1024 * 1024;
|
|
319
|
+
// The API's ceiling on one uploaded reference (MAX_UPLOAD_SIZE_BYTES in sogni-api).
|
|
320
|
+
const API_MEDIA_REFERENCE_UPLOAD_MAX_BYTES = 100 * 1024 * 1024;
|
|
321
|
+
// Content types the API accepts per reference kind (ALLOWED_IMAGE_CONTENT_TYPES,
|
|
322
|
+
// ALLOWED_AUDIO_CONTENT_TYPES and ALLOWED_VIDEO_CONTENT_TYPES in sogni-api).
|
|
323
|
+
const VENDOR_REFERENCE_UPLOAD_CONTENT_TYPES = Object.freeze({
|
|
324
|
+
image: Object.freeze(['image/png', 'image/jpeg', 'image/jpg', 'image/webp', 'image/gif']),
|
|
325
|
+
audio: Object.freeze(['audio/mp4', 'audio/mpeg', 'audio/flac', 'audio/wav', 'audio/x-wav', 'audio/wave']),
|
|
326
|
+
video: Object.freeze(['video/mp4', 'video/quicktime', 'video/webm']),
|
|
327
|
+
});
|
|
319
328
|
const DEFAULT_API_BASE_URL = 'https://api.sogni.ai';
|
|
320
329
|
const DEFAULT_SAFE_API_HOSTS = Object.freeze(['api.sogni.ai']);
|
|
321
330
|
const LOOPBACK_API_HOSTS = Object.freeze(['localhost', '127.0.0.1', '::1']);
|
|
@@ -402,6 +411,12 @@ for (const signal of Object.keys(SIGNAL_EXIT_CODES)) {
|
|
|
402
411
|
const SOCKET_EVENT_SUBSCRIPTIONS = Object.freeze({
|
|
403
412
|
modelAvailability: false
|
|
404
413
|
});
|
|
414
|
+
// MiniMax Music 3 is the default music model. ACE-Step 1.5 XL stays available
|
|
415
|
+
// by name (-m turbo|sft) for exact BPM/key controls and tracks over 300 s.
|
|
416
|
+
const DEFAULT_MUSIC_MODEL = 'music3';
|
|
417
|
+
// Music 3 ends early on an instrumental with no lyric sheet, so a run without
|
|
418
|
+
// lyrics sends this section skeleton in their place.
|
|
419
|
+
const MUSIC3_INSTRUMENTAL_SECTIONS = '[Intro]\n[Verse]\n[Chorus]\n[Verse]\n[Chorus]\n[Bridge]\n[Outro]';
|
|
405
420
|
const MUSIC_MODEL_IDS = {
|
|
406
421
|
music3: MUSIC3_MODEL_ID,
|
|
407
422
|
turbo: 'ace_step_1.5_xl_turbo',
|
|
@@ -765,6 +780,22 @@ function classifyCliError(error, context = {}) {
|
|
|
765
780
|
error = unwrapGenericProjectError(error);
|
|
766
781
|
const rawMessage = cliErrorMessage(error);
|
|
767
782
|
|
|
783
|
+
// HTTP 429: Sogni limits requests per network, and the browser of whoever runs
|
|
784
|
+
// this shares that budget. Say how long to wait, never "try again".
|
|
785
|
+
const rateLimit = rateLimitFromError(error);
|
|
786
|
+
if (rateLimit) {
|
|
787
|
+
const wait = rateLimit.retryAfterSeconds;
|
|
788
|
+
return {
|
|
789
|
+
error_type: 'RATE_LIMITED',
|
|
790
|
+
category: 'rate_limited',
|
|
791
|
+
message: `Sogni is limiting requests from this network (HTTP 429). Wait ${wait ?? 'at least 60'} seconds before any further Sogni request; ` +
|
|
792
|
+
'do not retry sooner and do not poll. To wait for a submitted project, run sogni-agent --result <projectId> --wait once.',
|
|
793
|
+
retryable: true,
|
|
794
|
+
metadata: { status: 429, retryAfterSeconds: wait },
|
|
795
|
+
technicalError: rawMessage
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
|
|
768
799
|
// Client-side CLI rejections are the plain `{ message, code }` shape built by
|
|
769
800
|
// buildCliErrorPayload (never an Error instance and never a vendor poll body).
|
|
770
801
|
// They are argument-validation failures, so skip the HappyHorse terminal
|
|
@@ -845,6 +876,17 @@ function classifyCliError(error, context = {}) {
|
|
|
845
876
|
return classifySkillError(error);
|
|
846
877
|
}
|
|
847
878
|
|
|
879
|
+
/** { retryAfterSeconds } when the error is an HTTP 429 (SDK ApiError or fetchApiJson), else null. */
|
|
880
|
+
function rateLimitFromError(error) {
|
|
881
|
+
if (!error || typeof error !== 'object') return null;
|
|
882
|
+
const statuses = [error.status, error.statusCode, error.details?.status, error.response?.status, error.payload?.status];
|
|
883
|
+
if (error.code !== 'RATE_LIMITED' && !statuses.some((status) => Number(status) === 429)) return null;
|
|
884
|
+
const retryAfter = [error.retryAfter, error.details?.retryAfter, error.payload?.retryAfter]
|
|
885
|
+
.map(Number)
|
|
886
|
+
.find((value) => Number.isFinite(value) && value >= 0);
|
|
887
|
+
return { retryAfterSeconds: retryAfter === undefined ? null : Math.ceil(retryAfter) };
|
|
888
|
+
}
|
|
889
|
+
|
|
848
890
|
const MINIMAX_H3_KEYFRAMES_UNAVAILABLE_CODE = '4100';
|
|
849
891
|
const MINIMAX_H3_KEYFRAMES_UNAVAILABLE_MESSAGE = 'No worker that can pin MiniMax H3 keyframes is online for this model right now. '
|
|
850
892
|
+ 'Try again shortly, or render without --keyframe.';
|
|
@@ -986,6 +1028,19 @@ process.on('unhandledRejection', reportFatalError);
|
|
|
986
1028
|
// Connect to Sogni, mapping a rejected connection into a clean auth error
|
|
987
1029
|
// where we can. (Detached SDK failures that never reach this await are caught
|
|
988
1030
|
// by the global handlers above.)
|
|
1031
|
+
/** The CLI's SDK client, signed in with the API key under one app ID. */
|
|
1032
|
+
function createSkillSogniClient(creds, appId) {
|
|
1033
|
+
return new SogniClientWrapper({
|
|
1034
|
+
appSource: SOGNI_APP_SOURCE,
|
|
1035
|
+
appId,
|
|
1036
|
+
attribution: clientAttribution(AGENT_ATTRIBUTION),
|
|
1037
|
+
network: openclawConfig?.defaultNetwork || 'fast',
|
|
1038
|
+
autoConnect: false,
|
|
1039
|
+
apiKey: creds.SOGNI_API_KEY,
|
|
1040
|
+
authType: 'apiKey'
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
|
|
989
1044
|
async function connectSogniClient(client) {
|
|
990
1045
|
try {
|
|
991
1046
|
await client.connect();
|
|
@@ -1993,6 +2048,55 @@ function getMusicModelDefaults(modelId) {
|
|
|
1993
2048
|
return MUSIC_MODEL_DEFAULTS[normalizeMusicModelId(modelId)] || null;
|
|
1994
2049
|
}
|
|
1995
2050
|
|
|
2051
|
+
/**
|
|
2052
|
+
* Settings on a run that did not name a music model which only ACE-Step can
|
|
2053
|
+
* honour. Such a run uses ACE-Step 1.5 XL Turbo, so commands written before
|
|
2054
|
+
* Music 3 became the default keep working.
|
|
2055
|
+
*/
|
|
2056
|
+
function aceOnlyMusicSettings(opts, set) {
|
|
2057
|
+
const music3 = MUSIC3_DEFAULTS;
|
|
2058
|
+
const turbo = MUSIC_MODEL_DEFAULTS[MUSIC_MODEL_IDS.turbo];
|
|
2059
|
+
const settings = [];
|
|
2060
|
+
if (set.musicShift) settings.push('--music-shift');
|
|
2061
|
+
if (set.musicComposerMode) settings.push(opts.musicComposerMode ? '--composer-mode' : '--no-composer-mode');
|
|
2062
|
+
if (set.musicCreativity) settings.push('--creativity');
|
|
2063
|
+
if (set.duration && Number.isFinite(opts.duration) && opts.duration > music3.duration.max) {
|
|
2064
|
+
settings.push(`--duration ${opts.duration} (Music 3 plays at most ${music3.duration.max} s)`);
|
|
2065
|
+
}
|
|
2066
|
+
if (set.steps && Number.isFinite(opts.steps) && opts.steps < music3.steps.min && opts.steps >= turbo.steps.min) {
|
|
2067
|
+
settings.push(`--steps ${opts.steps}`);
|
|
2068
|
+
}
|
|
2069
|
+
if (set.sampler && opts.sampler && !music3.sampler.allowed.includes(opts.sampler) && turbo.sampler.allowed.includes(opts.sampler)) {
|
|
2070
|
+
settings.push(`--sampler ${opts.sampler}`);
|
|
2071
|
+
}
|
|
2072
|
+
return settings;
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
const MUSIC3_TIME_SIGNATURE_LABELS = { 2: '2/4', 3: '3/4', 4: '4/4', 6: '6/8' };
|
|
2076
|
+
|
|
2077
|
+
function languageName(code) {
|
|
2078
|
+
const raw = String(code || '').trim();
|
|
2079
|
+
if (!/^[a-z]{2,3}(?:-[a-z0-9]{2,8})*$/i.test(raw)) return raw;
|
|
2080
|
+
try {
|
|
2081
|
+
return new Intl.DisplayNames(['en'], { type: 'language' }).of(raw) || raw;
|
|
2082
|
+
} catch {
|
|
2083
|
+
return raw;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
/**
|
|
2088
|
+
* Music 3 has no BPM, key, time-signature or language controls; it reads them
|
|
2089
|
+
* from the prompt. Returns the sentence added to the prompt ('' when none).
|
|
2090
|
+
*/
|
|
2091
|
+
function music3PromptDirections(opts) {
|
|
2092
|
+
const parts = [];
|
|
2093
|
+
if (opts.musicBpm !== null && opts.musicBpm !== undefined) parts.push(`Tempo: ${opts.musicBpm} BPM.`);
|
|
2094
|
+
if (opts.musicKeyscale) parts.push(`Key: ${opts.musicKeyscale}.`);
|
|
2095
|
+
if (opts.musicTimesig) parts.push(`Time signature: ${MUSIC3_TIME_SIGNATURE_LABELS[opts.musicTimesig] || opts.musicTimesig}.`);
|
|
2096
|
+
if (opts.musicLanguage) parts.push(`Sung in ${languageName(opts.musicLanguage)}.`);
|
|
2097
|
+
return parts.join(' ');
|
|
2098
|
+
}
|
|
2099
|
+
|
|
1996
2100
|
function normalizeMusicTimeSignature(value) {
|
|
1997
2101
|
const raw = String(value || '').trim();
|
|
1998
2102
|
if (!raw) return null;
|
|
@@ -3213,6 +3317,8 @@ const options = {
|
|
|
3213
3317
|
cancelOnTimeout: false,
|
|
3214
3318
|
// --status <id> | --result <id> | --recent [hours]
|
|
3215
3319
|
projectLookup: null,
|
|
3320
|
+
// --wait with --status/--result: follow the project over the socket until it ends.
|
|
3321
|
+
projectWait: false,
|
|
3216
3322
|
strictSize: false,
|
|
3217
3323
|
quality: null, // Quality tier: fast|hq|pro — auto-selects model, steps, dimensions
|
|
3218
3324
|
tokenType: null,
|
|
@@ -4542,6 +4648,8 @@ for (let i = 0; i < args.length; i++) {
|
|
|
4542
4648
|
options.detach = true;
|
|
4543
4649
|
} else if (arg === '--cancel-on-timeout') {
|
|
4544
4650
|
options.cancelOnTimeout = true;
|
|
4651
|
+
} else if (arg === '--wait') {
|
|
4652
|
+
options.projectWait = true;
|
|
4545
4653
|
} else if (arg === '--status' || arg === '--result') {
|
|
4546
4654
|
const projectId = requireFlagValue(args, i, arg);
|
|
4547
4655
|
i++;
|
|
@@ -4685,19 +4793,22 @@ Speech Options:
|
|
|
4685
4793
|
|
|
4686
4794
|
Music Options:
|
|
4687
4795
|
--music Generate music/audio instead of image
|
|
4688
|
-
--music-model <id> Music model: music3|turbo|sft (or full model ID
|
|
4689
|
-
--lyrics <text> Song lyrics; Music 3
|
|
4690
|
-
|
|
4691
|
-
--
|
|
4796
|
+
--music-model <id> Music model: music3 (default, MiniMax Music 3)|turbo|sft (ACE-Step), or full model ID
|
|
4797
|
+
--lyrics <text> Song lyrics; Music 3 uses plain section tags ([Verse], [Chorus]) and gets an
|
|
4798
|
+
[Intro]..[Outro] section skeleton when no lyrics are given
|
|
4799
|
+
--language <code> Lyrics language code (ACE-Step; Music 3 gets it in the prompt)
|
|
4800
|
+
--duration <sec> Music 3: 10–300s, default 60, a ceiling; ACE-Step: 10–600s, default 30
|
|
4692
4801
|
--length <sec> Alias for --duration
|
|
4693
|
-
--bpm <num> Beats per minute (30-300)
|
|
4694
|
-
--keyscale <text> Key/scale, e.g. "C major"
|
|
4695
|
-
--timesig <n> Time signature: 2|3|4|6 (also accepts 4/4)
|
|
4696
|
-
--composer-mode Enable AI composer mode
|
|
4697
|
-
--no-composer-mode Disable AI composer mode
|
|
4802
|
+
--bpm <num> Beats per minute (30-300; ACE-Step control, Music 3 gets it in the prompt)
|
|
4803
|
+
--keyscale <text> Key/scale, e.g. "C major" (ACE-Step control, Music 3 gets it in the prompt)
|
|
4804
|
+
--timesig <n> Time signature: 2|3|4|6 (also accepts 4/4; Music 3 gets it in the prompt)
|
|
4805
|
+
--composer-mode Enable AI composer mode (ACE-Step only)
|
|
4806
|
+
--no-composer-mode Disable AI composer mode (ACE-Step only)
|
|
4698
4807
|
--prompt-strength <n> Prompt adherence (0-10)
|
|
4699
|
-
--creativity <n> Composition variation/temperature (0-2)
|
|
4700
|
-
--music-shift <n> Audio model shift parameter (1-6)
|
|
4808
|
+
--creativity <n> Composition variation/temperature (0-2, ACE-Step only)
|
|
4809
|
+
--music-shift <n> Audio model shift parameter (1-6, ACE-Step only)
|
|
4810
|
+
Without --music-model, an ACE-Step-only setting or a duration over 300s
|
|
4811
|
+
runs on ACE-Step 1.5 XL Turbo and says so on stderr
|
|
4701
4812
|
--audio-format <f> Alias for --output-format: mp3|flac|wav
|
|
4702
4813
|
|
|
4703
4814
|
Video Options:
|
|
@@ -4829,10 +4940,13 @@ General:
|
|
|
4829
4940
|
later with --result
|
|
4830
4941
|
--cancel-on-timeout Cancel the project when --timeout runs out (the pre-3.53 behavior)
|
|
4831
4942
|
--detach, --no-wait Submit, print the project id, and exit without waiting. The project keeps
|
|
4832
|
-
running;
|
|
4943
|
+
running; follow it with --result <projectId> --wait
|
|
4833
4944
|
--status <projectId> Show a project's state and, while queued, why it is waiting
|
|
4834
4945
|
--result <projectId> Fetch a finished project's media (saved to -o when given), including one
|
|
4835
4946
|
that finished after an earlier run stopped waiting
|
|
4947
|
+
--wait With --status/--result: wait over the live connection until the project
|
|
4948
|
+
ends, then report it (bounded by --timeout, default 1800 s). Use this
|
|
4949
|
+
instead of re-running --status in a loop
|
|
4836
4950
|
--recent [hours] List this account's completed projects from the last N hours
|
|
4837
4951
|
(default 24, max 168); fetch one with --result
|
|
4838
4952
|
--steps <num> Override steps (model-dependent)
|
|
@@ -4950,8 +5064,9 @@ Video Upscale Model:
|
|
|
4950
5064
|
flashvsr_v1.1_tiny_long_bf16 Promptless FlashVSR upscale to 1080p/1440p (--upscale-video)
|
|
4951
5065
|
|
|
4952
5066
|
Music Models:
|
|
4953
|
-
|
|
4954
|
-
ace_step_1.
|
|
5067
|
+
minimax_music3 Default music generation (MiniMax Music 3, 10–300s)
|
|
5068
|
+
ace_step_1.5_xl_turbo ACE-Step draft model with exact BPM/key controls, up to 600s
|
|
5069
|
+
ace_step_1.5_xl_sft ACE-Step variant with stronger lyric handling
|
|
4955
5070
|
ace_step_1.5_turbo Legacy direct music generation
|
|
4956
5071
|
ace_step_1.5_sft Legacy lyric-focused music generation
|
|
4957
5072
|
|
|
@@ -5065,7 +5180,8 @@ Examples:
|
|
|
5065
5180
|
sogni-agent --source-reel ./images --reel-plan-only
|
|
5066
5181
|
sogni-agent --source-reel ./images --reel-image-seconds 3 --reel-transition-seconds 3 --reel-image-prompt "friendly camera-ready motion"
|
|
5067
5182
|
sogni-agent --music --duration 30 "uplifting cinematic synthwave theme for a product launch"
|
|
5068
|
-
sogni-agent --music --lyrics
|
|
5183
|
+
sogni-agent --music --lyrics $'[Verse]\\nRise with the morning light\\n[Chorus]\\nWe run' --output-format mp3 "bright indie pop chorus, 128 BPM, C major"
|
|
5184
|
+
sogni-agent --music -m turbo --bpm 128 --keyscale "C major" "bright indie pop chorus"
|
|
5069
5185
|
sogni-agent --video --reference-audio-identity voice.webm 'NARRATOR: "This is my voice."'
|
|
5070
5186
|
sogni-agent --api-chat "Create a 4-shot product video concept for a red sneaker"
|
|
5071
5187
|
sogni-agent --api-workflow --video-prompt "slow push-in as it comes alive" "a graphite robot sketch"
|
|
@@ -5257,7 +5373,7 @@ if (options.quality) {
|
|
|
5257
5373
|
});
|
|
5258
5374
|
}
|
|
5259
5375
|
if (options.music) {
|
|
5260
|
-
fatalCliError('--quality is not used for --music. Use --music-model turbo|sft for music model selection.', {
|
|
5376
|
+
fatalCliError('--quality is not used for --music. Use --music-model music3|turbo|sft for music model selection.', {
|
|
5261
5377
|
code: 'INVALID_ARGUMENT'
|
|
5262
5378
|
});
|
|
5263
5379
|
}
|
|
@@ -5868,7 +5984,7 @@ if (options._lastImagePath) {
|
|
|
5868
5984
|
|
|
5869
5985
|
// Set defaults based on type and context
|
|
5870
5986
|
if (options.music) {
|
|
5871
|
-
const configuredMusicModel = options.model || openclawConfig?.defaultMusicModel ||
|
|
5987
|
+
const configuredMusicModel = options.model || openclawConfig?.defaultMusicModel || DEFAULT_MUSIC_MODEL;
|
|
5872
5988
|
options.model = normalizeMusicModelId(configuredMusicModel);
|
|
5873
5989
|
if (!options.model) {
|
|
5874
5990
|
fatalCliError(`Unknown music model "${configuredMusicModel}". Use music3, turbo, sft, minimax_music3, ace_step_1.5_xl_turbo, or ace_step_1.5_xl_sft.`, {
|
|
@@ -5876,6 +5992,33 @@ if (options.music) {
|
|
|
5876
5992
|
details: { flag: cliSet.model ? '--model' : 'defaultMusicModel', value: configuredMusicModel }
|
|
5877
5993
|
});
|
|
5878
5994
|
}
|
|
5995
|
+
// A run that names Music 3 with -m keeps the hard error for ACE-only
|
|
5996
|
+
// controls below. A run that only inherits it as the default uses ACE-Step
|
|
5997
|
+
// Turbo when it asks for an ACE-only setting, and otherwise gets its
|
|
5998
|
+
// tempo, key, time signature and language written into the prompt.
|
|
5999
|
+
if (options.model === MUSIC3_MODEL_ID && !cliSet.model) {
|
|
6000
|
+
const aceOnly = aceOnlyMusicSettings(options, cliSet);
|
|
6001
|
+
if (aceOnly.length > 0) {
|
|
6002
|
+
options.model = MUSIC_MODEL_IDS.turbo;
|
|
6003
|
+
console.error(`Note: ${aceOnly.join(', ')} ${aceOnly.length === 1 ? 'is an ACE-Step setting' : 'are ACE-Step settings'}, so this run uses ACE-Step 1.5 XL Turbo (-m turbo). Leave ${aceOnly.length === 1 ? 'it' : 'them'} out to use the default, MiniMax Music 3.`);
|
|
6004
|
+
} else {
|
|
6005
|
+
if (options.musicTimesig && !MUSIC_TIME_SIGNATURES.has(options.musicTimesig)) {
|
|
6006
|
+
fatalCliError('--timesig must be one of 2, 3, 4, or 6.', {
|
|
6007
|
+
code: 'INVALID_ARGUMENT',
|
|
6008
|
+
details: { timesig: options.musicTimesig }
|
|
6009
|
+
});
|
|
6010
|
+
}
|
|
6011
|
+
const directions = music3PromptDirections(options);
|
|
6012
|
+
if (directions) {
|
|
6013
|
+
options.prompt = `${String(options.prompt || '').trim()} ${directions}`.trim();
|
|
6014
|
+
options.musicBpm = null;
|
|
6015
|
+
options.musicKeyscale = null;
|
|
6016
|
+
options.musicTimesig = null;
|
|
6017
|
+
options.musicLanguage = null;
|
|
6018
|
+
console.error(`Note: MiniMax Music 3 reads tempo, key, time signature and language from the prompt, so "${directions}" was added to it. Pass -m turbo for ACE-Step's exact controls.`);
|
|
6019
|
+
}
|
|
6020
|
+
}
|
|
6021
|
+
}
|
|
5879
6022
|
const musicDefaults = getMusicModelDefaults(options.model);
|
|
5880
6023
|
if (!cliSet.duration || !Number.isFinite(options.duration)) {
|
|
5881
6024
|
options.duration = (musicDefaults.duration || MUSIC_DURATION_LIMITS).default;
|
|
@@ -6122,8 +6265,11 @@ if (!options.video && !options.music && isGptImage2ModelSelection(options.model)
|
|
|
6122
6265
|
if (options.music) {
|
|
6123
6266
|
const musicDefaults = getMusicModelDefaults(options.model);
|
|
6124
6267
|
const durationLimits = musicDefaults.duration || MUSIC_DURATION_LIMITS;
|
|
6125
|
-
if (options.model === MUSIC3_MODEL_ID && (cliSet.musicShift || cliSet.musicBpm || cliSet.musicKeyscale || cliSet.musicTimesig || cliSet.musicLanguage || cliSet.musicComposerMode)) {
|
|
6126
|
-
fatalCliError('Music 3 does not use shift, BPM, key, time signature, language, or composer controls. Describe musical direction in the prompt and lyrics.', { code: 'INVALID_ARGUMENT' });
|
|
6268
|
+
if (options.model === MUSIC3_MODEL_ID && cliSet.model && (cliSet.musicShift || cliSet.musicBpm || cliSet.musicKeyscale || cliSet.musicTimesig || cliSet.musicLanguage || cliSet.musicComposerMode)) {
|
|
6269
|
+
fatalCliError('Music 3 does not use shift, BPM, key, time signature, language, or composer controls. Describe musical direction in the prompt and lyrics, or pass -m turbo for ACE-Step.', { code: 'INVALID_ARGUMENT' });
|
|
6270
|
+
}
|
|
6271
|
+
if (options.model === MUSIC3_MODEL_ID && !options.musicLyrics) {
|
|
6272
|
+
options.musicLyrics = MUSIC3_INSTRUMENTAL_SECTIONS;
|
|
6127
6273
|
}
|
|
6128
6274
|
if (options.duration < durationLimits.min || options.duration > durationLimits.max) {
|
|
6129
6275
|
fatalCliError(`Music duration must be between ${durationLimits.min} and ${durationLimits.max} seconds.`, {
|
|
@@ -6272,6 +6418,14 @@ if (!options.prompt && !options.projectLookup && !wan3HasMediaInput && !options.
|
|
|
6272
6418
|
fatalCliError('No prompt provided. Use --help for usage.', { code: 'INVALID_ARGUMENT' });
|
|
6273
6419
|
}
|
|
6274
6420
|
|
|
6421
|
+
// --wait follows one project that already exists; it never submits anything.
|
|
6422
|
+
if (options.projectWait && !(options.projectLookup && options.projectLookup.action !== 'recent')) {
|
|
6423
|
+
fatalCliError('--wait follows one project: use it with --status <projectId> or --result <projectId>.', {
|
|
6424
|
+
code: 'INVALID_ARGUMENT',
|
|
6425
|
+
details: { flag: '--wait' }
|
|
6426
|
+
});
|
|
6427
|
+
}
|
|
6428
|
+
|
|
6275
6429
|
// --detach returns after the first submission, so it only fits a run that
|
|
6276
6430
|
// submits one project up front; these flows submit more after the first ends.
|
|
6277
6431
|
if (options.detach) {
|
|
@@ -7971,13 +8125,27 @@ async function fetchApiJson(path, {
|
|
|
7971
8125
|
}
|
|
7972
8126
|
if (!response.ok) {
|
|
7973
8127
|
const err = new Error(payload?.message || payload?.error?.message || response.statusText || 'Sogni API request failed');
|
|
7974
|
-
err.code = 'API_REQUEST_FAILED';
|
|
8128
|
+
err.code = response.status === 429 ? 'RATE_LIMITED' : 'API_REQUEST_FAILED';
|
|
7975
8129
|
err.details = { url, status: response.status, payload };
|
|
8130
|
+
const retryAfter = parseRetryAfterSeconds(response.headers?.get?.('retry-after'));
|
|
8131
|
+
if (retryAfter !== null) {
|
|
8132
|
+
err.retryAfter = retryAfter;
|
|
8133
|
+
err.details.retryAfter = retryAfter;
|
|
8134
|
+
}
|
|
7976
8135
|
throw err;
|
|
7977
8136
|
}
|
|
7978
8137
|
return payload;
|
|
7979
8138
|
}
|
|
7980
8139
|
|
|
8140
|
+
/** A Retry-After header (seconds or an HTTP date) in whole seconds, or null. */
|
|
8141
|
+
function parseRetryAfterSeconds(value) {
|
|
8142
|
+
if (value === null || value === undefined || value === '') return null;
|
|
8143
|
+
const seconds = Number(value);
|
|
8144
|
+
if (Number.isFinite(seconds) && seconds >= 0) return Math.ceil(seconds);
|
|
8145
|
+
const at = Date.parse(value);
|
|
8146
|
+
return Number.isFinite(at) ? Math.max(0, Math.ceil((at - Date.now()) / 1000)) : null;
|
|
8147
|
+
}
|
|
8148
|
+
|
|
7981
8149
|
function getApiModeMediaReferences() {
|
|
7982
8150
|
const refs = [];
|
|
7983
8151
|
for (const value of options.contextImages || []) {
|
|
@@ -8084,12 +8252,6 @@ function apiMediaReferenceEndpoint(ref, action) {
|
|
|
8084
8252
|
: `/v1/media/${action}Url`;
|
|
8085
8253
|
}
|
|
8086
8254
|
|
|
8087
|
-
function apiMediaReferenceV2Endpoint(ref, action) {
|
|
8088
|
-
return ref.kind === 'image'
|
|
8089
|
-
? `/v2/image/${action}Url`
|
|
8090
|
-
: `/v2/media/${action}Url`;
|
|
8091
|
-
}
|
|
8092
|
-
|
|
8093
8255
|
function apiMediaReferenceUrlPath(ref, file, index, action, jobId) {
|
|
8094
8256
|
const params = new URLSearchParams();
|
|
8095
8257
|
params.set('type', apiMediaReferenceUploadType(ref, index));
|
|
@@ -8103,19 +8265,6 @@ function apiMediaReferenceUrlPath(ref, file, index, action, jobId) {
|
|
|
8103
8265
|
return `${apiMediaReferenceEndpoint(ref, action)}?${params.toString()}`;
|
|
8104
8266
|
}
|
|
8105
8267
|
|
|
8106
|
-
function apiMediaReferenceV2UrlPath(ref, file, index, action, jobId) {
|
|
8107
|
-
const params = new URLSearchParams();
|
|
8108
|
-
params.set('type', apiMediaReferenceUploadType(ref, index));
|
|
8109
|
-
params.set('jobId', jobId);
|
|
8110
|
-
params.set('contentType', file.mimeType);
|
|
8111
|
-
if (ref.kind === 'image') {
|
|
8112
|
-
params.set('imageId', `media_ref_${index + 1}`);
|
|
8113
|
-
} else {
|
|
8114
|
-
params.set('id', `media_ref_${index + 1}`);
|
|
8115
|
-
}
|
|
8116
|
-
return `${apiMediaReferenceV2Endpoint(ref, action)}?${params.toString()}`;
|
|
8117
|
-
}
|
|
8118
|
-
|
|
8119
8268
|
function apiStoredMediaUrl(payload, key) {
|
|
8120
8269
|
const data = extractApiEnvelopeData(payload);
|
|
8121
8270
|
const value = data?.[key] || payload?.[key];
|
|
@@ -8126,41 +8275,6 @@ function apiStoredMediaUrl(payload, key) {
|
|
|
8126
8275
|
throw err;
|
|
8127
8276
|
}
|
|
8128
8277
|
|
|
8129
|
-
function apiStoredMediaUploadPost(payload) {
|
|
8130
|
-
const data = extractApiEnvelopeData(payload);
|
|
8131
|
-
const url = data?.url || data?.uploadUrl;
|
|
8132
|
-
if (typeof url === 'string' && url) {
|
|
8133
|
-
const fields = data?.fields && typeof data.fields === 'object' ? data.fields : {};
|
|
8134
|
-
return { url, fields };
|
|
8135
|
-
}
|
|
8136
|
-
const err = new Error('Sogni API did not return a presigned POST URL for media reference upload.');
|
|
8137
|
-
err.code = 'MEDIA_UPLOAD_FAILED';
|
|
8138
|
-
err.details = { payload };
|
|
8139
|
-
throw err;
|
|
8140
|
-
}
|
|
8141
|
-
|
|
8142
|
-
async function postApiMediaUploadForm(uploadPayload, file) {
|
|
8143
|
-
const { url, fields } = apiStoredMediaUploadPost(uploadPayload);
|
|
8144
|
-
const form = new FormData();
|
|
8145
|
-
for (const [key, value] of Object.entries(fields)) {
|
|
8146
|
-
if (value === undefined || value === null) continue;
|
|
8147
|
-
form.append(key, String(value));
|
|
8148
|
-
}
|
|
8149
|
-
const body = file.buffer || readFileSync(file.filePath);
|
|
8150
|
-
form.append('file', new Blob([body], { type: file.mimeType }), file.filename);
|
|
8151
|
-
|
|
8152
|
-
const response = await fetchWithTimeout(url, {
|
|
8153
|
-
method: 'POST',
|
|
8154
|
-
body: form,
|
|
8155
|
-
}, UPLOAD_HTTP_TIMEOUT_MS);
|
|
8156
|
-
if (!response.ok) {
|
|
8157
|
-
const err = new Error(`Failed to upload ${file.filename} (${response.status} ${response.statusText}).`);
|
|
8158
|
-
err.code = 'MEDIA_UPLOAD_FAILED';
|
|
8159
|
-
err.details = { uploadUrl: url, status: response.status, statusText: response.statusText };
|
|
8160
|
-
throw err;
|
|
8161
|
-
}
|
|
8162
|
-
}
|
|
8163
|
-
|
|
8164
8278
|
async function putApiMediaUpload(uploadUrl, file) {
|
|
8165
8279
|
const response = await fetchWithTimeout(uploadUrl, {
|
|
8166
8280
|
method: 'PUT',
|
|
@@ -8253,29 +8367,44 @@ async function uploadPreparedApiMediaReference(ref, index, apiKey, file) {
|
|
|
8253
8367
|
};
|
|
8254
8368
|
}
|
|
8255
8369
|
|
|
8256
|
-
|
|
8370
|
+
// Seedance, Wan 3 and HappyHorse reference media used to upload through the
|
|
8371
|
+
// /v2 presigned form POST, whose storage policy enforced the API's limits.
|
|
8372
|
+
// Sogni's generation storage (Cloudflare R2) has no form POST, so these now
|
|
8373
|
+
// take the same /v1 presigned PUT as every other reference, like the SDK. A PUT
|
|
8374
|
+
// URL signs only the object and its Content-Type, so the limits the policy used
|
|
8375
|
+
// to enforce are checked here before any bytes are sent: the API's 100 MiB
|
|
8376
|
+
// ceiling (MAX_UPLOAD_SIZE_BYTES in sogni-api) and a content type the API
|
|
8377
|
+
// accepts for that kind of reference.
|
|
8378
|
+
function assertVendorReferenceUploadAllowed(ref, file) {
|
|
8379
|
+
const allowed = VENDOR_REFERENCE_UPLOAD_CONTENT_TYPES[ref.kind] || [];
|
|
8380
|
+
const mimeType = String(file.mimeType || '').trim().toLowerCase();
|
|
8381
|
+
if (!allowed.includes(mimeType)) {
|
|
8382
|
+
const err = new Error(
|
|
8383
|
+
`${ref.flag} ${ref.kind} reference "${file.filename}" is ${file.mimeType || 'of an unknown type'}; ` +
|
|
8384
|
+
`Sogni accepts ${allowed.join(', ')} for ${ref.kind} references.`,
|
|
8385
|
+
);
|
|
8386
|
+
err.code = 'UNSUPPORTED_MEDIA_TYPE';
|
|
8387
|
+
err.details = { flag: ref.flag, kind: ref.kind, filename: file.filename, mimeType: file.mimeType, allowed };
|
|
8388
|
+
throw err;
|
|
8389
|
+
}
|
|
8390
|
+
const byteLength = Number(file.byteLength ?? file.buffer?.length ?? 0);
|
|
8391
|
+
const maxBytes = Math.min(apiMediaReferenceMaxBytes(), API_MEDIA_REFERENCE_UPLOAD_MAX_BYTES);
|
|
8392
|
+
if (byteLength > maxBytes) {
|
|
8393
|
+
const err = new Error(`${ref.flag} media reference is ${byteLength} bytes, above the ${maxBytes} byte API upload limit.`);
|
|
8394
|
+
err.code = 'MEDIA_REFERENCE_TOO_LARGE';
|
|
8395
|
+
err.details = { flag: ref.flag, filename: file.filename, byteLength, maxBytes };
|
|
8396
|
+
throw err;
|
|
8397
|
+
}
|
|
8398
|
+
}
|
|
8399
|
+
|
|
8400
|
+
async function uploadVendorReferenceMedia(ref, index, apiKey, file) {
|
|
8257
8401
|
if (!apiKey) {
|
|
8258
8402
|
const err = new Error(`${ref.flag} media references require SOGNI_API_KEY so the CLI can upload them before execution.`);
|
|
8259
8403
|
err.code = 'MISSING_API_KEY';
|
|
8260
8404
|
throw err;
|
|
8261
8405
|
}
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
await postApiMediaUploadForm(uploadPayload, file);
|
|
8265
|
-
const downloadPayload = await fetchApiJson(apiMediaReferenceV2UrlPath(ref, file, index, 'download', jobId), { apiKey });
|
|
8266
|
-
const url = apiStoredMediaUrl(downloadPayload, 'downloadUrl');
|
|
8267
|
-
return {
|
|
8268
|
-
url,
|
|
8269
|
-
filename: file.filename,
|
|
8270
|
-
byte_length: file.byteLength,
|
|
8271
|
-
mime_type: file.mimeType,
|
|
8272
|
-
prompt_label: file.filename,
|
|
8273
|
-
storage: {
|
|
8274
|
-
jobId,
|
|
8275
|
-
type: apiMediaReferenceUploadType(ref, index),
|
|
8276
|
-
version: 'v2',
|
|
8277
|
-
},
|
|
8278
|
-
};
|
|
8406
|
+
assertVendorReferenceUploadAllowed(ref, file);
|
|
8407
|
+
return uploadPreparedApiMediaReference(ref, index, apiKey, file);
|
|
8279
8408
|
}
|
|
8280
8409
|
|
|
8281
8410
|
async function uploadLocalApiMediaReference(ref, index, apiKey) {
|
|
@@ -10862,7 +10991,7 @@ async function uploadSeedanceReferenceAudioUrl(pathOrUrl, apiKey, index = 0) {
|
|
|
10862
10991
|
const ref = { flag: '--ref-audio', value: pathOrUrl, kind: 'audio' };
|
|
10863
10992
|
const buffer = await fetchMediaBuffer(pathOrUrl);
|
|
10864
10993
|
const file = await prepareSeedanceReferenceAudioUploadFile(pathOrUrl, buffer);
|
|
10865
|
-
const uploaded = await
|
|
10994
|
+
const uploaded = await uploadVendorReferenceMedia(ref, index, apiKey, file);
|
|
10866
10995
|
return uploaded.url;
|
|
10867
10996
|
}
|
|
10868
10997
|
|
|
@@ -10870,7 +10999,7 @@ async function uploadSeedanceReferenceVideoUrl(pathOrUrl, apiKey, index = 0) {
|
|
|
10870
10999
|
const ref = { flag: '--ref-video', value: pathOrUrl, kind: 'video' };
|
|
10871
11000
|
const buffer = await fetchMediaBuffer(pathOrUrl);
|
|
10872
11001
|
const file = await prepareSeedanceReferenceVideoUploadFile(pathOrUrl, buffer);
|
|
10873
|
-
const uploaded = await
|
|
11002
|
+
const uploaded = await uploadVendorReferenceMedia(ref, index, apiKey, file);
|
|
10874
11003
|
return uploaded.url;
|
|
10875
11004
|
}
|
|
10876
11005
|
|
|
@@ -10899,7 +11028,7 @@ async function uploadWan3ReferenceAudioUrl(pathOrUrl, apiKey, index) {
|
|
|
10899
11028
|
sourceFormat,
|
|
10900
11029
|
});
|
|
10901
11030
|
const data = Buffer.from(prepared.data);
|
|
10902
|
-
const uploaded = await
|
|
11031
|
+
const uploaded = await uploadVendorReferenceMedia(ref, index, apiKey, {
|
|
10903
11032
|
buffer: data,
|
|
10904
11033
|
filename: withMediaExtension(inspected.filename, 'mp3'),
|
|
10905
11034
|
byteLength: data.length,
|
|
@@ -10922,7 +11051,7 @@ async function uploadWan3ReferenceVideoUrl(pathOrUrl, apiKey, index) {
|
|
|
10922
11051
|
: { data: inspected.buffer, mimeType: mimeTypeForPath(pathOrUrl, 'video/mp4') };
|
|
10923
11052
|
const data = Buffer.from(prepared.data);
|
|
10924
11053
|
const outputMimeType = prepared.mimeType || 'video/mp4';
|
|
10925
|
-
const uploaded = await
|
|
11054
|
+
const uploaded = await uploadVendorReferenceMedia(ref, index, apiKey, {
|
|
10926
11055
|
buffer: data,
|
|
10927
11056
|
filename: withMediaExtension(
|
|
10928
11057
|
inspected.filename,
|
|
@@ -10935,9 +11064,9 @@ async function uploadWan3ReferenceVideoUrl(pathOrUrl, apiKey, index) {
|
|
|
10935
11064
|
}
|
|
10936
11065
|
|
|
10937
11066
|
// Content types the Sogni media pipeline accepts for image references, mirroring
|
|
10938
|
-
// the
|
|
10939
|
-
//
|
|
10940
|
-
//
|
|
11067
|
+
// the API's image upload allowlist (ALLOWED_IMAGE_CONTENT_TYPES in sogni-api).
|
|
11068
|
+
// Kept as a constant so the skill validates exactly what the backend will store
|
|
11069
|
+
// rather than imposing a narrower client-side policy.
|
|
10941
11070
|
const SEEDANCE_REFERENCE_IMAGE_MIME_TYPES = Object.freeze([
|
|
10942
11071
|
'image/png', 'image/jpeg', 'image/webp', 'image/gif',
|
|
10943
11072
|
]);
|
|
@@ -11008,7 +11137,7 @@ async function uploadSeedanceReferenceImageUrl(pathOrUrl, apiKey, index = 0) {
|
|
|
11008
11137
|
const ref = { flag: '-c/--context', value: pathOrUrl, kind: 'image' };
|
|
11009
11138
|
const buffer = await fetchMediaBuffer(pathOrUrl);
|
|
11010
11139
|
const file = await prepareSeedanceReferenceImageUploadFile(pathOrUrl, buffer);
|
|
11011
|
-
const uploaded = await
|
|
11140
|
+
const uploaded = await uploadVendorReferenceMedia(ref, index, apiKey, file);
|
|
11012
11141
|
return uploaded.url;
|
|
11013
11142
|
}
|
|
11014
11143
|
|
|
@@ -12405,6 +12534,11 @@ function resultCommandFor(projectId) {
|
|
|
12405
12534
|
return `sogni-agent --result ${projectId}`;
|
|
12406
12535
|
}
|
|
12407
12536
|
|
|
12537
|
+
/** The shell command that waits for a project over the socket, then fetches it. */
|
|
12538
|
+
function waitCommandFor(projectId) {
|
|
12539
|
+
return `sogni-agent --result ${projectId} --wait`;
|
|
12540
|
+
}
|
|
12541
|
+
|
|
12408
12542
|
/**
|
|
12409
12543
|
* Wait bookkeeping for one run's projects. It announces each project id as
|
|
12410
12544
|
* soon as the project is submitted, reports why a project is queued in the
|
|
@@ -12505,6 +12639,34 @@ function createProjectWaitTracker(client, log, timeoutMs = options.timeout) {
|
|
|
12505
12639
|
};
|
|
12506
12640
|
}
|
|
12507
12641
|
|
|
12642
|
+
// SOGNI_AGENT_DETACH_ACK_TIMEOUT_MS shortens it for tests.
|
|
12643
|
+
const DETACH_ACK_TIMEOUT_MS = Number(process.env.SOGNI_AGENT_DETACH_ACK_TIMEOUT_MS) > 0 ? Number(process.env.SOGNI_AGENT_DETACH_ACK_TIMEOUT_MS) : 30_000;
|
|
12644
|
+
|
|
12645
|
+
/**
|
|
12646
|
+
* Wait until the server has answered every submitted project (queued, started or refused):
|
|
12647
|
+
* until then the request may only be buffered on this process's socket. Resolves the ids
|
|
12648
|
+
* that got no answer within DETACH_ACK_TIMEOUT_MS.
|
|
12649
|
+
*/
|
|
12650
|
+
async function awaitServerAnswer(projects, timeoutMs = DETACH_ACK_TIMEOUT_MS) {
|
|
12651
|
+
const answered = (project) => project?.status && project.status !== 'pending';
|
|
12652
|
+
await Promise.all(projects.map((project) => {
|
|
12653
|
+
if (!project?.id || answered(project) || typeof project.on !== 'function') return null;
|
|
12654
|
+
return new Promise((resolve) => {
|
|
12655
|
+
const done = () => {
|
|
12656
|
+
clearTimeout(timer);
|
|
12657
|
+
project.off?.('updated', check);
|
|
12658
|
+
project.off?.('failed', done);
|
|
12659
|
+
resolve();
|
|
12660
|
+
};
|
|
12661
|
+
const check = () => { if (answered(project)) done(); };
|
|
12662
|
+
const timer = setTimeout(done, timeoutMs);
|
|
12663
|
+
project.on('updated', check);
|
|
12664
|
+
project.on('failed', done);
|
|
12665
|
+
});
|
|
12666
|
+
}));
|
|
12667
|
+
return projects.filter((project) => project?.id && !answered(project)).map((project) => project.id);
|
|
12668
|
+
}
|
|
12669
|
+
|
|
12508
12670
|
/**
|
|
12509
12671
|
* Report projects submitted with --detach: they keep running on Sogni, and
|
|
12510
12672
|
* --status / --result fetch them later, including after the socket has stopped
|
|
@@ -12519,7 +12681,8 @@ function reportDetachedProjects(projects, projectWait) {
|
|
|
12519
12681
|
waitingReason,
|
|
12520
12682
|
message: describeWaitingReason(waitingReason),
|
|
12521
12683
|
statusCommand: `sogni-agent --status ${projectId}`,
|
|
12522
|
-
resultCommand: resultCommandFor(projectId)
|
|
12684
|
+
resultCommand: resultCommandFor(projectId),
|
|
12685
|
+
waitCommand: waitCommandFor(projectId)
|
|
12523
12686
|
};
|
|
12524
12687
|
});
|
|
12525
12688
|
if (options.json) {
|
|
@@ -12528,15 +12691,15 @@ function reportDetachedProjects(projects, projectWait) {
|
|
|
12528
12691
|
detached: true,
|
|
12529
12692
|
projectIds,
|
|
12530
12693
|
projects: entries,
|
|
12531
|
-
note: 'Submitted and still running on Sogni. Nothing was cancelled.
|
|
12694
|
+
note: 'Submitted and still running on Sogni. Nothing was cancelled. Run the waitCommand once to wait for it and fetch it; do not re-run statusCommand in a loop (at most once a minute), and do not resubmit it.'
|
|
12532
12695
|
}));
|
|
12533
12696
|
return;
|
|
12534
12697
|
}
|
|
12535
12698
|
for (const entry of entries) {
|
|
12536
12699
|
console.log(`Submitted Sogni project ${entry.projectId}; it keeps running on Sogni.`);
|
|
12537
12700
|
if (entry.message) console.log(entry.message);
|
|
12538
|
-
console.log(`
|
|
12539
|
-
console.log(`
|
|
12701
|
+
console.log(`Wait for it and fetch the result: ${entry.waitCommand}`);
|
|
12702
|
+
console.log(`Check it without waiting (at most once a minute): ${entry.statusCommand}`);
|
|
12540
12703
|
}
|
|
12541
12704
|
}
|
|
12542
12705
|
|
|
@@ -12658,8 +12821,8 @@ async function warnAboutInFlightProjects(client, log) {
|
|
|
12658
12821
|
'so this one may wait for them. If it does, it starts by itself; do not resubmit it.');
|
|
12659
12822
|
}
|
|
12660
12823
|
|
|
12661
|
-
/** --status <id>, --result <id>, --recent [hours]. */
|
|
12662
|
-
async function runProjectLookup(client, lookup) {
|
|
12824
|
+
/** --status <id>, --result <id>, --recent [hours]; with --wait, after the project ends. */
|
|
12825
|
+
async function runProjectLookup(client, lookup, { log = () => {}, creds } = {}) {
|
|
12663
12826
|
const projectsApi = sdkClientOf(client)?.projects;
|
|
12664
12827
|
const method = lookup.action === 'recent' ? 'listRecent' : 'getResult';
|
|
12665
12828
|
if (typeof projectsApi?.[method] !== 'function') {
|
|
@@ -12672,11 +12835,128 @@ async function runProjectLookup(client, lookup) {
|
|
|
12672
12835
|
printRecentProjects(projects, lookup.hours);
|
|
12673
12836
|
return;
|
|
12674
12837
|
}
|
|
12838
|
+
if (options.projectWait) {
|
|
12839
|
+
const timeoutMs = cliSet.timeout ? options.timeout : PROJECT_WAIT_DEFAULT_TIMEOUT_MS;
|
|
12840
|
+
await followProjectToEnd(client, lookup.projectId, { log, creds, timeoutMs });
|
|
12841
|
+
}
|
|
12675
12842
|
const result = await projectsApi.getResult(lookup.projectId);
|
|
12676
12843
|
if (lookup.action === 'status') printProjectStatus(result);
|
|
12677
12844
|
else await saveProjectResult(result);
|
|
12678
12845
|
}
|
|
12679
12846
|
|
|
12847
|
+
const PROJECT_WAIT_DEFAULT_TIMEOUT_MS = 1800 * 1000;
|
|
12848
|
+
// A project whose events go to another live process or app can only be watched
|
|
12849
|
+
// through the socket's list of in-flight projects; never more than once a minute.
|
|
12850
|
+
function inFlightCheckIntervalMs() {
|
|
12851
|
+
const testValue = getEnv('SOGNI_AGENT_TEST_STATE_PATH') ? Number(getEnv('SOGNI_AGENT_TEST_IN_FLIGHT_CHECK_MS')) : NaN;
|
|
12852
|
+
return Number.isFinite(testValue) && testValue > 0 ? testValue : 60 * 1000;
|
|
12853
|
+
}
|
|
12854
|
+
|
|
12855
|
+
/** Sync this client's projects with the socket, then return the tracked one with this id. */
|
|
12856
|
+
async function trackedProjectAfterSync(projectsApi, projectId) {
|
|
12857
|
+
await projectsApi.sync('wait');
|
|
12858
|
+
return (projectsApi.trackedProjects || []).find((project) => project?.id === projectId) || null;
|
|
12859
|
+
}
|
|
12860
|
+
|
|
12861
|
+
/**
|
|
12862
|
+
* --wait: follow a project to its end over the socket, never by re-reading its
|
|
12863
|
+
* status. The socket delivers a project's events only to the app ID that
|
|
12864
|
+
* submitted it, so one submitted from another of this installation's app-ID
|
|
12865
|
+
* slots is taken back by signing in as that slot, unless a live process holds
|
|
12866
|
+
* it. A project held by a live process or by another app (Sogni Web, another
|
|
12867
|
+
* device) is watched through the socket's in-flight list, once a minute, until
|
|
12868
|
+
* it leaves. Returns when the project ended or the socket no longer holds it;
|
|
12869
|
+
* the caller then reads the result once.
|
|
12870
|
+
*/
|
|
12871
|
+
async function followProjectToEnd(client, projectId, { log, creds, timeoutMs }) {
|
|
12872
|
+
const projectsApi = sdkClientOf(client)?.projects;
|
|
12873
|
+
for (const required of ['sync', 'listProjectsElsewhere']) {
|
|
12874
|
+
if (typeof projectsApi?.[required] !== 'function') {
|
|
12875
|
+
const error = new Error(`--wait needs @sogni-ai/sogni-client 5.58.0 or later (projects.${required}). Update the Sogni skill.`);
|
|
12876
|
+
error.code = 'SDK_UPDATE_REQUIRED';
|
|
12877
|
+
throw error;
|
|
12878
|
+
}
|
|
12879
|
+
}
|
|
12880
|
+
const deadline = Date.now() + timeoutMs;
|
|
12881
|
+
let tracked = await trackedProjectAfterSync(projectsApi, projectId);
|
|
12882
|
+
let sideClient = null;
|
|
12883
|
+
let claim = null;
|
|
12884
|
+
try {
|
|
12885
|
+
if (!tracked) {
|
|
12886
|
+
const inFlight = await projectsApi.listProjectsElsewhere();
|
|
12887
|
+
const holder = (inFlight || []).find((project) => project?.id === projectId);
|
|
12888
|
+
if (!holder) return;
|
|
12889
|
+
claim = holder.appId ? claimSogniAppIdSlot(holder.appId) : null;
|
|
12890
|
+
if (claim?.appId && creds) {
|
|
12891
|
+
log(`Taking project ${projectId} back from the run that submitted it...`);
|
|
12892
|
+
sideClient = createSkillSogniClient(creds, claim.appId);
|
|
12893
|
+
await connectSogniClient(sideClient);
|
|
12894
|
+
tracked = await trackedProjectAfterSync(sdkClientOf(sideClient).projects, projectId);
|
|
12895
|
+
}
|
|
12896
|
+
if (!tracked) {
|
|
12897
|
+
log(claim?.heldByPid
|
|
12898
|
+
? `Project ${projectId} is being followed by another sogni-agent process (pid ${claim.heldByPid}); waiting for it to finish.`
|
|
12899
|
+
: `Project ${projectId} was submitted from another app or device; waiting for it to finish.`);
|
|
12900
|
+
await waitUntilNotInFlight(projectsApi, projectId, deadline, timeoutMs);
|
|
12901
|
+
return;
|
|
12902
|
+
}
|
|
12903
|
+
}
|
|
12904
|
+
await settleTrackedProject(tracked, { log, deadline, timeoutMs });
|
|
12905
|
+
} finally {
|
|
12906
|
+
if (sideClient) {
|
|
12907
|
+
try { await sideClient.disconnect(); } catch { /* already closed */ }
|
|
12908
|
+
}
|
|
12909
|
+
claim?.release?.();
|
|
12910
|
+
}
|
|
12911
|
+
}
|
|
12912
|
+
|
|
12913
|
+
/** Wait for a tracked project's own completion or failure events (no requests). */
|
|
12914
|
+
async function settleTrackedProject(project, { log, deadline, timeoutMs }) {
|
|
12915
|
+
let lastLine = null;
|
|
12916
|
+
const report = () => {
|
|
12917
|
+
const line = describeWaitingReason(project.waitingReason) || `Project ${project.id}: ${project.status}`;
|
|
12918
|
+
if (line !== lastLine) {
|
|
12919
|
+
lastLine = line;
|
|
12920
|
+
log(line);
|
|
12921
|
+
}
|
|
12922
|
+
};
|
|
12923
|
+
let timer = null;
|
|
12924
|
+
project.on?.('updated', report);
|
|
12925
|
+
report();
|
|
12926
|
+
try {
|
|
12927
|
+
await Promise.race([
|
|
12928
|
+
// A failure is reported by the result read that follows, with its reason.
|
|
12929
|
+
project.waitForCompletion().catch(() => {}),
|
|
12930
|
+
new Promise((_, reject) => {
|
|
12931
|
+
timer = setTimeout(() => reject(projectStillRunningError(project.id, timeoutMs)), Math.max(0, deadline - Date.now()));
|
|
12932
|
+
})
|
|
12933
|
+
]);
|
|
12934
|
+
} finally {
|
|
12935
|
+
clearTimeout(timer);
|
|
12936
|
+
project.off?.('updated', report);
|
|
12937
|
+
}
|
|
12938
|
+
}
|
|
12939
|
+
|
|
12940
|
+
async function waitUntilNotInFlight(projectsApi, projectId, deadline, timeoutMs) {
|
|
12941
|
+
const intervalMs = inFlightCheckIntervalMs();
|
|
12942
|
+
for (;;) {
|
|
12943
|
+
if (Date.now() + intervalMs > deadline) throw projectStillRunningError(projectId, timeoutMs);
|
|
12944
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
12945
|
+
const inFlight = await projectsApi.listProjectsElsewhere();
|
|
12946
|
+
if (!(inFlight || []).some((project) => project?.id === projectId)) return;
|
|
12947
|
+
}
|
|
12948
|
+
}
|
|
12949
|
+
|
|
12950
|
+
function projectStillRunningError(projectId, timeoutMs) {
|
|
12951
|
+
const error = new Error(
|
|
12952
|
+
`Stopped waiting after ${Math.round(timeoutMs / 1000)}s; Sogni project ${projectId} is still running and was not cancelled. ` +
|
|
12953
|
+
`Wait for it again with: ${waitCommandFor(projectId)}`
|
|
12954
|
+
);
|
|
12955
|
+
error.code = 'PROJECT_TIMEOUT_STILL_RUNNING';
|
|
12956
|
+
error.details = { timeoutSeconds: timeoutMs / 1000, projectIds: [projectId], canceled: false, waitCommand: waitCommandFor(projectId) };
|
|
12957
|
+
return error;
|
|
12958
|
+
}
|
|
12959
|
+
|
|
12680
12960
|
/**
|
|
12681
12961
|
* What to do when a run stops waiting before its projects finish. By default
|
|
12682
12962
|
* nothing is cancelled: the projects keep going on Sogni and their results can
|
|
@@ -14084,22 +14364,14 @@ async function main() {
|
|
|
14084
14364
|
|
|
14085
14365
|
const creds = loadCredentials();
|
|
14086
14366
|
log('Connecting to Sogni...');
|
|
14087
|
-
client =
|
|
14088
|
-
appSource: SOGNI_APP_SOURCE,
|
|
14089
|
-
appId: getOrCreateSogniAppId(),
|
|
14090
|
-
attribution: clientAttribution(AGENT_ATTRIBUTION),
|
|
14091
|
-
network: openclawConfig?.defaultNetwork || 'fast',
|
|
14092
|
-
autoConnect: false,
|
|
14093
|
-
apiKey: creds.SOGNI_API_KEY,
|
|
14094
|
-
authType: 'apiKey'
|
|
14095
|
-
});
|
|
14367
|
+
client = createSkillSogniClient(creds, getOrCreateSogniAppId());
|
|
14096
14368
|
|
|
14097
14369
|
await connectSogniClient(client);
|
|
14098
14370
|
await disableLiveModelAvailabilityEvents(client);
|
|
14099
14371
|
log('Connected.');
|
|
14100
14372
|
|
|
14101
14373
|
if (options.projectLookup) {
|
|
14102
|
-
await runProjectLookup(client, options.projectLookup);
|
|
14374
|
+
await runProjectLookup(client, options.projectLookup, { log, creds });
|
|
14103
14375
|
return;
|
|
14104
14376
|
}
|
|
14105
14377
|
|
|
@@ -15335,6 +15607,18 @@ async function main() {
|
|
|
15335
15607
|
|
|
15336
15608
|
if (options.detach) {
|
|
15337
15609
|
projectWait.stop();
|
|
15610
|
+
// projects.create() resolves once the request is handed to the socket, before the server
|
|
15611
|
+
// has it, so exiting at once dropped every detached project (2026-10-01: none reached
|
|
15612
|
+
// the server, yet each was reported as submitted). Report only what the server answered.
|
|
15613
|
+
const unconfirmed = await awaitServerAnswer([...activeProjects]);
|
|
15614
|
+
const refused = [...activeProjects].find((project) => project?.status === 'failed');
|
|
15615
|
+
if (refused) throw buildProjectResultError({ error: refused.terminalError?.() ?? refused.error }, 'Sogni refused the project');
|
|
15616
|
+
if (unconfirmed.length) {
|
|
15617
|
+
const err = new Error(`Sogni did not confirm project ${unconfirmed.join(', ')} within ${DETACH_ACK_TIMEOUT_MS / 1000} s, so it may not have been received. Check once with --status before submitting again.`);
|
|
15618
|
+
err.code = 'PROJECT_SUBMISSION_UNCONFIRMED';
|
|
15619
|
+
err.details = { projectIds: unconfirmed };
|
|
15620
|
+
throw err;
|
|
15621
|
+
}
|
|
15338
15622
|
reportDetachedProjects([...activeProjects], projectWait);
|
|
15339
15623
|
return;
|
|
15340
15624
|
}
|