@vocalstack/payload 0.6.2 → 0.7.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 CHANGED
@@ -54,6 +54,7 @@ Then run `payload generate:importmap`. The plugin adds fields to the targeted co
54
54
  | `fileURL` | the doc's `url`, made absolute | `({ doc, collection, req }) => string`: the address VocalStack fetches. Point it at your bucket's public URL to skip the Payload file proxy. |
55
55
  | `access` | signed-in users who can update the doc | Extra check for transcribing, translating, speakers, voices and the admin lookups, and for changing the connection. |
56
56
  | `oneClickConnect` | `false` | Show **Connect VocalStack** (see below). |
57
+ | `updateCheck` | `true` | Say in the admin when a newer version is on npm; see below. `false` makes no outbound call. |
57
58
  | `apiURL` / `dashboardURL` | `https://api.vocalstack.com` / `https://app.vocalstack.com` | |
58
59
  | `enabled` | `true` | `false` keeps the schema but removes the button and the endpoints. |
59
60
  | `speakers` | none | Collections of people saved as VocalStack speakers, each with a cloned voice; see below. (`voices`, its name in 0.5, still works.) |
@@ -61,6 +62,19 @@ Then run `payload generate:importmap`. The plugin adds fields to the targeted co
61
62
  | `listeners` | off | `true`, or `{ languages?, speak?, access?, perHour? }`: let visitors ask for a transcript in their language; see below. |
62
63
  | `voiceMode` | the transcript's toggle | `({ collection, doc, req, row }) => 'synthetic' \| 'cloned' \| undefined`: the site decides how transcripts are read aloud, and the toggle is hidden. See below. |
63
64
 
65
+ ### Updates
66
+
67
+ The plugin is part of your site's code, so it can't update itself: a new version means changing `package.json`, rebuilding and deploying, and sometimes a migration. It does tell you when one is out. The server asks npm for the newest `@vocalstack/payload` at most every 6 hours (`GET /api/vocalstack/version`, signed-in users), and while a newer one is out the admin nav shows a notice linking to **Settings → VocalStack**, which shows both versions, the release notes and the steps. `VERSION` (from `@vocalstack/payload`) is the installed one.
68
+
69
+ To have updates proposed for you, let Renovate or Dependabot open a pull request for each release:
70
+
71
+ ```json
72
+ // renovate.json
73
+ { "extends": ["config:recommended"], "packageRules": [{ "matchPackageNames": ["@vocalstack/payload"], "labels": ["vocalstack"] }] }
74
+ ```
75
+
76
+ After updating, run `payload generate:importmap`, and with Postgres or SQLite `payload migrate:create`.
77
+
64
78
  ### Audio that isn't an upload
65
79
 
66
80
  Imported content often points at files by name or link instead of upload documents. `audioFields` gives each row of an array field its own button and `vocalstack` transcript:
@@ -1,10 +1,21 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { Button, TextInput, toast } from '@payloadcms/ui';
4
4
  import { useState } from 'react';
5
5
  import { BrandStyles, Logo } from './Brand.js';
6
6
  import { useConnection } from './useConnection.js';
7
+ import { useVersion } from './useVersion.js';
7
8
  const KEYS_URL = 'https://app.vocalstack.com/developers/keys';
9
+ const muted = { color: 'var(--theme-elevation-500)' };
10
+ /** The installed version, and the newer one when there is one. */
11
+ const VersionLine = () => {
12
+ const version = useVersion();
13
+ if (!version)
14
+ return null;
15
+ if (version.state !== 'outdated')
16
+ return _jsxs("p", { style: { ...muted, fontSize: 13, margin: 0 }, children: ["@vocalstack/payload ", version.current] });
17
+ return (_jsxs("div", { style: { background: 'var(--theme-warning-100)', borderRadius: 'var(--style-radius-s, 4px)', fontSize: 13, padding: '10px 12px' }, children: [_jsxs("strong", { children: ["@vocalstack/payload ", version.latest, " is out."] }), " This site runs ", version.current, ".", ' ', version.releaseURL && (_jsx("a", { href: version.releaseURL, rel: "noreferrer", target: "_blank", children: "What's new" })), _jsxs("p", { style: { margin: '6px 0 0' }, children: ["Update it in the site's code (", _jsx("code", { children: "pnpm up @vocalstack/payload" }), "), then run ", _jsx("code", { children: "payload generate:importmap" }), " and, with Postgres or SQLite,", ' ', _jsx("code", { children: "payload migrate:create" }), " before deploying."] })] }));
18
+ };
8
19
  export const ConnectionPanel = ({ oneClickConnect }) => {
9
20
  const { call, connect, connecting, connection, setConnection } = useConnection();
10
21
  const [apiKey, setAPIKey] = useState('');
@@ -26,16 +37,12 @@ export const ConnectionPanel = ({ oneClickConnect }) => {
26
37
  }
27
38
  };
28
39
  const save = () => void run(() => call('/vocalstack/key', { body: JSON.stringify({ apiKey }), method: 'POST' }), 'Connected to VocalStack.');
29
- const muted = { color: 'var(--theme-elevation-500)' };
30
40
  if (!connection)
31
41
  return _jsx("p", { style: muted, children: "Checking the VocalStack connection\u2026" });
32
- if (connection.source === 'options') {
33
- return _jsx("p", { style: muted, children: "Connected with the API key from the plugin config. Change it there." });
34
- }
35
- return (_jsxs("div", { className: "vs-brand", style: { display: 'grid', gap: 'var(--base)', marginBottom: 'calc(var(--base) * 2)', maxWidth: 560 }, children: [_jsx(BrandStyles, {}), _jsx(Logo, { height: 24 }), connection.connected ? (_jsxs(_Fragment, { children: [_jsxs("p", { style: { margin: 0 }, children: ["Connected to VocalStack", connection.account ? ` as ${connection.account}` : '', ". Audio uploads now have a Transcribe button."] }), _jsx("div", { children: _jsx(Button, { buttonStyle: "secondary", disabled: saving, margin: false, onClick: () => run(() => call('/vocalstack/key', { method: 'DELETE' }), 'Disconnected.'), children: "Disconnect" }) })] })) : (_jsxs(_Fragment, { children: [_jsx("p", { style: { margin: 0 }, children: "Connect a VocalStack account to transcribe audio uploads. Transcriptions use that account's credit." }), oneClickConnect && (_jsxs("div", { children: [_jsx(Button, { disabled: connecting, margin: false, onClick: () => connect().catch((e) => setError(e.message)), children: connecting ? 'Waiting for VocalStack…' : 'Connect VocalStack' }), _jsx("p", { style: { ...muted, fontSize: 13, marginBottom: 0 }, children: "Opens VocalStack in a new tab; click Authenticate there." })] })), _jsxs("div", { onKeyDown: (e) => {
42
+ return (_jsxs("div", { className: "vs-brand", style: { display: 'grid', gap: 'var(--base)', marginBottom: 'calc(var(--base) * 2)', maxWidth: 560 }, children: [_jsx(BrandStyles, {}), _jsx(Logo, { height: 24 }), connection.source === 'options' ? (_jsx("p", { style: { margin: 0 }, children: "Connected with the API key from the plugin config. Change it there." })) : connection.connected ? (_jsxs(_Fragment, { children: [_jsxs("p", { style: { margin: 0 }, children: ["Connected to VocalStack", connection.account ? ` as ${connection.account}` : '', ". Audio uploads now have a Transcribe button."] }), _jsx("div", { children: _jsx(Button, { buttonStyle: "secondary", disabled: saving, margin: false, onClick: () => run(() => call('/vocalstack/key', { method: 'DELETE' }), 'Disconnected.'), children: "Disconnect" }) })] })) : (_jsxs(_Fragment, { children: [_jsx("p", { style: { margin: 0 }, children: "Connect a VocalStack account to transcribe audio uploads. Transcriptions use that account's credit." }), oneClickConnect && (_jsxs("div", { children: [_jsx(Button, { disabled: connecting, margin: false, onClick: () => connect().catch((e) => setError(e.message)), children: connecting ? 'Waiting for VocalStack…' : 'Connect VocalStack' }), _jsx("p", { style: { ...muted, fontSize: 13, marginBottom: 0 }, children: "Opens VocalStack in a new tab; click Authenticate there." })] })), _jsxs("div", { onKeyDown: (e) => {
36
43
  if (e.key === 'Enter' && apiKey.trim()) {
37
44
  e.preventDefault();
38
45
  save();
39
46
  }
40
- }, style: { display: 'grid', gap: 'calc(var(--base) / 2)' }, children: [_jsx(TextInput, { label: oneClickConnect ? 'Or paste an API key' : 'API key', onChange: (e) => setAPIKey(e.target.value), path: "vocalstack-api-key", placeholder: "vs_key_\u2026", value: apiKey }), _jsxs("p", { style: { ...muted, fontSize: 13, margin: 0 }, children: ["Create one with Read and Write permissions under", ' ', _jsx("a", { href: KEYS_URL, rel: "noreferrer", target: "_blank", children: "Developers \u2192 API keys" }), ". It is stored on the server and never shown again."] }), _jsx("div", { children: _jsx(Button, { disabled: saving || !apiKey.trim(), margin: false, onClick: save, children: "Save key" }) })] })] })), error && _jsx("p", { style: { color: 'var(--theme-error-500)', margin: 0 }, children: error })] }));
47
+ }, style: { display: 'grid', gap: 'calc(var(--base) / 2)' }, children: [_jsx(TextInput, { label: oneClickConnect ? 'Or paste an API key' : 'API key', onChange: (e) => setAPIKey(e.target.value), path: "vocalstack-api-key", placeholder: "vs_key_\u2026", value: apiKey }), _jsxs("p", { style: { ...muted, fontSize: 13, margin: 0 }, children: ["Create one with Read and Write permissions under", ' ', _jsx("a", { href: KEYS_URL, rel: "noreferrer", target: "_blank", children: "Developers \u2192 API keys" }), ". It is stored on the server and never shown again."] }), _jsx("div", { children: _jsx(Button, { disabled: saving || !apiKey.trim(), margin: false, onClick: save, children: "Save key" }) })] })] })), error && _jsx("p", { style: { color: 'var(--theme-error-500)', margin: 0 }, children: error }), _jsx(VersionLine, {})] }));
41
48
  };
@@ -4,11 +4,20 @@ import { Button, toast, useConfig, useDocumentInfo, useForm } from '@payloadcms/
4
4
  import { useCallback, useEffect, useRef, useState } from 'react';
5
5
  import { BrandStyles, Logo } from './Brand.js';
6
6
  import { useAPI, useConnection } from './useConnection.js';
7
- import { RecordSample, VoiceFromRecording } from './VoiceSamples.js';
7
+ import { RecordSample, sampleStyles, VoiceFromRecording } from './VoiceSamples.js';
8
8
  const POLL_MS = 3000;
9
9
  const MIN_S = 30;
10
10
  const styles = `
11
- .vs-voice-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
11
+ .vs-create-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
12
+ .vs-seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--style-radius-m, 6px); background: var(--theme-elevation-100); }
13
+ .vs-seg button { border: 0; background: none; color: var(--theme-elevation-600); font: inherit; font-size: 13px; line-height: 1.2;
14
+ padding: 6px 12px; border-radius: var(--style-radius-s, 4px); cursor: pointer; white-space: nowrap; }
15
+ .vs-seg button:hover { color: var(--theme-text); }
16
+ .vs-seg button[aria-pressed='true'] { background: var(--theme-elevation-0); color: var(--theme-text); font-weight: 500; box-shadow: 0 1px 2px rgb(0 0 0 / .25); }
17
+ .vs-seg button:focus-visible, .vs-link:focus-visible { outline: 2px solid var(--vs-accent); outline-offset: 1px; }
18
+ .vs-link { border: 0; background: none; padding: 4px 2px; font: inherit; font-size: 13px; color: var(--theme-elevation-600); cursor: pointer; }
19
+ .vs-link:hover:not(:disabled) { color: var(--theme-text); text-decoration: underline; }
20
+ .vs-link:disabled { opacity: .5; cursor: default; }
12
21
  .vs-voice select, .vs-voice input[type=file] { width: 100%; font: inherit; }
13
22
  .vs-voice select { padding: 6px 8px; border: 1px solid var(--theme-elevation-150); border-radius: var(--style-radius-s, 4px);
14
23
  background: var(--theme-input-bg, var(--theme-elevation-0)); color: var(--theme-text); }
@@ -78,7 +87,7 @@ export const SpeakerField = () => {
78
87
  };
79
88
  const muted = { color: 'var(--theme-elevation-500)', fontSize: 13, margin: 0 };
80
89
  const state = voice?.state ?? 'none';
81
- return (_jsxs("div", { className: "field-type vs-brand vs-voice", style: { marginBottom: 'var(--base)' }, children: [_jsx(BrandStyles, {}), _jsx("style", { children: styles }), _jsxs("div", { className: "field-label", style: { alignItems: 'center', display: 'flex', gap: 8, marginBottom: 'calc(var(--base) / 2)' }, children: [_jsx(Logo, { height: 14 }), " ", _jsx("span", { children: "Speaker" })] }), !id ? (_jsx("p", { style: muted, children: "Save first, then save them as a speaker." })) : connection && !connection.connected ? (_jsx("p", { style: muted, children: "Connect VocalStack (Settings \u2192 VocalStack) to save them as a speaker." })) : !voice ? (_jsx("p", { style: muted, children: error ?? 'Checking…' })) : creating || state === 'none' || state === 'failed' ? (creating ? (_jsx(CreateVoice, { base: base, name: name, onCancel: () => setCreating(false), onCreated: (res) => {
90
+ return (_jsxs("div", { className: "field-type vs-brand vs-voice", style: { marginBottom: 'var(--base)' }, children: [_jsx(BrandStyles, {}), _jsx("style", { children: styles + sampleStyles }), _jsxs("div", { className: "field-label", style: { alignItems: 'center', display: 'flex', gap: 8, marginBottom: 'calc(var(--base) / 2)' }, children: [_jsx(Logo, { height: 14 }), " ", _jsx("span", { children: "Speaker" })] }), !id ? (_jsx("p", { style: muted, children: "Save first, then save them as a speaker." })) : connection && !connection.connected ? (_jsx("p", { style: muted, children: "Connect VocalStack (Settings \u2192 VocalStack) to save them as a speaker." })) : !voice ? (_jsx("p", { style: muted, children: error ?? 'Checking…' })) : creating || state === 'none' || state === 'failed' ? (creating ? (_jsx(CreateVoice, { base: base, name: name, onCancel: () => setCreating(false), onCreated: (res) => {
82
91
  apply(res);
83
92
  setCreating(false);
84
93
  timer.current = setTimeout(refresh, POLL_MS);
@@ -125,7 +134,7 @@ const ReadyVoice = ({ base, busy, onDelete, voice }) => {
125
134
  };
126
135
  const names = new Map(langs?.languages.map((l) => [l.code, l.name]));
127
136
  const muted = { color: 'var(--theme-elevation-500)', fontSize: 13, margin: 0 };
128
- return (_jsxs("div", { style: { display: 'grid', gap: 8 }, children: [_jsxs("p", { style: muted, children: ["Ready", voice.sampleS ? `, cloned from ${Math.round(voice.sampleS)} s of speech` : '', ". Translations are read in this voice."] }), _jsxs("div", { style: { display: 'flex', gap: 6 }, children: [_jsx("select", { "aria-label": "Preview language", onChange: (e) => setLang(e.target.value), value: lang, children: (langs?.voice ?? ['en']).map((code) => (_jsx("option", { value: code, children: names.get(code) ?? code }, code))) }), _jsx(Button, { buttonStyle: "secondary", disabled: waiting, margin: false, onClick: play, size: "small", children: waiting ? 'Making…' : '▶ Hear' })] }), src && _jsx("audio", { controls: true, ref: audio, src: src, style: { width: '100%' } }), error && _jsx("p", { style: { ...muted, color: 'var(--theme-error-500)' }, children: error }), _jsx("div", { children: _jsx(Button, { buttonStyle: "error", disabled: busy, margin: false, onClick: onDelete, size: "small", children: "Delete speaker" }) })] }));
137
+ return (_jsxs("div", { style: { display: 'grid', gap: 8 }, children: [_jsxs("p", { style: muted, children: ["Ready", voice.sampleS ? `, cloned from ${Math.round(voice.sampleS)} s of speech` : '', ". Translations are read in this voice."] }), _jsxs("div", { className: "vs-row", children: [_jsx("select", { "aria-label": "Preview language", onChange: (e) => setLang(e.target.value), value: lang, children: (langs?.voice ?? ['en']).map((code) => (_jsx("option", { value: code, children: names.get(code) ?? code }, code))) }), _jsx(Button, { buttonStyle: "secondary", disabled: waiting, margin: false, onClick: play, size: "small", children: waiting ? 'Making…' : '▶ Hear' })] }), src && _jsx("audio", { controls: true, ref: audio, src: src, style: { width: '100%' } }), error && _jsx("p", { style: { ...muted, color: 'var(--theme-error-500)' }, children: error }), _jsx("div", { children: _jsx(Button, { buttonStyle: "error", disabled: busy, margin: false, onClick: onDelete, size: "small", children: "Delete speaker" }) })] }));
129
138
  };
130
139
  const CreateVoice = ({ base, name, onCancel, onCreated }) => {
131
140
  const call = useAPI();
@@ -190,10 +199,10 @@ const CreateVoice = ({ base, name, onCancel, onCreated }) => {
190
199
  ['record', 'Record'],
191
200
  ['file', 'Upload'],
192
201
  ];
193
- return (_jsxs("div", { style: { display: 'grid', gap: 10 }, children: [_jsx("div", { className: "vs-voice-tabs", children: tabs.map(([key, label]) => (_jsx(Button, { buttonStyle: tab === key ? 'primary' : 'secondary', margin: false, onClick: () => switchTo(key), size: "small", children: label }, key))) }), tab === 'recording' ? (!sources ? (_jsx("p", { style: muted, children: error ? '' : 'Looking for transcribed recordings…' })) : !sources.length ? (_jsxs("p", { style: muted, children: ["No transcribed recordings of ", name || 'them', " yet. Transcribe one, or record a sample."] })) : (_jsx(VoiceFromRecording, { base: base, name: name, onCreated: onCreated, sources: sources }))) : (_jsxs(_Fragment, { children: [tab === 'record' ? (_jsx(RecordSample, { onRecorded: (f, seconds) => {
202
+ return (_jsxs("div", { style: { display: 'grid', gap: 10 }, children: [_jsxs("div", { className: "vs-create-head", children: [_jsx("div", { "aria-label": "Make the voice from", className: "vs-seg", role: "group", children: tabs.map(([key, label]) => (_jsx("button", { "aria-pressed": tab === key, onClick: () => switchTo(key), type: "button", children: label }, key))) }), _jsx("button", { className: "vs-link", disabled: busy, onClick: onCancel, type: "button", children: "Cancel" })] }), tab === 'recording' ? (!sources ? (_jsx("p", { style: muted, children: error ? '' : 'Looking for transcribed recordings…' })) : !sources.length ? (_jsxs("p", { style: muted, children: ["No transcribed recordings of ", name || 'them', " yet. Transcribe one, or record a sample."] })) : (_jsx(VoiceFromRecording, { base: base, name: name, onCreated: onCreated, sources: sources }))) : (_jsxs(_Fragment, { children: [tab === 'record' ? (_jsx(RecordSample, { onRecorded: (f, seconds) => {
194
203
  setFile(f);
195
204
  setFileS(seconds);
196
- } })) : (_jsxs(_Fragment, { children: [_jsxs("p", { style: muted, children: [MIN_S, " s to 2 min of ", name || 'them', " speaking alone, clearly, with no music. An MP3 or M4A of about a minute is ideal."] }), _jsx("input", { accept: "audio/*", onChange: (e) => pick(e.target.files?.[0]), type: "file" })] })), file && fileS !== undefined && !longEnough && _jsxs("p", { style: { ...muted, color: 'var(--theme-error-500)' }, children: ["That is ", Math.round(fileS), " s; at least ", MIN_S, " s is needed."] }), _jsxs("label", { style: { alignItems: 'flex-start', display: 'flex', fontSize: 13, gap: 8 }, children: [_jsx("input", { checked: consent, onChange: (e) => setConsent(e.target.checked), style: { marginTop: 3 }, type: "checkbox" }), _jsxs("span", { children: ["I have ", name || 'their', "\u2019s permission to clone their voice."] })] }), error && _jsx("p", { style: { ...muted, color: 'var(--theme-error-500)' }, children: error }), _jsx("div", { children: _jsx(Button, { disabled: busy || !consent || !longEnough || !file, margin: false, onClick: upload, size: "small", children: busy ? 'Creating…' : 'Create voice' }) })] })), _jsx("div", { children: _jsx(Button, { buttonStyle: "secondary", disabled: busy, margin: false, onClick: onCancel, size: "small", children: "Cancel" }) })] }));
205
+ } })) : (_jsxs(_Fragment, { children: [_jsxs("p", { style: muted, children: [MIN_S, " s to 2 min of ", name || 'them', " speaking alone, clearly, with no music. An MP3 or M4A of about a minute is ideal."] }), _jsx("input", { accept: "audio/*", onChange: (e) => pick(e.target.files?.[0]), type: "file" })] })), file && fileS !== undefined && !longEnough && _jsxs("p", { style: { ...muted, color: 'var(--theme-error-500)' }, children: ["That is ", Math.round(fileS), " s; at least ", MIN_S, " s is needed."] }), _jsxs("label", { style: { alignItems: 'flex-start', display: 'flex', fontSize: 13, gap: 8 }, children: [_jsx("input", { checked: consent, onChange: (e) => setConsent(e.target.checked), style: { marginTop: 3 }, type: "checkbox" }), _jsxs("span", { children: ["I have ", name || 'their', "\u2019s permission to clone their voice."] })] }), error && _jsx("p", { style: { ...muted, color: 'var(--theme-error-500)' }, children: error }), _jsx("div", { className: "vs-actions", children: _jsx(Button, { disabled: busy || !consent || !longEnough || !file, margin: false, onClick: upload, size: "small", children: busy ? 'Creating…' : 'Create voice' }) })] }))] }));
197
206
  };
198
207
  function useAPIBase() {
199
208
  const { config: { routes: { api }, serverURL, }, } = useConfig();
@@ -28,7 +28,9 @@ const styles = `
28
28
  .vs-bar span::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent);
29
29
  animation: vs-sweep 1.4s ease-in-out infinite; }
30
30
  @keyframes vs-sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
31
- @media (prefers-reduced-motion: reduce) { .vs-spin, .vs-bar span::after { animation: none; } }
31
+ .vs-bar--wait span { width: 30% !important; animation: vs-slide 1.6s ease-in-out infinite; transition: none; }
32
+ @keyframes vs-slide { from { left: -30%; } to { left: 100%; } }
33
+ @media (prefers-reduced-motion: reduce) { .vs-spin, .vs-bar span::after, .vs-bar--wait span { animation: none; } }
32
34
  `;
33
35
  const TRANSLATING = 'Translating…';
34
36
  /** The most languages one recording may have, besides its spoken one (VocalStack's limit). */
@@ -169,11 +171,13 @@ export const SpeechField = ({ field, path = '' }) => {
169
171
  ? `${t.sentences.length} of ${total} sentences translated`
170
172
  : t
171
173
  ? `${t.sentences.length} sentences translated`
172
- : 'Not translated' })] }), _jsxs("div", { style: { display: 'grid', gap: 6 }, children: [t?.pending ? (_jsxs(_Fragment, { children: [_jsx(Progress, { done: t.sentences.length, label: TRANSLATING, since: t.requestedAt ?? undefined, total: total }), s?.state === 'translating' && _jsx("span", { className: "vs-speech-muted", children: "Read aloud once translated." }), t.error && _jsxs("span", { className: "vs-speech-muted", children: [t.error, " Trying again shortly."] })] })) : busy ? (_jsxs("span", { className: "vs-speech-muted", children: [_jsx("span", { className: "vs-spin" }), busy] })) : s?.state === 'queued' || s?.state === 'running' ? (_jsx(Progress, { done: s.done ?? 0, label: s.state === 'queued' ? 'Waiting to be read aloud…' : 'Being read aloud…', since: s.requestedAt, total: t?.sentences.length ?? 0 })) : s?.state === 'sealed' ? (_jsxs(_Fragment, { children: [_jsx("audio", { controls: true, preload: "none", src: `${serverURL}${api}${base}/audio${withQuery({ lang, v: s.renderedAt ?? '' })}` }, s.renderedAt ?? ''), s.cast === 'cloned' && s.readIn === 'mixed' && (_jsx("span", { className: "vs-speech-muted", children: "Some speakers are read in stock voices: they have no cloned voice to use." })), s.cast === 'cloned' && s.readIn === 'synthetic' && (_jsx("span", { className: "vs-speech-muted", children: "Read in stock voices: no speaker has a cloned voice to use." }))] })) : t?.error && !t.sentences.length ? (_jsxs("p", { className: "vs-speech-error", children: ["Translating failed: ", t.error] })) : s?.state === 'translating' ? (_jsxs("span", { className: "vs-speech-muted", children: [_jsx("span", { className: "vs-spin" }), "Waiting for VocalStack to read it aloud\u2026"] })) : s?.state === 'failed' ? (_jsxs("p", { className: "vs-speech-error", children: ["Reading failed: ", s.error ?? 'no reason given'] })) : !canSpeak.has(lang) ? (_jsxs("span", { className: "vs-speech-muted", children: ["VocalStack cannot read ", names.get(lang) ?? lang, " aloud yet."] })) : null, canSpeak.has(lang) && !busy && !t?.pending && (!s || s.state === 'failed' || (s.state === 'sealed' && (s.cast ?? 'synthetic') !== voices)) && (_jsx("div", { children: _jsx(Button, { buttonStyle: "secondary", margin: false, onClick: () => speak([lang]), size: "small", children: !s ? 'Read aloud' : s.state === 'failed' ? 'Try again' : `Read again in ${voices} voices` }) }))] }), _jsx(Button, { buttonStyle: "secondary", disabled: Boolean(busy), margin: false, onClick: () => remove(lang), size: "small", children: "Remove" })] }, lang));
174
+ : 'Not translated' })] }), _jsxs("div", { style: { display: 'grid', gap: 6 }, children: [t?.pending ? (_jsxs(_Fragment, { children: [_jsx(Progress, { done: t.sentences.length, label: TRANSLATING, since: t.requestedAt ?? undefined, total: total }), s?.state === 'translating' && _jsx("span", { className: "vs-speech-muted", children: "Read aloud once translated." }), t.error && _jsxs("span", { className: "vs-speech-muted", children: [t.error, " Trying again shortly."] })] })) : busy ? (_jsxs("span", { className: "vs-speech-muted", children: [_jsx("span", { className: "vs-spin" }), busy] })) : s?.state === 'queued' || s?.state === 'running' ? (_jsx(Progress, { done: s.done ?? 0, label: s.state === 'queued' ? 'Waiting to be read aloud…' : 'Being read aloud…',
175
+ // Nothing spoken yet: VocalStack is starting a voice (a speech machine can take a couple of minutes).
176
+ waiting: !s.done ? 'Getting a voice ready… This can take a couple of minutes.' : undefined, since: s.requestedAt, total: t?.sentences.length ?? 0 })) : s?.state === 'sealed' ? (_jsxs(_Fragment, { children: [_jsx("audio", { controls: true, preload: "none", src: `${serverURL}${api}${base}/audio${withQuery({ lang, v: s.renderedAt ?? '' })}` }, s.renderedAt ?? ''), s.cast === 'cloned' && s.readIn === 'mixed' && (_jsx("span", { className: "vs-speech-muted", children: "Some speakers are read in stock voices: they have no cloned voice to use." })), s.cast === 'cloned' && s.readIn === 'synthetic' && (_jsx("span", { className: "vs-speech-muted", children: "Read in stock voices: no speaker has a cloned voice to use." }))] })) : t?.error && !t.sentences.length ? (_jsxs("p", { className: "vs-speech-error", children: ["Translating failed: ", t.error] })) : s?.state === 'translating' ? (_jsxs("span", { className: "vs-speech-muted", children: [_jsx("span", { className: "vs-spin" }), "Waiting for VocalStack to read it aloud\u2026"] })) : s?.state === 'failed' ? (_jsxs("p", { className: "vs-speech-error", children: ["Reading failed: ", s.error ?? 'no reason given'] })) : !canSpeak.has(lang) ? (_jsxs("span", { className: "vs-speech-muted", children: ["VocalStack cannot read ", names.get(lang) ?? lang, " aloud yet."] })) : null, canSpeak.has(lang) && !busy && !t?.pending && (!s || s.state === 'failed' || (s.state === 'sealed' && (s.cast ?? 'synthetic') !== voices)) && (_jsx("div", { children: _jsx(Button, { buttonStyle: "secondary", margin: false, onClick: () => speak([lang]), size: "small", children: !s ? 'Read aloud' : s.state === 'failed' ? 'Try again' : `Read again in ${voices} voices` }) }))] }), _jsx(Button, { buttonStyle: "secondary", disabled: Boolean(busy), margin: false, onClick: () => remove(lang), size: "small", children: "Remove" })] }, lang));
173
177
  }), _jsx(AddLanguages, { busy: Object.keys(working).length > 0, canSpeak: canSpeak, exclude: new Set([...shown, ...(spoken ? [spoken] : [])]), langs: langs, left: LANGUAGE_LIMIT - shown.filter((l) => l !== spoken).length, onAdd: (list, speakToo) => run(list, 'Starting…', () => request(list, speakToo)) }), error && _jsx("p", { className: "vs-speech-error", children: error })] }));
174
178
  };
175
179
  /** Work under way: the share of sentences done, counted up as each step is saved, and the time it has taken. */
176
- const Progress = ({ done, label, since, total }) => {
180
+ const Progress = ({ done, label, since, total, waiting }) => {
177
181
  const [started] = useState(() => (since ? new Date(since).getTime() : Date.now()));
178
182
  const [, tick] = useState(0);
179
183
  useEffect(() => {
@@ -184,7 +188,7 @@ const Progress = ({ done, label, since, total }) => {
184
188
  const elapsed = s < 60 ? `${s}s` : `${Math.floor(s / 60)}m ${String(s % 60).padStart(2, '0')}s`;
185
189
  done = Math.min(done, total);
186
190
  const share = total ? done / total : 0;
187
- return (_jsxs("div", { style: { display: 'grid', gap: 4 }, children: [_jsx("div", { "aria-valuemax": total, "aria-valuemin": 0, "aria-valuenow": done, className: "vs-bar", role: "progressbar", children: _jsx("span", { style: { width: `${share * 100}%` } }) }), _jsxs("span", { className: "vs-speech-muted", children: [_jsx("span", { className: "vs-spin" }), label, " ", total ? `${done} of ${total} sentences` : '', " \u00B7 ", elapsed] })] }));
191
+ return (_jsxs("div", { style: { display: 'grid', gap: 4 }, children: [waiting ? (_jsx("div", { "aria-valuetext": waiting, className: "vs-bar vs-bar--wait", role: "progressbar", children: _jsx("span", {}) })) : (_jsx("div", { "aria-valuemax": total, "aria-valuemin": 0, "aria-valuenow": done, className: "vs-bar", role: "progressbar", children: _jsx("span", { style: { width: `${share * 100}%` } }) })), _jsxs("span", { className: "vs-speech-muted", children: [_jsx("span", { className: "vs-spin" }), waiting ?? `${label} ${total ? `${done} of ${total} sentences` : ''}`, " \u00B7 ", elapsed] })] }));
188
192
  };
189
193
  const AddLanguages = ({ busy, canSpeak, exclude, langs, left, onAdd }) => {
190
194
  const [open, setOpen] = useState(false);
@@ -0,0 +1,2 @@
1
+ /** In the admin nav, only while a newer version is out: links to Settings → VocalStack. */
2
+ export declare const UpdateNotice: React.FC;
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useConfig } from '@payloadcms/ui';
4
+ import { SETTINGS_SLUG } from '../settings.js';
5
+ import { BrandStyles, Mark } from './Brand.js';
6
+ import { useVersion } from './useVersion.js';
7
+ /** In the admin nav, only while a newer version is out: links to Settings → VocalStack. */
8
+ export const UpdateNotice = () => {
9
+ const version = useVersion();
10
+ const { config: { routes: { admin }, }, } = useConfig();
11
+ if (version?.state !== 'outdated')
12
+ return null;
13
+ return (_jsxs("a", { className: "vs-brand", href: `${admin}/globals/${SETTINGS_SLUG}`, style: {
14
+ alignItems: 'center',
15
+ border: '1px solid var(--theme-elevation-150)',
16
+ borderRadius: 'var(--style-radius-s, 4px)',
17
+ color: 'inherit',
18
+ display: 'flex',
19
+ fontSize: 13,
20
+ gap: 8,
21
+ lineHeight: 1.3,
22
+ marginTop: 'var(--base)',
23
+ padding: '8px 10px',
24
+ textDecoration: 'none',
25
+ }, title: `@vocalstack/payload ${version.current} is installed; ${version.latest} is out.`, children: [_jsx(BrandStyles, {}), _jsx(Mark, { height: 14 }), _jsxs("span", { children: ["VocalStack ", version.latest, " is out", _jsxs("span", { style: { color: 'var(--theme-elevation-500)', display: 'block' }, children: ["You have ", version.current] })] })] }));
26
+ };
@@ -1,7 +1,7 @@
1
1
  import type { SpeakerAnswer, SpeakerSource } from '../types.js';
2
2
  /** As in the VocalStack dashboard: at least 5 s makes a voice, 20 s a steadier one, 25 s is plenty; 60 s at most. */
3
3
  export declare const PICK_MIN_S = 5;
4
- export declare const sampleStyles = "\n .vs-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 4px; }\n .vs-step { border-top: 3px solid var(--theme-elevation-150); padding-top: 6px; font-size: 12px; color: var(--theme-elevation-500); }\n .vs-step--on { border-color: var(--vs-accent); color: var(--theme-text); font-weight: 600; }\n .vs-step--done { border-color: color-mix(in srgb, var(--vs-accent) 45%, transparent); }\n .vs-sample { border: 1px solid var(--theme-elevation-150); border-radius: 8px; overflow: hidden; }\n .vs-sample-body { padding: 10px 12px; display: grid; gap: 8px; }\n .vs-sample-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--theme-elevation-500); }\n .vs-sample-text { font-size: 14px; line-height: 1.45; min-height: 2.9em; }\n .vs-sample-play { display: flex; align-items: center; gap: 10px; }\n .vs-play { width: 34px; height: 34px; flex: none; border-radius: 50%; border: 0; background: var(--vs-accent); color: #fff; cursor: pointer; font-size: 12px; }\n .vs-play:disabled { opacity: .5; cursor: default; }\n .vs-wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 28px; min-width: 0; }\n .vs-wave span { flex: 1; border-radius: 1px; background: var(--theme-elevation-250); }\n .vs-wave span.on { background: var(--vs-accent); }\n .vs-sample-use { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--theme-elevation-150);\n background: var(--theme-elevation-50); font-size: 14px; cursor: pointer; }\n .vs-pager { display: flex; gap: 4px; }\n .vs-pager button { border: 0; background: none; color: var(--theme-text); cursor: pointer; font-size: 16px; padding: 0 6px; }\n .vs-pager button:disabled { opacity: .3; cursor: default; }\n .vs-meter { position: relative; height: 6px; border-radius: 3px; background: var(--theme-elevation-100); overflow: hidden; }\n .vs-meter span { position: absolute; inset: 0 auto 0 0; background: var(--vs-accent); transition: width .3s; }\n .vs-meter-marks { position: relative; height: 16px; font-size: 11px; color: var(--theme-elevation-500); }\n .vs-meter-marks span { position: absolute; transform: translateX(-50%); }\n .vs-chips { display: flex; flex-wrap: wrap; gap: 6px; }\n .vs-chip { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--theme-elevation-150); border-radius: 12px; padding: 2px 4px 2px 10px; font-size: 12px; }\n .vs-chip button { border: 0; background: none; cursor: pointer; color: var(--theme-elevation-500); }\n .vs-chips--none { border: 1px dashed var(--theme-elevation-200); border-radius: 12px; padding: 4px 10px; font-size: 12px; color: var(--theme-elevation-500); }\n";
4
+ export declare const sampleStyles = "\n .vs-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 4px; }\n .vs-step { border-top: 3px solid var(--theme-elevation-150); padding-top: 6px; font-size: 12px; color: var(--theme-elevation-500); }\n .vs-step--on { border-color: var(--vs-accent); color: var(--theme-text); font-weight: 600; }\n .vs-step--done { border-color: color-mix(in srgb, var(--vs-accent) 45%, transparent); }\n .vs-sample { border: 1px solid var(--theme-elevation-150); border-radius: 8px; overflow: hidden; }\n .vs-sample-body { padding: 10px 12px; display: grid; gap: 8px; }\n .vs-sample-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--theme-elevation-500); }\n .vs-sample-text { font-size: 14px; line-height: 1.45; min-height: 2.9em; }\n .vs-sample-play { display: flex; align-items: center; gap: 10px; }\n .vs-play { width: 34px; height: 34px; flex: none; border-radius: 50%; border: 0; background: var(--vs-accent); color: #fff; cursor: pointer; font-size: 12px; }\n .vs-play:disabled { opacity: .5; cursor: default; }\n .vs-wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 28px; min-width: 0; }\n .vs-wave span { flex: 1; border-radius: 1px; background: var(--theme-elevation-250); }\n .vs-wave span.on { background: var(--vs-accent); }\n .vs-sample-use { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--theme-elevation-150);\n background: var(--theme-elevation-50); font-size: 14px; cursor: pointer; }\n .vs-pager { display: flex; gap: 4px; }\n .vs-pager button { border: 0; background: none; color: var(--theme-text); cursor: pointer; font-size: 16px; padding: 0 6px; }\n .vs-pager button:disabled { opacity: .3; cursor: default; }\n .vs-meter { position: relative; height: 6px; border-radius: 3px; background: var(--theme-elevation-100); overflow: hidden; }\n .vs-meter span { position: absolute; inset: 0 auto 0 0; background: var(--vs-accent); transition: width .3s; }\n .vs-meter-marks { position: relative; height: 16px; font-size: 11px; color: var(--theme-elevation-500); }\n .vs-meter-marks span { position: absolute; transform: translateX(-50%); }\n .vs-chips { display: flex; flex-wrap: wrap; gap: 6px; }\n .vs-chip { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--theme-elevation-150); border-radius: 12px; padding: 2px 4px 2px 10px; font-size: 12px; }\n .vs-chip button { border: 0; background: none; cursor: pointer; color: var(--theme-elevation-500); }\n .vs-row { display: flex; gap: 8px; align-items: stretch; }\n .vs-row select { flex: 1; min-width: 0; }\n .vs-row .btn { flex: none; white-space: nowrap; }\n .vs-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 12px; border-top: 1px solid var(--theme-elevation-100); }\n .vs-actions .btn { min-width: 84px; justify-content: center; }\n .vs-chips--none { border: 1px dashed var(--theme-elevation-200); border-radius: 12px; padding: 4px 10px; font-size: 12px; color: var(--theme-elevation-500); }\n";
5
5
  /**
6
6
  * Clone a voice from sentences of one of the person's own transcribed recordings, as in the
7
7
  * VocalStack dashboard: pick samples (or have them chosen), hear the voice, then name and keep it.
@@ -35,6 +35,11 @@ export const sampleStyles = `
35
35
  .vs-chips { display: flex; flex-wrap: wrap; gap: 6px; }
36
36
  .vs-chip { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--theme-elevation-150); border-radius: 12px; padding: 2px 4px 2px 10px; font-size: 12px; }
37
37
  .vs-chip button { border: 0; background: none; cursor: pointer; color: var(--theme-elevation-500); }
38
+ .vs-row { display: flex; gap: 8px; align-items: stretch; }
39
+ .vs-row select { flex: 1; min-width: 0; }
40
+ .vs-row .btn { flex: none; white-space: nowrap; }
41
+ .vs-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 12px; border-top: 1px solid var(--theme-elevation-100); }
42
+ .vs-actions .btn { min-width: 84px; justify-content: center; }
38
43
  .vs-chips--none { border: 1px dashed var(--theme-elevation-200); border-radius: 12px; padding: 4px 10px; font-size: 12px; color: var(--theme-elevation-500); }
39
44
  `;
40
45
  const secs = (c) => Math.max(0, c.end - c.start);
@@ -245,7 +250,7 @@ export const VoiceFromRecording = ({ base, name, onCreated, sources }) => {
245
250
  ? `Enough for a voice. ${PICK_GOOD_S}s or more sounds steadier.`
246
251
  : `Good. About ${PICK_TARGET_S}s gives it more to choose from.` }), picked.size ? (_jsx("div", { className: "vs-chips", children: [...picked]
247
252
  .sort((a, b) => a - b)
248
- .map((i) => (_jsxs("span", { className: "vs-chip", children: [_jsxs("button", { onClick: () => setIdx(i), style: { color: 'inherit', padding: 0 }, type: "button", children: [i + 1, " \u00B7 ", Math.round(secs(clips[i])), "s"] }), _jsx("button", { "aria-label": `Leave sample ${i + 1} out`, onClick: () => toggle(i), type: "button", children: "\u2715" })] }, i))) })) : (_jsx("span", { className: "vs-chips--none", children: "No samples picked yet" })), _jsx("div", { children: _jsx(Button, { disabled: !enough || busy, margin: false, onClick: tryVoice, size: "small", children: "Next" }) })] })), step === 2 && (_jsxs(_Fragment, { children: [!trial || trial.state === 'training' || trial.state === 'queued' ? (_jsxs("p", { style: muted, children: ["Making the voice", trial?.progress ? ` · ${trial.progress}%` : '…', " It takes a minute or two."] })) : trial.state === 'failed' ? (_jsxs("p", { style: { ...muted, color: 'var(--theme-error-500)' }, children: ["The voice could not be made: ", trial.error ?? 'no reason given', ". Pick other samples."] })) : (_jsx(TrialPreview, { base: base, voice: trial.id })), _jsxs("div", { style: { display: 'flex', gap: 6 }, children: [_jsx(Button, { buttonStyle: "secondary", margin: false, onClick: () => setStep(1), size: "small", children: "Back" }), _jsx(Button, { disabled: trial?.state !== 'ready', margin: false, onClick: () => setStep(3), size: "small", children: "Next" })] })] })), step === 3 && (_jsxs(_Fragment, { children: [_jsxs("label", { style: { display: 'grid', fontSize: 13, gap: 4 }, children: ["Name", _jsx("input", { maxLength: 60, onChange: (e) => setVoiceName(e.target.value), style: { font: 'inherit', padding: '6px 8px' }, value: voiceName })] }), _jsxs("label", { style: { alignItems: 'flex-start', display: 'flex', fontSize: 13, gap: 8 }, children: [_jsx("input", { checked: consent, onChange: (e) => setConsent(e.target.checked), style: { marginTop: 3 }, type: "checkbox" }), _jsxs("span", { children: ["I have ", name || 'their', "\u2019s permission to clone their voice."] })] }), _jsxs("div", { style: { display: 'flex', gap: 6 }, children: [_jsx(Button, { buttonStyle: "secondary", disabled: busy, margin: false, onClick: () => setStep(2), size: "small", children: "Back" }), _jsx(Button, { disabled: busy || !consent || !voiceName.trim(), margin: false, onClick: keep, size: "small", children: busy ? 'Saving…' : 'Save speaker' })] })] })), error && _jsx("p", { style: { ...muted, color: 'var(--theme-error-500)' }, children: error })] }));
253
+ .map((i) => (_jsxs("span", { className: "vs-chip", children: [_jsxs("button", { onClick: () => setIdx(i), style: { color: 'inherit', padding: 0 }, type: "button", children: [i + 1, " \u00B7 ", Math.round(secs(clips[i])), "s"] }), _jsx("button", { "aria-label": `Leave sample ${i + 1} out`, onClick: () => toggle(i), type: "button", children: "\u2715" })] }, i))) })) : (_jsx("span", { className: "vs-chips--none", children: "No samples picked yet" })), _jsx("div", { className: "vs-actions", children: _jsx(Button, { disabled: !enough || busy, margin: false, onClick: tryVoice, size: "small", children: "Next" }) })] })), step === 2 && (_jsxs(_Fragment, { children: [!trial || trial.state === 'training' || trial.state === 'queued' ? (_jsxs("p", { style: muted, children: ["Making the voice", trial?.progress ? ` · ${trial.progress}%` : '…', " It takes a minute or two."] })) : trial.state === 'failed' ? (_jsxs("p", { style: { ...muted, color: 'var(--theme-error-500)' }, children: ["The voice could not be made: ", trial.error ?? 'no reason given', ". Pick other samples."] })) : (_jsx(TrialPreview, { base: base, voice: trial.id })), _jsxs("div", { className: "vs-actions", children: [_jsx(Button, { buttonStyle: "secondary", margin: false, onClick: () => setStep(1), size: "small", children: "Back" }), _jsx(Button, { disabled: trial?.state !== 'ready', margin: false, onClick: () => setStep(3), size: "small", children: "Next" })] })] })), step === 3 && (_jsxs(_Fragment, { children: [_jsxs("label", { style: { display: 'grid', fontSize: 13, gap: 4 }, children: ["Name", _jsx("input", { maxLength: 60, onChange: (e) => setVoiceName(e.target.value), style: { font: 'inherit', padding: '6px 8px' }, value: voiceName })] }), _jsxs("label", { style: { alignItems: 'flex-start', display: 'flex', fontSize: 13, gap: 8 }, children: [_jsx("input", { checked: consent, onChange: (e) => setConsent(e.target.checked), style: { marginTop: 3 }, type: "checkbox" }), _jsxs("span", { children: ["I have ", name || 'their', "\u2019s permission to clone their voice."] })] }), _jsxs("div", { className: "vs-actions", children: [_jsx(Button, { buttonStyle: "secondary", disabled: busy, margin: false, onClick: () => setStep(2), size: "small", children: "Back" }), _jsx(Button, { disabled: busy || !consent || !voiceName.trim(), margin: false, onClick: keep, size: "small", children: busy ? 'Saving…' : 'Save speaker' })] })] })), error && _jsx("p", { style: { ...muted, color: 'var(--theme-error-500)' }, children: error })] }));
249
254
  };
250
255
  /** Ogg/Opus where the browser plays it, else CAF (Safari). */
251
256
  const previewFormat = () => (typeof Audio !== 'undefined' && new Audio().canPlayType('audio/ogg; codecs=opus') ? 'ogg' : 'caf');
@@ -289,7 +294,7 @@ const TrialPreview = ({ base, voice }) => {
289
294
  }
290
295
  };
291
296
  const names = new Map(langs?.languages.map((l) => [l.code, l.name]));
292
- return (_jsxs("div", { style: { display: 'grid', gap: 8 }, children: [_jsx("p", { style: { color: 'var(--theme-elevation-500)', fontSize: 13, margin: 0 }, children: "Hear it before you keep it. Not right? Go back and pick other samples." }), _jsxs("div", { style: { display: 'flex', gap: 6 }, children: [_jsx("select", { "aria-label": "Preview language", onChange: (e) => setLang(e.target.value), value: lang, children: (langs?.voice ?? ['en']).map((code) => (_jsx("option", { value: code, children: names.get(code) ?? code }, code))) }), _jsx(Button, { buttonStyle: "secondary", disabled: waiting, margin: false, onClick: play, size: "small", children: waiting ? 'Making…' : '▶ Hear the voice' })] }), src && _jsx("audio", { controls: true, ref: audio, src: src, style: { width: '100%' } }), error && _jsx("p", { style: { color: 'var(--theme-error-500)', fontSize: 13, margin: 0 }, children: error })] }));
297
+ return (_jsxs("div", { style: { display: 'grid', gap: 8 }, children: [_jsx("p", { style: { color: 'var(--theme-elevation-500)', fontSize: 13, margin: 0 }, children: "Hear it before you keep it. Not right? Go back and pick other samples." }), _jsxs("div", { className: "vs-row", children: [_jsx("select", { "aria-label": "Preview language", onChange: (e) => setLang(e.target.value), value: lang, children: (langs?.voice ?? ['en']).map((code) => (_jsx("option", { value: code, children: names.get(code) ?? code }, code))) }), _jsx(Button, { buttonStyle: "secondary", disabled: waiting, margin: false, onClick: play, size: "small", children: waiting ? 'Making…' : '▶ Hear the voice' })] }), src && _jsx("audio", { controls: true, ref: audio, src: src, style: { width: '100%' } }), error && _jsx("p", { style: { color: 'var(--theme-error-500)', fontSize: 13, margin: 0 }, children: error })] }));
293
298
  };
294
299
  /** Record them speaking, in the browser, as the sample to clone from. */
295
300
  export const RecordSample = ({ onRecorded }) => {
@@ -0,0 +1,3 @@
1
+ import type { VersionResponse } from '../types.js';
2
+ /** This plugin's version against the newest on npm (the server asks npm, and keeps the answer). */
3
+ export declare function useVersion(): VersionResponse | undefined;
@@ -0,0 +1,22 @@
1
+ 'use client';
2
+ import { useEffect, useState } from 'react';
3
+ import { useAPI } from './useConnection.js';
4
+ // One ask per page load, shared by the nav and the settings panel.
5
+ let asked;
6
+ /** This plugin's version against the newest on npm (the server asks npm, and keeps the answer). */
7
+ export function useVersion() {
8
+ const call = useAPI();
9
+ const [version, setVersion] = useState();
10
+ useEffect(() => {
11
+ let live = true;
12
+ asked ??= call('/vocalstack/version').catch(() => {
13
+ asked = undefined;
14
+ return undefined;
15
+ });
16
+ void asked.then((v) => live && setVersion(v));
17
+ return () => {
18
+ live = false;
19
+ };
20
+ }, [call]);
21
+ return version;
22
+ }
@@ -0,0 +1,5 @@
1
+ import type { Endpoint } from 'payload';
2
+ import type { VocalStackPluginOptions } from '../types.js';
3
+ /** Semver order: below 0 when a is older than b. */
4
+ export declare function compareVersions(a: string, b: string): number;
5
+ export declare function versionEndpoint(options: VocalStackPluginOptions): Endpoint;
@@ -0,0 +1,81 @@
1
+ import { PACKAGE_NAME, VERSION } from '../version.js';
2
+ const REGISTRY = `https://registry.npmjs.org/${PACKAGE_NAME.replace('/', '%2F')}/latest`;
3
+ const RELEASES = 'https://github.com/vocalstack/payload-plugin/releases/tag/v';
4
+ /** npm asked again after this long. */
5
+ const FRESH_MS = 6 * 60 * 60 * 1000;
6
+ /** After a failed ask, wait this long before the next. */
7
+ const RETRY_MS = 15 * 60 * 1000;
8
+ const parse = (v) => {
9
+ const m = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/.exec(v.trim());
10
+ return m ? { core: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ? m[4].split('.') : [] } : null;
11
+ };
12
+ /** Semver order: below 0 when a is older than b. */
13
+ export function compareVersions(a, b) {
14
+ const x = parse(a);
15
+ const y = parse(b);
16
+ if (!x || !y)
17
+ return 0;
18
+ for (let i = 0; i < 3; i++)
19
+ if (x.core[i] !== y.core[i])
20
+ return x.core[i] - y.core[i];
21
+ // A prerelease comes before its release.
22
+ if (!x.pre.length || !y.pre.length)
23
+ return y.pre.length - x.pre.length;
24
+ for (let i = 0; i < Math.max(x.pre.length, y.pre.length); i++) {
25
+ const p = x.pre[i];
26
+ const q = y.pre[i];
27
+ if (p === undefined)
28
+ return -1;
29
+ if (q === undefined)
30
+ return 1;
31
+ if (p === q)
32
+ continue;
33
+ const pn = /^\d+$/.test(p);
34
+ const qn = /^\d+$/.test(q);
35
+ if (pn && qn)
36
+ return Number(p) - Number(q);
37
+ if (pn !== qn)
38
+ return pn ? -1 : 1;
39
+ return p < q ? -1 : 1;
40
+ }
41
+ return 0;
42
+ }
43
+ // Per server process: one ask to npm shared by every admin, and by every page.
44
+ let known;
45
+ let asking;
46
+ async function fromNpm() {
47
+ try {
48
+ const r = await fetch(REGISTRY, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(5000) });
49
+ if (!r.ok)
50
+ return null;
51
+ const v = String((await r.json()).version ?? '');
52
+ return parse(v) ? v : null;
53
+ }
54
+ catch {
55
+ return null;
56
+ }
57
+ }
58
+ /** The newest version on npm: the last answer while it is fresh, the last good one when npm can't be reached. */
59
+ async function latest() {
60
+ if (known && Date.now() - known.at < (known.ok ? FRESH_MS : RETRY_MS))
61
+ return known.v;
62
+ asking ??= fromNpm().then((v) => {
63
+ asking = undefined;
64
+ known = { at: Date.now(), ok: Boolean(v), v: v ?? known?.v ?? null };
65
+ return known.v;
66
+ });
67
+ return asking;
68
+ }
69
+ export function versionEndpoint(options) {
70
+ return {
71
+ method: 'get',
72
+ path: '/vocalstack/version',
73
+ handler: async (req) => {
74
+ if (!req.user)
75
+ return Response.json({ error: 'Sign in first.' }, { status: 401 });
76
+ const v = options.updateCheck === false ? null : await latest();
77
+ const state = !v ? 'unknown' : compareVersions(VERSION, v) < 0 ? 'outdated' : 'current';
78
+ return Response.json({ current: VERSION, latest: v, releaseURL: state === 'outdated' ? `${RELEASES}${v}` : undefined, state }, { headers: { 'cache-control': 'private, max-age=300' } });
79
+ },
80
+ };
81
+ }
@@ -3,3 +3,4 @@ export { SpeakerField } from '../components/SpeakerField.js';
3
3
  export { SpeechField } from '../components/SpeechField.js';
4
4
  export { TranscribeButton } from '../components/TranscribeButton.js';
5
5
  export { TranscriptField } from '../components/TranscriptField.js';
6
+ export { UpdateNotice } from '../components/UpdateNotice.js';
@@ -4,3 +4,4 @@ export { SpeakerField } from '../components/SpeakerField.js';
4
4
  export { SpeechField } from '../components/SpeechField.js';
5
5
  export { TranscribeButton } from '../components/TranscribeButton.js';
6
6
  export { TranscriptField } from '../components/TranscriptField.js';
7
+ export { UpdateNotice } from '../components/UpdateNotice.js';
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ import type { VocalStackPluginOptions } from './types.js';
3
3
  export type * from './types.js';
4
4
  export { spokenSentences, timedTokens, transcriptText } from './text.js';
5
5
  export { migrateSpeakerFields, speakerData } from './endpoints/voices.js';
6
+ export { VERSION } from './version.js';
6
7
  export declare const vocalstackPlugin: (options?: VocalStackPluginOptions) => Plugin;
package/dist/index.js CHANGED
@@ -2,11 +2,13 @@ import { connectionEndpoints } from './endpoints/connection.js';
2
2
  import { refreshAfterRead, speechEndpoints } from './endpoints/speech.js';
3
3
  import { streamEndpoint } from './endpoints/stream.js';
4
4
  import { transcribeEndpoints } from './endpoints/transcribe.js';
5
+ import { versionEndpoint } from './endpoints/version.js';
5
6
  import { lookupEndpoints, speakerEndpoints } from './endpoints/voices.js';
6
7
  import { readingsCollection, readingsSlug } from './readings.js';
7
8
  import { settingsGlobal } from './settings.js';
8
9
  export { spokenSentences, timedTokens, transcriptText } from './text.js';
9
10
  export { migrateSpeakerFields, speakerData } from './endpoints/voices.js';
11
+ export { VERSION } from './version.js';
10
12
  const isAudioDoc = (data) => typeof data?.mimeType === 'string' && data.mimeType.startsWith('audio/');
11
13
  /** An upload collection that can hold audio: `audio/*`, a wildcard, or no restriction at all. */
12
14
  function acceptsAudio(collection) {
@@ -173,8 +175,18 @@ export const vocalstackPlugin = (options = {}) => (config) => {
173
175
  if (!collections.some((c) => c.slug === v.collection))
174
176
  throw new Error(`vocalstackPlugin: no collection "${v.collection}" for speakers`);
175
177
  }
178
+ const updateCheck = enabled && options.updateCheck !== false;
176
179
  return {
177
180
  ...config,
181
+ admin: updateCheck
182
+ ? {
183
+ ...config.admin,
184
+ components: {
185
+ ...config.admin?.components,
186
+ afterNavLinks: [...(config.admin?.components?.afterNavLinks ?? []), '@vocalstack/payload/client#UpdateNotice'],
187
+ },
188
+ }
189
+ : config.admin,
178
190
  collections: [...collections, ...(readings && !collections.some((c) => c.slug === readings) ? [(options.readings && options.readings.overrides ? options.readings.overrides : (c) => c)(readingsCollection(readings))] : [])].map((original) => {
179
191
  const speaker = speakers.find((v) => v.collection === original.slug);
180
192
  const collection = speaker
@@ -212,7 +224,7 @@ export const vocalstackPlugin = (options = {}) => (config) => {
212
224
  : collection.hooks,
213
225
  };
214
226
  }),
215
- endpoints: enabled ? [...(config.endpoints ?? []), ...connectionEndpoints(options), ...lookupEndpoints(options)] : config.endpoints,
227
+ endpoints: enabled ? [...(config.endpoints ?? []), ...connectionEndpoints(options), ...lookupEndpoints(options), versionEndpoint(options)] : config.endpoints,
216
228
  globals: [...(config.globals ?? []), settingsGlobal(options)],
217
229
  };
218
230
  };
package/dist/types.d.ts CHANGED
@@ -44,6 +44,12 @@ export type VocalStackPluginOptions = {
44
44
  * Authenticate there). Needs the dashboard's /connect flow; until then, paste a key.
45
45
  */
46
46
  oneClickConnect?: boolean;
47
+ /**
48
+ * Check npm for a newer version of this plugin (from the server, at most every
49
+ * 6 hours) and say so in the admin: in the nav and on Settings → VocalStack.
50
+ * Default `true`; `false` makes no outbound call and shows nothing.
51
+ */
52
+ updateCheck?: boolean;
47
53
  /** A Whisper language code (`en`, `ro`, …). Leave out to auto-detect. */
48
54
  spokenLanguage?: string;
49
55
  /**
@@ -269,6 +275,15 @@ export type StatusResponse = {
269
275
  stopped?: boolean;
270
276
  vocalstack?: VocalStackFieldData;
271
277
  };
278
+ export type VersionResponse = {
279
+ /** This plugin's version, as installed. */
280
+ current: string;
281
+ /** The newest version on npm, or `null` when it is not known (offline, or `updateCheck: false`). */
282
+ latest: null | string;
283
+ /** Its release notes. */
284
+ releaseURL?: string;
285
+ state: 'current' | 'outdated' | 'unknown';
286
+ };
272
287
  export type ConnectionResponse = {
273
288
  account?: string;
274
289
  connected: boolean;
@@ -0,0 +1,2 @@
1
+ export declare const PACKAGE_NAME = "@vocalstack/payload";
2
+ export declare const VERSION = "0.7.0";
@@ -0,0 +1,3 @@
1
+ // Written by scripts/version.mjs from package.json. Do not edit.
2
+ export const PACKAGE_NAME = "@vocalstack/payload";
3
+ export const VERSION = "0.7.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocalstack/payload",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "VocalStack for Payload CMS: transcribe audio, translate it into other languages and read it aloud, kept in your own database and storage.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,8 +20,9 @@
20
20
  "dist"
21
21
  ],
22
22
  "scripts": {
23
- "build": "tsc -p tsconfig.json",
24
- "typecheck": "tsc -p tsconfig.json --noEmit"
23
+ "version": "node scripts/version.mjs && git add src/version.ts",
24
+ "build": "node scripts/version.mjs && tsc -p tsconfig.json",
25
+ "typecheck": "node scripts/version.mjs && tsc -p tsconfig.json --noEmit"
25
26
  },
26
27
  "peerDependencies": {
27
28
  "@payloadcms/ui": "^3.0.0",