@dqnamo/voicecontrol 0.0.1

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.
Files changed (4) hide show
  1. package/README.md +20 -0
  2. package/index.d.ts +35 -0
  3. package/index.js +38 -0
  4. package/package.json +31 -0
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @dqnamo/voicecontrol
2
+
3
+ Composable primitives for building voice-controlled web interfaces.
4
+
5
+ This is the first experimental release. The React provider, action component,
6
+ transcription transport, and Jev decision adapter are under active development.
7
+
8
+ ```js
9
+ import { defineVoiceAction, voiceControlAttributes } from "@dqnamo/voicecontrol";
10
+
11
+ const action = defineVoiceAction({
12
+ id: "todo.complete",
13
+ description: "Complete the selected task",
14
+ execute: ({ transcript }) => {
15
+ console.log("Run from voice command:", transcript);
16
+ },
17
+ });
18
+
19
+ const attributes = voiceControlAttributes(action);
20
+ ```
package/index.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ export type VoiceActionContext = {
2
+ probability: number;
3
+ signal: AbortSignal;
4
+ transcript: string;
5
+ turnId: number;
6
+ };
7
+
8
+ export type VoiceActionDefinition = {
9
+ confirmation?: boolean;
10
+ description: string;
11
+ enabled?: boolean;
12
+ execute: (context: VoiceActionContext) => void | Promise<void>;
13
+ id: string;
14
+ kind?: "action" | "navigation";
15
+ };
16
+
17
+ export type VoiceControlAttributes = {
18
+ "data-voice-control-confirm": "true" | undefined;
19
+ "data-voice-control-desc": string;
20
+ "data-voice-control-id": string;
21
+ };
22
+
23
+ export declare const voiceControlAttributeNames: Readonly<{
24
+ confirmation: "data-voice-control-confirm";
25
+ description: "data-voice-control-desc";
26
+ id: "data-voice-control-id";
27
+ }>;
28
+
29
+ export declare function defineVoiceAction<
30
+ const Action extends VoiceActionDefinition,
31
+ >(action: Action): Readonly<Action>;
32
+
33
+ export declare function voiceControlAttributes(
34
+ action: Pick<VoiceActionDefinition, "confirmation" | "description" | "id">,
35
+ ): VoiceControlAttributes;
package/index.js ADDED
@@ -0,0 +1,38 @@
1
+ const idAttribute = "data-voice-control-id";
2
+ const descriptionAttribute = "data-voice-control-desc";
3
+ const confirmationAttribute = "data-voice-control-confirm";
4
+
5
+ export const voiceControlAttributeNames = Object.freeze({
6
+ confirmation: confirmationAttribute,
7
+ description: descriptionAttribute,
8
+ id: idAttribute,
9
+ });
10
+
11
+ export function defineVoiceAction(action) {
12
+ if (!action || typeof action !== "object") {
13
+ throw new TypeError("A voice action definition is required.");
14
+ }
15
+ if (typeof action.id !== "string" || !action.id.trim()) {
16
+ throw new TypeError("A voice action needs a non-empty id.");
17
+ }
18
+ if (typeof action.description !== "string" || !action.description.trim()) {
19
+ throw new TypeError("A voice action needs a non-empty description.");
20
+ }
21
+ if (typeof action.execute !== "function") {
22
+ throw new TypeError("A voice action needs an execute function.");
23
+ }
24
+
25
+ return Object.freeze({
26
+ ...action,
27
+ description: action.description.trim(),
28
+ id: action.id.trim(),
29
+ });
30
+ }
31
+
32
+ export function voiceControlAttributes(action) {
33
+ return {
34
+ [confirmationAttribute]: action.confirmation ? "true" : undefined,
35
+ [descriptionAttribute]: action.description,
36
+ [idAttribute]: action.id,
37
+ };
38
+ }
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@dqnamo/voicecontrol",
3
+ "version": "0.0.1",
4
+ "description": "Composable primitives for building voice-controlled web interfaces.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "default": "./index.js"
10
+ }
11
+ },
12
+ "main": "./index.js",
13
+ "types": "./index.d.ts",
14
+ "files": [
15
+ "index.js",
16
+ "index.d.ts",
17
+ "README.md"
18
+ ],
19
+ "sideEffects": false,
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "keywords": [
24
+ "voice-control",
25
+ "speech",
26
+ "react",
27
+ "accessibility",
28
+ "jev"
29
+ ],
30
+ "author": "dqnamo"
31
+ }