segmind 0.5.1 → 0.6.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 +60 -0
- package/dist/chunk-74UKKBOO.cjs +115 -0
- package/dist/chunk-74UKKBOO.cjs.map +1 -0
- package/dist/chunk-HWZJ36WC.cjs +186 -0
- package/dist/chunk-HWZJ36WC.cjs.map +1 -0
- package/dist/chunk-PS5KUT7P.js +115 -0
- package/dist/chunk-PS5KUT7P.js.map +1 -0
- package/dist/chunk-USGY6G4C.js +186 -0
- package/dist/chunk-USGY6G4C.js.map +1 -0
- package/dist/errors-CcHEuSmR.d.cts +258 -0
- package/dist/errors-CcHEuSmR.d.ts +258 -0
- package/dist/index.cjs +204 -294
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -60
- package/dist/index.d.ts +39 -60
- package/dist/index.js +47 -104
- package/dist/index.js.map +1 -1
- package/dist/realtime/browser/index.cjs +307 -0
- package/dist/realtime/browser/index.cjs.map +1 -0
- package/dist/realtime/browser/index.d.cts +122 -0
- package/dist/realtime/browser/index.d.ts +122 -0
- package/dist/realtime/browser/index.js +307 -0
- package/dist/realtime/browser/index.js.map +1 -0
- package/dist/realtime/index.cjs +549 -0
- package/dist/realtime/index.cjs.map +1 -0
- package/dist/realtime/index.d.cts +114 -0
- package/dist/realtime/index.d.ts +114 -0
- package/dist/realtime/index.js +549 -0
- package/dist/realtime/index.js.map +1 -0
- package/dist/vad-B-BeifvT.d.cts +245 -0
- package/dist/vad-BcBkqh2p.d.ts +245 -0
- package/package.json +44 -3
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { R as RealtimeSession, V as VadOptions } from '../vad-B-BeifvT.cjs';
|
|
2
|
+
export { C as ClientOptions, D as DEFAULT_REALTIME_URL, E as EnergyVad, a as EventListener, b as RealtimeClient, S as SessionEnd, c as SessionOpenError, d as SessionOptions, e as StateListener, T as TypedEventListener, f as VadDecision, W as WebSocketLike, g as connect } from '../vad-B-BeifvT.cjs';
|
|
3
|
+
import { e as SessionCreatedEvent, f as AudioFormat, g as ServerEvent, C as ClientEvent, E as EndReason } from '../errors-CcHEuSmR.cjs';
|
|
4
|
+
import { SegmindError } from '../index.cjs';
|
|
5
|
+
export { h as AudioDeltaEvent, i as ErrorEvent, j as InputSpeechStartedEvent, k as InputSpeechStoppedEvent, M as MediaStreamSpec, P as PROTOCOL_VERSION, l as PongEvent, m as RefusalCode, n as STREAM_TAGS, o as ServerEventType, p as SessionEndedEvent, q as SessionLimits, r as SessionState, S as SessionToken, a as SessionTokenProvider, s as SessionUpdateParams, t as SessionUpdatedEvent, T as TranscriptDeltaEvent, u as TurnEndReason, v as TurnEndedEvent, w as TurnStartedEvent, U as UpstreamEvent, x as Usage, y as UsageEvent, z as UsageFacts } from '../errors-CcHEuSmR.cjs';
|
|
6
|
+
|
|
7
|
+
/** A server frame this client cannot read. The session ignores it; `decodeServerEvent` throws it. */
|
|
8
|
+
declare class ProtocolError extends SegmindError {
|
|
9
|
+
readonly raw?: unknown | undefined;
|
|
10
|
+
constructor(message: string, raw?: unknown | undefined);
|
|
11
|
+
}
|
|
12
|
+
/** One server text frame → a typed event, or a ProtocolError. */
|
|
13
|
+
declare function decodeServerEvent(text: string): ServerEvent;
|
|
14
|
+
declare function encodeClientEvent(event: ClientEvent): string;
|
|
15
|
+
/** Close codes the server refuses an open with. Nothing was reserved or billed. */
|
|
16
|
+
declare const REFUSAL_CLOSE_CODES: {
|
|
17
|
+
readonly bad_request: 4000;
|
|
18
|
+
readonly unauthorized: 4001;
|
|
19
|
+
readonly insufficient_credits: 4002;
|
|
20
|
+
readonly unknown_model: 4004;
|
|
21
|
+
readonly capacity: 4029;
|
|
22
|
+
/** A dependency (Redis, Spot) is unreachable, or the server is draining; retry shortly. */
|
|
23
|
+
readonly try_again: 1013;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The reason a socket close implies when no `session.ended` frame was seen.
|
|
27
|
+
* The server closes with the ending as the close reason, so a known reason
|
|
28
|
+
* wins; otherwise the code decides. Mirrors the server's `CLOSE_CODES`: 4008
|
|
29
|
+
* is shared by every policy limit, so without a reason it is `limit`.
|
|
30
|
+
* Anything unknown is a lost connection.
|
|
31
|
+
*/
|
|
32
|
+
declare function reasonFromCloseCode(code: number, closeReason?: string): EndReason;
|
|
33
|
+
/** True for a refusal the client may retry shortly (close code 1013). */
|
|
34
|
+
declare function isRetryableRefusal(closeCode: number | undefined): boolean;
|
|
35
|
+
/** Why a `session.created` cannot be used by this client, or null when it can. */
|
|
36
|
+
declare function unsupportedSession(created: SessionCreatedEvent): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* The session's audio stream from `session.created.media`, or null when the
|
|
39
|
+
* session carries no audio this client can handle (only 16-bit PCM).
|
|
40
|
+
*/
|
|
41
|
+
declare function audioFormat(created: SessionCreatedEvent | null): AudioFormat | null;
|
|
42
|
+
/** True when the client may send on this stream. */
|
|
43
|
+
declare function acceptsInput(format: {
|
|
44
|
+
direction: string;
|
|
45
|
+
} | null): boolean;
|
|
46
|
+
/** One binary frame: the stream tag, then the payload bytes. */
|
|
47
|
+
declare function mediaFrame(tag: number, payload: ArrayBuffer | ArrayBufferView): ArrayBuffer;
|
|
48
|
+
/** Builds the socket URL for a slug, with the token on the query string
|
|
49
|
+
* (a browser WebSocket cannot set headers). `path` is the session's path on
|
|
50
|
+
* the service (the model record's `endpoints.session`); without one it is
|
|
51
|
+
* `/<slug>`. Each path segment is encoded, so the URL stays under `root`. */
|
|
52
|
+
declare function sessionUrl(root: string, slug: string, token: string, query?: Record<string, string>, path?: string): string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Wires a session, a microphone and a playback buffer into a conversation:
|
|
56
|
+
* every mic frame goes to the session; incoming audio goes to playback;
|
|
57
|
+
* the user speaking over a reply flushes playback and interrupts upstream.
|
|
58
|
+
*
|
|
59
|
+
* Two triggers end a reply early, and both flush: local speech detection
|
|
60
|
+
* (fast — within a frame or two of the user speaking) and the server's own
|
|
61
|
+
* `input.speech_started` (slower, but authoritative). Audio for a turn the
|
|
62
|
+
* server has already ended is dropped on the floor rather than played late.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Where microphone audio comes from: s16le frames at `sampleRate`. The
|
|
67
|
+
* browser's `MicrophoneCapture` is one; a React Native module can be another.
|
|
68
|
+
*/
|
|
69
|
+
interface AudioSource {
|
|
70
|
+
readonly sampleRate: number;
|
|
71
|
+
onFrame(listener: (frame: Int16Array) => void): () => void;
|
|
72
|
+
}
|
|
73
|
+
/** Where reply audio goes: base64 or raw s16le at `sampleRate`, flushed on barge-in. */
|
|
74
|
+
interface AudioSink {
|
|
75
|
+
readonly sampleRate: number;
|
|
76
|
+
enqueue(audio: string | Int16Array): void;
|
|
77
|
+
flush(): void;
|
|
78
|
+
}
|
|
79
|
+
interface BargeInOptions {
|
|
80
|
+
session: RealtimeSession;
|
|
81
|
+
capture: AudioSource;
|
|
82
|
+
playback: AudioSink;
|
|
83
|
+
/** Detect speech locally and interrupt before the upstream's VAD reports it. Default on. */
|
|
84
|
+
localVad?: boolean | VadOptions;
|
|
85
|
+
/** Called with the level meter value on every mic frame. */
|
|
86
|
+
onLevel?: (rms: number) => void;
|
|
87
|
+
/** Called when the local detector decides speech started / ended. */
|
|
88
|
+
onLocalSpeech?: (speaking: boolean) => void;
|
|
89
|
+
/**
|
|
90
|
+
* Push-to-talk gate: when it returns false, microphone frames are dropped
|
|
91
|
+
* (not sent, not fed to the detector) so the capture can stay running
|
|
92
|
+
* between presses without the latency of reopening the device.
|
|
93
|
+
*/
|
|
94
|
+
shouldSend?: () => boolean;
|
|
95
|
+
}
|
|
96
|
+
interface BargeIn {
|
|
97
|
+
detach(): void;
|
|
98
|
+
/** True while a reply is being delivered (between turn.started and turn.ended). */
|
|
99
|
+
readonly replying: boolean;
|
|
100
|
+
}
|
|
101
|
+
declare function attachBargeIn(options: BargeInOptions): BargeIn;
|
|
102
|
+
|
|
103
|
+
/** PCM helpers shared by the session and the audio primitives. */
|
|
104
|
+
declare const SESSION_SAMPLE_RATE = 24000;
|
|
105
|
+
declare function pcmSeconds(byteLength: number, sampleRate?: number): number;
|
|
106
|
+
declare function encodePcm(pcm: Int16Array | ArrayBuffer): string;
|
|
107
|
+
declare function decodePcm(base64: string): Int16Array;
|
|
108
|
+
/** Float32 [-1, 1] → Int16 little-endian (the platform's byte order is little-endian everywhere a browser runs). */
|
|
109
|
+
declare function floatToInt16(samples: Float32Array): Int16Array;
|
|
110
|
+
/** Root mean square of a PCM frame, on the Int16 scale (0–32767). */
|
|
111
|
+
declare function rms(pcm: Int16Array): number;
|
|
112
|
+
|
|
113
|
+
export { AudioFormat, ClientEvent, EndReason, ProtocolError, REFUSAL_CLOSE_CODES, RealtimeSession, SESSION_SAMPLE_RATE, ServerEvent, SessionCreatedEvent, VadOptions, acceptsInput, attachBargeIn, audioFormat, decodePcm, decodeServerEvent, encodeClientEvent, encodePcm, floatToInt16, isRetryableRefusal, mediaFrame, pcmSeconds, reasonFromCloseCode, rms, sessionUrl, unsupportedSession };
|
|
114
|
+
export type { AudioSink, AudioSource, BargeIn, BargeInOptions };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { R as RealtimeSession, V as VadOptions } from '../vad-BcBkqh2p.js';
|
|
2
|
+
export { C as ClientOptions, D as DEFAULT_REALTIME_URL, E as EnergyVad, a as EventListener, b as RealtimeClient, S as SessionEnd, c as SessionOpenError, d as SessionOptions, e as StateListener, T as TypedEventListener, f as VadDecision, W as WebSocketLike, g as connect } from '../vad-BcBkqh2p.js';
|
|
3
|
+
import { e as SessionCreatedEvent, f as AudioFormat, g as ServerEvent, C as ClientEvent, E as EndReason } from '../errors-CcHEuSmR.js';
|
|
4
|
+
import { SegmindError } from '../index.js';
|
|
5
|
+
export { h as AudioDeltaEvent, i as ErrorEvent, j as InputSpeechStartedEvent, k as InputSpeechStoppedEvent, M as MediaStreamSpec, P as PROTOCOL_VERSION, l as PongEvent, m as RefusalCode, n as STREAM_TAGS, o as ServerEventType, p as SessionEndedEvent, q as SessionLimits, r as SessionState, S as SessionToken, a as SessionTokenProvider, s as SessionUpdateParams, t as SessionUpdatedEvent, T as TranscriptDeltaEvent, u as TurnEndReason, v as TurnEndedEvent, w as TurnStartedEvent, U as UpstreamEvent, x as Usage, y as UsageEvent, z as UsageFacts } from '../errors-CcHEuSmR.js';
|
|
6
|
+
|
|
7
|
+
/** A server frame this client cannot read. The session ignores it; `decodeServerEvent` throws it. */
|
|
8
|
+
declare class ProtocolError extends SegmindError {
|
|
9
|
+
readonly raw?: unknown | undefined;
|
|
10
|
+
constructor(message: string, raw?: unknown | undefined);
|
|
11
|
+
}
|
|
12
|
+
/** One server text frame → a typed event, or a ProtocolError. */
|
|
13
|
+
declare function decodeServerEvent(text: string): ServerEvent;
|
|
14
|
+
declare function encodeClientEvent(event: ClientEvent): string;
|
|
15
|
+
/** Close codes the server refuses an open with. Nothing was reserved or billed. */
|
|
16
|
+
declare const REFUSAL_CLOSE_CODES: {
|
|
17
|
+
readonly bad_request: 4000;
|
|
18
|
+
readonly unauthorized: 4001;
|
|
19
|
+
readonly insufficient_credits: 4002;
|
|
20
|
+
readonly unknown_model: 4004;
|
|
21
|
+
readonly capacity: 4029;
|
|
22
|
+
/** A dependency (Redis, Spot) is unreachable, or the server is draining; retry shortly. */
|
|
23
|
+
readonly try_again: 1013;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The reason a socket close implies when no `session.ended` frame was seen.
|
|
27
|
+
* The server closes with the ending as the close reason, so a known reason
|
|
28
|
+
* wins; otherwise the code decides. Mirrors the server's `CLOSE_CODES`: 4008
|
|
29
|
+
* is shared by every policy limit, so without a reason it is `limit`.
|
|
30
|
+
* Anything unknown is a lost connection.
|
|
31
|
+
*/
|
|
32
|
+
declare function reasonFromCloseCode(code: number, closeReason?: string): EndReason;
|
|
33
|
+
/** True for a refusal the client may retry shortly (close code 1013). */
|
|
34
|
+
declare function isRetryableRefusal(closeCode: number | undefined): boolean;
|
|
35
|
+
/** Why a `session.created` cannot be used by this client, or null when it can. */
|
|
36
|
+
declare function unsupportedSession(created: SessionCreatedEvent): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* The session's audio stream from `session.created.media`, or null when the
|
|
39
|
+
* session carries no audio this client can handle (only 16-bit PCM).
|
|
40
|
+
*/
|
|
41
|
+
declare function audioFormat(created: SessionCreatedEvent | null): AudioFormat | null;
|
|
42
|
+
/** True when the client may send on this stream. */
|
|
43
|
+
declare function acceptsInput(format: {
|
|
44
|
+
direction: string;
|
|
45
|
+
} | null): boolean;
|
|
46
|
+
/** One binary frame: the stream tag, then the payload bytes. */
|
|
47
|
+
declare function mediaFrame(tag: number, payload: ArrayBuffer | ArrayBufferView): ArrayBuffer;
|
|
48
|
+
/** Builds the socket URL for a slug, with the token on the query string
|
|
49
|
+
* (a browser WebSocket cannot set headers). `path` is the session's path on
|
|
50
|
+
* the service (the model record's `endpoints.session`); without one it is
|
|
51
|
+
* `/<slug>`. Each path segment is encoded, so the URL stays under `root`. */
|
|
52
|
+
declare function sessionUrl(root: string, slug: string, token: string, query?: Record<string, string>, path?: string): string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Wires a session, a microphone and a playback buffer into a conversation:
|
|
56
|
+
* every mic frame goes to the session; incoming audio goes to playback;
|
|
57
|
+
* the user speaking over a reply flushes playback and interrupts upstream.
|
|
58
|
+
*
|
|
59
|
+
* Two triggers end a reply early, and both flush: local speech detection
|
|
60
|
+
* (fast — within a frame or two of the user speaking) and the server's own
|
|
61
|
+
* `input.speech_started` (slower, but authoritative). Audio for a turn the
|
|
62
|
+
* server has already ended is dropped on the floor rather than played late.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Where microphone audio comes from: s16le frames at `sampleRate`. The
|
|
67
|
+
* browser's `MicrophoneCapture` is one; a React Native module can be another.
|
|
68
|
+
*/
|
|
69
|
+
interface AudioSource {
|
|
70
|
+
readonly sampleRate: number;
|
|
71
|
+
onFrame(listener: (frame: Int16Array) => void): () => void;
|
|
72
|
+
}
|
|
73
|
+
/** Where reply audio goes: base64 or raw s16le at `sampleRate`, flushed on barge-in. */
|
|
74
|
+
interface AudioSink {
|
|
75
|
+
readonly sampleRate: number;
|
|
76
|
+
enqueue(audio: string | Int16Array): void;
|
|
77
|
+
flush(): void;
|
|
78
|
+
}
|
|
79
|
+
interface BargeInOptions {
|
|
80
|
+
session: RealtimeSession;
|
|
81
|
+
capture: AudioSource;
|
|
82
|
+
playback: AudioSink;
|
|
83
|
+
/** Detect speech locally and interrupt before the upstream's VAD reports it. Default on. */
|
|
84
|
+
localVad?: boolean | VadOptions;
|
|
85
|
+
/** Called with the level meter value on every mic frame. */
|
|
86
|
+
onLevel?: (rms: number) => void;
|
|
87
|
+
/** Called when the local detector decides speech started / ended. */
|
|
88
|
+
onLocalSpeech?: (speaking: boolean) => void;
|
|
89
|
+
/**
|
|
90
|
+
* Push-to-talk gate: when it returns false, microphone frames are dropped
|
|
91
|
+
* (not sent, not fed to the detector) so the capture can stay running
|
|
92
|
+
* between presses without the latency of reopening the device.
|
|
93
|
+
*/
|
|
94
|
+
shouldSend?: () => boolean;
|
|
95
|
+
}
|
|
96
|
+
interface BargeIn {
|
|
97
|
+
detach(): void;
|
|
98
|
+
/** True while a reply is being delivered (between turn.started and turn.ended). */
|
|
99
|
+
readonly replying: boolean;
|
|
100
|
+
}
|
|
101
|
+
declare function attachBargeIn(options: BargeInOptions): BargeIn;
|
|
102
|
+
|
|
103
|
+
/** PCM helpers shared by the session and the audio primitives. */
|
|
104
|
+
declare const SESSION_SAMPLE_RATE = 24000;
|
|
105
|
+
declare function pcmSeconds(byteLength: number, sampleRate?: number): number;
|
|
106
|
+
declare function encodePcm(pcm: Int16Array | ArrayBuffer): string;
|
|
107
|
+
declare function decodePcm(base64: string): Int16Array;
|
|
108
|
+
/** Float32 [-1, 1] → Int16 little-endian (the platform's byte order is little-endian everywhere a browser runs). */
|
|
109
|
+
declare function floatToInt16(samples: Float32Array): Int16Array;
|
|
110
|
+
/** Root mean square of a PCM frame, on the Int16 scale (0–32767). */
|
|
111
|
+
declare function rms(pcm: Int16Array): number;
|
|
112
|
+
|
|
113
|
+
export { AudioFormat, ClientEvent, EndReason, ProtocolError, REFUSAL_CLOSE_CODES, RealtimeSession, SESSION_SAMPLE_RATE, ServerEvent, SessionCreatedEvent, VadOptions, acceptsInput, attachBargeIn, audioFormat, decodePcm, decodeServerEvent, encodeClientEvent, encodePcm, floatToInt16, isRetryableRefusal, mediaFrame, pcmSeconds, reasonFromCloseCode, rms, sessionUrl, unsupportedSession };
|
|
114
|
+
export type { AudioSink, AudioSource, BargeIn, BargeInOptions };
|