dsh-audiogen 0.4.4 → 0.4.6

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/src/routes.ts CHANGED
@@ -16,7 +16,7 @@ import { discoverAudioModels } from './audio-models.ts'
16
16
  import { AUDIO_PRESETS } from './audio-presets.ts'
17
17
  import { appendHistory, clearHistory, listHistory, readAudioFile, removeHistory, saveAudioFile, listLibrary, saveToLibrary, updateLibraryEntry, removeLibraryEntries, readLibraryFile } from './audio-store.ts'
18
18
  import {
19
- AUDIO_API, AUDIOGEN_SETTINGS_NAMESPACE, GENERATE_API, HISTORY_API, LIBRARY_API, MODEL_API, PRESETS_API, SETTINGS_API, TASK_API,
19
+ AUDIO_API, AUDIOGEN_SETTINGS_NAMESPACE, ENHANCE_API, GENERATE_API, HISTORY_API, LIBRARY_API, MODEL_API, PRESETS_API, SETTINGS_API, TASK_API,
20
20
  LIBRARY_TYPES,
21
21
  type GenerateAudioRequest, type GeneratedAudio, type HistoryEntryInput, type LibraryAudioInput, type LibraryProvenance, type LibraryType,
22
22
  } from './protocol.ts'
@@ -47,6 +47,8 @@ export interface AudiogenRoutesDeps {
47
47
  autoSave: () => boolean
48
48
  /** Global upstream concurrency gate (maxConcurrentGenerations). */
49
49
  budget: GenerationBudget
50
+ /** 提示词增强:调用 Agent 默认模型,返回增强后的文本。 */
51
+ enhance: (prompt: string, mode: GenerateAudioRequest['mode']) => Promise<string>
50
52
  }
51
53
 
52
54
  function isLoopbackRequest(request: IncomingMessage): boolean {
@@ -528,6 +530,27 @@ export function makeRoutes(deps: AudiogenRoutesDeps): WebRoute[] {
528
530
  writeJson(res, 200, { ok: true, aborted: controllers !== undefined ? controllers.size : 0 })
529
531
  },
530
532
  },
533
+ // ------------------------------------------------------- prompt enhance
534
+ {
535
+ kind: 'exact',
536
+ path: ENHANCE_API,
537
+ handler: async (req, res) => {
538
+ if (!guard(req, res, 'POST')) return
539
+ const body = await readJsonBody(req)
540
+ const prompt = typeof body?.prompt === 'string' ? body.prompt.trim() : ''
541
+ if (prompt === '') {
542
+ writeJson(res, 200, { ok: false, code: 'bad-request', message: 'prompt is required' })
543
+ return
544
+ }
545
+ const mode = body?.mode === 'music' ? 'music' : body?.mode === 'sfx' ? 'sfx' : body?.mode === 'voice_design' ? 'voice_design' : 'tts'
546
+ try {
547
+ const enhanced = await deps.enhance(prompt, mode)
548
+ writeJson(res, 200, { ok: true, enhanced })
549
+ } catch (error) {
550
+ writeJson(res, 200, { ok: false, code: 'enhance-failed', message: messageOf(error) })
551
+ }
552
+ },
553
+ },
531
554
  // ----------------------------------------------------------- audio file
532
555
  {
533
556
  kind: 'prefix',