@hartren/assistant-js 0.0.0-stage → 2.3.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/CHANGELOG.md +140 -0
- package/LICENSE +21 -0
- package/README.md +273 -2
- package/THIRD_PARTY_NOTICES.md +917 -0
- package/dist/CopilotAgent/AuthenticationService.d.ts +47 -0
- package/dist/CopilotAgent/CommandsManager.d.ts +20 -0
- package/dist/CopilotAgent/CopilotAgent.d.ts +148 -0
- package/dist/CopilotAgent/CopilotProxy.d.ts +17 -0
- package/dist/CopilotAgent/UserSessionService.d.ts +9 -0
- package/dist/CopilotAgent/index.d.ts +2 -0
- package/dist/CustomSpeechRecognition/CustomSpeechRecognition.d.ts +93 -0
- package/dist/MicrophoneAccess/MicrophoneAccess.d.ts +65 -0
- package/dist/SpeakingService/SpeakingService.d.ts +14 -0
- package/dist/SpeakingService/index.d.ts +2 -0
- package/dist/SpeechRecognitionService/ResultsGroupingService.d.ts +44 -0
- package/dist/SpeechRecognitionService/SpeechRecognitionService.d.ts +108 -0
- package/dist/SpeechRecognitionService/index.d.ts +2 -0
- package/dist/SpeechRecognitionService/speechConfig.d.ts +96 -0
- package/dist/debugLog.d.ts +9 -0
- package/dist/enums.d.ts +42 -0
- package/dist/httpError.d.ts +9 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +5 -0
- package/dist/types.d.ts +57 -0
- package/package.json +54 -5
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Speech provider configuration.
|
|
3
|
+
*
|
|
4
|
+
* HIPAA: dictation audio and spoken replies can contain PHI. The default provider is the hosted
|
|
5
|
+
* Hartren API speech service (`/ws/speech/transcribe` and `/ws/speech/speak`, backed by Deepgram).
|
|
6
|
+
* Browser Web Speech (SpeechRecognition / webkitSpeechRecognition / speechSynthesis) may send audio
|
|
7
|
+
* or text to the browser/OS vendor (e.g. Google, Microsoft), which has no BAA with us. It is used ONLY
|
|
8
|
+
* when the host explicitly sets `speechProvider: 'browser'`, or explicitly opts into
|
|
9
|
+
* `browserTranscriptionFallback: true` (default false). Never as an automatic fallback by default.
|
|
10
|
+
*/
|
|
11
|
+
export declare const speechProvider: {
|
|
12
|
+
/** Hosted transcription/TTS over WebSocket (Deepgram). Default. */
|
|
13
|
+
readonly DEEPGRAM: "deepgram";
|
|
14
|
+
/** Browser Web Speech APIs. Opt-in only (see also the separate browserTranscriptionFallback opt-in). */
|
|
15
|
+
readonly BROWSER: "browser";
|
|
16
|
+
};
|
|
17
|
+
export type SpeechProvider = (typeof speechProvider)[keyof typeof speechProvider];
|
|
18
|
+
/** Anything other than an explicit 'browser' means the hosted (Deepgram) provider. */
|
|
19
|
+
export declare function normalizeSpeechProvider(provider?: string | null): SpeechProvider;
|
|
20
|
+
export interface SpeechRetryOptions {
|
|
21
|
+
/** Reconnect attempts after a failure before the final error. Default 3. */
|
|
22
|
+
maxRetries?: number;
|
|
23
|
+
/** First retry delay; doubles on each attempt. Default 1000 ms. */
|
|
24
|
+
baseDelayMs?: number;
|
|
25
|
+
/** Upper bound for a single retry delay. Default 8000 ms. */
|
|
26
|
+
maxDelayMs?: number;
|
|
27
|
+
}
|
|
28
|
+
export declare const DEFAULT_SPEECH_RETRY: Required<SpeechRetryOptions>;
|
|
29
|
+
export declare function resolveSpeechRetry(options?: SpeechRetryOptions | null): Required<SpeechRetryOptions>;
|
|
30
|
+
/** Exponential backoff: base * 2^(attempt-1), capped at maxDelayMs. `attempt` starts at 1. */
|
|
31
|
+
export declare function retryDelayMs(attempt: number, options: Required<SpeechRetryOptions>): number;
|
|
32
|
+
/**
|
|
33
|
+
* Default speech WebSocket origin for a Copilot API URL. The Hartren API serves `/ws/speech/*` at the
|
|
34
|
+
* host root, so `https://api.example.com/api` → `wss://api.example.com`. A relative API URL ('/api')
|
|
35
|
+
* resolves against `baseOrigin` (default: window.location.origin). Returns null when it cannot be
|
|
36
|
+
* resolved to an http(s) URL (the caller then reports transcription-not-configured).
|
|
37
|
+
*/
|
|
38
|
+
export declare function deriveTranscribeWssUrl(copilotApi?: string | null, baseOrigin?: string | null): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* True when the user's access token may be sent to this speech WebSocket URL: any `wss://` URL, or
|
|
41
|
+
* plain `ws://` only to localhost / 127.0.0.1 / [::1] (local development). Anything else (a remote
|
|
42
|
+
* `ws://`, another scheme, an unparsable URL) would expose the token in clear text, so it is refused.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isSpeechSocketUrlAllowed(url?: string | null): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The access token has characters a WebSocket subprotocol cannot carry. Retrying cannot help (the
|
|
47
|
+
* same token comes back), so this is reported once, as final. Fixed text: never includes the token.
|
|
48
|
+
*/
|
|
49
|
+
export declare class InvalidSpeechTokenError extends Error {
|
|
50
|
+
constructor();
|
|
51
|
+
}
|
|
52
|
+
/** Thrown before any token is read when the speech URL is not allowed (see isSpeechSocketUrlAllowed). */
|
|
53
|
+
export declare class InsecureSpeechUrlError extends Error {
|
|
54
|
+
constructor();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* WebSocket subprotocol offered on the speech sockets. The Hartren API selects (echoes) only this one;
|
|
58
|
+
* it never echoes the bearer entry.
|
|
59
|
+
*/
|
|
60
|
+
export declare const SPEECH_WS_PROTOCOL = "hartren.speech.v1";
|
|
61
|
+
/** Prefix of the subprotocol entry that carries the access token: `bearer.<token>`. */
|
|
62
|
+
export declare const SPEECH_WS_BEARER_PREFIX = "bearer.";
|
|
63
|
+
/**
|
|
64
|
+
* Subprotocols for a speech socket. With a token: [SPEECH_WS_PROTOCOL, 'bearer.<token>'], so the token
|
|
65
|
+
* travels in the Sec-WebSocket-Protocol header and never in the URL. Without one: none (unchanged
|
|
66
|
+
* anonymous handshake). Throws (fixed text, no token) when the token has characters a subprotocol
|
|
67
|
+
* cannot carry.
|
|
68
|
+
*/
|
|
69
|
+
export declare function speechSocketProtocols(token?: string | null): string[];
|
|
70
|
+
/** `code` values on onCopilotError events raised by speech. */
|
|
71
|
+
export declare const SpeechErrorCodes: {
|
|
72
|
+
/** Deepgram connection failed; a retry is scheduled (`final: false`). */
|
|
73
|
+
readonly TRANSCRIPTION_RETRYING: "transcription-retrying";
|
|
74
|
+
/** Deepgram still unavailable after all retries (`final: true`). Dictation stopped. */
|
|
75
|
+
readonly TRANSCRIPTION_FAILED: "transcription-failed";
|
|
76
|
+
/** No usable transcription WebSocket URL (none could be determined, or a remote plain ws:// URL was refused). */
|
|
77
|
+
readonly TRANSCRIPTION_NOT_CONFIGURED: "transcription-not-configured";
|
|
78
|
+
/** The transcription service sent an error message on an open socket (`final: false`). Its text is in `message`. */
|
|
79
|
+
readonly TRANSCRIPTION_ERROR: "transcription-error";
|
|
80
|
+
/** Hosted TTS (/ws/speech/speak) failed. No browser fallback. */
|
|
81
|
+
readonly TTS_FAILED: "tts-failed";
|
|
82
|
+
/** Hosted TTS unavailable (no usable WebSocket URL). No browser fallback. */
|
|
83
|
+
readonly TTS_NOT_CONFIGURED: "tts-not-configured";
|
|
84
|
+
/** Microphone/VAD setup failed (permission, device). Dictation stopped; no retry. */
|
|
85
|
+
readonly AUDIO_SETUP_FAILED: "audio-setup-failed";
|
|
86
|
+
/**
|
|
87
|
+
* browserTranscriptionFallback only: the hosted socket failed while the browser is online, and
|
|
88
|
+
* dictation continues with the browser's SpeechRecognition (`final: false`, `reason` says why).
|
|
89
|
+
*/
|
|
90
|
+
readonly TRANSCRIPTION_FALLBACK: "transcription-fallback";
|
|
91
|
+
/** browserTranscriptionFallback only: the connection is back and dictation returned to hosted (`final: false`). */
|
|
92
|
+
readonly TRANSCRIPTION_RESTORED: "transcription-restored";
|
|
93
|
+
/** speechProvider 'browser' was chosen but this browser has no SpeechRecognition. */
|
|
94
|
+
readonly BROWSER_SPEECH_UNSUPPORTED: "browser-speech-unsupported";
|
|
95
|
+
};
|
|
96
|
+
export type SpeechErrorCode = (typeof SpeechErrorCodes)[keyof typeof SpeechErrorCodes];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function setCopilotDebugLogging(on: boolean): void;
|
|
2
|
+
export declare function isCopilotDebugLogging(): boolean;
|
|
3
|
+
/** Logs only when debug logging is on. Use for any message that includes user or AI text. */
|
|
4
|
+
export declare function debugLog(level: 'log' | 'info' | 'error', ...args: unknown[]): void;
|
|
5
|
+
/**
|
|
6
|
+
* A safe label for an error: its name or code only, never its message (which can carry text).
|
|
7
|
+
* HTTP failures are labelled by status code, e.g. `HTTP_500`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function errorLabel(error: unknown): string;
|
package/dist/enums.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SpeechRecognitionFailure } from './MicrophoneAccess/MicrophoneAccess';
|
|
2
|
+
export declare enum SpeechRecognitionError {
|
|
3
|
+
Network = "network",
|
|
4
|
+
NotAllowed = "not-allowed",
|
|
5
|
+
ServiceNotAllowed = "service-not-allowed",
|
|
6
|
+
Aborted = "aborted",
|
|
7
|
+
AudioCapture = "audio-capture",
|
|
8
|
+
LanguageNotSupported = "language-not-supported",
|
|
9
|
+
BadGrammar = "bad-grammar",
|
|
10
|
+
NoSpeech = "no-speech",
|
|
11
|
+
MicDenied = "mic-denied",
|
|
12
|
+
MicDismissed = "mic-dismissed",
|
|
13
|
+
MicOsBlocked = "mic-os-blocked",
|
|
14
|
+
MicPolicyBlocked = "mic-policy-blocked",
|
|
15
|
+
MicNoDevice = "mic-no-device",
|
|
16
|
+
MicConstraints = "mic-constraints",
|
|
17
|
+
MicBusy = "mic-busy",
|
|
18
|
+
MicUnsupported = "mic-unsupported",
|
|
19
|
+
MicInsecureContext = "mic-insecure-context",
|
|
20
|
+
MicFailed = "mic-failed",
|
|
21
|
+
SessionFailed = "session-failed",
|
|
22
|
+
SocketFailed = "socket-failed",
|
|
23
|
+
VadAssetFailed = "vad-asset-failed",
|
|
24
|
+
EngineUnavailable = "engine-unavailable",
|
|
25
|
+
AudioSetupFailed = "audio-setup-failed"
|
|
26
|
+
}
|
|
27
|
+
export interface ErrorHandlingConfig {
|
|
28
|
+
action: "stop" | "restart" | "none";
|
|
29
|
+
emitEvent?: {
|
|
30
|
+
message: string;
|
|
31
|
+
stopAgent?: boolean;
|
|
32
|
+
asPopup?: boolean;
|
|
33
|
+
code?: SpeechRecognitionFailure;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export declare const ERROR_HANDLING_STRATEGIES: Record<SpeechRecognitionError, ErrorHandlingConfig>;
|
|
37
|
+
export declare enum GeneralErrorMessage {
|
|
38
|
+
ExecutionError = "An error occurred while executing the function. Please try again or contact support if the issue continues.",
|
|
39
|
+
UnexpectedError = "An unexpected error occurred. Please try again.",
|
|
40
|
+
NetworkIssue = "Network connection issue detected. Trying to reconnect...",
|
|
41
|
+
PermissionDenied = "Microphone access denied. Please enable permissions."
|
|
42
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A failed HTTP response. `code` (`HTTP_<status>`) is what gets logged: it is safe to print, while
|
|
3
|
+
* response bodies are never read into the error.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpError extends Error {
|
|
6
|
+
readonly status: number;
|
|
7
|
+
readonly code: string;
|
|
8
|
+
constructor(context: string, status: number);
|
|
9
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import CopilotAgent from './CopilotAgent';
|
|
2
|
+
export { copilotMode, normalizeCopilotMode } from './types';
|
|
3
|
+
export type { CopilotMode } from './types';
|
|
4
|
+
export { speechProvider, SpeechErrorCodes, DEFAULT_SPEECH_RETRY, SPEECH_WS_PROTOCOL } from './SpeechRecognitionService/speechConfig';
|
|
5
|
+
export type { SpeechProvider, SpeechRetryOptions, SpeechErrorCode } from './SpeechRecognitionService/speechConfig';
|
|
6
|
+
export type { CopilotError } from './CopilotAgent/CopilotAgent';
|
|
7
|
+
export { setCopilotDebugLogging, isCopilotDebugLogging } from './debugLog';
|
|
8
|
+
export { HttpError } from './httpError';
|
|
9
|
+
export type { AccessTokenProvider, UnauthorizedHandler } from './CopilotAgent/AuthenticationService';
|
|
10
|
+
export type { SpeechRecognitionFailure, MicrophoneEnvironment, } from './MicrophoneAccess/MicrophoneAccess';
|
|
11
|
+
export { SPEECH_RECOGNITION_FAILURES } from './MicrophoneAccess/MicrophoneAccess';
|
|
12
|
+
export default CopilotAgent;
|