@vocalstack/payload 0.6.2 → 0.8.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 +30 -7
- package/dist/api.d.ts +2 -0
- package/dist/api.js +17 -2
- package/dist/components/ConnectionPanel.js +21 -8
- package/dist/components/SpeakerField.js +15 -6
- package/dist/components/SpeechField.js +8 -4
- package/dist/components/UpdateNotice.d.ts +2 -0
- package/dist/components/UpdateNotice.js +26 -0
- package/dist/components/VoiceSamples.d.ts +1 -1
- package/dist/components/VoiceSamples.js +7 -2
- package/dist/components/WorkspaceMark.d.ts +11 -0
- package/dist/components/WorkspaceMark.js +30 -0
- package/dist/components/useConnection.d.ts +1 -0
- package/dist/components/useConnection.js +7 -1
- package/dist/components/useVersion.d.ts +3 -0
- package/dist/components/useVersion.js +22 -0
- package/dist/endpoints/connection.d.ts +2 -0
- package/dist/endpoints/connection.js +77 -8
- package/dist/endpoints/transcribe.js +12 -2
- package/dist/endpoints/version.d.ts +5 -0
- package/dist/endpoints/version.js +81 -0
- package/dist/exports/client.d.ts +1 -0
- package/dist/exports/client.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -1
- package/dist/types.d.ts +20 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/dist/workspace.d.ts +20 -0
- package/dist/workspace.js +22 -0
- package/dist/workspaceMark.d.ts +8 -0
- package/dist/workspaceMark.js +24 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Then run `payload generate:importmap`. The plugin adds fields to the targeted co
|
|
|
41
41
|
- `POST …/vocalstack/voices { voices: 'synthetic' | 'cloned' }`, `POST …/vocalstack/request { langs, speak? }` (translate, and read aloud unless `speak: false`; carried on by the server), `POST …/vocalstack/translate { langs }` (one step; answers `more: true` when it stopped for time), `DELETE …/vocalstack/translate?lang=`, `POST …/vocalstack/speak { langs }`, `GET …/vocalstack/speak`, and the public `GET …/vocalstack/audio?lang=`, which redirects to the reading's MP3 (or, with no `lang` or the spoken one, the recording's audio) for anyone who may read the document.
|
|
42
42
|
- **Languages for listeners** (opt in with `listeners`): visitors pick any language VocalStack offers, and it is made for them and kept for everyone after. `GET /api/vocalstack/languages` is public, `POST …/vocalstack/listen { lang }` asks for a language and `GET …/vocalstack/listen?lang=` says where it stands; see below.
|
|
43
43
|
- **Speakers** (opt in with `speakers`): documents of a collection of people get a sidebar panel that saves that person as a VocalStack speaker and clones their voice, from a minute of a recording they speak in or from an uploaded sample, with their permission. Kept in a hidden `vocalstackSpeaker` group (`speakerId`, `cloneId`, `state` of the voice: `none`/`training`/`ready`/`failed`, `progress`, `error`, `sampleS`, `consentAt`, `createdAt`), with `GET`/`POST`/`DELETE /api/{collection}/:id/vocalstack/speaker`, `…/speaker/sources` and `…/speaker/preview`.
|
|
44
|
-
- **Settings → VocalStack** (a global), where an editor connects
|
|
44
|
+
- **Settings → VocalStack** (a global), where an editor connects a VocalStack workspace. It shows the workspace the site works in, with its name and icon, and **Change** picks another. The key is stored server-side and is unreadable over the REST and GraphQL APIs.
|
|
45
45
|
|
|
46
46
|
## Options
|
|
47
47
|
|
|
@@ -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:
|
|
@@ -162,11 +176,19 @@ The translation is saved on the document, and where VocalStack can read the lang
|
|
|
162
176
|
|
|
163
177
|
When VocalStack does not answer (an outage, an upgrade), the endpoints say *VocalStack is unavailable, try again shortly.* instead of waiting.
|
|
164
178
|
|
|
165
|
-
**How the audio reaches VocalStack.** If the file has a public address, VocalStack fetches it (`POST /v1/transcriptions { url }`). Otherwise (localhost, a private network) the plugin uploads the bytes. Either way the job runs on VocalStack, and the admin polls every 3 s. The
|
|
179
|
+
**How the audio reaches VocalStack.** If the file has a public address, VocalStack fetches it (`POST /v1/transcriptions { url }`). Otherwise (localhost, a private network) the plugin uploads the bytes. Either way the job runs on VocalStack, and the admin polls every 3 s. The connected workspace is billed per second, with a 5-minute minimum per transcription.
|
|
180
|
+
|
|
181
|
+
## The workspace
|
|
182
|
+
|
|
183
|
+
A VocalStack API key belongs to one workspace: what the site transcribes is kept in that workspace and uses its credit. **Settings → VocalStack** shows it under **Workspace**, with its name and its mark as the VocalStack Dashboard draws it (its own icon; a person for the personal workspace; otherwise its initials on its colour). The name and icon are read from `GET /v1/me` whenever the connection is checked (at most once a minute), so a rename or a new icon in VocalStack shows up here, and a pasted key or a key from the plugin config shows its workspace too. `GET /api/vocalstack/connection` answers `{ connected, source, account, workspace: { id, name, personal, iconUrl } }`, with `iconUrl` an absolute link the browser can load as it is.
|
|
184
|
+
|
|
185
|
+
A key never moves to another workspace. With `oneClickConnect`, **Change** next to the workspace runs the connect flow again: pick another workspace on VocalStack's consent screen and click Authenticate, and the site swaps to the new key. Cancelling, in VocalStack or with **Cancel** in the admin, leaves the connection as it was. Connecting again makes a new key; the old one keeps working until it is revoked in VocalStack under **Developers → API keys**. Without `oneClickConnect`, disconnect and paste a key made in the other workspace. A key from the plugin config is changed there.
|
|
186
|
+
|
|
187
|
+
Transcripts stay in the workspace that made them. After a change, the transcripts, translations and readings already saved on your documents are still there and still served, but asking VocalStack for more of one made in the old workspace (another language, a reading, a speaker's sample) answers *This transcript is not in the connected VocalStack workspace…*; transcribe the file again to work with it in the new workspace. A transcription that was still running when the workspace changed ends as failed with the same sentence.
|
|
166
188
|
|
|
167
189
|
## One-click connect (protocol)
|
|
168
190
|
|
|
169
|
-
The alternative to pasting a key: **Connect VocalStack** opens the dashboard in a new tab, the person clicks **Authenticate**, and the tab closes. This is OAuth 2.0 authorization code + PKCE (RFC 7636) with an API key as the access token. There is no client registration: the consent screen shows the `redirect_uri` host instead.
|
|
191
|
+
The alternative to pasting a key: **Connect VocalStack** opens the dashboard in a new tab, the person chooses a workspace and clicks **Authenticate**, and the tab closes. **Change** runs the same flow while connected; the stored key is replaced only once the new one has been issued. This is OAuth 2.0 authorization code + PKCE (RFC 7636) with an API key as the access token. There is no client registration: the consent screen shows the `redirect_uri` host instead.
|
|
170
192
|
|
|
171
193
|
```
|
|
172
194
|
CMS admin CMS server app.vocalstack.com / api.vocalstack.com
|
|
@@ -175,20 +197,21 @@ click Connect ── POST /api/vocalstack/connect ─▶ state, verifier (10 min
|
|
|
175
197
|
◀──────────── { url } ──────────────
|
|
176
198
|
new tab ─▶ GET app/connect?response_type=code&client_name=…&redirect_uri=…&state=…
|
|
177
199
|
&code_challenge=…&code_challenge_method=S256&scope=read write
|
|
178
|
-
(sign in if needed; pick the
|
|
200
|
+
(sign in if needed; pick the workspace; "example.com wants to transcribe with VocalStack")
|
|
179
201
|
click Authenticate ─▶ API stores a single-use grant (code hash, challenge, redirect, scopes, principal; 2 min)
|
|
180
202
|
◀── 302 redirect_uri?code=…&state=…
|
|
181
203
|
tab ─────── GET /api/vocalstack/callback ─▶ check state (+ admin session)
|
|
182
204
|
POST api/v1/connect/token (form) ─▶ grant_type=authorization_code, code,
|
|
183
205
|
code_verifier, redirect_uri
|
|
184
206
|
verify, burn the code, create the key
|
|
185
|
-
◀── { access_token: "vs_key_…", token_type: "api_key", key_id, account: { name }
|
|
207
|
+
◀── { access_token: "vs_key_…", token_type: "api_key", key_id, account: { name },
|
|
208
|
+
workspace: { id, name, personal, iconUrl } }
|
|
186
209
|
stores the key (never sent to a browser)
|
|
187
210
|
tab: "Connected", BroadcastChannel('vocalstack') ─▶ admin refreshes; tab closes
|
|
188
211
|
```
|
|
189
212
|
|
|
190
|
-
Cancel redirects with `?error=access_denied&state
|
|
213
|
+
Cancel redirects with `?error=access_denied&state=…`; `DELETE /api/vocalstack/connect` drops a pending connect from the admin side. The key appears in the dashboard's API keys list as `example.com (Payload CMS)`, where it can be revoked.
|
|
191
214
|
|
|
192
215
|
## Releasing
|
|
193
216
|
|
|
194
|
-
Bump `version` in `package.json` and push to `main`. The `publish` workflow publishes that version to npm (trusted publishing, with provenance), tags `v<version>` and creates the GitHub release. A version npm already has is skipped. A prerelease (`0.5.0-beta.1`) goes to the `next` dist-tag. Nobody publishes from a laptop.
|
|
217
|
+
Bump `version` in `package.json` and push to `main`. The `publish` workflow runs the tests (`pnpm test`: a build, then `node --test` over `test/`), publishes that version to npm (trusted publishing, with provenance), tags `v<version>` and creates the GitHub release. A version npm already has is skipped. A prerelease (`0.5.0-beta.1`) goes to the `next` dist-tag. Nobody publishes from a laptop.
|
package/dist/api.d.ts
CHANGED
|
@@ -107,6 +107,8 @@ export type Languages = {
|
|
|
107
107
|
voice: string[];
|
|
108
108
|
};
|
|
109
109
|
export declare const UNAVAILABLE = "VocalStack is unavailable, try again shortly.";
|
|
110
|
+
/** A stored recording the connected key cannot see: made in another workspace (the workspace was changed), or deleted. */
|
|
111
|
+
export declare const NOT_IN_WORKSPACE = "This transcript is not in the connected VocalStack workspace: it was made in another workspace, or deleted in VocalStack. Transcribe the file again to work with it here.";
|
|
110
112
|
export declare class VocalStackAPIError extends Error {
|
|
111
113
|
code: string;
|
|
112
114
|
status: number;
|
package/dist/api.js
CHANGED
|
@@ -24,6 +24,9 @@ function savedSpeakerOf(raw) {
|
|
|
24
24
|
const speakerRoutes = new Map();
|
|
25
25
|
const both = (rest) => ({ speakers: `/v1/speakers${rest}`, voices: `/v1/voices${rest}` });
|
|
26
26
|
export const UNAVAILABLE = 'VocalStack is unavailable, try again shortly.';
|
|
27
|
+
/** A stored recording the connected key cannot see: made in another workspace (the workspace was changed), or deleted. */
|
|
28
|
+
export const NOT_IN_WORKSPACE = 'This transcript is not in the connected VocalStack workspace: it was made in another workspace, or deleted in VocalStack. Transcribe the file again to work with it here.';
|
|
29
|
+
const isGone = (status, message) => status === 404 && /^no such (recording|transcription|job)\b/i.test(message.trim());
|
|
27
30
|
export class VocalStackAPIError extends Error {
|
|
28
31
|
code;
|
|
29
32
|
status;
|
|
@@ -52,6 +55,8 @@ function toAPIError(err) {
|
|
|
52
55
|
const down = err.code === 'unavailable' || (err.code === 'internal' && (err.status === 502 || err.status === 503 || err.status === 504));
|
|
53
56
|
if (down)
|
|
54
57
|
return new VocalStackAPIError(503, 'unavailable', UNAVAILABLE);
|
|
58
|
+
if (isGone(err.status, err.message))
|
|
59
|
+
return new VocalStackAPIError(404, 'not_found', NOT_IN_WORKSPACE);
|
|
55
60
|
return new VocalStackAPIError(err.status ?? 500, err.code, err.message);
|
|
56
61
|
}
|
|
57
62
|
if (err instanceof Error && (err.name === 'AbortError' || err.name === 'TimeoutError'))
|
|
@@ -90,8 +95,16 @@ export class VocalStackAPI {
|
|
|
90
95
|
transcribeFile(file, fileName, opts) {
|
|
91
96
|
return call(() => this.sdk.transcriptions.create({ file, fileName, name: opts.name, settings: opts.spokenLanguage ? { spokenLanguage: opts.spokenLanguage } : undefined }, { idempotencyKey: opts.idempotencyKey }));
|
|
92
97
|
}
|
|
93
|
-
job(recordingId) {
|
|
94
|
-
|
|
98
|
+
async job(recordingId) {
|
|
99
|
+
try {
|
|
100
|
+
return await call(() => this.sdk.jobs.get(recordingId));
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
// Any "not found" for a job that was started here means this key cannot see it (a wrong address says "no route").
|
|
104
|
+
if (err instanceof VocalStackAPIError && err.status === 404 && !/^no route\b/i.test(err.message))
|
|
105
|
+
throw new VocalStackAPIError(404, 'not_found', NOT_IN_WORKSPACE);
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
95
108
|
}
|
|
96
109
|
/** Stop a job before it is done. Its job fails with `stopped`; what was transcribed so far stays in VocalStack. */
|
|
97
110
|
stop(recordingId, reason) {
|
|
@@ -142,6 +155,8 @@ export class VocalStackAPI {
|
|
|
142
155
|
return body;
|
|
143
156
|
if (res.status === 502 || res.status === 503 || res.status === 504)
|
|
144
157
|
throw new VocalStackAPIError(503, 'unavailable', UNAVAILABLE);
|
|
158
|
+
if (isGone(res.status, body?.message ?? ''))
|
|
159
|
+
throw new VocalStackAPIError(404, 'not_found', NOT_IN_WORKSPACE);
|
|
145
160
|
throw new VocalStackAPIError(res.status, body?.code ?? 'http_error', body?.message ?? `VocalStack answered ${res.status}`);
|
|
146
161
|
}
|
|
147
162
|
voiceTracks(recordingId, lang) {
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
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';
|
|
8
|
+
import { WorkspaceMark, WorkspaceMarkStyles } from './WorkspaceMark.js';
|
|
7
9
|
const KEYS_URL = 'https://app.vocalstack.com/developers/keys';
|
|
10
|
+
const muted = { color: 'var(--theme-elevation-500)' };
|
|
11
|
+
/** The installed version, and the newer one when there is one. */
|
|
12
|
+
const VersionLine = () => {
|
|
13
|
+
const version = useVersion();
|
|
14
|
+
if (!version)
|
|
15
|
+
return null;
|
|
16
|
+
if (version.state !== 'outdated')
|
|
17
|
+
return _jsxs("p", { style: { ...muted, fontSize: 13, margin: 0 }, children: ["@vocalstack/payload ", version.current] });
|
|
18
|
+
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."] })] }));
|
|
19
|
+
};
|
|
20
|
+
/** The workspace the key works in: its mark and name under a "Workspace" label, with room for a button beside it. */
|
|
21
|
+
const WorkspaceRow = ({ children, workspace }) => (_jsxs("div", { style: { alignItems: 'center', display: 'flex', gap: 12 }, children: [_jsx(WorkspaceMarkStyles, {}), _jsx(WorkspaceMark, { size: 40, workspace: workspace }), _jsxs("div", { "aria-label": `Workspace: ${workspace.name}`, role: "group", style: { flex: 1, minWidth: 0 }, children: [_jsx("div", { style: { ...muted, fontSize: 11, fontWeight: 600, letterSpacing: '.08em', lineHeight: 1.4, textTransform: 'uppercase' }, children: "Workspace" }), _jsx("div", { style: { fontWeight: 600, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, children: workspace.name })] }), children] }));
|
|
8
22
|
export const ConnectionPanel = ({ oneClickConnect }) => {
|
|
9
|
-
const { call, connect, connecting, connection, setConnection } = useConnection();
|
|
23
|
+
const { call, cancel, connect, connecting, connection, setConnection } = useConnection();
|
|
10
24
|
const [apiKey, setAPIKey] = useState('');
|
|
11
25
|
const [saving, setSaving] = useState(false);
|
|
12
26
|
const [error, setError] = useState();
|
|
@@ -26,16 +40,15 @@ export const ConnectionPanel = ({ oneClickConnect }) => {
|
|
|
26
40
|
}
|
|
27
41
|
};
|
|
28
42
|
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
43
|
if (!connection)
|
|
31
44
|
return _jsx("p", { style: muted, children: "Checking the VocalStack connection\u2026" });
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
45
|
+
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' ? (_jsxs(_Fragment, { children: [connection.workspace && _jsx(WorkspaceRow, { workspace: connection.workspace }), _jsx("p", { style: { margin: 0 }, children: "Connected with the API key from the plugin config. Change it there." })] })) : connection.connected ? (_jsxs(_Fragment, { children: [connection.workspace ? (_jsxs(_Fragment, { children: [_jsx(WorkspaceRow, { workspace: connection.workspace, children: oneClickConnect && (_jsx(Button, { "aria-label": connecting ? 'Cancel changing the workspace' : 'Change workspace', buttonStyle: "secondary", disabled: saving, margin: false, onClick: () => {
|
|
46
|
+
setError(undefined);
|
|
47
|
+
void (connecting ? cancel() : connect().catch((e) => setError(e.message)));
|
|
48
|
+
}, size: "small", children: connecting ? 'Cancel' : 'Change' })) }), _jsx("p", { style: { margin: 0 }, children: "Connected to VocalStack. Audio uploads have a Transcribe button, and what is transcribed here is kept in this workspace and uses its credit." }), oneClickConnect && (_jsx("p", { style: { ...muted, fontSize: 13, margin: 0 }, children: connecting ? ('Choose a workspace in the VocalStack tab, then click Authenticate. Until then this workspace stays connected.') : (_jsxs(_Fragment, { children: ["Change connects again, to the workspace you pick in VocalStack. That makes a new API key; the old one keeps working until it is revoked in VocalStack under", ' ', _jsx("a", { href: KEYS_URL, rel: "noreferrer", target: "_blank", children: "Developers \u2192 API keys" }), ". Transcripts made in another workspace stay in it."] })) }))] })) : (_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 || connecting, margin: false, onClick: () => run(() => call('/vocalstack/key', { method: 'DELETE' }), 'Disconnected.'), children: "Disconnect" }) })] })) : (_jsxs(_Fragment, { children: [_jsx("p", { style: { margin: 0 }, children: "Connect a VocalStack workspace to transcribe audio uploads. Transcriptions are kept in that workspace and use its 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; choose a workspace and click Authenticate there." })] })), _jsxs("div", { onKeyDown: (e) => {
|
|
36
49
|
if (e.key === 'Enter' && apiKey.trim()) {
|
|
37
50
|
e.preventDefault();
|
|
38
51
|
save();
|
|
39
52
|
}
|
|
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 })] }));
|
|
53
|
+
}, 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
54
|
};
|
|
@@ -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-
|
|
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", {
|
|
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: [
|
|
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' }) })] }))
|
|
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
|
-
|
|
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…',
|
|
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" }),
|
|
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,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", {
|
|
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", {
|
|
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,11 @@
|
|
|
1
|
+
import type { Workspace } from '../workspace.js';
|
|
2
|
+
/** The mark's looks, as in the VocalStack Dashboard, on Payload's theme colours. */
|
|
3
|
+
export declare const WorkspaceMarkStyles: () => import("react").JSX.Element;
|
|
4
|
+
/**
|
|
5
|
+
* A workspace's mark, as the VocalStack Dashboard draws it: its own icon when it has
|
|
6
|
+
* one, a person for the personal workspace, else its initials on its colour.
|
|
7
|
+
*/
|
|
8
|
+
export declare const WorkspaceMark: React.FC<{
|
|
9
|
+
size?: number;
|
|
10
|
+
workspace: Workspace;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { workspaceHue, workspaceInitials } from '../workspaceMark.js';
|
|
5
|
+
const PERSON = 'M15.75 6a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0ZM4.501 20.118a7.5 7.5 0 0 1 14.998 0A17.933 17.933 0 0 1 12 21.75c-2.676 0-5.216-.584-7.499-1.632Z';
|
|
6
|
+
/** The mark's looks, as in the VocalStack Dashboard, on Payload's theme colours. */
|
|
7
|
+
export const WorkspaceMarkStyles = () => (_jsx("style", { children: `
|
|
8
|
+
.vs-wsmark { flex: none; display: grid; place-items: center; font-weight: 600; letter-spacing: .02em; line-height: 1; --ws-c: oklch(.66 .13 var(--ws-h, 252)); background: color-mix(in oklab, var(--ws-c) 22%, transparent); color: color-mix(in oklab, var(--ws-c) 72%, var(--theme-text)); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ws-c) 30%, transparent); }
|
|
9
|
+
.vs-wsmark--me { background: var(--theme-elevation-100); color: var(--theme-elevation-650); box-shadow: inset 0 0 0 1px var(--theme-elevation-150); }
|
|
10
|
+
.vs-wsmark--img { overflow: hidden; background: var(--theme-elevation-50); box-shadow: inset 0 0 0 1px var(--theme-elevation-150); }
|
|
11
|
+
.vs-wsmark--img img { display: block; width: 100%; height: 100%; object-fit: cover; }
|
|
12
|
+
` }));
|
|
13
|
+
/**
|
|
14
|
+
* A workspace's mark, as the VocalStack Dashboard draws it: its own icon when it has
|
|
15
|
+
* one, a person for the personal workspace, else its initials on its colour.
|
|
16
|
+
*/
|
|
17
|
+
export const WorkspaceMark = ({ size = 28, workspace }) => {
|
|
18
|
+
// An icon that does not load (its link ran out, the network) gives way to the drawn mark.
|
|
19
|
+
const [broken, setBroken] = useState();
|
|
20
|
+
const style = { borderRadius: Math.round(size * 0.29), fontSize: Math.round(size * 0.39), height: size, width: size };
|
|
21
|
+
const icon = workspace.iconUrl && workspace.iconUrl !== broken ? workspace.iconUrl : undefined;
|
|
22
|
+
if (icon) {
|
|
23
|
+
return (_jsx("span", { "aria-hidden": "true", className: "vs-wsmark vs-wsmark--img", style: style, children: _jsx("img", { alt: "", draggable: false, onError: () => setBroken(icon), src: icon }) }));
|
|
24
|
+
}
|
|
25
|
+
if (workspace.personal) {
|
|
26
|
+
const glyph = Math.round(size * 0.55);
|
|
27
|
+
return (_jsx("span", { "aria-hidden": "true", className: "vs-wsmark vs-wsmark--me", style: style, children: _jsx("svg", { fill: "none", height: glyph, stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.6, viewBox: "0 0 24 24", width: glyph, children: _jsx("path", { d: PERSON }) }) }));
|
|
28
|
+
}
|
|
29
|
+
return (_jsx("span", { "aria-hidden": "true", className: "vs-wsmark", style: { ...style, '--ws-h': workspaceHue(workspace.id) }, children: workspaceInitials(workspace.name) }));
|
|
30
|
+
};
|
|
@@ -3,6 +3,7 @@ export declare function useAPI(): <T>(path: string, init?: RequestInit) => Promi
|
|
|
3
3
|
/** The VocalStack connection, and the one-click flow that opens the dashboard in a new tab. */
|
|
4
4
|
export declare function useConnection(): {
|
|
5
5
|
call: <T>(path: string, init?: RequestInit) => Promise<T>;
|
|
6
|
+
cancel: () => Promise<void>;
|
|
6
7
|
connect: () => Promise<void>;
|
|
7
8
|
connecting: boolean;
|
|
8
9
|
connection: ConnectionResponse | undefined;
|
|
@@ -55,5 +55,11 @@ export function useConnection() {
|
|
|
55
55
|
throw err;
|
|
56
56
|
}
|
|
57
57
|
}, [call]);
|
|
58
|
-
|
|
58
|
+
/** Give up a connect that is waiting: its link stops working, and the connection in use stays. */
|
|
59
|
+
const cancel = useCallback(async () => {
|
|
60
|
+
setConnecting(false);
|
|
61
|
+
await call('/vocalstack/connect', { method: 'DELETE' }).catch(() => undefined);
|
|
62
|
+
await refresh();
|
|
63
|
+
}, [call, refresh]);
|
|
64
|
+
return { call, cancel, connect, connecting, connection, refresh, setConnection };
|
|
59
65
|
}
|
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Endpoint } from 'payload';
|
|
2
2
|
import type { VocalStackPluginOptions } from '../types.js';
|
|
3
|
+
/** Forget what was read from `/v1/me` (tests). */
|
|
4
|
+
export declare const forgetOwners: () => void;
|
|
3
5
|
/**
|
|
4
6
|
* One-click connect, as OAuth 2.0 authorization code + PKCE (RFC 7636) whose
|
|
5
7
|
* token is a VocalStack API key:
|
|
@@ -1,9 +1,47 @@
|
|
|
1
1
|
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
2
|
import { accountLabel, DEFAULT_API_URL, DEFAULT_DASHBOARD_URL, VocalStackAPI, VocalStackAPIError } from '../api.js';
|
|
3
3
|
import { readSettings, writeSettings } from '../settings.js';
|
|
4
|
+
import { workspaceOf } from '../workspace.js';
|
|
4
5
|
const json = (body, status = 200) => Response.json(body, { status });
|
|
5
6
|
const base64url = (b) => b.toString('base64url');
|
|
6
7
|
const CONNECT_TTL_MS = 10 * 60 * 1000;
|
|
8
|
+
const OWNER_FRESH_MS = 60_000;
|
|
9
|
+
const OWNER_RETRY_MS = 15_000;
|
|
10
|
+
const OWNER_TIMEOUT_MS = 6_000;
|
|
11
|
+
const owners = new Map();
|
|
12
|
+
const ownerKey = (apiKey, apiURL) => createHash('sha256').update(`${apiURL}\n${apiKey}`).digest('hex');
|
|
13
|
+
/** Forget what was read from `/v1/me` (tests). */
|
|
14
|
+
export const forgetOwners = () => owners.clear();
|
|
15
|
+
const ownerOf = (me, apiURL) => {
|
|
16
|
+
const workspace = workspaceOf(me.workspace, apiURL);
|
|
17
|
+
return { account: workspace?.name ?? accountLabel(me), workspace };
|
|
18
|
+
};
|
|
19
|
+
function remember(apiKey, apiURL, owner, ms = OWNER_FRESH_MS) {
|
|
20
|
+
if (owners.size > 50)
|
|
21
|
+
owners.clear();
|
|
22
|
+
owners.set(ownerKey(apiKey, apiURL), { owner, until: Date.now() + ms });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The key's workspace as `/v1/me` has it now, so a new name or icon set in the VocalStack
|
|
26
|
+
* Dashboard reaches the admin. Asked at most once a minute per key; `undefined` when
|
|
27
|
+
* VocalStack did not answer in time.
|
|
28
|
+
*/
|
|
29
|
+
async function lookUpOwner(apiKey, apiURL) {
|
|
30
|
+
const hit = owners.get(ownerKey(apiKey, apiURL));
|
|
31
|
+
if (hit && Date.now() < hit.until)
|
|
32
|
+
return hit.owner;
|
|
33
|
+
const owner = await Promise.race([
|
|
34
|
+
new VocalStackAPI(apiKey, apiURL).me().then((me) => ownerOf(me, apiURL), () => undefined),
|
|
35
|
+
new Promise((resolve) => {
|
|
36
|
+
const timer = setTimeout(resolve, OWNER_TIMEOUT_MS);
|
|
37
|
+
timer.unref?.();
|
|
38
|
+
}),
|
|
39
|
+
]);
|
|
40
|
+
// Through a blip the last good answer stays, and VocalStack is asked again sooner.
|
|
41
|
+
const last = owner ?? hit?.owner;
|
|
42
|
+
remember(apiKey, apiURL, last, owner ? OWNER_FRESH_MS : OWNER_RETRY_MS);
|
|
43
|
+
return last;
|
|
44
|
+
}
|
|
7
45
|
/**
|
|
8
46
|
* One-click connect, as OAuth 2.0 authorization code + PKCE (RFC 7636) whose
|
|
9
47
|
* token is a VocalStack API key:
|
|
@@ -27,10 +65,18 @@ export function connectionEndpoints(options) {
|
|
|
27
65
|
handler: async (req) => {
|
|
28
66
|
if (!req.user)
|
|
29
67
|
return json({ error: 'Sign in first.' }, 401);
|
|
30
|
-
if (options.apiKey)
|
|
31
|
-
|
|
68
|
+
if (options.apiKey) {
|
|
69
|
+
const owner = await lookUpOwner(options.apiKey, apiURL);
|
|
70
|
+
return json({ account: owner?.account, connected: true, source: 'options', workspace: owner?.workspace });
|
|
71
|
+
}
|
|
32
72
|
const settings = await readSettings(req);
|
|
33
|
-
|
|
73
|
+
if (!settings.apiKey)
|
|
74
|
+
return json({ account: settings.account ?? undefined, connected: false });
|
|
75
|
+
const owner = await lookUpOwner(settings.apiKey, apiURL);
|
|
76
|
+
// The stored label follows a rename, so it is still right when VocalStack cannot be asked.
|
|
77
|
+
if (owner?.account && owner.account !== settings.account)
|
|
78
|
+
await writeSettings(req, { account: owner.account }).catch(() => undefined);
|
|
79
|
+
return json({ account: owner?.account ?? settings.account ?? undefined, connected: true, source: 'admin', workspace: owner?.workspace });
|
|
34
80
|
},
|
|
35
81
|
},
|
|
36
82
|
{
|
|
@@ -45,9 +91,10 @@ export function connectionEndpoints(options) {
|
|
|
45
91
|
if (!apiKey?.startsWith('vs_key_'))
|
|
46
92
|
return json({ error: 'A VocalStack API key starts with vs_key_.' }, 400);
|
|
47
93
|
try {
|
|
48
|
-
const
|
|
49
|
-
await writeSettings(req, { account, apiKey });
|
|
50
|
-
|
|
94
|
+
const owner = ownerOf(await new VocalStackAPI(apiKey, apiURL).me(), apiURL);
|
|
95
|
+
await writeSettings(req, { account: owner.account ?? null, apiKey });
|
|
96
|
+
remember(apiKey, apiURL, owner);
|
|
97
|
+
return json({ account: owner.account, connected: true, source: 'admin', workspace: owner.workspace });
|
|
51
98
|
}
|
|
52
99
|
catch (err) {
|
|
53
100
|
const message = err instanceof VocalStackAPIError && err.status === 401 ? 'VocalStack refused that key.' : String(err.message);
|
|
@@ -65,6 +112,17 @@ export function connectionEndpoints(options) {
|
|
|
65
112
|
return json({ connected: Boolean(options.apiKey), source: options.apiKey ? 'options' : undefined });
|
|
66
113
|
},
|
|
67
114
|
},
|
|
115
|
+
{
|
|
116
|
+
// Give up a connect that was started: its link stops working, and the key in use stays.
|
|
117
|
+
method: 'delete',
|
|
118
|
+
path: '/vocalstack/connect',
|
|
119
|
+
handler: async (req) => {
|
|
120
|
+
if (!(await canManage(req)))
|
|
121
|
+
return json({ error: 'You may not change the VocalStack connection.' }, 403);
|
|
122
|
+
await writeSettings(req, { connectExpiresAt: null, connectState: null, connectVerifier: null });
|
|
123
|
+
return json({ ok: true });
|
|
124
|
+
},
|
|
125
|
+
},
|
|
68
126
|
{
|
|
69
127
|
method: 'post',
|
|
70
128
|
path: '/vocalstack/connect',
|
|
@@ -112,10 +170,21 @@ export function connectionEndpoints(options) {
|
|
|
112
170
|
method: 'POST',
|
|
113
171
|
});
|
|
114
172
|
const token = (await res.json().catch(() => ({})));
|
|
173
|
+
// Nothing was stored yet: a refused or cancelled connect leaves the key in use as it was.
|
|
115
174
|
if (!res.ok || !token.access_token)
|
|
116
175
|
return page(`VocalStack did not issue a key: ${token.error_description ?? res.status}`, false);
|
|
117
|
-
|
|
118
|
-
|
|
176
|
+
let workspace = workspaceOf(token.workspace, apiURL);
|
|
177
|
+
let account = workspace?.name ?? token.account?.name;
|
|
178
|
+
if (!workspace) {
|
|
179
|
+
// An API from before workspaces were named on this answer: ask /v1/me.
|
|
180
|
+
const owner = ownerOf(await new VocalStackAPI(token.access_token, apiURL).me().catch(() => ({})), apiURL);
|
|
181
|
+
workspace = owner.workspace;
|
|
182
|
+
account = workspace?.name ?? account ?? owner.account;
|
|
183
|
+
}
|
|
184
|
+
await writeSettings(req, { account: account ?? null, apiKey: token.access_token });
|
|
185
|
+
remember(token.access_token, apiURL, { account, workspace });
|
|
186
|
+
if (workspace)
|
|
187
|
+
return page(`Connected to the VocalStack workspace ${workspace.name}.`, true);
|
|
119
188
|
return page(account ? `Connected to VocalStack as ${account}.` : 'Connected to VocalStack.', true);
|
|
120
189
|
},
|
|
121
190
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { DEFAULT_API_URL, VocalStackAPI, VocalStackAPIError } from '../api.js';
|
|
2
|
+
import { DEFAULT_API_URL, NOT_IN_WORKSPACE, VocalStackAPI, VocalStackAPIError } from '../api.js';
|
|
3
3
|
import { fetchFile, isPublicURL, resolveFileURL } from '../fileSource.js';
|
|
4
4
|
import { attachWords, transcriptText } from '../text.js';
|
|
5
5
|
import { resolveAPIKey } from '../settings.js';
|
|
@@ -118,7 +118,17 @@ export function apiError(err) {
|
|
|
118
118
|
* whole transcript when done, the reason when it failed.
|
|
119
119
|
*/
|
|
120
120
|
export async function checkJob(api, target, recordingId) {
|
|
121
|
-
|
|
121
|
+
let job;
|
|
122
|
+
try {
|
|
123
|
+
job = await api.job(recordingId);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
if (!(err instanceof VocalStackAPIError && err.message === NOT_IN_WORKSPACE))
|
|
127
|
+
throw err;
|
|
128
|
+
// The job is not this key's to see (the workspace was changed while it ran, or it was deleted):
|
|
129
|
+
// it would otherwise stay "processing" for ever. An earlier transcript stays; the file can be transcribed again.
|
|
130
|
+
return { error: NOT_IN_WORKSPACE, status: 'failed', vocalstack: await target.save({ error: NOT_IN_WORKSPACE, status: 'failed' }) };
|
|
131
|
+
}
|
|
122
132
|
if (job.state === 'stopped' || (job.state === 'failed' && job.errorCode === 'stopped'))
|
|
123
133
|
return restore(target);
|
|
124
134
|
if (job.state === 'failed' || job.state === 'cropping') {
|
|
@@ -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
|
+
}
|
package/dist/exports/client.d.ts
CHANGED
|
@@ -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';
|
package/dist/exports/client.js
CHANGED
|
@@ -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
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { CollectionConfig, CollectionSlug, PayloadRequest, TypeWithID } from 'payload';
|
|
2
|
+
import type { Workspace } from './workspace.js';
|
|
3
|
+
export type { Workspace } from './workspace.js';
|
|
2
4
|
export type VocalStackPluginOptions = {
|
|
3
5
|
/**
|
|
4
6
|
* Where finished spoken readings are kept: the plugin downloads each one's MP3
|
|
@@ -44,6 +46,12 @@ export type VocalStackPluginOptions = {
|
|
|
44
46
|
* Authenticate there). Needs the dashboard's /connect flow; until then, paste a key.
|
|
45
47
|
*/
|
|
46
48
|
oneClickConnect?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Check npm for a newer version of this plugin (from the server, at most every
|
|
51
|
+
* 6 hours) and say so in the admin: in the nav and on Settings → VocalStack.
|
|
52
|
+
* Default `true`; `false` makes no outbound call and shows nothing.
|
|
53
|
+
*/
|
|
54
|
+
updateCheck?: boolean;
|
|
47
55
|
/** A Whisper language code (`en`, `ro`, …). Leave out to auto-detect. */
|
|
48
56
|
spokenLanguage?: string;
|
|
49
57
|
/**
|
|
@@ -269,11 +277,23 @@ export type StatusResponse = {
|
|
|
269
277
|
stopped?: boolean;
|
|
270
278
|
vocalstack?: VocalStackFieldData;
|
|
271
279
|
};
|
|
280
|
+
export type VersionResponse = {
|
|
281
|
+
/** This plugin's version, as installed. */
|
|
282
|
+
current: string;
|
|
283
|
+
/** The newest version on npm, or `null` when it is not known (offline, or `updateCheck: false`). */
|
|
284
|
+
latest: null | string;
|
|
285
|
+
/** Its release notes. */
|
|
286
|
+
releaseURL?: string;
|
|
287
|
+
state: 'current' | 'outdated' | 'unknown';
|
|
288
|
+
};
|
|
272
289
|
export type ConnectionResponse = {
|
|
290
|
+
/** A label for what the key belongs to: the workspace's name when VocalStack says which workspace it is. */
|
|
273
291
|
account?: string;
|
|
274
292
|
connected: boolean;
|
|
275
293
|
/** `options`: the key is in the plugin config; `admin`: connected from the admin panel. */
|
|
276
294
|
source?: 'admin' | 'options';
|
|
295
|
+
/** The VocalStack workspace the key works in. Missing when VocalStack did not say (an older API, or unreachable just now). */
|
|
296
|
+
workspace?: Workspace;
|
|
277
297
|
};
|
|
278
298
|
/** Where one language of a transcript stands, for a listener: what the listen endpoint answers. */
|
|
279
299
|
export type ListenStatus = {
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The VocalStack workspace an API key belongs to. Everything the key makes lands
|
|
3
|
+
* there and is billed there, and a key never changes workspace: working in another
|
|
4
|
+
* one takes a new key, from connecting again.
|
|
5
|
+
*/
|
|
6
|
+
export type Workspace = {
|
|
7
|
+
/** The workspace's own icon (a PNG that needs no key to load), or `null` when it has none. */
|
|
8
|
+
iconUrl: null | string;
|
|
9
|
+
id: string;
|
|
10
|
+
/** As the VocalStack Dashboard shows it (`Personal workspace` for an unnamed personal one). */
|
|
11
|
+
name: string;
|
|
12
|
+
/** The workspace every person starts with. */
|
|
13
|
+
personal: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The `workspace` of `GET /v1/me` or of the `POST /v1/connect/token` answer, with its
|
|
17
|
+
* icon's address made absolute (the API sends it relative to its own address).
|
|
18
|
+
* `undefined` when there is none: an older API leaves it out.
|
|
19
|
+
*/
|
|
20
|
+
export declare function workspaceOf(raw: unknown, apiURL: string): undefined | Workspace;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `workspace` of `GET /v1/me` or of the `POST /v1/connect/token` answer, with its
|
|
3
|
+
* icon's address made absolute (the API sends it relative to its own address).
|
|
4
|
+
* `undefined` when there is none: an older API leaves it out.
|
|
5
|
+
*/
|
|
6
|
+
export function workspaceOf(raw, apiURL) {
|
|
7
|
+
if (!raw || typeof raw !== 'object')
|
|
8
|
+
return undefined;
|
|
9
|
+
const { iconUrl, id, name, personal } = raw;
|
|
10
|
+
if (typeof id !== 'string' || !id || typeof name !== 'string' || !name.trim())
|
|
11
|
+
return undefined;
|
|
12
|
+
let icon = null;
|
|
13
|
+
if (typeof iconUrl === 'string' && iconUrl) {
|
|
14
|
+
try {
|
|
15
|
+
const url = new URL(iconUrl, `${apiURL.replace(/\/+$/, '')}/`);
|
|
16
|
+
if (url.protocol === 'https:' || url.protocol === 'http:')
|
|
17
|
+
icon = url.toString();
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
20
|
+
}
|
|
21
|
+
return { iconUrl: icon, id, name: name.trim(), personal: personal === true };
|
|
22
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A workspace's mark when it has no icon of its own, exactly as the VocalStack
|
|
3
|
+
* Dashboard draws it: one or two letters, on a tile tinted with the workspace's colour.
|
|
4
|
+
*/
|
|
5
|
+
/** The first letter of the first two words, or the first two letters of a single word. */
|
|
6
|
+
export declare function workspaceInitials(name: string): string;
|
|
7
|
+
/** The tile's hue in degrees (`oklch(.66 .13 <hue>)`), always the same for one workspace id. */
|
|
8
|
+
export declare function workspaceHue(id: string): number;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A workspace's mark when it has no icon of its own, exactly as the VocalStack
|
|
3
|
+
* Dashboard draws it: one or two letters, on a tile tinted with the workspace's colour.
|
|
4
|
+
*/
|
|
5
|
+
/** The first letter of the first two words, or the first two letters of a single word. */
|
|
6
|
+
export function workspaceInitials(name) {
|
|
7
|
+
const words = name.trim().split(/\s+/).filter((w) => /[\p{L}\p{N}]/u.test(w));
|
|
8
|
+
const first = (w) => Array.from(w.replace(/^[^\p{L}\p{N}]+/u, ''))[0] ?? '';
|
|
9
|
+
if (words.length === 0)
|
|
10
|
+
return '?';
|
|
11
|
+
if (words.length === 1)
|
|
12
|
+
return Array.from(words[0].replace(/[^\p{L}\p{N}]/gu, '')).slice(0, 2).join('').toUpperCase() || '?';
|
|
13
|
+
return (first(words[0]) + first(words[1])).toUpperCase();
|
|
14
|
+
}
|
|
15
|
+
const HUES = [252, 200, 160, 128, 85, 40, 12, 330, 296];
|
|
16
|
+
/** The tile's hue in degrees (`oklch(.66 .13 <hue>)`), always the same for one workspace id. */
|
|
17
|
+
export function workspaceHue(id) {
|
|
18
|
+
let h = 2166136261;
|
|
19
|
+
for (let i = 0; i < id.length; i++) {
|
|
20
|
+
h ^= id.charCodeAt(i);
|
|
21
|
+
h = Math.imul(h, 16777619);
|
|
22
|
+
}
|
|
23
|
+
return HUES[(h >>> 0) % HUES.length];
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vocalstack/payload",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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,10 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
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",
|
|
26
|
+
"test": "pnpm build && node --test \"test/*.test.*\""
|
|
25
27
|
},
|
|
26
28
|
"peerDependencies": {
|
|
27
29
|
"@payloadcms/ui": "^3.0.0",
|