@hosty-sdk/app 0.38.0 → 0.41.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.
- package/README.md +4 -2
- package/dist/agent-sessions.d.ts +73 -0
- package/dist/agent-sessions.js +1 -0
- package/dist/feedback-capture.d.ts +5 -1
- package/dist/feedback-capture.js +41 -2
- package/dist/feedback-channel.d.ts +91 -0
- package/dist/feedback-channel.js +187 -0
- package/dist/feedback-client.d.ts +8 -0
- package/dist/feedback-client.js +26 -0
- package/dist/feedback-draft.d.ts +1 -5
- package/dist/feedback-draft.js +0 -31
- package/dist/feedback-react.d.ts +6 -2
- package/dist/feedback-react.js +235 -357
- package/dist/feedback-rpc.d.ts +7 -0
- package/dist/feedback-rpc.js +42 -0
- package/dist/feedback-workspace.d.ts +13 -0
- package/dist/feedback-workspace.js +28 -0
- package/dist/history.d.ts +354 -0
- package/dist/history.js +1 -0
- package/dist/providers-server.d.ts +17 -1
- package/dist/providers-server.js +33 -1
- package/dist/providers.d.ts +76 -1
- package/dist/sdk-chrome.d.ts +1 -1
- package/dist/sdk-chrome.js +4 -0
- package/dist/tasks-server.d.ts +11 -0
- package/dist/tasks-server.js +15 -0
- package/dist/ui-embedded.d.ts +10 -0
- package/dist/ui-embedded.js +61 -0
- package/dist/ui-frame.js +1 -0
- package/dist/ui-host.d.ts +15 -2
- package/dist/ui-host.js +128 -27
- package/dist/ui-navigation-react.js +9 -4
- package/dist/ui-react.d.ts +5 -1
- package/dist/ui-react.js +59 -15
- package/dist/ui-server.d.ts +2 -0
- package/dist/ui-server.js +28 -3
- package/dist/ui-standalone-context.d.ts +8 -0
- package/dist/ui-standalone-context.js +3 -0
- package/dist/ui-standalone-preferences.d.ts +17 -0
- package/dist/ui-standalone-preferences.js +77 -0
- package/dist/ui-standalone-react.d.ts +24 -0
- package/dist/ui-standalone-react.js +47 -0
- package/dist/ui-transport.js +1 -1
- package/dist/ui-types.d.ts +5 -0
- package/dist/ui-workspaces.d.ts +7 -0
- package/dist/ui-workspaces.js +1 -1
- package/dist/ui.d.ts +1 -0
- package/package.json +13 -1
- package/dist/feedback-audio.d.ts +0 -3
- package/dist/feedback-audio.js +0 -40
- package/dist/feedback-speech.d.ts +0 -6
- package/dist/feedback-speech.js +0 -119
package/dist/feedback-speech.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useRef, useState } from "react";
|
|
4
|
-
import { appFetch } from "./browser-auth.js";
|
|
5
|
-
import { recordingWave } from "./feedback-audio.js";
|
|
6
|
-
const dispose = (op) => { if (!op)
|
|
7
|
-
return; op.controller.abort(); clearTimeout(op.timer); if (op.recorder?.state === "recording")
|
|
8
|
-
op.recorder.stop(); op.stream?.getTracks().forEach(t => t.stop()); };
|
|
9
|
-
export function FeedbackSpeech({ path, disabled, onText, onBusyChange }) {
|
|
10
|
-
const [providers, setProviders] = useState([]), [choice, setChoice] = useState("");
|
|
11
|
-
const [phase, setPhase] = useState("idle"), [error, setError] = useState("");
|
|
12
|
-
const active = useRef(null), result = useRef(onText);
|
|
13
|
-
result.current = onText;
|
|
14
|
-
const endpoint = path + "/speech";
|
|
15
|
-
useEffect(() => { onBusyChange(phase !== "idle"); return () => onBusyChange(false); }, [phase, onBusyChange]);
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
const abort = new AbortController();
|
|
18
|
-
void appFetch(endpoint, { credentials: "include", signal: abort.signal }).then(async (response) => {
|
|
19
|
-
const value = await response.json();
|
|
20
|
-
if (!response.ok)
|
|
21
|
-
throw new Error(value.message ?? "Speech input is unavailable.");
|
|
22
|
-
if (!abort.signal.aborted) {
|
|
23
|
-
setProviders(value.providers ?? []);
|
|
24
|
-
if (!value.granted)
|
|
25
|
-
setError("Speech input is not enabled for this application.");
|
|
26
|
-
}
|
|
27
|
-
}).catch(e => { if (!abort.signal.aborted)
|
|
28
|
-
setError(e.message); });
|
|
29
|
-
return () => { abort.abort(); dispose(active.current); active.current = null; };
|
|
30
|
-
}, [endpoint]);
|
|
31
|
-
useEffect(() => { if (disabled) {
|
|
32
|
-
dispose(active.current);
|
|
33
|
-
active.current = null;
|
|
34
|
-
setPhase("idle");
|
|
35
|
-
} }, [disabled]);
|
|
36
|
-
const selected = providers.find(p => JSON.stringify([p.appId, p.key]) === choice) ?? (providers.length === 1 ? providers[0] : undefined);
|
|
37
|
-
function cancel() { dispose(active.current); active.current = null; setPhase("idle"); }
|
|
38
|
-
async function start() {
|
|
39
|
-
if (!selected?.available || disabled || active.current)
|
|
40
|
-
return;
|
|
41
|
-
const op = { controller: new AbortController() };
|
|
42
|
-
active.current = op;
|
|
43
|
-
const valid = () => active.current === op && !op.controller.signal.aborted;
|
|
44
|
-
setPhase("starting");
|
|
45
|
-
setError("");
|
|
46
|
-
try {
|
|
47
|
-
if (!navigator.mediaDevices?.getUserMedia || typeof MediaRecorder === "undefined")
|
|
48
|
-
throw new Error("This browser cannot record audio here. Type your comment instead.");
|
|
49
|
-
op.stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
50
|
-
if (!valid()) {
|
|
51
|
-
dispose(op);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const recorder = new MediaRecorder(op.stream);
|
|
55
|
-
op.recorder = recorder;
|
|
56
|
-
const chunks = [];
|
|
57
|
-
let bytes = 0;
|
|
58
|
-
recorder.ondataavailable = e => { bytes += e.data.size; if (bytes > 16 * 1024 * 1024) {
|
|
59
|
-
cancel();
|
|
60
|
-
setError("Recording is too large. Try a shorter comment.");
|
|
61
|
-
}
|
|
62
|
-
else if (e.data.size)
|
|
63
|
-
chunks.push(e.data); };
|
|
64
|
-
recorder.onerror = () => { if (valid()) {
|
|
65
|
-
cancel();
|
|
66
|
-
setError("Recording failed. Type your comment or try again.");
|
|
67
|
-
} };
|
|
68
|
-
recorder.onstop = () => {
|
|
69
|
-
clearTimeout(op.timer);
|
|
70
|
-
op.stream?.getTracks().forEach(t => t.stop());
|
|
71
|
-
if (!valid())
|
|
72
|
-
return;
|
|
73
|
-
setPhase("transcribing");
|
|
74
|
-
void (async () => {
|
|
75
|
-
try {
|
|
76
|
-
const wave = await recordingWave(new Blob(chunks, { type: recorder.mimeType }));
|
|
77
|
-
if (!valid())
|
|
78
|
-
return;
|
|
79
|
-
const data = new Uint8Array(await wave.arrayBuffer());
|
|
80
|
-
let binary = "";
|
|
81
|
-
for (let at = 0; at < data.length; at += 8192)
|
|
82
|
-
binary += String.fromCharCode(...data.subarray(at, at + 8192));
|
|
83
|
-
const response = await appFetch(endpoint, { method: "POST", credentials: "include", signal: op.controller.signal,
|
|
84
|
-
headers: { "content-type": "application/json" }, body: JSON.stringify({ appId: selected.appId, key: selected.key, audio: btoa(binary) }) });
|
|
85
|
-
const value = await response.json();
|
|
86
|
-
if (!response.ok)
|
|
87
|
-
throw new Error(value.message ?? "Speech recognition failed.");
|
|
88
|
-
if (valid()) {
|
|
89
|
-
if (typeof value.text === "string" && value.text.trim())
|
|
90
|
-
result.current(value.text.trim());
|
|
91
|
-
else
|
|
92
|
-
setError("No speech detected.");
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
catch (e) {
|
|
96
|
-
if (valid())
|
|
97
|
-
setError(e instanceof Error ? e.message : "Speech recognition failed.");
|
|
98
|
-
}
|
|
99
|
-
finally {
|
|
100
|
-
if (active.current === op)
|
|
101
|
-
cancel();
|
|
102
|
-
}
|
|
103
|
-
})();
|
|
104
|
-
};
|
|
105
|
-
recorder.start(1000);
|
|
106
|
-
setPhase("recording");
|
|
107
|
-
op.timer = setTimeout(() => { if (recorder.state === "recording")
|
|
108
|
-
recorder.stop(); }, 60_000);
|
|
109
|
-
}
|
|
110
|
-
catch (e) {
|
|
111
|
-
if (valid()) {
|
|
112
|
-
cancel();
|
|
113
|
-
setError(e instanceof Error ? e.message : "Microphone access failed.");
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return _jsxs("div", { className: "hf-speech", children: [providers.length > 1 && _jsxs("label", { children: ["Speech provider", _jsxs("select", { value: choice, disabled: phase !== "idle" || disabled, onChange: e => setChoice(e.target.value), children: [_jsx("option", { value: "", children: "Choose provider" }), providers.map(p => _jsx("option", { value: JSON.stringify([p.appId, p.key]), disabled: !p.available, children: p.displayName }, JSON.stringify([p.appId, p.key])))] })] }), phase === "idle" ? _jsx("button", { disabled: disabled || !selected?.available, title: error || "Dictate up to one minute", onClick: () => void start(), children: "Dictate" })
|
|
118
|
-
: _jsxs(_Fragment, { children: [_jsx("button", { disabled: phase !== "recording", onClick: () => active.current?.recorder?.stop(), children: phase === "recording" ? "Stop and transcribe" : phase === "starting" ? "Opening microphone…" : "Transcribing…" }), _jsx("button", { onClick: cancel, children: "Cancel dictation" })] }), error && _jsx("small", { role: "status", children: error })] });
|
|
119
|
-
}
|