@nimiplatform/app-tools 0.7.5 → 0.12.0
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 +59 -5
- package/bin/nimi-app.mjs +11 -3
- package/lib/app-access-declaration.mjs +1 -0
- package/lib/app-dependency-combinations.mjs +16 -28
- package/lib/app-doctor-update.mjs +66 -7
- package/lib/app-info.mjs +8 -1
- package/lib/app-project-lifecycle.mjs +82 -9
- package/lib/app-scaffold-capabilities.mjs +3 -3
- package/lib/app-scaffold-profiles.mjs +96 -26
- package/lib/app-scaffold.mjs +54 -7
- package/lib/canonical-capability-ids.generated.mjs +4 -0
- package/package.json +26 -25
- package/scripts/dev-shell.mjs +61 -17
- package/skills/nimi-app-lifecycle/references/acceptance.md +1 -1
- package/skills/nimi-app-lifecycle/references/adapt.md +2 -2
- package/skills/nimi-app-lifecycle/references/release.md +1 -1
- package/skills/nimi-app-lifecycle/references/upgrade-platform.md +14 -0
- package/templates/app-source/src/ai-studio-core/ai-config.ts +17 -3
- package/templates/app-source/src/ai-studio-core/ai-studio-core.css +40 -3
- package/templates/app-source/src/ai-studio-core/audio-separation-request.ts +24 -0
- package/templates/app-source/src/ai-studio-core/contexts.tsx +4 -0
- package/templates/app-source/src/ai-studio-core/history-policy.ts +395 -41
- package/templates/app-source/src/ai-studio-core/history.ts +262 -10
- package/templates/app-source/src/ai-studio-core/host-context.tsx +15 -2
- package/templates/app-source/src/ai-studio-core/index.ts +15 -4
- package/templates/app-source/src/ai-studio-core/job-recovery-panel.tsx +105 -0
- package/templates/app-source/src/ai-studio-core/job-recovery.ts +224 -0
- package/templates/app-source/src/ai-studio-core/managed-result-references.ts +79 -0
- package/templates/app-source/src/ai-studio-core/messages/en.json +185 -10
- package/templates/app-source/src/ai-studio-core/messages/zh.json +185 -10
- package/templates/app-source/src/ai-studio-core/module-registration.ts +9 -1
- package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +81 -2
- package/templates/app-source/src/ai-studio-core/parameters.ts +34 -1
- package/templates/app-source/src/ai-studio-core/runtime-types.ts +124 -8
- package/templates/app-source/src/ai-studio-core/runtime.ts +218 -20
- package/templates/app-source/src/ai-studio-core/section-ai-testing-annotation-result.tsx +123 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +3 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-audio-separation-result.tsx +26 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +14 -7
- package/templates/app-source/src/ai-studio-core/section-ai-testing-decision-result.tsx +76 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-exchange-result.tsx +71 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +20 -4
- package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +29 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-music-result.tsx +45 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +132 -10
- package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +122 -38
- package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +4 -3
- package/templates/app-source/src/ai-studio-core/section-ai-testing-session-result.tsx +66 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +100 -22
- package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +6 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-transcript-result.tsx +45 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-transcription-result.tsx +106 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +23 -4
- package/templates/app-source/src/ai-studio-core/section-ai-testing-voice-asset-actions.tsx +40 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-voice-conversion-result.tsx +20 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +219 -35
- package/templates/app-source/src/ai-studio-core/text-annotation-document.ts +50 -0
- package/templates/app-source/src/ai-studio-core/text-media-replay.ts +51 -0
- package/templates/app-source/src/ai-studio-core/voice-assets.ts +17 -0
- package/templates/app-source/src/ai-studio-core/workspace.tsx +48 -6
- package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +1 -1
- package/templates/app-source/src/studio-modules/studio-create/messages/en.json +13 -1
- package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +13 -1
- package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +11 -2
- package/templates/app-source/src/studio-modules/studio-create/parameters.ts +2 -2
- package/templates/app-source/src/studio-modules/studio-create/registration.ts +2 -2
- package/templates/app-source/src/studio-modules/studio-create/runtime.ts +121 -3
- package/templates/app-source/src/studio-modules/studio-media/audio-separate-parameters.tsx +72 -0
- package/templates/app-source/src/studio-modules/studio-media/audio-separate-runtime.ts +90 -0
- package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +16 -1
- package/templates/app-source/src/studio-modules/studio-media/index.ts +2 -0
- package/templates/app-source/src/studio-modules/studio-media/messages/en.json +225 -7
- package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +225 -7
- package/templates/app-source/src/studio-modules/studio-media/music-parameters.tsx +85 -0
- package/templates/app-source/src/studio-modules/studio-media/music-transcription-parameters.tsx +85 -0
- package/templates/app-source/src/studio-modules/studio-media/music-transcription-runtime.ts +64 -0
- package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +9 -26
- package/templates/app-source/src/studio-modules/studio-media/parameters.ts +170 -6
- package/templates/app-source/src/studio-modules/studio-media/registration.ts +29 -1
- package/templates/app-source/src/studio-modules/studio-media/runtime.ts +90 -6
- package/templates/app-source/src/studio-modules/studio-media/vision-parameters.tsx +1 -0
- package/templates/app-source/src/studio-modules/studio-media/vision-runtime.ts +23 -5
- package/templates/app-source/src/studio-modules/studio-media/voice-convert-parameters.tsx +132 -0
- package/templates/app-source/src/studio-modules/studio-media/voice-convert-runtime.ts +120 -0
- package/templates/app-source/src/studio-modules/studio-voice/audio-url.ts +25 -0
- package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +4 -4
- package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +4 -4
- package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +28 -0
- package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +66 -30
- package/templates/app-source/src/workbench-core/index.ts +2 -0
- package/templates/app-source/src/workbench-core/runtime-gate.tsx +102 -6
- package/templates/app-source/src/workbench-core/workbench-core.css +42 -0
- package/templates/app-source/src/workbench-core/workbench-core.tsx +69 -18
- package/templates/app-source.manifest.json +100 -0
- package/templates/default-starter/README.md +2 -1
- package/templates/default-starter/src/shell/workbench-target-adapter.ts +102 -12
- package/templates/default-starter.manifest.json +0 -4
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Button, SelectField, TextareaField } from '@nimiplatform/kit/ui';
|
|
3
|
+
import type { NimiMusicInputCapabilities } from '@nimiplatform/sdk/ai';
|
|
4
|
+
import { useAIStudioHost } from '../../ai-studio-core/host-context.js';
|
|
5
|
+
import { StudioBooleanParameter, StudioNumberParameter, StudioParameterField, type StudioParameterPanelProps } from '../../ai-studio-core/parameter-fields.js';
|
|
6
|
+
import type { StudioMusicGenerationParameters } from './parameters.js';
|
|
7
|
+
|
|
8
|
+
export function MusicFields(props: StudioParameterPanelProps) {
|
|
9
|
+
const host = useAIStudioHost();
|
|
10
|
+
const { translate: t } = host;
|
|
11
|
+
const parameters = props.parameters as StudioMusicGenerationParameters;
|
|
12
|
+
const update = props.onChange as (next: StudioMusicGenerationParameters) => void;
|
|
13
|
+
const [capabilities, setCapabilities] = useState<NimiMusicInputCapabilities | null>(null);
|
|
14
|
+
const [loading, setLoading] = useState(true);
|
|
15
|
+
const [error, setError] = useState('');
|
|
16
|
+
const [importing, setImporting] = useState(false);
|
|
17
|
+
const input = useRef<HTMLInputElement>(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
let active = true;
|
|
20
|
+
// Closing the drawer and a commit can both refresh; only the newest read
|
|
21
|
+
// applies, so a slower, older snapshot never undoes a newer one.
|
|
22
|
+
let requestGeneration = 0;
|
|
23
|
+
const refresh = () => {
|
|
24
|
+
const generation = ++requestGeneration;
|
|
25
|
+
setLoading(true);
|
|
26
|
+
void host.sdk.aiConfig.getSnapshot().then((snapshot) => {
|
|
27
|
+
if (!active || generation !== requestGeneration) return;
|
|
28
|
+
const selection = snapshot.effectiveSelections.find((item) => item.capabilityContract === 'music.generate');
|
|
29
|
+
const resource = selection?.resource;
|
|
30
|
+
const next = resource?.oneofKind === 'local' ? resource.local.musicInput : resource?.oneofKind === 'cloud' ? resource.cloud.target?.musicInput : undefined;
|
|
31
|
+
setCapabilities(selection?.state === 'ready' && next ? next : null);
|
|
32
|
+
setError('');
|
|
33
|
+
}).catch((cause: unknown) => {
|
|
34
|
+
if (active && generation === requestGeneration) { setCapabilities(null); setError(cause instanceof Error ? cause.message : String(cause)); }
|
|
35
|
+
}).finally(() => { if (active && generation === requestGeneration) setLoading(false); });
|
|
36
|
+
};
|
|
37
|
+
refresh();
|
|
38
|
+
const unsubscribe = host.app.events.subscribeAIConfigRefresh(refresh);
|
|
39
|
+
return () => { active = false; unsubscribe(); };
|
|
40
|
+
}, [host]);
|
|
41
|
+
const profile = capabilities?.generation.find((item) => item.scoreMode === (parameters.scoreRelativePath ? 'required' : 'unsupported'));
|
|
42
|
+
const scoreProfile = capabilities?.generation.find((item) => item.scoreMode === 'required' && item.scoreFormats.includes('abc'));
|
|
43
|
+
const disabled = props.disabled || importing || loading || !profile;
|
|
44
|
+
async function importScore(file: File) {
|
|
45
|
+
if (!scoreProfile || file.size < 1 || file.size > scoreProfile.maxScoreBytes) { setError(t('Music.scoreTooLarge')); return; }
|
|
46
|
+
setImporting(true); setError('');
|
|
47
|
+
try {
|
|
48
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
49
|
+
new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
50
|
+
const asset = await host.sdk.assets.write({ relativePath: `studio/music/inputs/${crypto.randomUUID()}.abc`, body: bytes, mediaType: 'text/vnd.abc', overwrite: false });
|
|
51
|
+
update({ ...parameters, scoreRelativePath: asset.relativePath, scoreName: file.name, scoreConditioning: 'melody-and-harmony', returnGeneratedScore: false });
|
|
52
|
+
} catch (cause) { setError(cause instanceof Error ? cause.message : String(cause)); }
|
|
53
|
+
finally { setImporting(false); }
|
|
54
|
+
}
|
|
55
|
+
return <div className="space-y-4">
|
|
56
|
+
{loading ? <p>{t('Music.loadingInputs')}</p> : !capabilities ? <p>{t('Music.configureInputs')}</p> : null}
|
|
57
|
+
<StudioParameterField label={t('Studio.parameters.fields.lyrics')}>
|
|
58
|
+
<TextareaField value={parameters.lyrics ?? ''} disabled={disabled || parameters.instrumental === true}
|
|
59
|
+
textareaClassName="min-h-36 font-mono" onChange={(event) => update({ ...parameters, lyrics: event.currentTarget.value })} />
|
|
60
|
+
</StudioParameterField>
|
|
61
|
+
{profile?.lyricsMode === 'unsupported' ? <p className="text-sm opacity-70">{t('Music.lyricsUnsupported')}</p> : null}
|
|
62
|
+
<StudioNumberParameter current={parameters} field="durationSeconds" label={t('Music.duration', { max: profile?.maxDurationSeconds ?? '—' })} onChange={update} disabled={disabled} />
|
|
63
|
+
<p className="text-sm opacity-70">{profile && profile.maxDurationSeconds > 0 && profile.maxDurationSeconds === profile.defaultDurationSeconds
|
|
64
|
+
? t('Music.fixedClipDuration', { seconds: profile.defaultDurationSeconds }) : t('Music.durationHint')}</p>
|
|
65
|
+
{profile?.supportsSeed ? <StudioNumberParameter current={parameters} field="seed" label={t('Music.seed')} onChange={update} disabled={disabled} /> : null}
|
|
66
|
+
{profile?.supportsInstrumental ? <StudioBooleanParameter current={parameters} field="instrumental" label={t('Music.instrumental')} onChange={(next) => update({ ...next, ...(next.instrumental ? { lyrics: '' } : {}) })} disabled={disabled} /> : null}
|
|
67
|
+
{scoreProfile ? <StudioParameterField label={t('Music.score')}>
|
|
68
|
+
<input ref={input} type="file" accept=".abc,text/vnd.abc" hidden onChange={(event) => {
|
|
69
|
+
const file = event.currentTarget.files?.[0]; event.currentTarget.value = ''; if (file) void importScore(file);
|
|
70
|
+
}} />
|
|
71
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
72
|
+
<Button disabled={props.disabled || importing} onClick={() => input.current?.click()}>{t(importing ? 'Music.importing' : 'Music.importScore')}</Button>
|
|
73
|
+
{parameters.scoreRelativePath ? <><span>{parameters.scoreName || t('Music.importedScore')}</span><Button disabled={props.disabled} onClick={() => {
|
|
74
|
+
const { scoreRelativePath, scoreName, scoreConditioning, ...rest } = parameters; update(rest);
|
|
75
|
+
}}>{t('Music.clearScore')}</Button></> : null}
|
|
76
|
+
</div>
|
|
77
|
+
{parameters.scoreRelativePath ? <SelectField value={parameters.scoreConditioning ?? 'melody-and-harmony'} disabled={disabled}
|
|
78
|
+
onChange={(event) => update({ ...parameters, scoreConditioning: event.currentTarget.value as 'melody-only' | 'melody-and-harmony' })}
|
|
79
|
+
options={scoreProfile.scoreConditioning.map((value) => ({ value, label: t(value === 'melody-only' ? 'Music.melodyOnly' : 'Music.melodyHarmony') }))} /> : null}
|
|
80
|
+
<p className="text-sm opacity-70">{t('Music.scoreHint')}</p>
|
|
81
|
+
</StudioParameterField> : null}
|
|
82
|
+
{profile?.supportsGeneratedScore ? <StudioBooleanParameter current={parameters} field="returnGeneratedScore" label={t('Music.returnScore')} onChange={update} disabled={disabled} /> : null}
|
|
83
|
+
{error ? <p role="alert">{error}</p> : null}
|
|
84
|
+
</div>;
|
|
85
|
+
}
|
package/templates/app-source/src/studio-modules/studio-media/music-transcription-parameters.tsx
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Button, SelectField } from '@nimiplatform/kit/ui';
|
|
3
|
+
import type { NimiMusicTranscriptionInputProfile } from '@nimiplatform/sdk/ai';
|
|
4
|
+
import { useAIStudioHost } from '../../ai-studio-core/host-context.js';
|
|
5
|
+
import { StudioNumberParameter, StudioParameterField, type StudioParameterPanelProps } from '../../ai-studio-core/parameter-fields.js';
|
|
6
|
+
import type { StudioMusicTranscriptionParameters } from './parameters.js';
|
|
7
|
+
|
|
8
|
+
export function MusicTranscriptionFields(props: StudioParameterPanelProps) {
|
|
9
|
+
const host = useAIStudioHost(); const { translate: t } = host;
|
|
10
|
+
const parameters = props.parameters as StudioMusicTranscriptionParameters;
|
|
11
|
+
const update = props.onChange as (next: StudioMusicTranscriptionParameters) => void;
|
|
12
|
+
const [profiles, setProfiles] = useState<readonly NimiMusicTranscriptionInputProfile[]>([]);
|
|
13
|
+
const [busy, setBusy] = useState(false); const [error, setError] = useState('');
|
|
14
|
+
const fileInput = useRef<HTMLInputElement>(null);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
let active = true;
|
|
17
|
+
// Closing the drawer and a commit can both refresh; only the newest read
|
|
18
|
+
// applies, so a slower, older snapshot never undoes a newer one.
|
|
19
|
+
let requestGeneration = 0;
|
|
20
|
+
const refresh = () => {
|
|
21
|
+
const generation = ++requestGeneration;
|
|
22
|
+
void host.sdk.aiConfig.getSnapshot().then(snapshot => {
|
|
23
|
+
if (!active || generation !== requestGeneration) return;
|
|
24
|
+
const selected = snapshot.effectiveSelections.find(item => item.capabilityContract === 'music.transcribe');
|
|
25
|
+
setProfiles(selected?.state === 'ready' && selected.resource?.oneofKind === 'local' ? selected.resource.local.musicInput?.transcription ?? [] : []);
|
|
26
|
+
setError('');
|
|
27
|
+
}).catch((cause: unknown) => { if (active && generation === requestGeneration) { setProfiles([]); setError(String(cause)); } });
|
|
28
|
+
};
|
|
29
|
+
refresh(); const unsubscribe = host.app.events.subscribeAIConfigRefresh(refresh);
|
|
30
|
+
return () => { active = false; unsubscribe(); };
|
|
31
|
+
}, [host]);
|
|
32
|
+
const profile = profiles.find(item => item.parts.includes(parameters.requestedPart ?? item.parts[0]!)) ?? profiles[0];
|
|
33
|
+
const disabled = props.disabled || busy;
|
|
34
|
+
async function importAudio(file: File) {
|
|
35
|
+
const extension = file.name.match(/\.(mp3|wav|flac)$/iu)?.[1]?.toLowerCase();
|
|
36
|
+
if (!extension || !profile || file.size < 1 || file.size > profile.maxSourceBytes) { setError(t('Transcription.fileInvalid')); return; }
|
|
37
|
+
const mimeType = extension === 'mp3' ? 'audio/mpeg' : extension === 'flac' ? 'audio/flac' : 'audio/wav';
|
|
38
|
+
// Do not leave the previous recording executable while its replacement is
|
|
39
|
+
// still being copied. The composer requires a committed source asset.
|
|
40
|
+
update({ requestedFormats: [...profile.formats], requestedPart: profile.parts[0] });
|
|
41
|
+
setBusy(true); setError('');
|
|
42
|
+
try {
|
|
43
|
+
async function* chunks() {
|
|
44
|
+
const reader = file.stream().getReader();
|
|
45
|
+
try { while (true) { const next = await reader.read(); if (next.done) break; yield next.value; } }
|
|
46
|
+
finally { await reader.cancel(); reader.releaseLock(); }
|
|
47
|
+
}
|
|
48
|
+
const asset = await host.sdk.assets.write({ relativePath: `studio/music/imports/${crypto.randomUUID()}/source.${extension}`, body: chunks(), mediaType: mimeType, overwrite: false });
|
|
49
|
+
update({ sourceRelativePath: asset.relativePath, sourceName: file.name, sourceMimeType: mimeType,
|
|
50
|
+
requestedFormats: [...profile.formats], requestedPart: profile.parts[0] });
|
|
51
|
+
} catch (cause) { setError(cause instanceof Error ? cause.message : String(cause)); }
|
|
52
|
+
finally { setBusy(false); }
|
|
53
|
+
}
|
|
54
|
+
return <div className="space-y-4">
|
|
55
|
+
{!profile ? <p>{t('Transcription.configureInputs')}</p> : <p>{t('Transcription.inputHint', { seconds: profile.maxDurationSeconds, mib: Math.floor(profile.maxSourceBytes / 1048576) })}</p>}
|
|
56
|
+
<StudioParameterField label={t('Transcription.source')}>
|
|
57
|
+
<input ref={fileInput} hidden type="file" accept=".mp3,.wav,.flac" onChange={event => {
|
|
58
|
+
const file = event.currentTarget.files?.[0]; event.currentTarget.value = ''; if (file) void importAudio(file);
|
|
59
|
+
}} />
|
|
60
|
+
<Button disabled={disabled || !profile} onClick={() => fileInput.current?.click()}>{t(busy ? 'Music.importing' : 'Transcription.chooseSource')}</Button>
|
|
61
|
+
{parameters.sourceRelativePath ? <p>{parameters.sourceName}</p> : null}
|
|
62
|
+
</StudioParameterField>
|
|
63
|
+
{profile ? <>
|
|
64
|
+
<StudioParameterField label={t('Transcription.part')}>
|
|
65
|
+
<SelectField value={parameters.requestedPart ?? profile.parts[0]} disabled={disabled}
|
|
66
|
+
options={[...new Set(profiles.flatMap(item => item.parts))].map(value => ({ value, label: t(`Transcription.parts.${value}`) }))}
|
|
67
|
+
onChange={event => { const part = event.currentTarget.value as NonNullable<StudioMusicTranscriptionParameters['requestedPart']>; const next = profiles.find(item => item.parts.includes(part)); update({ ...parameters, requestedPart: part, requestedFormats: next ? [...next.formats] : [] }); }} />
|
|
68
|
+
</StudioParameterField>
|
|
69
|
+
<StudioParameterField label={t('Transcription.formats')}>
|
|
70
|
+
<div className="flex flex-wrap gap-4">{profile.formats.map(format => <label key={format} className="flex items-center gap-2">
|
|
71
|
+
<input type="checkbox" checked={parameters.requestedFormats?.includes(format) ?? false} disabled={disabled}
|
|
72
|
+
onChange={event => update({ ...parameters, requestedFormats: event.currentTarget.checked ? [...(parameters.requestedFormats ?? []), format] : parameters.requestedFormats?.filter(item => item !== format) })} />
|
|
73
|
+
{format === 'timeline' ? t('Transcription.timeline') : format.toUpperCase()}
|
|
74
|
+
</label>)}</div>
|
|
75
|
+
</StudioParameterField>
|
|
76
|
+
{profile.supportsRange ? <>
|
|
77
|
+
<StudioNumberParameter current={parameters} field="startSeconds" label={t('Transcription.start')} onChange={update} disabled={disabled} />
|
|
78
|
+
<StudioNumberParameter current={parameters} field="endSeconds" label={t('Transcription.end')} onChange={update} disabled={disabled} />
|
|
79
|
+
<p className="text-sm opacity-70">{t('Transcription.rangeHint')}</p>
|
|
80
|
+
</> : null}
|
|
81
|
+
</> : null}
|
|
82
|
+
<p className="text-sm opacity-70">{t('Transcription.preparationHint')}</p>
|
|
83
|
+
{error ? <p role="alert">{error}</p> : null}
|
|
84
|
+
</div>;
|
|
85
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { beginStudioJobRecovery, recordedStudioScenarioJobClient, recoverStudioJobId, readStudioJobRecovery, restoreSavedStudioJobResult, saveStudioJobRecoveryResult, studioJobRecoverySignal } from '../../ai-studio-core/job-recovery.js';
|
|
2
|
+
import { createStudioScenarioJobClient, projectStudioArtifactRunnerResult, type StudioCapabilityRuntimeContext } from '../../ai-studio-core/runtime.js';
|
|
3
|
+
import type { StudioManagedArtifact } from '../../ai-studio-core/runtime-types.js';
|
|
4
|
+
import type { StudioMusicTranscriptionParameters } from './parameters.js';
|
|
5
|
+
|
|
6
|
+
// @nimi-authority: rule.nimi.runtime.ai-provider.music-transcription
|
|
7
|
+
export async function runMusicTranscribe(context: StudioCapabilityRuntimeContext) {
|
|
8
|
+
const parameters = context.input.parameters as StudioMusicTranscriptionParameters | undefined;
|
|
9
|
+
const client = context.host.client; const signal = context.input.signal;
|
|
10
|
+
if (parameters?.recoverySubmissionId) {
|
|
11
|
+
const entry = (await readStudioJobRecovery(client.storage, 'music.transcribe')).find(item => item.clientSubmissionId === parameters.recoverySubmissionId);
|
|
12
|
+
if (!entry?.sourceAudio) throw new Error(context.host.translate('Music.recoveryMissing'));
|
|
13
|
+
const saved = await restoreSavedStudioJobResult(entry, context.capability.label, 'music.transcribe', client.storage.assets, studioJobRecoverySignal(context.input));
|
|
14
|
+
if (saved) return saved;
|
|
15
|
+
const recoveredJobId = await recoverStudioJobId(client, entry, 'music.transcribe');
|
|
16
|
+
const result = await context.host.runners.musicTranscriptionObserve({ runtime: { ai: createStudioScenarioJobClient(context) },
|
|
17
|
+
jobId: recoveredJobId, signal: context.input.observationSignal, cancelSignal: signal, onObservation: context.input.onObservation, abortReason: context.host.abortReason, onJobUpdate: context.input.onJobUpdate });
|
|
18
|
+
const projected = await projectStudioArtifactRunnerResult({ ...context, musicSourceAudio: entry.sourceAudio }, result);
|
|
19
|
+
await saveStudioJobRecoveryResult(client.storage, entry.clientSubmissionId, projected, 'music.transcribe');
|
|
20
|
+
return projected;
|
|
21
|
+
}
|
|
22
|
+
const invalid = () => context.host.nonSuccess(context.capability, 'input-invalid', context.host.translate('Transcription.configureInputs'));
|
|
23
|
+
if (!parameters?.sourceRelativePath || !parameters.sourceMimeType || !parameters.requestedFormats?.length || !parameters.requestedPart) return invalid();
|
|
24
|
+
const snapshot = await client.aiConfig.get();
|
|
25
|
+
const selection = snapshot.effectiveSelections.find(item => item.capabilityContract === 'music.transcribe');
|
|
26
|
+
const resource = selection?.resource;
|
|
27
|
+
const capabilities = resource?.oneofKind === 'local' ? resource.local.musicInput : undefined;
|
|
28
|
+
const formats = parameters.requestedFormats; const part = parameters.requestedPart;
|
|
29
|
+
const hasRange = parameters.startSeconds !== undefined || parameters.endSeconds !== undefined;
|
|
30
|
+
const profile = capabilities?.transcription?.find(item => formats.every(format => item.formats.includes(format)) && item.parts.includes(part) && (!hasRange || item.supportsRange));
|
|
31
|
+
if (selection?.state !== 'ready' || !profile) return invalid();
|
|
32
|
+
const original = await client.storage.assets.stat(parameters.sourceRelativePath);
|
|
33
|
+
if (original.sizeBytes < 1 || original.sizeBytes > profile.maxSourceBytes || original.mediaType !== parameters.sourceMimeType) return invalid();
|
|
34
|
+
signal?.throwIfAborted();
|
|
35
|
+
// Runtime owns decoding and the frame basis. This unary preparation cannot be
|
|
36
|
+
// interrupted by the App; cancellation abandons submission when it settles.
|
|
37
|
+
const prepared = await client.ai.artifacts.upload({ source: { kind: 'app-asset', relativePath: original.relativePath },
|
|
38
|
+
mimeType: parameters.sourceMimeType, audioPreparation: { profile: 'canonical-pcm-v1' } });
|
|
39
|
+
signal?.throwIfAborted();
|
|
40
|
+
const info = prepared.audioInfo;
|
|
41
|
+
if (!info || prepared.mimeType !== 'audio/wav' || info.frameCount / info.sampleRateHz > profile.maxDurationSeconds) return invalid();
|
|
42
|
+
const startFrame = Math.round((parameters.startSeconds ?? 0) * info.sampleRateHz);
|
|
43
|
+
const endFrame = parameters.endSeconds === undefined ? info.frameCount : Math.round(parameters.endSeconds * info.sampleRateHz);
|
|
44
|
+
if (!Number.isSafeInteger(startFrame) || !Number.isSafeInteger(endFrame) || startFrame < 0 || startFrame >= endFrame || endFrame > info.frameCount) return invalid();
|
|
45
|
+
const adopted = await client.storage.assets.adoptArtifact({ artifactId: prepared.artifactId,
|
|
46
|
+
relativePath: `studio/music/transcription-inputs/${crypto.randomUUID()}/canonical.wav`, overwrite: false });
|
|
47
|
+
const sourceAudio: StudioManagedArtifact = { relativePath: adopted.relativePath, mediaType: adopted.mediaType,
|
|
48
|
+
sizeBytes: adopted.sizeBytes, sha256: adopted.sha256, displayName: parameters.sourceName, previewSource: 'managed-asset' };
|
|
49
|
+
let clientSubmissionId: string;
|
|
50
|
+
try {
|
|
51
|
+
signal?.throwIfAborted();
|
|
52
|
+
if (adopted.sizeBytes !== prepared.sizeBytes || adopted.mediaType !== prepared.mimeType) throw new Error('Canonical source adoption changed metadata');
|
|
53
|
+
clientSubmissionId = await beginStudioJobRecovery(client.storage, 'music.transcribe', sourceAudio, undefined,
|
|
54
|
+
undefined, context.input.recordedRunConfig, context.input.prompt);
|
|
55
|
+
} catch (cause) { await client.storage.assets.remove(adopted.relativePath); throw cause; }
|
|
56
|
+
const scenarioClient = recordedStudioScenarioJobClient(context, clientSubmissionId, 'music.transcribe');
|
|
57
|
+
const result = await context.host.runners.musicTranscribe({ runtime: { ai: scenarioClient }, appId: context.host.appId,
|
|
58
|
+
sourceAudio: { artifactId: prepared.artifactId, ...(hasRange ? { range: { startFrame, endFrame } } : {}) },
|
|
59
|
+
requestedFormats: formats, requestedParts: [part], scenarioId: context.scenarioId, surfaceId: context.host.surfaceId,
|
|
60
|
+
signal, observationSignal: context.input.observationSignal, onObservation: context.input.onObservation, abortReason: context.host.abortReason, onJobUpdate: context.input.onJobUpdate });
|
|
61
|
+
const projected = await projectStudioArtifactRunnerResult({ ...context, musicSourceAudio: sourceAudio }, result);
|
|
62
|
+
await saveStudioJobRecoveryResult(client.storage, clientSubmissionId, projected, 'music.transcribe');
|
|
63
|
+
return projected;
|
|
64
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MusicFields } from './music-parameters.js';
|
|
1
2
|
import { useRef, useState, type ChangeEvent } from 'react';
|
|
2
3
|
import { Button, SelectField, TextareaField } from '@nimiplatform/kit/ui';
|
|
3
4
|
import { Trash2, Upload } from 'lucide-react';
|
|
@@ -17,7 +18,6 @@ import { useAIStudioHost } from '../../ai-studio-core/host-context.js';
|
|
|
17
18
|
import {
|
|
18
19
|
MAX_STUDIO_ARTIFACT_UPLOAD_BYTES,
|
|
19
20
|
type StudioImageGenerationParameters,
|
|
20
|
-
type StudioMusicGenerationParameters,
|
|
21
21
|
type StudioVideoGenerationParameters,
|
|
22
22
|
} from './parameters.js';
|
|
23
23
|
|
|
@@ -28,27 +28,6 @@ function isStudioImageMimeType(value: string): value is StudioImageMimeType {
|
|
|
28
28
|
return STUDIO_IMAGE_MIME_TYPES.includes(value as StudioImageMimeType);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function MusicFields(props: StudioParameterPanelProps) {
|
|
32
|
-
const { translate: t } = useAIStudioHost();
|
|
33
|
-
const parameters = props.parameters as StudioMusicGenerationParameters;
|
|
34
|
-
const update = props.onChange as (next: StudioMusicGenerationParameters) => void;
|
|
35
|
-
const translate: StudioParameterTranslate = (key, values) => t(key, values);
|
|
36
|
-
const fields: StudioParameterFieldDefinition[] = [{
|
|
37
|
-
field: 'lyrics',
|
|
38
|
-
label: t('Studio.parameters.fields.lyrics'),
|
|
39
|
-
render: (routeDisabled) => (
|
|
40
|
-
<StudioParameterField label={t('Studio.parameters.fields.lyrics')}>
|
|
41
|
-
<TextareaField
|
|
42
|
-
value={parameters.lyrics ?? ''}
|
|
43
|
-
disabled={props.disabled || routeDisabled}
|
|
44
|
-
textareaClassName="min-h-36 font-mono"
|
|
45
|
-
onChange={(event) => update({ ...parameters, lyrics: event.currentTarget.value })}
|
|
46
|
-
/>
|
|
47
|
-
</StudioParameterField>
|
|
48
|
-
),
|
|
49
|
-
}];
|
|
50
|
-
return <StudioRouteAwareParameterFields contract={props.contract} source={props.source} fields={fields} translate={translate} />;
|
|
51
|
-
}
|
|
52
31
|
|
|
53
32
|
function ImageFields(props: StudioParameterPanelProps) {
|
|
54
33
|
const host = useAIStudioHost();
|
|
@@ -60,6 +39,7 @@ function ImageFields(props: StudioParameterPanelProps) {
|
|
|
60
39
|
const [uploading, setUploading] = useState(false);
|
|
61
40
|
const [uploadError, setUploadError] = useState('');
|
|
62
41
|
const [uploadedFileName, setUploadedFileName] = useState('');
|
|
42
|
+
const imageMimes = props.source === 'cloud' ? ['image/png', 'image/jpeg'] : STUDIO_IMAGE_MIME_TYPES;
|
|
63
43
|
async function selectReferenceImage(event: ChangeEvent<HTMLInputElement>) {
|
|
64
44
|
const file = event.currentTarget.files?.[0];
|
|
65
45
|
event.currentTarget.value = '';
|
|
@@ -68,8 +48,8 @@ function ImageFields(props: StudioParameterPanelProps) {
|
|
|
68
48
|
setUploadError(t('Studio.parameters.imageFileTooLarge'));
|
|
69
49
|
return;
|
|
70
50
|
}
|
|
71
|
-
if (!isStudioImageMimeType(file.type)) {
|
|
72
|
-
setUploadError(t('Studio.parameters.imageFileMimeUnsupported'));
|
|
51
|
+
if (!isStudioImageMimeType(file.type) || !imageMimes.includes(file.type as StudioImageMimeType)) {
|
|
52
|
+
setUploadError(t(props.source === 'cloud' ? 'Studio.parameters.cloudImageFileMimeUnsupported' : 'Studio.parameters.imageFileMimeUnsupported'));
|
|
73
53
|
return;
|
|
74
54
|
}
|
|
75
55
|
setUploading(true);
|
|
@@ -118,7 +98,7 @@ function ImageFields(props: StudioParameterPanelProps) {
|
|
|
118
98
|
{
|
|
119
99
|
field: 'seed',
|
|
120
100
|
label: t('Studio.parameters.fields.seed'),
|
|
121
|
-
render: (routeDisabled) => <StudioNumberParameter current={parameters} field="seed" label={t('Studio.parameters.fields.seed')} onChange={update} disabled={props.disabled || routeDisabled} step={1} />,
|
|
101
|
+
render: (routeDisabled) => <StudioNumberParameter current={parameters} field="seed" label={t('Studio.parameters.fields.seed')} onChange={update} disabled={props.disabled || routeDisabled} min={-1} max={2147483647} step={1} />,
|
|
122
102
|
},
|
|
123
103
|
textField('aspectRatio', t('Studio.parameters.fields.aspectRatio')),
|
|
124
104
|
textField('quality', t('Studio.parameters.fields.quality')),
|
|
@@ -133,7 +113,7 @@ function ImageFields(props: StudioParameterPanelProps) {
|
|
|
133
113
|
label: t('Studio.parameters.fields.referenceImageFile'),
|
|
134
114
|
render: (routeDisabled) => (
|
|
135
115
|
<StudioParameterField label={t('Studio.parameters.fields.referenceImageFile')}>
|
|
136
|
-
<input ref={inputRef} className="studio-parameters__file-input" type="file" accept=
|
|
116
|
+
<input ref={inputRef} className="studio-parameters__file-input" type="file" accept={imageMimes.join(',')} disabled={props.disabled || routeDisabled || uploading} onChange={(event) => void selectReferenceImage(event)} />
|
|
137
117
|
<div className="studio-parameters__file-row">
|
|
138
118
|
<Button type="button" tone="ghost" size="sm" disabled={props.disabled || routeDisabled || uploading} leadingIcon={<Upload size={14} aria-hidden="true" />} onClick={() => inputRef.current?.click()}>
|
|
139
119
|
{uploading ? t('Studio.parameters.uploadingImage') : t('Studio.parameters.chooseImageFile')}
|
|
@@ -146,6 +126,7 @@ function ImageFields(props: StudioParameterPanelProps) {
|
|
|
146
126
|
) : null}
|
|
147
127
|
</div>
|
|
148
128
|
{uploadError ? <small>{uploadError}</small> : null}
|
|
129
|
+
<small>{t(props.source === 'cloud' ? 'Studio.parameters.cloudImageReferenceHint' : 'Studio.parameters.imageReferenceHint')}</small>
|
|
149
130
|
</StudioParameterField>
|
|
150
131
|
),
|
|
151
132
|
},
|
|
@@ -219,6 +200,7 @@ function VideoFields(props: StudioParameterPanelProps) {
|
|
|
219
200
|
disabled={props.disabled || routeDisabled}
|
|
220
201
|
options={[
|
|
221
202
|
{ value: 't2v', label: t('Studio.parameters.videoModeT2v') },
|
|
203
|
+
...(props.source === 'cloud' ? [{ value: 'i2v-first-frame', label: t('Studio.parameters.videoModeFirstFrame') }] : []),
|
|
222
204
|
{ value: 'i2v-reference', label: t('Studio.parameters.videoModeReference') },
|
|
223
205
|
]}
|
|
224
206
|
onValueChange={(value) => update({ ...parameters, mode: value as StudioVideoGenerationParameters['mode'] })}
|
|
@@ -226,6 +208,7 @@ function VideoFields(props: StudioParameterPanelProps) {
|
|
|
226
208
|
</StudioParameterField>
|
|
227
209
|
),
|
|
228
210
|
},
|
|
211
|
+
...(parameters.mode === 'i2v-first-frame' ? [textField('firstFrameImageUrl', t('Studio.parameters.fields.firstFrameImageUrl'), 'https://…')] : []),
|
|
229
212
|
...(parameters.mode === 'i2v-reference' ? [{
|
|
230
213
|
field: 'referenceArtifactId',
|
|
231
214
|
label: referenceLabel,
|
|
@@ -6,6 +6,47 @@ import {
|
|
|
6
6
|
UNSUPPORTED_STUDIO_PARAMETER,
|
|
7
7
|
defineStudioParameters,
|
|
8
8
|
} from '../../ai-studio-core/parameters.js';
|
|
9
|
+
import type { StudioManagedArtifact } from '../../ai-studio-core/runtime-types.js';
|
|
10
|
+
|
|
11
|
+
const audioMimeTypes = ['audio/wav', 'audio/mpeg', 'audio/flac'] as const;
|
|
12
|
+
const recordedMediaStrings = new Set(['sourceRelativePath', 'sourceName', 'sourceMimeType', 'requestedPart',
|
|
13
|
+
'targetKind', 'targetRelativePath', 'targetName', 'targetMimeType', 'targetPresetVoiceId', 'targetVoiceAssetId']);
|
|
14
|
+
const recordedMediaRanges = new Set(['startSeconds', 'endSeconds', 'sourceStartSeconds', 'sourceEndSeconds', 'targetStartSeconds', 'targetEndSeconds']);
|
|
15
|
+
|
|
16
|
+
function restoreMediaControls(snapshot: Readonly<Record<string, unknown>>): Record<string, unknown> | null {
|
|
17
|
+
const restored: Record<string, unknown> = {};
|
|
18
|
+
for (const [key, value] of Object.entries(snapshot)) {
|
|
19
|
+
if (value === undefined || key === 'recoverySubmissionId') continue;
|
|
20
|
+
if (recordedMediaStrings.has(key)) {
|
|
21
|
+
if (typeof value !== 'string') return null;
|
|
22
|
+
} else if (recordedMediaRanges.has(key)) {
|
|
23
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) return null;
|
|
24
|
+
} else if (key === 'semitoneShift') {
|
|
25
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < -12 || value > 12) return null;
|
|
26
|
+
} else if (key === 'includeInstrumentParts') {
|
|
27
|
+
if (typeof value !== 'boolean') return null;
|
|
28
|
+
} else if (key === 'requestedFormats') {
|
|
29
|
+
if (!Array.isArray(value) || !value.length || value.some(item => !['abc', 'midi', 'timeline'].includes(String(item)))) return null;
|
|
30
|
+
} else return null;
|
|
31
|
+
restored[key] = Array.isArray(value) ? [...value] : value;
|
|
32
|
+
}
|
|
33
|
+
return restored;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function restoreAudioReference(restored: Record<string, unknown>, role: 'source' | 'target', saved?: StudioManagedArtifact): boolean {
|
|
37
|
+
const path = saved?.relativePath ?? restored[`${role}RelativePath`];
|
|
38
|
+
const mime = saved?.mediaType ?? restored[`${role}MimeType`];
|
|
39
|
+
if (typeof path !== 'string' || !path.trim() || !audioMimeTypes.includes(mime as typeof audioMimeTypes[number])) return false;
|
|
40
|
+
restored[`${role}RelativePath`] = path;
|
|
41
|
+
restored[`${role}MimeType`] = mime;
|
|
42
|
+
const name = saved?.displayName ?? restored[`${role}Name`];
|
|
43
|
+
if (typeof name === 'string') restored[`${role}Name`] = name;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function recordedRangeValid(restored: Record<string, unknown>, start: string, end: string): boolean {
|
|
48
|
+
return restored[end] === undefined || Number(restored[end]) > Number(restored[start] ?? 0);
|
|
49
|
+
}
|
|
9
50
|
|
|
10
51
|
export type StudioImageGenerationParameters = {
|
|
11
52
|
negativePrompt?: string;
|
|
@@ -21,7 +62,8 @@ export type StudioImageGenerationParameters = {
|
|
|
21
62
|
};
|
|
22
63
|
|
|
23
64
|
export type StudioVideoGenerationParameters = {
|
|
24
|
-
mode?: 't2v' | 'i2v-reference';
|
|
65
|
+
mode?: 't2v' | 'i2v-first-frame' | 'i2v-reference';
|
|
66
|
+
firstFrameImageUrl?: string;
|
|
25
67
|
referenceArtifactId?: string;
|
|
26
68
|
negativePrompt?: string;
|
|
27
69
|
resolution?: string;
|
|
@@ -41,8 +83,124 @@ export type StudioVideoGenerationParameters = {
|
|
|
41
83
|
|
|
42
84
|
export type StudioMusicGenerationParameters = {
|
|
43
85
|
lyrics?: string;
|
|
86
|
+
durationSeconds?: number;
|
|
87
|
+
seed?: number;
|
|
88
|
+
instrumental?: boolean;
|
|
89
|
+
returnGeneratedScore?: boolean;
|
|
90
|
+
scoreRelativePath?: string;
|
|
91
|
+
scoreName?: string;
|
|
92
|
+
recoverySubmissionId?: string;
|
|
93
|
+
scoreConditioning?: 'melody-only' | 'melody-and-harmony';
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type StudioMusicTranscriptionParameters = {
|
|
97
|
+
sourceRelativePath?: string;
|
|
98
|
+
sourceName?: string;
|
|
99
|
+
sourceMimeType?: 'audio/wav' | 'audio/mpeg' | 'audio/flac';
|
|
100
|
+
requestedFormats?: ('abc' | 'midi' | 'timeline')[];
|
|
101
|
+
requestedPart?: 'vocal-melody' | 'lead-sheet' | 'full-arrangement' | 'note-events';
|
|
102
|
+
startSeconds?: number;
|
|
103
|
+
endSeconds?: number;
|
|
104
|
+
recoverySubmissionId?: string;
|
|
44
105
|
};
|
|
45
106
|
|
|
107
|
+
export const studioMusicTranscribeParameters = defineStudioParameters<StudioMusicTranscriptionParameters>({
|
|
108
|
+
initial: () => ({}),
|
|
109
|
+
restoreRecordedParameters: (snapshot, result) => {
|
|
110
|
+
if (!snapshot) return null;
|
|
111
|
+
const restored = restoreMediaControls(snapshot);
|
|
112
|
+
const saved = result?.ok && result.kind === 'artifacts' ? result.musicTranscription?.sourceAudio : undefined;
|
|
113
|
+
if (!restored || !restoreAudioReference(restored, 'source', saved)) return null;
|
|
114
|
+
if (!['vocal-melody', 'lead-sheet', 'full-arrangement', 'note-events'].includes(String(restored.requestedPart))
|
|
115
|
+
|| !Array.isArray(restored.requestedFormats) || !restored.requestedFormats.length
|
|
116
|
+
|| !recordedRangeValid(restored, 'startSeconds', 'endSeconds')) return null;
|
|
117
|
+
return restored as StudioMusicTranscriptionParameters;
|
|
118
|
+
},
|
|
119
|
+
hasAlternativeInput: (value) => Boolean(value.sourceRelativePath || value.recoverySubmissionId),
|
|
120
|
+
routeMatrix: Object.fromEntries(['sourceRelativePath', 'sourceName', 'sourceMimeType', 'requestedFormats', 'requestedPart', 'startSeconds', 'endSeconds', 'recoverySubmissionId'].map(key => [key, LOCAL_ONLY_STUDIO_PARAMETER])),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export type StudioVoiceConvertParameters = {
|
|
124
|
+
sourceRelativePath?: string;
|
|
125
|
+
sourceName?: string;
|
|
126
|
+
sourceMimeType?: 'audio/wav' | 'audio/mpeg' | 'audio/flac';
|
|
127
|
+
sourceStartSeconds?: number;
|
|
128
|
+
sourceEndSeconds?: number;
|
|
129
|
+
targetKind?: 'reference-audio' | 'preset' | 'voice-asset';
|
|
130
|
+
targetRelativePath?: string;
|
|
131
|
+
targetName?: string;
|
|
132
|
+
targetMimeType?: 'audio/wav' | 'audio/mpeg' | 'audio/flac';
|
|
133
|
+
targetStartSeconds?: number;
|
|
134
|
+
targetEndSeconds?: number;
|
|
135
|
+
targetPresetVoiceId?: string;
|
|
136
|
+
targetVoiceAssetId?: string;
|
|
137
|
+
semitoneShift?: number;
|
|
138
|
+
recoverySubmissionId?: string;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
function voiceConvertTargetReady(value: StudioVoiceConvertParameters): boolean {
|
|
142
|
+
if (value.targetKind === 'preset') return Boolean(value.targetPresetVoiceId?.trim());
|
|
143
|
+
if (value.targetKind === 'voice-asset') return Boolean(value.targetVoiceAssetId?.trim());
|
|
144
|
+
return value.targetKind === 'reference-audio' ? Boolean(value.targetRelativePath && value.targetMimeType) : false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const studioVoiceConvertParameters = defineStudioParameters<StudioVoiceConvertParameters>({
|
|
148
|
+
initial: () => ({}),
|
|
149
|
+
restoreRecordedParameters: (snapshot, result) => {
|
|
150
|
+
if (!snapshot) return null;
|
|
151
|
+
const restored = restoreMediaControls(snapshot);
|
|
152
|
+
const saved = result?.ok && result.kind === 'artifacts' ? result.voiceConversion : undefined;
|
|
153
|
+
if (!restored || !restoreAudioReference(restored, 'source', saved?.sourceVocal)) return null;
|
|
154
|
+
if (saved?.targetVoice || restored.targetKind === 'reference-audio') {
|
|
155
|
+
if (!restoreAudioReference(restored, 'target', saved?.targetVoice)) return null;
|
|
156
|
+
restored.targetKind = 'reference-audio';
|
|
157
|
+
} else if (restored.targetKind === 'preset') {
|
|
158
|
+
if (typeof restored.targetPresetVoiceId !== 'string' || !restored.targetPresetVoiceId.trim()) return null;
|
|
159
|
+
} else if (restored.targetKind === 'voice-asset') {
|
|
160
|
+
if (typeof restored.targetVoiceAssetId !== 'string' || !restored.targetVoiceAssetId.trim()) return null;
|
|
161
|
+
} else return null;
|
|
162
|
+
if (!recordedRangeValid(restored, 'sourceStartSeconds', 'sourceEndSeconds')
|
|
163
|
+
|| !recordedRangeValid(restored, 'targetStartSeconds', 'targetEndSeconds')) return null;
|
|
164
|
+
return restored as StudioVoiceConvertParameters;
|
|
165
|
+
},
|
|
166
|
+
hasAlternativeInput: (value) => Boolean(value.recoverySubmissionId
|
|
167
|
+
|| (value.sourceRelativePath && value.sourceMimeType && voiceConvertTargetReady(value))),
|
|
168
|
+
routeMatrix: Object.fromEntries(['sourceRelativePath', 'sourceName', 'sourceMimeType', 'sourceStartSeconds', 'sourceEndSeconds',
|
|
169
|
+
'targetKind', 'targetRelativePath', 'targetName', 'targetMimeType', 'targetStartSeconds', 'targetEndSeconds',
|
|
170
|
+
'targetPresetVoiceId', 'targetVoiceAssetId', 'semitoneShift', 'recoverySubmissionId'].map(key => [key, LOCAL_ONLY_STUDIO_PARAMETER])),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
export type StudioAudioSeparateParameters = {
|
|
174
|
+
sourceRelativePath?: string;
|
|
175
|
+
sourceName?: string;
|
|
176
|
+
sourceMimeType?: 'audio/wav' | 'audio/mpeg' | 'audio/flac';
|
|
177
|
+
startSeconds?: number;
|
|
178
|
+
endSeconds?: number;
|
|
179
|
+
includeInstrumentParts?: boolean;
|
|
180
|
+
recoverySubmissionId?: string;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const studioAudioSeparateParameters = defineStudioParameters<StudioAudioSeparateParameters>({
|
|
184
|
+
initial: () => ({}),
|
|
185
|
+
restoreRecordedParameters: (snapshot, result) => {
|
|
186
|
+
const saved = result?.ok && result.kind === 'artifacts' ? result.audioSeparation : undefined;
|
|
187
|
+
// A saved separation request itself records full-source versus range.
|
|
188
|
+
// Without it, absent request context cannot be treated as empty controls.
|
|
189
|
+
if (!snapshot && !saved?.request) return null;
|
|
190
|
+
const restored = restoreMediaControls(snapshot ?? {});
|
|
191
|
+
if (!restored || !restoreAudioReference(restored, 'source', saved?.sourceAudio)) return null;
|
|
192
|
+
if (restored.startSeconds === undefined && restored.endSeconds === undefined && saved?.request?.kind === 'range') {
|
|
193
|
+
restored.startSeconds = saved.request.startSeconds;
|
|
194
|
+
if (saved.request.endSeconds !== undefined) restored.endSeconds = saved.request.endSeconds;
|
|
195
|
+
}
|
|
196
|
+
if (!recordedRangeValid(restored, 'startSeconds', 'endSeconds')) return null;
|
|
197
|
+
return restored as StudioAudioSeparateParameters;
|
|
198
|
+
},
|
|
199
|
+
hasAlternativeInput: (value) => Boolean(value.sourceRelativePath || value.recoverySubmissionId),
|
|
200
|
+
routeMatrix: Object.fromEntries(['sourceRelativePath', 'sourceName', 'sourceMimeType', 'startSeconds', 'endSeconds',
|
|
201
|
+
'includeInstrumentParts', 'recoverySubmissionId'].map(key => [key, LOCAL_ONLY_STUDIO_PARAMETER])),
|
|
202
|
+
});
|
|
203
|
+
|
|
46
204
|
const LOCAL_APP_UNAVAILABLE = Object.freeze({
|
|
47
205
|
local: UNSUPPORTED_STUDIO_PARAMETER,
|
|
48
206
|
cloud: UNSUPPORTED_STUDIO_PARAMETER,
|
|
@@ -61,16 +219,17 @@ export const studioImageGenerateParameters = defineStudioParameters<StudioImageG
|
|
|
61
219
|
quality: CLOUD_ONLY_STUDIO_PARAMETER,
|
|
62
220
|
style: CLOUD_ONLY_STUDIO_PARAMETER,
|
|
63
221
|
referenceImage: CLOUD_ONLY_STUDIO_PARAMETER,
|
|
64
|
-
referenceImageArtifactId:
|
|
222
|
+
referenceImageArtifactId: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
|
|
65
223
|
mask: CLOUD_ONLY_STUDIO_PARAMETER,
|
|
66
224
|
},
|
|
67
225
|
});
|
|
68
226
|
|
|
69
227
|
export const studioVideoGenerateParameters = defineStudioParameters<StudioVideoGenerationParameters>({
|
|
70
|
-
|
|
228
|
+
initial: () => ({ mode: 't2v' }),
|
|
71
229
|
routeMatrix: {
|
|
72
230
|
mode: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
|
|
73
|
-
referenceArtifactId:
|
|
231
|
+
referenceArtifactId: LOCAL_ONLY_STUDIO_PARAMETER,
|
|
232
|
+
firstFrameImageUrl: CLOUD_ONLY_STUDIO_PARAMETER,
|
|
74
233
|
negativePrompt: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
|
|
75
234
|
resolution: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
|
|
76
235
|
frames: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
|
|
@@ -89,6 +248,11 @@ export const studioVideoGenerateParameters = defineStudioParameters<StudioVideoG
|
|
|
89
248
|
});
|
|
90
249
|
|
|
91
250
|
export const studioMusicGenerateParameters = defineStudioParameters<StudioMusicGenerationParameters>({
|
|
92
|
-
initial: () => ({
|
|
93
|
-
routeMatrix: {
|
|
251
|
+
initial: () => ({}),
|
|
252
|
+
routeMatrix: {
|
|
253
|
+
lyrics: LOCAL_AND_CLOUD_STUDIO_PARAMETER, durationSeconds: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
|
|
254
|
+
seed: LOCAL_AND_CLOUD_STUDIO_PARAMETER, instrumental: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
|
|
255
|
+
returnGeneratedScore: LOCAL_AND_CLOUD_STUDIO_PARAMETER, scoreRelativePath: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
|
|
256
|
+
scoreName: LOCAL_AND_CLOUD_STUDIO_PARAMETER, scoreConditioning: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
|
|
257
|
+
},
|
|
94
258
|
});
|
|
@@ -1,13 +1,41 @@
|
|
|
1
|
-
import { Image as ImageIcon, Music2, Video, ScanSearch } from 'lucide-react';
|
|
1
|
+
import { Image as ImageIcon, Music2, Video, ScanSearch, AudioWaveform, AudioLines } from 'lucide-react';
|
|
2
2
|
import { StudioVisionParameterPanel, studioVisionLocateParameters } from './vision-parameters.js';
|
|
3
3
|
import type { AIStudioModuleRegistration } from '../../ai-studio-core/module-registration.js';
|
|
4
4
|
import { studioMediaDescriptors, type StudioMediaCapabilityId } from './descriptors.js';
|
|
5
5
|
import { studioImageGenerateParameters, studioMusicGenerateParameters, studioVideoGenerateParameters } from './parameters.js';
|
|
6
6
|
import { StudioMediaParameterPanel } from './parameter-panel.js';
|
|
7
|
+
import { MusicTranscriptionFields } from './music-transcription-parameters.js';
|
|
8
|
+
import { VoiceConvertFields } from './voice-convert-parameters.js';
|
|
9
|
+
import { AudioSeparateFields } from './audio-separate-parameters.js';
|
|
10
|
+
import { studioAudioSeparateParameters, studioMusicTranscribeParameters, studioVoiceConvertParameters } from './parameters.js';
|
|
7
11
|
|
|
8
12
|
export const studioMediaModule = Object.freeze({
|
|
9
13
|
id: 'studio-media', navigationLabel: 'Media', order: 20,
|
|
10
14
|
capabilities: [
|
|
15
|
+
{
|
|
16
|
+
descriptor: studioMediaDescriptors[4], icon: Music2,
|
|
17
|
+
profile: {
|
|
18
|
+
studioTag: 'Music', inputTitleKey: 'Studio.profiles.musicTranscribe.inputTitle', inputPlaceholderKey: 'Studio.profiles.musicTranscribe.inputPlaceholder', inputKind: 'none', supportsAttachments: false, controls: [], primaryLabelKey: 'Studio.profiles.musicTranscribe.primaryLabel', primaryRunningLabelKey: 'Studio.profiles.musicTranscribe.primaryRunningLabel', resultTitle: 'Estimated score', emptyTitleKey: 'Studio.profiles.musicTranscribe.emptyTitle', emptyHintKey: 'Studio.profiles.musicTranscribe.emptyHint', resultKind: 'artifacts', footnoteKey: 'Studio.profiles.musicTranscribe.footnote',
|
|
19
|
+
},
|
|
20
|
+
preset: { id: 'transcribe-recording', label: 'Transcribe a recording', prompt: '' },
|
|
21
|
+
runtimeMethod: 'kit.generation.runRuntimeMusicTranscribe', parameters: studioMusicTranscribeParameters, parameterPanel: MusicTranscriptionFields,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
descriptor: studioMediaDescriptors[5], icon: AudioWaveform,
|
|
25
|
+
profile: {
|
|
26
|
+
studioTag: 'Music', inputTitleKey: 'Studio.profiles.voiceConvert.inputTitle', inputPlaceholderKey: 'Studio.profiles.voiceConvert.inputPlaceholder', inputKind: 'none', supportsAttachments: false, controls: [], primaryLabelKey: 'Studio.profiles.voiceConvert.primaryLabel', primaryRunningLabelKey: 'Studio.profiles.voiceConvert.primaryRunningLabel', resultTitle: 'Converted vocal', emptyTitleKey: 'Studio.profiles.voiceConvert.emptyTitle', emptyHintKey: 'Studio.profiles.voiceConvert.emptyHint', resultKind: 'artifacts', footnoteKey: 'Studio.profiles.voiceConvert.footnote',
|
|
27
|
+
},
|
|
28
|
+
preset: { id: 'convert-singing-voice', label: 'Convert a singing voice', prompt: '' },
|
|
29
|
+
runtimeMethod: 'kit.generation.runRuntimeVoiceConvert', parameters: studioVoiceConvertParameters, parameterPanel: VoiceConvertFields,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
descriptor: studioMediaDescriptors[6], icon: AudioLines,
|
|
33
|
+
profile: {
|
|
34
|
+
studioTag: 'Music', inputTitleKey: 'Studio.profiles.audioSeparate.inputTitle', inputPlaceholderKey: 'Studio.profiles.audioSeparate.inputPlaceholder', inputKind: 'none', supportsAttachments: false, controls: [], primaryLabelKey: 'Studio.profiles.audioSeparate.primaryLabel', primaryRunningLabelKey: 'Studio.profiles.audioSeparate.primaryRunningLabel', resultTitle: 'Separated stems', emptyTitleKey: 'Studio.profiles.audioSeparate.emptyTitle', emptyHintKey: 'Studio.profiles.audioSeparate.emptyHint', resultKind: 'artifacts', footnoteKey: 'Studio.profiles.audioSeparate.footnote',
|
|
35
|
+
},
|
|
36
|
+
preset: { id: 'separate-vocals-background', label: 'Separate vocals and background', prompt: '' },
|
|
37
|
+
runtimeMethod: 'kit.generation.runRuntimeAudioSeparation', parameters: studioAudioSeparateParameters, parameterPanel: AudioSeparateFields,
|
|
38
|
+
},
|
|
11
39
|
{
|
|
12
40
|
descriptor: studioMediaDescriptors[3], icon: ScanSearch,
|
|
13
41
|
profile: {
|