@nimiplatform/app-tools 0.16.0-rc.14 → 0.16.0-rc.18
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/README.md +5 -42
- package/bin/nimi-app.mjs +25 -6
- package/lib/app-dependency-combinations.mjs +1 -0
- package/lib/app-doctor-update.mjs +8 -6
- package/lib/app-info.mjs +39 -19
- package/lib/app-lifecycle-guidance.mjs +1 -1
- package/lib/app-pack.mjs +31 -13
- package/lib/app-project-lifecycle.mjs +32 -12
- package/lib/app-resources.mjs +36 -0
- package/lib/app-scaffold-profiles.mjs +72 -2
- package/lib/app-scaffold.mjs +11 -13
- package/lib/index.mjs +7 -0
- package/lib/public-storefront.mjs +327 -0
- package/lib/storefront-media.mjs +8 -4
- package/lib/storefront-pack.mjs +152 -0
- package/lib/storefront-release-verification.mjs +31 -0
- package/lib/storefront-source.mjs +161 -0
- package/lib/web-coordination.mjs +4 -1
- package/lib/web-scaffold.mjs +3 -3
- package/package.json +9 -6
- package/scripts/sync-app-source.mjs +5 -12
- package/skills/nimi-app-lifecycle/SKILL.md +1 -0
- package/skills/nimi-app-lifecycle/references/storefront.md +28 -0
- package/templates/app-source/src/ai-studio-core/ai-config.ts +12 -0
- package/templates/app-source/src/ai-studio-core/ai-studio-core.css +138 -117
- package/templates/app-source/src/ai-studio-core/history.ts +10 -8
- package/templates/app-source/src/ai-studio-core/host-context.tsx +1 -0
- package/templates/app-source/src/ai-studio-core/job-recovery-panel.tsx +15 -10
- package/templates/app-source/src/ai-studio-core/job-recovery.ts +505 -115
- package/templates/app-source/src/ai-studio-core/messages/en.json +55 -9
- package/templates/app-source/src/ai-studio-core/messages/zh.json +55 -9
- package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +8 -2
- package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +2 -0
- package/templates/app-source/src/ai-studio-core/parameters.ts +5 -4
- package/templates/app-source/src/ai-studio-core/run-target.ts +12 -1
- package/templates/app-source/src/ai-studio-core/runtime-types.ts +3 -0
- package/templates/app-source/src/ai-studio-core/runtime.ts +50 -12
- package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +6 -7
- package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +88 -27
- package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +33 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-music-result.tsx +2 -2
- package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +10 -3
- package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +6 -4
- package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +121 -40
- package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +34 -8
- package/templates/app-source/src/ai-studio-core/section-ai-testing-transcript-result.tsx +16 -2
- package/templates/app-source/src/ai-studio-core/section-ai-testing-transcription-result.tsx +18 -7
- package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +1 -1
- package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +78 -9
- package/templates/app-source/src/ai-studio-core/text-media-replay.ts +2 -1
- package/templates/app-source/src/ai-studio-core/workspace.tsx +138 -3
- package/templates/app-source/src/product-modules/agent-center/index.tsx +19 -3
- package/templates/app-source/src/product-modules/agent-conversation/index.tsx +19 -3
- package/templates/app-source/src/product-modules/agent-realtime/index.tsx +19 -3
- package/templates/app-source/src/product-modules/kit-recipes/gallery.tsx +12 -7
- package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-surface.tsx +48 -20
- package/templates/app-source/src/studio-modules/studio-create/messages/en.json +2 -2
- package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +2 -2
- package/templates/app-source/src/studio-modules/studio-create/registration.ts +1 -1
- package/templates/app-source/src/studio-modules/studio-create/runtime.ts +11 -19
- package/templates/app-source/src/studio-modules/studio-media/audio-separate-parameters.tsx +7 -4
- package/templates/app-source/src/studio-modules/studio-media/audio-separate-runtime.ts +14 -10
- package/templates/app-source/src/studio-modules/studio-media/messages/en.json +3 -1
- package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +3 -1
- package/templates/app-source/src/studio-modules/studio-media/music-parameters.tsx +6 -5
- package/templates/app-source/src/studio-modules/studio-media/music-transcription-parameters.tsx +19 -11
- package/templates/app-source/src/studio-modules/studio-media/music-transcription-runtime.ts +14 -10
- package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +54 -16
- package/templates/app-source/src/studio-modules/studio-media/runtime.ts +22 -9
- package/templates/app-source/src/studio-modules/studio-media/vision-runtime.ts +19 -10
- package/templates/app-source/src/studio-modules/studio-media/voice-convert-parameters.tsx +12 -6
- package/templates/app-source/src/studio-modules/studio-media/voice-convert-runtime.ts +11 -9
- package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +5 -0
- package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +5 -0
- package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +18 -7
- package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +28 -4
- package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +12 -8
- package/templates/app-source/src/workbench-core/runtime-gate.tsx +171 -44
- package/templates/app-source/src/workbench-core/workbench-core.css +226 -23
- package/templates/app-source/src/workbench-core/workbench-core.tsx +5 -5
- package/templates/app-source.manifest.json +2 -2
- package/templates/default-starter/NIMI_APP.md +11 -3
- package/templates/default-starter.manifest.json +2 -2
- package/templates/storefront-release.yml +97 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { createNimiAppRecordStore } from '@nimiplatform/kit/core/app-record-storage';
|
|
1
2
|
import { ScenarioType, VisionLocateGeometry } from '@nimiplatform/sdk/runtime/generated';
|
|
2
3
|
import { isJsonObject } from '@nimiplatform/sdk/types';
|
|
3
4
|
import type { NimiLocalAppClient } from '@nimiplatform/sdk/app';
|
|
4
|
-
import type { JsonValue } from '@nimiplatform/sdk/types';
|
|
5
5
|
import { createStudioRunHistoryResultSnapshot, restoreStudioCapabilityRunResult, type StudioRunHistoryResultSnapshot } from './history.js';
|
|
6
6
|
import { validateManagedArtifact, validateStudioHistoryResult, validateRunConfig, validateFaceSwapHistory } from './history-policy.js';
|
|
7
7
|
import type { StudioRunConfigSnapshot } from './history.js';
|
|
@@ -9,8 +9,13 @@ import { studioResultAssetPaths, studioResultAssetReferences, verifyStudioManage
|
|
|
9
9
|
import type { StudioAudioSeparationRequest, StudioCapabilityRunResult, StudioManagedArtifact } from './runtime-types.js';
|
|
10
10
|
import { isAudioSeparationRequest } from './audio-separation-request.js';
|
|
11
11
|
|
|
12
|
-
type
|
|
12
|
+
export type StudioJobRecoveryAssets = Pick<NimiLocalAppClient['storage']['assets'], 'list' | 'read' | 'write' | 'remove'>;
|
|
13
|
+
|
|
14
|
+
export type StudioJobRecoveryState = 'pending' | 'acknowledged' | 'completed' | 'rejected';
|
|
15
|
+
|
|
13
16
|
export type StudioJobRecoveryEntry = {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly state: StudioJobRecoveryState;
|
|
14
19
|
readonly details?: StudioJobRecoveryDetails;
|
|
15
20
|
readonly clientSubmissionId: string;
|
|
16
21
|
readonly createdAt: string;
|
|
@@ -23,7 +28,9 @@ export type StudioJobRecoveryEntry = {
|
|
|
23
28
|
readonly prompt?: string;
|
|
24
29
|
readonly runConfig?: StudioRunConfigSnapshot;
|
|
25
30
|
};
|
|
26
|
-
|
|
31
|
+
|
|
32
|
+
export type StudioJobRecoveryCapability = (typeof STUDIO_JOB_RECOVERY_CAPABILITY_LIST)[number];
|
|
33
|
+
|
|
27
34
|
export type StudioJobRecoveryDetails = {
|
|
28
35
|
readonly sourceImage?: StudioManagedArtifact;
|
|
29
36
|
readonly scenarioType: import('@nimiplatform/sdk/runtime/generated').ScenarioType;
|
|
@@ -33,133 +40,470 @@ export type StudioJobRecoveryDetails = {
|
|
|
33
40
|
readonly texts?: readonly string[];
|
|
34
41
|
readonly faceSwap?: import('./runtime-types.js').StudioFaceSwap;
|
|
35
42
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
43
|
+
|
|
44
|
+
export const STUDIO_JOB_RECOVERY_PREFIX = 'studio/recovery/';
|
|
45
|
+
|
|
46
|
+
const STUDIO_JOB_RECOVERY_CAPABILITY_LIST = [
|
|
47
|
+
'image.upscale',
|
|
48
|
+
'video.upscale',
|
|
49
|
+
'audio.speaker.embed',
|
|
50
|
+
'image.generate',
|
|
51
|
+
'video.generate',
|
|
52
|
+
'audio.synthesize',
|
|
53
|
+
'audio.transcribe',
|
|
54
|
+
'voice.create',
|
|
55
|
+
'vision.locate',
|
|
56
|
+
'text.annotate',
|
|
57
|
+
'image.face_swap',
|
|
58
|
+
'video.face_swap',
|
|
59
|
+
'music.generate',
|
|
60
|
+
'music.transcribe',
|
|
61
|
+
'audio.voice.convert',
|
|
62
|
+
'audio.separate',
|
|
63
|
+
] as const;
|
|
64
|
+
|
|
65
|
+
const STUDIO_JOB_RECOVERY_CAPABILITIES = new Set<string>(STUDIO_JOB_RECOVERY_CAPABILITY_LIST);
|
|
66
|
+
const MAX_RECOVERY_RECORD_BYTES = 240 * 1024;
|
|
67
|
+
const MAX_RECOVERY_ENTRIES_PER_CAPABILITY = 128;
|
|
68
|
+
|
|
69
|
+
export function studioJobRecoveryPrefix(capability: StudioJobRecoveryCapability): string {
|
|
70
|
+
return `${STUDIO_JOB_RECOVERY_PREFIX}${capability}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function studioJobRecoveryRecordPath(capability: StudioJobRecoveryCapability, id: string): string {
|
|
74
|
+
return `${studioJobRecoveryPrefix(capability)}/${encodeURIComponent(id)}.json`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isStorageNotFoundError(cause: unknown): boolean {
|
|
78
|
+
if (!cause || typeof cause !== 'object') return false;
|
|
79
|
+
const error = cause as { reasonCode?: unknown; code?: unknown };
|
|
80
|
+
const code = String(error.reasonCode ?? error.code ?? '').toLowerCase().replaceAll('-', '_');
|
|
81
|
+
return code === 'not_found' || code === 'app_storage_entry_not_found' || code === 'app_asset_not_found';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function parseStudioJobRecoveryEntry(capability: StudioJobRecoveryCapability, item: unknown): StudioJobRecoveryEntry {
|
|
85
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
|
86
|
+
throw new Error('Invalid saved task recovery entry');
|
|
87
|
+
}
|
|
88
|
+
const record = item as Record<string, unknown>;
|
|
89
|
+
const allowedKeys = [
|
|
90
|
+
'id',
|
|
91
|
+
'state',
|
|
92
|
+
'clientSubmissionId',
|
|
93
|
+
'createdAt',
|
|
94
|
+
'message',
|
|
95
|
+
'result',
|
|
96
|
+
'prompt',
|
|
97
|
+
'runConfig',
|
|
98
|
+
'jobId',
|
|
99
|
+
'details',
|
|
100
|
+
...(capability === 'music.generate' ? [] : ['sourceAudio']),
|
|
101
|
+
...(capability === 'audio.voice.convert' ? ['targetAudio'] : []),
|
|
102
|
+
...(capability === 'audio.separate' ? ['separationRequest'] : []),
|
|
103
|
+
];
|
|
104
|
+
if (
|
|
105
|
+
typeof record.clientSubmissionId !== 'string'
|
|
106
|
+
|| !/^[A-Za-z0-9_-]{1,128}$/.test(record.clientSubmissionId)
|
|
107
|
+
|| record.id !== record.clientSubmissionId
|
|
108
|
+
|| !['pending', 'acknowledged', 'completed', 'rejected'].includes(String(record.state))
|
|
109
|
+
|| typeof record.createdAt !== 'string'
|
|
110
|
+
|| !Number.isFinite(Date.parse(record.createdAt))
|
|
111
|
+
|| Object.keys(record).some((key) => !allowedKeys.includes(key))
|
|
112
|
+
) {
|
|
113
|
+
throw new Error('Invalid saved task recovery entry');
|
|
114
|
+
}
|
|
115
|
+
const state = record.state as StudioJobRecoveryState;
|
|
116
|
+
if (record.details !== undefined) validateRecoveryDetails(record.details);
|
|
117
|
+
if (record.prompt !== undefined && typeof record.prompt !== 'string') throw new Error('Invalid saved task prompt');
|
|
118
|
+
if (record.runConfig !== undefined) {
|
|
119
|
+
validateRunConfig(record.runConfig, 'task recovery request');
|
|
120
|
+
if ((record.runConfig as StudioRunConfigSnapshot).target.capabilityId !== capability) {
|
|
121
|
+
throw new Error('Task recovery request has a different capability');
|
|
63
122
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
123
|
+
}
|
|
124
|
+
if (record.separationRequest !== undefined && !isAudioSeparationRequest(record.separationRequest)) {
|
|
125
|
+
throw new Error('Invalid saved separation request');
|
|
126
|
+
}
|
|
127
|
+
if (
|
|
128
|
+
record.jobId !== undefined
|
|
129
|
+
&& (typeof record.jobId !== 'string' || record.jobId.length < 1 || record.jobId.length > 256 || record.jobId !== record.jobId.trim())
|
|
130
|
+
) {
|
|
131
|
+
throw new Error('Invalid saved task recovery entry');
|
|
132
|
+
}
|
|
133
|
+
if ((state === 'pending' || state === 'rejected') && (record.jobId !== undefined || record.result !== undefined)) {
|
|
134
|
+
throw new Error('Invalid saved task recovery state');
|
|
135
|
+
}
|
|
136
|
+
if (state === 'acknowledged' && record.jobId === undefined) {
|
|
137
|
+
throw new Error('Acknowledged task recovery entry is missing jobId');
|
|
138
|
+
}
|
|
139
|
+
if (['music.transcribe', 'audio.voice.convert', 'audio.separate'].includes(capability)) {
|
|
140
|
+
validateManagedArtifact(record.sourceAudio, 'task recovery source');
|
|
141
|
+
}
|
|
142
|
+
if (capability === 'audio.voice.convert' && record.targetAudio !== undefined) {
|
|
143
|
+
validateManagedArtifact(record.targetAudio, 'voice conversion recovery target');
|
|
144
|
+
}
|
|
145
|
+
if (record.result !== undefined) {
|
|
146
|
+
validateStudioHistoryResult(record.result, 'task recovery');
|
|
147
|
+
const result = record.result as StudioRunHistoryResultSnapshot;
|
|
148
|
+
const complete = capability === 'music.transcribe' ? (result.ok && result.kind === 'artifacts' ? result.musicTranscription : undefined)
|
|
149
|
+
: capability === 'audio.voice.convert' ? (result.ok && result.kind === 'artifacts' ? result.voiceConversion : undefined)
|
|
150
|
+
: capability === 'audio.separate' ? (result.ok && result.kind === 'artifacts' ? result.audioSeparation : undefined)
|
|
151
|
+
: capability === 'music.generate' ? (result.ok && result.kind === 'artifacts' ? result.musicGeneration : undefined)
|
|
152
|
+
: true;
|
|
153
|
+
if (!result.ok || !complete || typeof record.message !== 'string') {
|
|
154
|
+
throw new Error('Incomplete saved task result');
|
|
155
|
+
}
|
|
156
|
+
const savedRequest = capability === 'audio.separate' && result.ok && result.kind === 'artifacts'
|
|
157
|
+
? result.audioSeparation?.request
|
|
158
|
+
: undefined;
|
|
159
|
+
const separationRequest = record.separationRequest as StudioAudioSeparationRequest | undefined;
|
|
160
|
+
if (
|
|
161
|
+
savedRequest
|
|
162
|
+
&& separationRequest
|
|
163
|
+
&& (
|
|
164
|
+
savedRequest.kind !== separationRequest.kind
|
|
165
|
+
|| (savedRequest.kind === 'range' && separationRequest.kind === 'range'
|
|
166
|
+
&& (savedRequest.startSeconds !== separationRequest.startSeconds || savedRequest.endSeconds !== separationRequest.endSeconds))
|
|
167
|
+
)
|
|
168
|
+
) {
|
|
169
|
+
throw new Error('Saved separation request conflicts with its result');
|
|
79
170
|
}
|
|
171
|
+
} else if (state === 'completed') {
|
|
172
|
+
throw new Error('Completed task recovery entry is missing result');
|
|
80
173
|
}
|
|
81
|
-
return
|
|
174
|
+
return record as unknown as StudioJobRecoveryEntry;
|
|
82
175
|
}
|
|
83
176
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
177
|
+
function recoveryStore(assets: StudioJobRecoveryAssets, capability: StudioJobRecoveryCapability) {
|
|
178
|
+
return createNimiAppRecordStore<StudioJobRecoveryEntry>(
|
|
179
|
+
assets,
|
|
180
|
+
studioJobRecoveryPrefix(capability),
|
|
181
|
+
(value) => parseStudioJobRecoveryEntry(capability, value),
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function readStudioJobRecovery(
|
|
186
|
+
assets: StudioJobRecoveryAssets,
|
|
187
|
+
capability: StudioJobRecoveryCapability = 'music.generate',
|
|
188
|
+
): Promise<readonly StudioJobRecoveryEntry[]> {
|
|
189
|
+
const versions = await recoveryStore(assets, capability).listVersions();
|
|
190
|
+
return versions
|
|
191
|
+
.map((item) => item.record)
|
|
192
|
+
.filter((entry) => entry.state !== 'rejected')
|
|
193
|
+
.sort((left, right) => (
|
|
194
|
+
Date.parse(left.createdAt) - Date.parse(right.createdAt)
|
|
195
|
+
|| left.clientSubmissionId.localeCompare(right.clientSubmissionId)
|
|
196
|
+
));
|
|
96
197
|
}
|
|
97
198
|
|
|
98
|
-
export
|
|
99
|
-
|
|
199
|
+
export class StudioRecoveryWriteUnconfirmed extends Error {
|
|
200
|
+
constructor(readonly submissionId: string, cause: unknown) {
|
|
201
|
+
super(cause instanceof Error ? cause.message : String(cause), { cause });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export async function beginStudioJobRecovery(
|
|
206
|
+
assets: StudioJobRecoveryAssets,
|
|
207
|
+
capability: StudioJobRecoveryCapability = 'music.generate',
|
|
208
|
+
sourceAudio?: StudioManagedArtifact,
|
|
209
|
+
targetAudio?: StudioManagedArtifact,
|
|
210
|
+
separationRequest?: StudioAudioSeparationRequest,
|
|
211
|
+
runConfig?: StudioRunConfigSnapshot,
|
|
212
|
+
prompt?: string,
|
|
213
|
+
details?: StudioJobRecoveryDetails,
|
|
214
|
+
): Promise<string> {
|
|
215
|
+
if (['music.transcribe', 'audio.voice.convert', 'audio.separate'].includes(capability)) {
|
|
216
|
+
validateManagedArtifact(sourceAudio, 'task recovery source');
|
|
217
|
+
}
|
|
100
218
|
if (targetAudio !== undefined) validateManagedArtifact(targetAudio, 'voice conversion recovery target');
|
|
101
|
-
if (separationRequest !== undefined && (capability !== 'audio.separate' || !isAudioSeparationRequest(separationRequest)))
|
|
219
|
+
if (separationRequest !== undefined && (capability !== 'audio.separate' || !isAudioSeparationRequest(separationRequest))) {
|
|
220
|
+
throw new Error('Invalid separation request');
|
|
221
|
+
}
|
|
102
222
|
if (details) validateRecoveryDetails(details);
|
|
103
223
|
const clientSubmissionId = crypto.randomUUID();
|
|
104
|
-
|
|
224
|
+
const entry: StudioJobRecoveryEntry = {
|
|
225
|
+
id: clientSubmissionId,
|
|
226
|
+
state: 'pending',
|
|
227
|
+
clientSubmissionId,
|
|
228
|
+
createdAt: new Date().toISOString(),
|
|
229
|
+
...(sourceAudio ? { sourceAudio } : {}),
|
|
230
|
+
...(targetAudio ? { targetAudio } : {}),
|
|
231
|
+
...(separationRequest ? { separationRequest } : {}),
|
|
232
|
+
...(runConfig ? { runConfig } : {}),
|
|
233
|
+
...(prompt === undefined ? {} : { prompt }),
|
|
234
|
+
...(details ? { details } : {}),
|
|
235
|
+
};
|
|
236
|
+
if (new TextEncoder().encode(JSON.stringify(entry)).byteLength > MAX_RECOVERY_RECORD_BYTES) {
|
|
237
|
+
throw new Error('Task recovery storage is full; explicitly remove completed recovery entries after verifying their saved history.');
|
|
238
|
+
}
|
|
239
|
+
const existing = await readStudioJobRecovery(assets, capability);
|
|
240
|
+
if (existing.length >= MAX_RECOVERY_ENTRIES_PER_CAPABILITY) {
|
|
241
|
+
throw new Error('Task recovery storage is full; explicitly remove completed recovery entries after verifying their saved history.');
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
await recoveryStore(assets, capability).write(entry, null);
|
|
245
|
+
} catch (cause) {
|
|
246
|
+
// The file may already own its inputs when the write receipt is lost.
|
|
247
|
+
throw new StudioRecoveryWriteUnconfirmed(clientSubmissionId, cause);
|
|
248
|
+
}
|
|
105
249
|
return clientSubmissionId;
|
|
106
250
|
}
|
|
107
251
|
|
|
108
|
-
export async function captureStudioJobRecoveryJobId(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
252
|
+
export async function captureStudioJobRecoveryJobId(
|
|
253
|
+
assets: StudioJobRecoveryAssets,
|
|
254
|
+
id: string,
|
|
255
|
+
jobId: string,
|
|
256
|
+
capability: StudioJobRecoveryCapability = 'music.generate',
|
|
257
|
+
) {
|
|
258
|
+
if (!jobId || jobId.length > 256 || jobId !== jobId.trim()) {
|
|
259
|
+
throw new Error('Invalid task recovery job identity');
|
|
260
|
+
}
|
|
261
|
+
const store = recoveryStore(assets, capability);
|
|
262
|
+
const current = await store.readVersion(id);
|
|
263
|
+
if (!current || current.record.state === 'rejected') {
|
|
264
|
+
throw new Error('Saved action was already rejected or removed');
|
|
265
|
+
}
|
|
266
|
+
if (current.record.jobId && current.record.jobId !== jobId) {
|
|
267
|
+
throw new Error('Saved action has a different Job identity');
|
|
268
|
+
}
|
|
269
|
+
if (current.record.jobId === jobId && (current.record.state === 'acknowledged' || current.record.state === 'completed')) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const next: StudioJobRecoveryEntry = {
|
|
273
|
+
...current.record,
|
|
274
|
+
jobId,
|
|
275
|
+
state: current.record.state === 'completed' ? 'completed' : 'acknowledged',
|
|
276
|
+
};
|
|
277
|
+
await store.write(next, current.sha256);
|
|
115
278
|
}
|
|
116
279
|
|
|
117
|
-
export async function saveStudioJobRecoveryResult(
|
|
118
|
-
|
|
280
|
+
export async function saveStudioJobRecoveryResult(
|
|
281
|
+
assets: StudioJobRecoveryAssets,
|
|
282
|
+
id: string,
|
|
283
|
+
result: StudioCapabilityRunResult,
|
|
284
|
+
capability: StudioJobRecoveryCapability = 'music.generate',
|
|
285
|
+
): Promise<StudioCapabilityRunResult> {
|
|
119
286
|
if (result.capabilityId !== capability) throw new Error('Saved result belongs to a different capability');
|
|
120
|
-
if (
|
|
287
|
+
if (!result.ok) {
|
|
288
|
+
if (result.terminalJobFailure && result.jobId) {
|
|
289
|
+
try {
|
|
290
|
+
const current = await recoveryStore(assets, capability).readVersion(id);
|
|
291
|
+
if (current?.record.state === 'acknowledged' && current.record.jobId === result.jobId) {
|
|
292
|
+
await forgetStudioJobRecovery(assets, id, capability);
|
|
293
|
+
}
|
|
294
|
+
} catch {
|
|
295
|
+
return { ...result, recoveryCleanupUnconfirmed: true };
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
if (['music.generate', 'music.transcribe', 'audio.voice.convert', 'audio.separate'].includes(capability) && result.output.kind !== 'artifacts') {
|
|
301
|
+
throw new Error('Recovery requires the complete adopted result');
|
|
302
|
+
}
|
|
121
303
|
const media = result.output.kind === 'artifacts' ? result.output : undefined;
|
|
122
304
|
const complete = capability === 'music.transcribe' ? media?.musicTranscription
|
|
123
305
|
: capability === 'audio.voice.convert' ? media?.voiceConversion
|
|
124
|
-
: capability === 'audio.separate' ? media?.audioSeparation
|
|
306
|
+
: capability === 'audio.separate' ? media?.audioSeparation
|
|
307
|
+
: capability === 'music.generate' ? media?.musicGeneration
|
|
308
|
+
: true;
|
|
125
309
|
if (!complete) throw new Error('Task recovery requires the complete adopted result');
|
|
126
310
|
const snapshot = createStudioRunHistoryResultSnapshot(result);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
311
|
+
const store = recoveryStore(assets, capability);
|
|
312
|
+
const current = await store.readVersion(id);
|
|
313
|
+
if (
|
|
314
|
+
!current
|
|
315
|
+
|| current.record.state === 'rejected'
|
|
316
|
+
|| !('jobId' in result.output)
|
|
317
|
+
|| (current.record.jobId && current.record.jobId !== result.output.jobId)
|
|
318
|
+
) {
|
|
319
|
+
throw new Error('Saved result does not belong to the recorded action');
|
|
320
|
+
}
|
|
321
|
+
const next: StudioJobRecoveryEntry = {
|
|
322
|
+
...current.record,
|
|
323
|
+
jobId: current.record.jobId ?? result.output.jobId,
|
|
324
|
+
state: 'completed',
|
|
325
|
+
message: result.message,
|
|
326
|
+
result: snapshot,
|
|
327
|
+
};
|
|
328
|
+
if (new TextEncoder().encode(JSON.stringify(next)).byteLength > MAX_RECOVERY_RECORD_BYTES) {
|
|
329
|
+
throw new Error('Task recovery storage is full; explicitly remove completed recovery entries after verifying their saved history.');
|
|
330
|
+
}
|
|
331
|
+
await store.write(next, current.sha256);
|
|
332
|
+
return result;
|
|
132
333
|
}
|
|
133
334
|
|
|
134
|
-
export async function forgetStudioJobRecovery(
|
|
135
|
-
|
|
335
|
+
export async function forgetStudioJobRecovery(
|
|
336
|
+
assets: StudioJobRecoveryAssets,
|
|
337
|
+
id: string,
|
|
338
|
+
capability: StudioJobRecoveryCapability = 'music.generate',
|
|
339
|
+
) {
|
|
340
|
+
try {
|
|
341
|
+
await assets.remove(studioJobRecoveryRecordPath(capability, id));
|
|
342
|
+
} catch (cause) {
|
|
343
|
+
if (!isStorageNotFoundError(cause)) throw cause;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export type ForgetPendingRecoveryResult =
|
|
348
|
+
| { readonly removed: true; readonly entry: StudioJobRecoveryEntry }
|
|
349
|
+
| { readonly removed: false; readonly reason: 'read-unconfirmed' | 'missing' | 'already-acknowledged' | 'cas-conflict' | 'remove-unconfirmed' };
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Two-phase atomic cleanup for a definite pre-admission rejection:
|
|
353
|
+
* 1. Read current record + sha256 and require state === 'pending' with no jobId/result.
|
|
354
|
+
* 2. CAS-transition the record to state === 'rejected' with expectedSha256.
|
|
355
|
+
* If another observer already filled jobId, CAS fails and we leave the record intact.
|
|
356
|
+
* 3. Only the CAS winner calls assets.remove(path), returning removed: true only when
|
|
357
|
+
* assets.remove confirms { removed: true }.
|
|
358
|
+
*/
|
|
359
|
+
export async function forgetPendingStudioJobRecoveryIfUnacknowledged(
|
|
360
|
+
assets: StudioJobRecoveryAssets,
|
|
361
|
+
capability: StudioJobRecoveryCapability,
|
|
362
|
+
id: string,
|
|
363
|
+
): Promise<ForgetPendingRecoveryResult> {
|
|
364
|
+
const store = recoveryStore(assets, capability);
|
|
365
|
+
let current;
|
|
366
|
+
try {
|
|
367
|
+
current = await store.readVersion(id);
|
|
368
|
+
} catch {
|
|
369
|
+
return { removed: false, reason: 'read-unconfirmed' };
|
|
370
|
+
}
|
|
371
|
+
if (!current) return { removed: false, reason: 'missing' };
|
|
372
|
+
if (current.record.state !== 'pending' || current.record.jobId || current.record.result) {
|
|
373
|
+
return { removed: false, reason: 'already-acknowledged' };
|
|
374
|
+
}
|
|
375
|
+
try {
|
|
376
|
+
await store.write({ ...current.record, state: 'rejected' }, current.sha256);
|
|
377
|
+
} catch {
|
|
378
|
+
return { removed: false, reason: 'cas-conflict' };
|
|
379
|
+
}
|
|
380
|
+
try {
|
|
381
|
+
const deletion = await assets.remove(studioJobRecoveryRecordPath(capability, id));
|
|
382
|
+
if (deletion?.removed === true) {
|
|
383
|
+
return { removed: true, entry: current.record };
|
|
384
|
+
}
|
|
385
|
+
return { removed: false, reason: 'remove-unconfirmed' };
|
|
386
|
+
} catch {
|
|
387
|
+
return { removed: false, reason: 'remove-unconfirmed' };
|
|
388
|
+
}
|
|
136
389
|
}
|
|
137
390
|
|
|
138
|
-
|
|
139
|
-
|
|
391
|
+
function normalizedReasonCode(cause: unknown): string {
|
|
392
|
+
if (!cause || typeof cause !== 'object' || !('reasonCode' in cause)) return '';
|
|
393
|
+
const raw = (cause as { reasonCode?: unknown }).reasonCode;
|
|
394
|
+
if (typeof raw !== 'string') return '';
|
|
395
|
+
return raw.trim().replaceAll('-', '_').toUpperCase();
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Narrow D1 pre-admission rejection classifier:
|
|
400
|
+
* - AI_LOCAL_ASSET_SLOT_MISSING is guaranteed pre-Job-persistence in Runtime.
|
|
401
|
+
* - AI_MEDIA_OPTION_UNSUPPORTED on vision.locate is guaranteed pre-Job-persistence
|
|
402
|
+
* (local_vision_execution.go:70).
|
|
403
|
+
* Explicitly excludes PROTOCOL_ENVELOPE_INVALID / invalid-payload, timeouts,
|
|
404
|
+
* aborts, network errors, and post-acknowledgement local persistence failures.
|
|
405
|
+
*/
|
|
406
|
+
export function isDefiniteStudioPreAdmissionRejection(
|
|
407
|
+
capability: StudioJobRecoveryCapability,
|
|
408
|
+
cause: unknown,
|
|
409
|
+
): boolean {
|
|
410
|
+
const reasonCode = normalizedReasonCode(cause);
|
|
411
|
+
if (reasonCode === 'AI_LOCAL_ASSET_SLOT_MISSING') return true;
|
|
412
|
+
if (capability === 'vision.locate' && reasonCode === 'AI_MEDIA_OPTION_UNSUPPORTED') return true;
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Some validation codes also occur after a Job was issued. On the submit
|
|
417
|
+
// boundary, resolve the exact idempotency key before discarding its record.
|
|
418
|
+
export async function reconcileStudioSubmitRejection(
|
|
419
|
+
client: { readonly ai: Pick<NimiLocalAppClient['ai'], 'scenarioJobs'>; readonly storage: { readonly assets: StudioJobRecoveryAssets } },
|
|
420
|
+
capability: StudioJobRecoveryCapability,
|
|
421
|
+
id: string,
|
|
422
|
+
cause: unknown,
|
|
423
|
+
) {
|
|
424
|
+
const assets = client.storage.assets;
|
|
425
|
+
if (isDefiniteStudioPreAdmissionRejection(capability, cause)) {
|
|
426
|
+
await cleanupRejectedStudioRecoveryEntry(assets, capability, id);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const reason = normalizedReasonCode(cause);
|
|
430
|
+
if (!['AI_MEDIA_OPTION_UNSUPPORTED', 'AI_VOICE_INPUT_INVALID', 'AI_VOICE_TARGET_MODEL_MISMATCH',
|
|
431
|
+
'AI_VOICE_ASSET_NOT_FOUND', 'AI_VOICE_ASSET_EXPIRED', 'AI_ROUTE_UNSUPPORTED', 'AI_INPUT_INVALID',
|
|
432
|
+
'AI_INPUT_LIMIT_EXCEEDED', 'AI_MEDIA_SPEC_INVALID', 'AI_LOCAL_EXECUTION_LOAD_FAILED'].includes(reason)) return;
|
|
433
|
+
let found;
|
|
434
|
+
try {
|
|
435
|
+
found = await client.ai.scenarioJobs.lookupSubmission(id);
|
|
436
|
+
} catch (lookupError) {
|
|
437
|
+
if (normalizedReasonCode(lookupError) === 'AI_MEDIA_JOB_NOT_FOUND') await cleanupRejectedStudioRecoveryEntry(assets, capability, id);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
await captureStudioJobRecoveryJobId(assets, id, found.job.jobId, capability);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export function isDefiniteUninvokedRunnerRejection(cause: unknown): boolean {
|
|
444
|
+
return normalizedReasonCode(cause) === 'SDK_LOCAL_APP_INPUT_INVALID';
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export async function cleanupRejectedStudioRecoveryEntry(
|
|
448
|
+
assets: StudioJobRecoveryAssets,
|
|
449
|
+
capability: StudioJobRecoveryCapability,
|
|
450
|
+
id: string,
|
|
451
|
+
): Promise<ForgetPendingRecoveryResult> {
|
|
452
|
+
const outcome = await forgetPendingStudioJobRecoveryIfUnacknowledged(assets, capability, id);
|
|
453
|
+
if (!outcome.removed) return outcome;
|
|
454
|
+
const ownedInputPaths = [
|
|
455
|
+
...new Set([
|
|
456
|
+
...(outcome.entry.sourceAudio ? [outcome.entry.sourceAudio.relativePath] : []),
|
|
457
|
+
...(outcome.entry.targetAudio ? [outcome.entry.targetAudio.relativePath] : []),
|
|
458
|
+
...(outcome.entry.details?.sourceImage ? [outcome.entry.details.sourceImage.relativePath] : []),
|
|
459
|
+
]),
|
|
460
|
+
];
|
|
461
|
+
for (const relativePath of ownedInputPaths) {
|
|
462
|
+
await assets.remove(relativePath).catch(() => undefined);
|
|
463
|
+
}
|
|
464
|
+
return outcome;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export async function restoreSavedStudioJobResult(
|
|
468
|
+
entry: StudioJobRecoveryEntry,
|
|
469
|
+
label: string,
|
|
470
|
+
capability: StudioJobRecoveryCapability,
|
|
471
|
+
assets: Pick<NimiLocalAppClient['storage']['assets'], 'read'>,
|
|
472
|
+
signal?: AbortSignal,
|
|
473
|
+
): Promise<StudioCapabilityRunResult | null> {
|
|
140
474
|
if (!entry.result) return null;
|
|
141
475
|
await verifySavedStudioJobAssets(entry, assets, signal);
|
|
142
476
|
signal?.throwIfAborted();
|
|
143
477
|
const result = restoreStudioCapabilityRunResult({ capabilityId: capability, result: entry.result, message: entry.message ?? '' }, () => label);
|
|
144
478
|
if (capability === 'audio.separate' && entry.separationRequest && result?.ok && result.output.kind === 'artifacts' && result.output.audioSeparation) {
|
|
145
|
-
return {
|
|
146
|
-
|
|
479
|
+
return {
|
|
480
|
+
...result,
|
|
481
|
+
output: {
|
|
482
|
+
...result.output,
|
|
483
|
+
audioSeparation: { ...result.output.audioSeparation, request: entry.separationRequest },
|
|
484
|
+
},
|
|
485
|
+
};
|
|
147
486
|
}
|
|
148
487
|
return result;
|
|
149
488
|
}
|
|
150
489
|
|
|
151
|
-
export async function verifySavedStudioJobAssets(
|
|
152
|
-
|
|
490
|
+
export async function verifySavedStudioJobAssets(
|
|
491
|
+
entry: StudioJobRecoveryEntry,
|
|
492
|
+
assets: Pick<NimiLocalAppClient['storage']['assets'], 'read'>,
|
|
493
|
+
signal?: AbortSignal,
|
|
494
|
+
): Promise<void> {
|
|
153
495
|
if (!entry.result) return;
|
|
154
496
|
const refs = studioResultAssetReferences(entry.result);
|
|
155
497
|
for (const path of studioResultAssetPaths(entry.result)) {
|
|
156
|
-
const references = refs.filter(ref => ref.relativePath === path);
|
|
498
|
+
const references = refs.filter((ref) => ref.relativePath === path);
|
|
157
499
|
const expected: { relativePath: string; sha256?: string; sizeBytes?: number; mediaType?: string } = { relativePath: path };
|
|
158
500
|
for (const ref of references) {
|
|
159
501
|
for (const key of ['sha256', 'sizeBytes', 'mediaType'] as const) {
|
|
160
502
|
const value = ref[key];
|
|
161
503
|
if (value === undefined) continue;
|
|
162
|
-
if ((key === 'sizeBytes' ? typeof value !== 'number' : typeof value !== 'string') || (expected[key] !== undefined && expected[key] !== value))
|
|
504
|
+
if ((key === 'sizeBytes' ? typeof value !== 'number' : typeof value !== 'string') || (expected[key] !== undefined && expected[key] !== value)) {
|
|
505
|
+
throw new Error('Saved asset roles disagree');
|
|
506
|
+
}
|
|
163
507
|
Object.assign(expected, { [key]: value });
|
|
164
508
|
}
|
|
165
509
|
}
|
|
@@ -167,56 +511,102 @@ export async function verifySavedStudioJobAssets(entry: StudioJobRecoveryEntry,
|
|
|
167
511
|
}
|
|
168
512
|
}
|
|
169
513
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
clientSubmissionId: string,
|
|
514
|
+
export function createRecordedStudioScenarioJobSession(
|
|
515
|
+
context: import('./runtime.js').StudioCapabilityRuntimeContext,
|
|
516
|
+
clientSubmissionId: string,
|
|
517
|
+
capability: StudioJobRecoveryCapability,
|
|
518
|
+
) {
|
|
173
519
|
const api = context.host.client.ai;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
520
|
+
const assets = context.host.client.storage.assets;
|
|
521
|
+
let submitInvoked = false;
|
|
522
|
+
const client = context.host.createScenarioJobClient({
|
|
523
|
+
...api,
|
|
524
|
+
scenarioJobs: {
|
|
525
|
+
...api.scenarioJobs,
|
|
526
|
+
async submit(spec, options) {
|
|
527
|
+
context.input.observationSignal?.throwIfAborted();
|
|
528
|
+
context.input.signal?.throwIfAborted();
|
|
529
|
+
const current = await recoveryStore(assets, capability).readVersion(clientSubmissionId);
|
|
530
|
+
if (!current || current.record.state !== 'pending' || current.record.jobId) {
|
|
531
|
+
throw new Error('The recorded action is missing or already submitted');
|
|
532
|
+
}
|
|
533
|
+
context.input.observationSignal?.throwIfAborted();
|
|
534
|
+
context.input.signal?.throwIfAborted();
|
|
535
|
+
submitInvoked = true;
|
|
536
|
+
let response;
|
|
537
|
+
try {
|
|
538
|
+
response = await api.scenarioJobs.submit(spec, { ...options, clientSubmissionId });
|
|
539
|
+
} catch (cause) {
|
|
540
|
+
await reconcileStudioSubmitRejection(context.host.client, capability, clientSubmissionId, cause);
|
|
541
|
+
throw cause;
|
|
542
|
+
}
|
|
543
|
+
// Post-acknowledgement local persistence failure must never remove the recovery record.
|
|
544
|
+
await captureStudioJobRecoveryJobId(assets, clientSubmissionId, response.job.jobId, capability);
|
|
545
|
+
return response;
|
|
546
|
+
},
|
|
185
547
|
},
|
|
186
|
-
}
|
|
548
|
+
});
|
|
549
|
+
return {
|
|
550
|
+
client,
|
|
551
|
+
wasSubmitInvoked: () => submitInvoked,
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/** Submit only after beginStudioJobRecovery has durably recorded this action. */
|
|
556
|
+
export function recordedStudioScenarioJobClient(
|
|
557
|
+
context: import('./runtime.js').StudioCapabilityRuntimeContext,
|
|
558
|
+
clientSubmissionId: string,
|
|
559
|
+
capability: StudioJobRecoveryCapability,
|
|
560
|
+
) {
|
|
561
|
+
return createRecordedStudioScenarioJobSession(context, clientSubmissionId, capability).client;
|
|
187
562
|
}
|
|
188
563
|
|
|
189
|
-
export async function recoverStudioJobId(
|
|
190
|
-
|
|
191
|
-
|
|
564
|
+
export async function recoverStudioJobId(
|
|
565
|
+
client: { readonly ai: Pick<NimiLocalAppClient['ai'], 'scenarioJobs'>; readonly storage: { readonly assets: StudioJobRecoveryAssets } },
|
|
566
|
+
entry: StudioJobRecoveryEntry,
|
|
567
|
+
capability: StudioJobRecoveryCapability,
|
|
568
|
+
): Promise<string> {
|
|
569
|
+
const response = entry.jobId
|
|
570
|
+
? await client.ai.scenarioJobs.get(entry.jobId)
|
|
571
|
+
: await client.ai.scenarioJobs.lookupSubmission(entry.clientSubmissionId);
|
|
572
|
+
await captureStudioJobRecoveryJobId(client.storage.assets, entry.clientSubmissionId, response.job.jobId, capability);
|
|
192
573
|
return response.job.jobId;
|
|
193
574
|
}
|
|
194
575
|
|
|
195
576
|
export function isStudioJobRecoveryCapability(value: string): value is StudioJobRecoveryCapability {
|
|
196
|
-
return
|
|
577
|
+
return STUDIO_JOB_RECOVERY_CAPABILITIES.has(value);
|
|
197
578
|
}
|
|
198
579
|
|
|
199
580
|
function validateRecoveryDetails(value: unknown): asserts value is StudioJobRecoveryDetails {
|
|
200
581
|
const fail = () => { throw new Error('Saved task inputs are invalid'); };
|
|
201
|
-
if (
|
|
202
|
-
|
|
582
|
+
if (
|
|
583
|
+
!isJsonObject(value)
|
|
584
|
+
|| Object.keys(value).some((key) => !['scenarioType', 'sourceImage', 'expectedVision', 'creationSource', 'timestamps', 'texts', 'faceSwap'].includes(key))
|
|
585
|
+
|| typeof value.scenarioType !== 'number'
|
|
586
|
+
|| value.scenarioType <= 0
|
|
587
|
+
|| !Object.values(ScenarioType).includes(value.scenarioType)
|
|
588
|
+
) return fail();
|
|
203
589
|
if (value.expectedVision !== undefined || value.sourceImage !== undefined) {
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
||
|
|
207
|
-
||
|
|
590
|
+
if (
|
|
591
|
+
value.scenarioType !== ScenarioType.VISION_LOCATE
|
|
592
|
+
|| !isJsonObject(value.expectedVision)
|
|
593
|
+
|| Object.keys(value.expectedVision).some((key) => !['imageArtifactId', 'geometry'].includes(key))
|
|
594
|
+
|| typeof value.expectedVision.imageArtifactId !== 'string'
|
|
595
|
+
|| !value.expectedVision.imageArtifactId.trim()
|
|
596
|
+
|| ![VisionLocateGeometry.BOX, VisionLocateGeometry.POINT].includes(Number(value.expectedVision.geometry))
|
|
597
|
+
) return fail();
|
|
208
598
|
validateManagedArtifact(value.sourceImage, 'saved Locate image');
|
|
209
599
|
}
|
|
210
600
|
if (value.creationSource !== undefined && (value.scenarioType !== ScenarioType.VOICE_CREATE || !['reference-audio', 'text-description'].includes(String(value.creationSource)))) return fail();
|
|
211
601
|
if (value.timestamps !== undefined && (value.scenarioType !== ScenarioType.SPEECH_TRANSCRIBE || typeof value.timestamps !== 'boolean')) return fail();
|
|
212
|
-
if (value.texts !== undefined && (value.scenarioType !== ScenarioType.TEXT_ANNOTATE || !Array.isArray(value.texts) || !value.texts.length || value.texts.length > 64 || value.texts.some(text => typeof text !== 'string'))) return fail();
|
|
602
|
+
if (value.texts !== undefined && (value.scenarioType !== ScenarioType.TEXT_ANNOTATE || !Array.isArray(value.texts) || !value.texts.length || value.texts.length > 64 || value.texts.some((text) => typeof text !== 'string'))) return fail();
|
|
213
603
|
if (value.faceSwap !== undefined) {
|
|
214
604
|
if (![ScenarioType.IMAGE_FACE_SWAP, ScenarioType.VIDEO_FACE_SWAP].includes(value.scenarioType)) return fail();
|
|
215
605
|
validateFaceSwapHistory(value.faceSwap, 'saved face replacement');
|
|
216
606
|
}
|
|
217
607
|
}
|
|
218
608
|
|
|
219
|
-
export const studioJobRecoveryCapabilities = Object.freeze(
|
|
609
|
+
export const studioJobRecoveryCapabilities = Object.freeze([...STUDIO_JOB_RECOVERY_CAPABILITY_LIST]);
|
|
220
610
|
|
|
221
611
|
/** Local result work stops for either view disposal or the current user action. */
|
|
222
612
|
export function studioJobRecoverySignal(input: { readonly signal?: AbortSignal; readonly observationSignal?: AbortSignal }): AbortSignal {
|