@idoall/dsh-notify 0.2.2

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.
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Sound choices shared by the Host (file validation) and the client (playback). Kept free of any
3
+ * Node or browser API so both bundles can import exactly one source of truth.
4
+ */
5
+ export const BUILTIN_SOUNDS = Object.freeze(['chime', 'ping', 'alert', 'none']);
6
+ export const SOUND_BYTES = 1024 * 1024;
7
+ const EXTENSIONS = Object.freeze({ '.mp3': 'audio/mpeg', '.m4a': 'audio/mp4', '.aac': 'audio/aac', '.wav': 'audio/wav', '.ogg': 'audio/ogg', '.oga': 'audio/ogg', '.flac': 'audio/flac', '.webm': 'audio/webm' });
8
+ const NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
9
+
10
+ /** MIME type for an allow-listed audio extension, or undefined when the extension is not allowed. */
11
+ export function extensionOf(name) {
12
+ const index = typeof name === 'string' ? name.lastIndexOf('.') : -1;
13
+ if (index <= 0) return undefined;
14
+ return EXTENSIONS[name.slice(index).toLowerCase()];
15
+ }
16
+ /** A sound file name must be a single path segment with an allow-listed audio extension. */
17
+ export function validSoundName(name) {
18
+ if (typeof name !== 'string' || !NAME_PATTERN.test(name) || name.includes('..') || name.includes('/') || name.includes('\\')) return false;
19
+ return extensionOf(name) !== undefined;
20
+ }
21
+ /** Normalise an upload name to the stored `<stem>.<ext>` form, or undefined when it is unusable. */
22
+ export function soundFileName(name) {
23
+ if (!validSoundName(name)) return undefined;
24
+ const index = name.lastIndexOf('.');
25
+ return `${name.slice(0, index).replace(/[^A-Za-z0-9._-]/g, '_')}${name.slice(index).toLowerCase()}`;
26
+ }
27
+ /** Parse a stored setting into a concrete choice: a built-in id or `custom:<file>`. */
28
+ export function parseSoundChoice(value) {
29
+ if (typeof value !== 'string' || value.length === 0) return { kind: 'builtin', id: 'chime' };
30
+ if (value.startsWith('custom:')) {
31
+ const name = value.slice('custom:'.length);
32
+ return validSoundName(name) ? { kind: 'custom', name } : { kind: 'builtin', id: 'chime' };
33
+ }
34
+ return { kind: 'builtin', id: BUILTIN_SOUNDS.includes(value) ? value : 'chime' };
35
+ }
36
+ /**
37
+ * Built-in sounds are synthesised: no audio asset ships in the package, nothing is fetched, and the
38
+ * same notes behave identically on every platform. Each note is `{ freq, at, dur, gain, type }`
39
+ * seconds into the cue.
40
+ */
41
+ export const SOUND_PRESETS = Object.freeze({
42
+ chime: Object.freeze([{ freq: 880, at: 0, dur: 0.14, gain: 0.16, type: 'sine' }, { freq: 1318.5, at: 0.11, dur: 0.22, gain: 0.12, type: 'sine' }]),
43
+ ping: Object.freeze([{ freq: 1318.5, at: 0, dur: 0.16, gain: 0.15, type: 'sine' }]),
44
+ alert: Object.freeze([{ freq: 660, at: 0, dur: 0.11, gain: 0.2, type: 'triangle' }, { freq: 660, at: 0.17, dur: 0.11, gain: 0.2, type: 'triangle' }]),
45
+ none: Object.freeze([]),
46
+ });
47
+ /** User-facing labels for the settings select, in display order. */
48
+ export const SOUND_LABELS = Object.freeze({ chime: '叮咚(默认)', ping: '轻提示', alert: '双响提醒', none: '静音' });
package/dist/sounds.js ADDED
@@ -0,0 +1,63 @@
1
+ import { mkdir, readFile, readdir, rename, stat, unlink, writeFile } from 'node:fs/promises';
2
+ import { basename, join } from 'node:path';
3
+ import { SOUND_BYTES as SOUND_LIMIT, extensionOf, soundFileName, validSoundName } from './sound-choices.js';
4
+
5
+ /**
6
+ * Notification sounds.
7
+ *
8
+ * Built-ins are synthesised in the browser with WebAudio (no assets ship in the package), so they
9
+ * work offline and in every browser. Users who want their own sound upload it into the
10
+ * profile-owned data directory (`<dataDir>/sounds/`) — never into the plugin package, which is
11
+ * replaced on every reinstall. The Host owns listing, validation and serving; the client owns
12
+ * playback.
13
+ */
14
+ export const SOUND_DIR = 'sounds';
15
+ export { BUILTIN_SOUNDS, SOUND_BYTES, extensionOf, parseSoundChoice, soundFileName, validSoundName } from './sound-choices.js';
16
+ const safeJoin = (dir, name) => join(dir, basename(name));
17
+
18
+ export function createSoundLibrary({ dataDir } = {}) {
19
+ const enabled = typeof dataDir === 'string' && dataDir.length > 0;
20
+ const dir = enabled ? join(dataDir, SOUND_DIR) : undefined;
21
+ const ensure = async () => { await mkdir(dir, { recursive: true }); };
22
+ return {
23
+ enabled,
24
+ dir,
25
+ /** Names + sizes of the uploaded sounds, newest first; never throws for a missing directory. */
26
+ async list() {
27
+ if (!enabled) return [];
28
+ try {
29
+ await ensure();
30
+ const names = (await readdir(dir)).filter((name) => validSoundName(name)).sort();
31
+ const entries = [];
32
+ for (const name of names) {
33
+ try { const info = await stat(safeJoin(dir, name)); entries.push({ name, bytes: info.size, at: info.mtimeMs }); } catch { /* vanished */ }
34
+ }
35
+ return entries.sort((left, right) => right.at - left.at);
36
+ } catch { return []; }
37
+ },
38
+ /** Store one upload. Returns a discriminated result; never writes outside `dir`. */
39
+ async put(name, bytes) {
40
+ if (!enabled) return { ok: false, reason: 'persistence-disabled' };
41
+ const file = soundFileName(name);
42
+ if (!file) return { ok: false, reason: 'invalid-name' };
43
+ if (!bytes || bytes.byteLength === 0) return { ok: false, reason: 'empty' };
44
+ if (bytes.byteLength > SOUND_LIMIT) return { ok: false, reason: 'too-large' };
45
+ try {
46
+ await ensure();
47
+ const target = safeJoin(dir, file);
48
+ const staging = `${target}.upload`;
49
+ await writeFile(staging, bytes);
50
+ await rename(staging, target);
51
+ return { ok: true, name: file, bytes: bytes.byteLength };
52
+ } catch { return { ok: false, reason: 'write-failed' }; }
53
+ },
54
+ async read(name) {
55
+ if (!enabled || !validSoundName(name)) return undefined;
56
+ try { const bytes = await readFile(safeJoin(dir, name)); return { bytes, type: extensionOf(name) }; } catch { return undefined; }
57
+ },
58
+ async remove(name) {
59
+ if (!enabled || !validSoundName(name)) return false;
60
+ try { await unlink(safeJoin(dir, name)); return true; } catch { return false; }
61
+ },
62
+ };
63
+ }
package/package.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "@idoall/dsh-notify",
3
+ "version": "0.2.2",
4
+ "type": "module",
5
+ "description": "DSH web plugin: in-page task notifications for DeepSeek Harness — a stacking top-right toast (answer buttons, live action state, background-tab flash and a WebAudio cue that also plays while the page is hidden). Live delivery only: no history, no service worker, no web push, no OS notification matrix.",
6
+ "main": "./dist/index.js",
7
+ "exports": {
8
+ ".": "./dist/index.js",
9
+ "./client": "./dist/client.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "assets",
15
+ "cordis.patch.yml",
16
+ "README.md",
17
+ "README.zh.md",
18
+ "CHANGELOG.md",
19
+ "LICENSE"
20
+ ],
21
+ "dsh": {
22
+ "bundle": {
23
+ "patch": "./cordis.patch.yml"
24
+ },
25
+ "client": {
26
+ "platform": "web",
27
+ "inject": [
28
+ "@deepseek-ai/dsh-client-ui-renderer",
29
+ "@deepseek-ai/dsh-client-ui-layout",
30
+ "@deepseek-ai/dsh-client-ui-settings",
31
+ "@deepseek-ai/dsh-client-ui-settings-general"
32
+ ]
33
+ }
34
+ },
35
+ "scripts": {
36
+ "typecheck": "node tscheck.mjs && tsc --noEmit",
37
+ "test": "node --test test/*.test.js",
38
+ "build": "node scripts/build.mjs",
39
+ "prepare": "node scripts/build.mjs",
40
+ "prepack": "node scripts/build.mjs",
41
+ "pack:check": "node scripts/pack-check.mjs",
42
+ "verify": "npm run typecheck && npm run test && npm run build && npm run pack:check"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "dependencies": {
48
+ "@deepseek-ai/schemastery": "^3.18.2"
49
+ },
50
+ "peerDependencies": {
51
+ "react": "^18.2.0"
52
+ },
53
+ "devDependencies": {
54
+ "@deepseek-ai/cordis": "4.0.2",
55
+ "@types/node": "^22.15.29",
56
+ "@types/react": "^18.3.23",
57
+ "esbuild": "^0.25.5",
58
+ "jsdom": "^26.1.0",
59
+ "react": "^18.3.1",
60
+ "react-dom": "^18.3.1",
61
+ "typescript": "^5.7.3"
62
+ },
63
+ "license": "MIT",
64
+ "engines": {
65
+ "node": ">=20"
66
+ },
67
+ "repository": {
68
+ "type": "git",
69
+ "url": "git+https://github.com/idoall/dsh-notify.git"
70
+ },
71
+ "homepage": "https://github.com/idoall/dsh-notify#readme",
72
+ "bugs": {
73
+ "url": "https://github.com/idoall/dsh-notify/issues"
74
+ },
75
+ "keywords": [
76
+ "dsh",
77
+ "dsh-plugin",
78
+ "deepseek",
79
+ "deepseek-harness",
80
+ "harness",
81
+ "cordis",
82
+ "plugin",
83
+ "notifications",
84
+ "toast",
85
+ "web"
86
+ ]
87
+ }