@howaboua/pi-durable-gippity-voice 0.10.0 → 0.13.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/NOTICE +5 -0
- package/README.md +4 -2
- package/dist/activation.js +2108 -989
- package/dist/index.js +2115 -996
- package/dist/internal/voice/agent-observation.d.ts +13 -0
- package/dist/internal/voice/browser-provider.d.ts +65 -0
- package/dist/internal/voice/browser-settings.d.ts +24 -0
- package/dist/internal/voice/handoff-contract.d.ts +28 -0
- package/dist/internal/voice/lan-client-sdk.d.ts +1 -0
- package/dist/internal/voice/lan-listener-proof.d.ts +2 -0
- package/dist/packages/execution/src/invocation-state.d.ts +1 -1
- package/dist/packages/execution/src/invocation.d.ts +79 -2
- package/dist/packages/execution/src/native-tools.d.ts +18 -7
- package/dist/packages/execution/src/nested-call.d.ts +11 -3
- package/dist/packages/execution/src/nested-park.d.ts +9 -0
- package/dist/packages/execution/src/nested-result.d.ts +1 -1
- package/dist/packages/execution/src/tool-contract.d.ts +10 -3
- package/dist/packages/execution/src/tool-namespaces.d.ts +31 -0
- package/dist/packages/execution/src/tool-origin.d.ts +9 -1
- package/dist/packages/gippity-voice/src/controller.d.ts +10 -3
- package/dist/packages/gippity-voice/src/host.d.ts +6 -0
- package/dist/packages/gippity-voice/src/index.d.ts +2 -1
- package/dist/packages/gippity-voice/src/voice/browser-reservation.d.ts +30 -0
- package/dist/packages/gippity-voice/src/voice/conversation/peer.d.ts +6 -0
- package/dist/packages/gippity-voice/src/voice/conversation/public-turns.d.ts +2 -1
- package/dist/packages/gippity-voice/src/voice/conversation/session.d.ts +2 -0
- package/dist/packages/gippity-voice/src/voice/handoff-departure.d.ts +5 -0
- package/dist/packages/gippity-voice/src/voice/handoff-peer.d.ts +12 -0
- package/dist/packages/gippity-voice/src/voice/handoff-wire.d.ts +1 -1
- package/dist/packages/gippity-voice/src/voice/helper-protocol.d.ts +35 -0
- package/dist/packages/gippity-voice/src/voice/lan/browser-clients.d.ts +2 -1
- package/dist/packages/gippity-voice/src/voice/lan/browser-connections.d.ts +17 -0
- package/dist/packages/gippity-voice/src/voice/lan/browser-peer.d.ts +4 -0
- package/dist/packages/gippity-voice/src/voice/lan/browser-session.d.ts +10 -4
- package/dist/packages/gippity-voice/src/voice/lan/pcm-bridge.d.ts +25 -0
- package/dist/packages/gippity-voice/src/voice/lan/playback-drain.d.ts +8 -0
- package/dist/packages/gippity-voice/src/voice/lan/protocol.d.ts +4 -0
- package/dist/packages/gippity-voice/src/voice/lan/server.d.ts +5 -3
- package/dist/packages/gippity-voice/src/voice/lan/takeover.d.ts +2 -3
- package/dist/packages/gippity-voice/src/voice/lan/unified-settings.d.ts +3 -0
- package/dist/packages/gippity-voice/src/voice/realtime-auth.d.ts +3 -2
- package/dist/packages/gippity-voice/src/voice/turns.d.ts +2 -1
- package/dist/voice/bin/darwin-arm64/pi-codex-voice +0 -0
- package/dist/voice/bin/darwin-x64/pi-codex-voice +0 -0
- package/dist/voice/bin/linux-arm64/pi-codex-voice +0 -0
- package/dist/voice/bin/linux-x64/pi-codex-voice +0 -0
- package/dist/voice/bin/win32-arm64/pi-codex-voice.exe +0 -0
- package/dist/voice/bin/win32-x64/pi-codex-voice.exe +0 -0
- package/package.json +10 -9
- package/src/voice/rust/src/audio.rs +2 -2
- package/src/voice/rust/src/playout.rs +68 -8
- package/src/voice/rust/src/protocol.rs +43 -1
- package/src/voice/rust/src/v3_media.rs +138 -31
- /package/dist/{packages/gippity-voice/src → internal/voice}/deferred.d.ts +0 -0
- /package/dist/{packages/gippity-voice/src/voice/lan/activity.d.ts → internal/voice/lan-activity.d.ts} +0 -0
- /package/dist/{packages/gippity-voice/src/voice/lan/draft.d.ts → internal/voice/lan-draft.d.ts} +0 -0
- /package/dist/{packages/gippity-voice/src/voice/lan → internal/voice}/remote-json.d.ts +0 -0
|
@@ -56,6 +56,9 @@ export type VoiceHelperEvent = {
|
|
|
56
56
|
epoch?: number;
|
|
57
57
|
} | {
|
|
58
58
|
type: "playback_activity";
|
|
59
|
+
} | {
|
|
60
|
+
type: "audio_diagnostics";
|
|
61
|
+
diagnostics: VoiceAudioDiagnostics;
|
|
59
62
|
} | {
|
|
60
63
|
type: "error";
|
|
61
64
|
message: string;
|
|
@@ -67,6 +70,38 @@ export interface VoiceDevice {
|
|
|
67
70
|
name: string;
|
|
68
71
|
is_default: boolean;
|
|
69
72
|
}
|
|
73
|
+
export interface VoiceAudioDiagnostics {
|
|
74
|
+
epoch: number;
|
|
75
|
+
suppressed: boolean;
|
|
76
|
+
elapsed_ms: number;
|
|
77
|
+
transitions: number;
|
|
78
|
+
drained_packets: number;
|
|
79
|
+
release_drained_packets: number;
|
|
80
|
+
rejected_packets: number;
|
|
81
|
+
buffering_entries: number;
|
|
82
|
+
tail_flushes: number;
|
|
83
|
+
clock_rebases: number;
|
|
84
|
+
decode_failures: number;
|
|
85
|
+
received_packets: number;
|
|
86
|
+
missing_packets: number;
|
|
87
|
+
decoded_packets: number;
|
|
88
|
+
decoded_packet_samples: number;
|
|
89
|
+
min_decoded_packet_samples: number;
|
|
90
|
+
max_decoded_packet_samples: number;
|
|
91
|
+
late_packets: number;
|
|
92
|
+
duplicate_packets: number;
|
|
93
|
+
reordered_packets: number;
|
|
94
|
+
resyncs: number;
|
|
95
|
+
resync_discarded_packets: number;
|
|
96
|
+
read_gaps_over_40ms: number;
|
|
97
|
+
max_read_gap_ms: number;
|
|
98
|
+
max_playout_lateness_us: number;
|
|
99
|
+
bridge_frames: number;
|
|
100
|
+
bridge_channel_full: number;
|
|
101
|
+
bridge_sends_over_1ms: number;
|
|
102
|
+
max_bridge_send_us: number;
|
|
103
|
+
first_packet_ms: number | null;
|
|
104
|
+
}
|
|
70
105
|
export declare class BoundedJsonlReader {
|
|
71
106
|
private readonly chunks;
|
|
72
107
|
private readonly maxLineBytes;
|
|
@@ -15,9 +15,10 @@ export declare class LanVoiceBrowserClients {
|
|
|
15
15
|
broadcastControl(value: unknown): void;
|
|
16
16
|
takeover(token: string): Promise<void>;
|
|
17
17
|
sendConversationAudio(pcm: Buffer): void;
|
|
18
|
+
drainPlayback(signal: AbortSignal, seal: () => Promise<void>): Promise<void>;
|
|
18
19
|
setConversationSpeakerSuppressed(suppressed: boolean): void;
|
|
19
20
|
resetConversationInputLevel(): void;
|
|
20
|
-
release(clientId: string, socket?: WebSocket, terminateConversation?: boolean):
|
|
21
|
+
release(clientId: string, socket?: WebSocket, terminateConversation?: boolean): Promise<boolean>;
|
|
21
22
|
heartbeat(): void;
|
|
22
23
|
close(): Promise<void>;
|
|
23
24
|
private receive;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import type { ServerResponse } from "node:http";
|
|
2
2
|
import { type RawData, WebSocket } from "ws";
|
|
3
|
+
export interface LanPlaybackDiagnostics {
|
|
4
|
+
source: "lan-playback";
|
|
5
|
+
reason: "interval" | "closed" | "replaced" | "server-closed";
|
|
6
|
+
windowMs: number;
|
|
7
|
+
sentFrames: number;
|
|
8
|
+
sentBytes: number;
|
|
9
|
+
droppedFrames: number;
|
|
10
|
+
droppedBytes: number;
|
|
11
|
+
maxSocketBacklogBytes: number;
|
|
12
|
+
sourcePcmArrivalGapMaxMs: number;
|
|
13
|
+
sourcePcmArrivalGapIncludesPauses: true;
|
|
14
|
+
}
|
|
3
15
|
interface AudioConnectionCallbacks {
|
|
4
16
|
onMessage(data: RawData, isBinary: boolean): void;
|
|
5
17
|
onReplaced(previous: WebSocket): void;
|
|
@@ -8,6 +20,9 @@ interface AudioConnectionCallbacks {
|
|
|
8
20
|
export declare class LanVoiceBrowserConnections {
|
|
9
21
|
private readonly eventResponses;
|
|
10
22
|
private readonly audioSockets;
|
|
23
|
+
private readonly audioReports;
|
|
24
|
+
private readonly onAudioDiagnostics;
|
|
25
|
+
constructor(onAudioDiagnostics?: (report: LanPlaybackDiagnostics) => void);
|
|
11
26
|
connectEvents(clientId: string, response: ServerResponse, closed: boolean): void;
|
|
12
27
|
connectAudio(clientId: string, socket: WebSocket, closed: boolean, callbacks: AudioConnectionCallbacks): void;
|
|
13
28
|
isCurrentAudio(clientId: string, socket: WebSocket): boolean;
|
|
@@ -16,6 +31,8 @@ export declare class LanVoiceBrowserConnections {
|
|
|
16
31
|
hasAudioClients(): boolean;
|
|
17
32
|
broadcastControl(value: unknown): void;
|
|
18
33
|
sendAudio(socket: WebSocket, pcm: Buffer): void;
|
|
34
|
+
private flushAudioReport;
|
|
35
|
+
private finishAudioReport;
|
|
19
36
|
sendAudioControl(socket: WebSocket, value: unknown): void;
|
|
20
37
|
heartbeat(): void;
|
|
21
38
|
close(failures: unknown[]): void;
|
|
@@ -6,12 +6,14 @@ export declare class LanHostRealtimePeer implements CodexRealtimeWebRtcPeer {
|
|
|
6
6
|
private readonly helper;
|
|
7
7
|
private readonly onAudio;
|
|
8
8
|
private readonly onSpeakerSuppressed;
|
|
9
|
+
private readonly drain;
|
|
9
10
|
private playbackEpoch;
|
|
10
11
|
private speakerSuppressed;
|
|
11
12
|
private inputState;
|
|
12
13
|
constructor(host: GippityAudioHost, options: {
|
|
13
14
|
onAudio(pcm: Buffer): void;
|
|
14
15
|
onSpeakerSuppressed(suppressed: boolean): void;
|
|
16
|
+
drain?(signal: AbortSignal, seal: () => Promise<void>): Promise<void>;
|
|
15
17
|
});
|
|
16
18
|
get isSpeakerSuppressed(): boolean;
|
|
17
19
|
onEvent(listener: (event: CodexRealtimePeerEvent) => void): () => void;
|
|
@@ -22,5 +24,7 @@ export declare class LanHostRealtimePeer implements CodexRealtimeWebRtcPeer {
|
|
|
22
24
|
sendAudio(pcm: Buffer): void;
|
|
23
25
|
setInputMuted(muted: boolean): void;
|
|
24
26
|
setSpeakerSuppressed(suppressed: boolean): void;
|
|
27
|
+
get playbackSealed(): boolean;
|
|
28
|
+
finishPlayback(signal: AbortSignal): Promise<void>;
|
|
25
29
|
close(): Promise<void>;
|
|
26
30
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { WebSocket } from "ws";
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
2
|
+
import type { LanVoiceDraftSelection } from "../../../../../internal/voice/lan-draft.ts";
|
|
3
|
+
import type { LanPlaybackDiagnostics, LanVoiceBrowserConnections } from "./browser-connections.ts";
|
|
4
4
|
export type LanVoiceBrowserMode = "conversation" | "dictation";
|
|
5
5
|
export interface LanVoiceBrowserClientsOptions {
|
|
6
|
+
onAudioDiagnostics?(diagnostics: LanPlaybackDiagnostics): void;
|
|
6
7
|
ensureConversation(takeoverToken?: string): Promise<void>;
|
|
7
8
|
startDictation(clientId: string): Promise<void>;
|
|
8
9
|
finishDictation(clientId: string, draft?: string, revision?: number, selection?: LanVoiceDraftSelection): Promise<void>;
|
|
@@ -20,16 +21,21 @@ export declare class LanVoiceBrowserSession {
|
|
|
20
21
|
private state;
|
|
21
22
|
private operation;
|
|
22
23
|
private conversationOwnerId;
|
|
24
|
+
private stopCompletion;
|
|
23
25
|
private conversationSpeakerSuppressed;
|
|
26
|
+
private readonly playbackDrain;
|
|
24
27
|
private readonly microphoneLevel;
|
|
25
28
|
constructor(options: LanVoiceBrowserClientsOptions, connections: LanVoiceBrowserConnections);
|
|
26
29
|
get closed(): boolean;
|
|
27
30
|
get conversationSocket(): WebSocket | undefined;
|
|
28
31
|
sendConversationAudio(pcm: Buffer): void;
|
|
29
32
|
setConversationSpeakerSuppressed(suppressed: boolean): void;
|
|
30
|
-
|
|
33
|
+
drainPlayback(signal: AbortSignal, seal: () => Promise<void>): Promise<void>;
|
|
34
|
+
acknowledgePlayback(socket: WebSocket, id: string): void;
|
|
35
|
+
replaceSocket(clientId: string, socket: WebSocket): void;
|
|
36
|
+
release(clientId: string, socket?: WebSocket, terminateConversation?: boolean): Promise<boolean>;
|
|
31
37
|
releaseStarting(clientId: string, socket?: WebSocket): void;
|
|
32
|
-
claim(clientId: string, socket: WebSocket, mode: LanVoiceBrowserMode, takeoverToken?: string): Promise<void>;
|
|
38
|
+
claim(clientId: string, socket: WebSocket, mode: LanVoiceBrowserMode, takeoverToken?: string, playbackDrain?: boolean): Promise<void>;
|
|
33
39
|
finish(clientId: string, socket: WebSocket, draft: string, revision: number, selection: LanVoiceDraftSelection): Promise<void>;
|
|
34
40
|
cancelDictation(clientId: string): Promise<void>;
|
|
35
41
|
resetConversationInputLevel(): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BrowserVoiceAudio, BrowserVoiceMode } from "../../../../../internal/voice/browser-provider.ts";
|
|
2
|
+
import type { GippityAudioHost } from "../../host.ts";
|
|
3
|
+
import type { CodexVoiceAuth } from "../auth.ts";
|
|
4
|
+
import { LanHostRealtimePeer } from "./browser-peer.ts";
|
|
5
|
+
/** A retained browser endpoint outlives a peer replacement, never its owning selection. */
|
|
6
|
+
export declare class GippityBrowserAudio {
|
|
7
|
+
status: string;
|
|
8
|
+
transcript: string;
|
|
9
|
+
error: string | undefined;
|
|
10
|
+
private peer;
|
|
11
|
+
private transcriber;
|
|
12
|
+
private shutdown;
|
|
13
|
+
private failure;
|
|
14
|
+
readonly mode: BrowserVoiceMode;
|
|
15
|
+
private readonly audio;
|
|
16
|
+
private readonly onFailure;
|
|
17
|
+
constructor(mode: BrowserVoiceMode, audio: BrowserVoiceAudio, onFailure: (error: Error) => void);
|
|
18
|
+
createPeer(host: GippityAudioHost): LanHostRealtimePeer;
|
|
19
|
+
startCapture(): Promise<void>;
|
|
20
|
+
startDictation(auth: CodexVoiceAuth, signal: AbortSignal): Promise<void>;
|
|
21
|
+
setMuted(muted: boolean): void;
|
|
22
|
+
finish(): Promise<string>;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
private fail;
|
|
25
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WebSocket } from "ws";
|
|
2
|
+
/** One ordered final-playback marker, owned by the exact audio socket. */
|
|
3
|
+
export declare class LanPlaybackDrain {
|
|
4
|
+
private pending;
|
|
5
|
+
wait(socket: WebSocket, signal: AbortSignal, seal: () => Promise<void>): Promise<void>;
|
|
6
|
+
acknowledge(socket: WebSocket, id: string): void;
|
|
7
|
+
cancel(): void;
|
|
8
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Context } from "@earendil-works/chord";
|
|
2
|
-
import type {
|
|
1
|
+
import type { Context } from "@earendil-works/chord/context";
|
|
2
|
+
import type { EntryRecord } from "@earendil-works/pi-durable";
|
|
3
3
|
import type { GippityVoiceControls } from "../../controller.ts";
|
|
4
4
|
import type { AudioLease, GippityAppFiles, GippityAudioHost, GippityLanPermission, GippityPresentation } from "../../host.ts";
|
|
5
5
|
import type { CodexVoiceAuth } from "../auth.ts";
|
|
@@ -14,7 +14,8 @@ export interface GippityLanServer {
|
|
|
14
14
|
releaseForTakeover(): Promise<void>;
|
|
15
15
|
publish(event: GippityPresentation): void;
|
|
16
16
|
broadcast(event: unknown): void;
|
|
17
|
-
|
|
17
|
+
agentState(working: boolean): void;
|
|
18
|
+
agentEntry(entry: EntryRecord): void;
|
|
18
19
|
sessionEvent(event: string, data: unknown): void;
|
|
19
20
|
close(): Promise<void>;
|
|
20
21
|
}
|
|
@@ -30,6 +31,7 @@ export declare function startGippityLanServer(options: {
|
|
|
30
31
|
context: Context;
|
|
31
32
|
resolveAuth(): Promise<CodexVoiceAuth>;
|
|
32
33
|
remoteApps: GippityRemoteApps;
|
|
34
|
+
onAudioDiagnostics?(diagnostics: import("./browser-connections.ts").LanPlaybackDiagnostics): void;
|
|
33
35
|
takeoverToken?: string;
|
|
34
36
|
startConversation?(factory: () => LanHostRealtimePeer, token?: string): Promise<void>;
|
|
35
37
|
}): Promise<GippityLanServer>;
|
|
@@ -7,13 +7,12 @@ export interface LanTakeoverOffer extends LanTakeoverIdentity {
|
|
|
7
7
|
}
|
|
8
8
|
export interface PreparedLanTakeover {
|
|
9
9
|
offer: LanTakeoverOffer;
|
|
10
|
-
|
|
10
|
+
verify(value: unknown, signal: AbortSignal): Promise<void>;
|
|
11
|
+
claim(value: unknown): string;
|
|
11
12
|
}
|
|
12
13
|
export declare function prepareLanTakeover(certificate: GippityLanPermission): PreparedLanTakeover;
|
|
13
14
|
export declare function decodeLanTakeoverOffer(value: unknown): LanTakeoverOffer;
|
|
14
15
|
export declare function assertLanTakeoverIdentity(source: LanTakeoverIdentity, target: LanTakeoverIdentity): void;
|
|
15
|
-
/** The destination must reach this exact listener through its own loopback. */
|
|
16
|
-
export declare function verifyLanTakeoverListener(certificate: string | Buffer, value: unknown, signal?: AbortSignal): Promise<void>;
|
|
17
16
|
/** Only the reconnect carrying the source token may use the prepared snapshot. */
|
|
18
17
|
export declare class LanTakeoverArrival<T> {
|
|
19
18
|
private pending;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type GippityControlConfig, type VoiceContextModel } from "../../config.ts";
|
|
2
|
+
export declare function gippityBrowserFields(config: GippityControlConfig["voice"], models: readonly VoiceContextModel[], contextAllowed: boolean): import("../../../../../internal/voice/browser-settings.ts").BrowserVoiceSetting[];
|
|
3
|
+
export declare function decodeGippityBrowserSettings(patch: Record<string, unknown>, config: GippityControlConfig["voice"], models: readonly VoiceContextModel[], contextAllowed: boolean): Record<string, unknown>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Models
|
|
1
|
+
import type { Models } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { JsonSchema } from "@earendil-works/pi-schema";
|
|
2
3
|
import type { CodexVoiceAuth } from "./auth.ts";
|
|
3
4
|
export interface PublicRealtimeAccess {
|
|
4
5
|
tools: {
|
|
@@ -6,7 +7,7 @@ export interface PublicRealtimeAccess {
|
|
|
6
7
|
type: "function";
|
|
7
8
|
name: string;
|
|
8
9
|
description: string;
|
|
9
|
-
parameters:
|
|
10
|
+
parameters: JsonSchema;
|
|
10
11
|
}>;
|
|
11
12
|
execute(name: string, args: unknown, context: {
|
|
12
13
|
signal: AbortSignal;
|
|
@@ -19,6 +19,7 @@ export declare class RealtimeVoiceTurnTracker {
|
|
|
19
19
|
private delegatedUserFinishes;
|
|
20
20
|
private readonly delegatedUserTurns;
|
|
21
21
|
private readonly delegationIds;
|
|
22
|
+
private readonly delegatedTurnInputs;
|
|
22
23
|
private readonly outstandingDelegations;
|
|
23
24
|
private readonly outstandingInputs;
|
|
24
25
|
get hasPendingInput(): boolean;
|
|
@@ -26,7 +27,7 @@ export declare class RealtimeVoiceTurnTracker {
|
|
|
26
27
|
inputAdded(input: string): void;
|
|
27
28
|
outputAdded(output: string): void;
|
|
28
29
|
userFinished(input: string): boolean;
|
|
29
|
-
delegated(input: string, delegationId: string): TrackedRealtimeDelegation | undefined;
|
|
30
|
+
delegated(input: string, delegationId: string, userTurnId?: string): TrackedRealtimeDelegation | undefined;
|
|
30
31
|
delegationSettled(delegationId: string): void;
|
|
31
32
|
assistantFinished(output?: string): RealtimeVoiceTurn | undefined;
|
|
32
33
|
takeTranscriptTail(): string | undefined;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-durable-gippity-voice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Codex Live and OpenAI Realtime WebRTC voice and dictation for Pi Durable",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,16 +39,17 @@
|
|
|
39
39
|
"build:native": "node scripts/build-voice-helper.mjs"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"typebox": "1.
|
|
43
|
-
"undici": "8.
|
|
44
|
-
"ws": "8.
|
|
45
|
-
"@howaboua/pi-durable-components": "0.
|
|
42
|
+
"typebox": "1.4.7",
|
|
43
|
+
"undici": "8.14.0",
|
|
44
|
+
"ws": "8.23.1",
|
|
45
|
+
"@howaboua/pi-durable-components": "0.13.0",
|
|
46
|
+
"@earendil-works/pi-schema": "1.8.0"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
|
-
"@earendil-works/chord": "1.
|
|
49
|
-
"@earendil-works/pi-ai": "1.
|
|
50
|
-
"@earendil-works/pi-durable": "1.
|
|
51
|
-
"@modelcontextprotocol/sdk": ">=1.
|
|
49
|
+
"@earendil-works/chord": "1.8.0",
|
|
50
|
+
"@earendil-works/pi-ai": "1.8.0",
|
|
51
|
+
"@earendil-works/pi-durable": "1.8.0",
|
|
52
|
+
"@modelcontextprotocol/sdk": ">=1.32.2 <2"
|
|
52
53
|
},
|
|
53
54
|
"publishConfig": {
|
|
54
55
|
"access": "public"
|
|
@@ -253,7 +253,7 @@ mod tests {
|
|
|
253
253
|
crate::v3_media::drain_ready_packets(&mut read, || {
|
|
254
254
|
Box::pin(queued_read(Arc::clone(&remaining)))
|
|
255
255
|
}),
|
|
256
|
-
crate::v3_media::ReadyDrain::Pending
|
|
256
|
+
crate::v3_media::ReadyDrain::Pending(budget)
|
|
257
257
|
);
|
|
258
258
|
assert_eq!(remaining.load(Ordering::Acquire), 0);
|
|
259
259
|
remaining.store(1, Ordering::Release);
|
|
@@ -261,7 +261,7 @@ mod tests {
|
|
|
261
261
|
crate::v3_media::drain_ready_packets(&mut read, || {
|
|
262
262
|
Box::pin(queued_read(Arc::clone(&remaining)))
|
|
263
263
|
}),
|
|
264
|
-
crate::v3_media::ReadyDrain::Pending
|
|
264
|
+
crate::v3_media::ReadyDrain::Pending(1)
|
|
265
265
|
);
|
|
266
266
|
assert_eq!(remaining.load(Ordering::Acquire), 0);
|
|
267
267
|
|
|
@@ -5,6 +5,8 @@ use bytes::Bytes;
|
|
|
5
5
|
use tokio::time::Instant;
|
|
6
6
|
|
|
7
7
|
const START_PACKETS: usize = 3;
|
|
8
|
+
// Retain the reorder warmup, but never strand a short utterance or resumed tail.
|
|
9
|
+
const MAX_BUFFERING_WAIT: Duration = Duration::from_millis(60);
|
|
8
10
|
const MAX_SEQUENCE_DISTANCE: usize = 6;
|
|
9
11
|
const MAX_PENDING_PACKETS: usize = MAX_SEQUENCE_DISTANCE + 1;
|
|
10
12
|
|
|
@@ -12,13 +14,23 @@ const MAX_PENDING_PACKETS: usize = MAX_SEQUENCE_DISTANCE + 1;
|
|
|
12
14
|
pub enum PlayoutFrame {
|
|
13
15
|
Buffering,
|
|
14
16
|
Packet(Bytes),
|
|
15
|
-
Missing,
|
|
17
|
+
Missing { successor: Option<Bytes> },
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
pub enum PacketAdmission {
|
|
21
|
+
// Reordering within the pending window, not a network loss estimate.
|
|
22
|
+
Accepted { reordered: bool },
|
|
23
|
+
// Includes already-played duplicates; only pending duplicates are distinct.
|
|
24
|
+
Late,
|
|
25
|
+
Duplicate,
|
|
26
|
+
Resynchronized { discarded: usize },
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
pub struct PacketPlayout {
|
|
19
30
|
pending: BTreeMap<i64, Bytes>,
|
|
20
31
|
expected: Option<i64>,
|
|
21
32
|
playing: bool,
|
|
33
|
+
buffering_since: Option<Instant>,
|
|
22
34
|
}
|
|
23
35
|
|
|
24
36
|
pub struct PlayoutClock {
|
|
@@ -38,12 +50,17 @@ impl PlayoutClock {
|
|
|
38
50
|
self.deadline
|
|
39
51
|
}
|
|
40
52
|
|
|
41
|
-
pub fn advance(&mut self, samples: usize, sample_rate: u32) {
|
|
53
|
+
pub fn advance(&mut self, samples: usize, sample_rate: u32) -> bool {
|
|
42
54
|
let Some(deadline) = self.deadline else {
|
|
43
|
-
return;
|
|
55
|
+
return false;
|
|
44
56
|
};
|
|
45
57
|
let frame_duration = Duration::from_secs_f64(samples as f64 / sample_rate as f64);
|
|
46
|
-
|
|
58
|
+
let now = Instant::now();
|
|
59
|
+
let late = now.saturating_duration_since(deadline) >= frame_duration;
|
|
60
|
+
// Small scheduler jitter preserves cadence. A full missed frame rebases
|
|
61
|
+
// without discarding audio or emitting a run of immediately due frames.
|
|
62
|
+
self.deadline = Some(if late { now } else { deadline } + frame_duration);
|
|
63
|
+
late
|
|
47
64
|
}
|
|
48
65
|
|
|
49
66
|
pub fn stop(&mut self) {
|
|
@@ -57,24 +74,42 @@ impl PacketPlayout {
|
|
|
57
74
|
pending: BTreeMap::new(),
|
|
58
75
|
expected: None,
|
|
59
76
|
playing: false,
|
|
77
|
+
buffering_since: None,
|
|
60
78
|
}
|
|
61
79
|
}
|
|
62
80
|
|
|
63
|
-
pub fn push(&mut self, sequence: u16, payload: Bytes) {
|
|
81
|
+
pub fn push(&mut self, sequence: u16, payload: Bytes) -> PacketAdmission {
|
|
64
82
|
let expected = *self.expected.get_or_insert(sequence as i64);
|
|
65
83
|
let delta = sequence.wrapping_sub(expected as u16) as i16 as i64;
|
|
66
84
|
let extended = expected + delta;
|
|
85
|
+
let mut admission = PacketAdmission::Accepted {
|
|
86
|
+
reordered: self
|
|
87
|
+
.pending
|
|
88
|
+
.keys()
|
|
89
|
+
.next_back()
|
|
90
|
+
.is_some_and(|last| *last > extended),
|
|
91
|
+
};
|
|
67
92
|
if extended < expected {
|
|
68
93
|
if self.playing || expected - extended > MAX_SEQUENCE_DISTANCE as i64 {
|
|
69
|
-
return;
|
|
94
|
+
return PacketAdmission::Late;
|
|
70
95
|
}
|
|
71
96
|
self.expected = Some(extended);
|
|
72
97
|
} else if extended - expected > MAX_SEQUENCE_DISTANCE as i64 {
|
|
98
|
+
admission = PacketAdmission::Resynchronized {
|
|
99
|
+
discarded: self.pending.len(),
|
|
100
|
+
};
|
|
73
101
|
self.pending.clear();
|
|
74
102
|
self.expected = Some(extended);
|
|
75
103
|
self.playing = false;
|
|
104
|
+
self.buffering_since = None;
|
|
105
|
+
}
|
|
106
|
+
if self.pending.contains_key(&extended) {
|
|
107
|
+
admission = PacketAdmission::Duplicate;
|
|
76
108
|
}
|
|
77
109
|
self.pending.entry(extended).or_insert(payload);
|
|
110
|
+
if !self.playing {
|
|
111
|
+
self.buffering_since.get_or_insert_with(Instant::now);
|
|
112
|
+
}
|
|
78
113
|
while self.pending.len() > MAX_PENDING_PACKETS {
|
|
79
114
|
let Some(oldest) = self.pending.keys().next().copied() else {
|
|
80
115
|
break;
|
|
@@ -84,9 +119,16 @@ impl PacketPlayout {
|
|
|
84
119
|
if !self.playing && self.pending.len() >= START_PACKETS {
|
|
85
120
|
self.playing = true;
|
|
86
121
|
}
|
|
122
|
+
admission
|
|
87
123
|
}
|
|
88
124
|
|
|
89
125
|
pub fn next(&mut self) -> PlayoutFrame {
|
|
126
|
+
if self
|
|
127
|
+
.buffering_deadline()
|
|
128
|
+
.is_some_and(|deadline| deadline <= Instant::now())
|
|
129
|
+
{
|
|
130
|
+
self.playing = true;
|
|
131
|
+
}
|
|
90
132
|
if !self.playing {
|
|
91
133
|
return PlayoutFrame::Buffering;
|
|
92
134
|
}
|
|
@@ -101,9 +143,13 @@ impl PacketPlayout {
|
|
|
101
143
|
.next()
|
|
102
144
|
.is_some_and(|sequence| *sequence > expected)
|
|
103
145
|
{
|
|
104
|
-
|
|
146
|
+
// Borrow redundancy without consuming the successor's own slot.
|
|
147
|
+
PlayoutFrame::Missing {
|
|
148
|
+
successor: self.pending.get(&(expected + 1)).cloned(),
|
|
149
|
+
}
|
|
105
150
|
} else {
|
|
106
151
|
self.playing = false;
|
|
152
|
+
self.buffering_since = None;
|
|
107
153
|
return PlayoutFrame::Buffering;
|
|
108
154
|
};
|
|
109
155
|
self.expected = Some(expected + 1);
|
|
@@ -114,10 +160,19 @@ impl PacketPlayout {
|
|
|
114
160
|
self.playing
|
|
115
161
|
}
|
|
116
162
|
|
|
163
|
+
pub fn buffering_deadline(&self) -> Option<Instant> {
|
|
164
|
+
if self.playing || self.pending.is_empty() {
|
|
165
|
+
None
|
|
166
|
+
} else {
|
|
167
|
+
self.buffering_since.map(|since| since + MAX_BUFFERING_WAIT)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
117
171
|
pub fn reset(&mut self) {
|
|
118
172
|
self.pending.clear();
|
|
119
173
|
self.expected = None;
|
|
120
174
|
self.playing = false;
|
|
175
|
+
self.buffering_since = None;
|
|
121
176
|
}
|
|
122
177
|
}
|
|
123
178
|
|
|
@@ -147,7 +202,12 @@ mod tests {
|
|
|
147
202
|
gap.push(22, packet(22));
|
|
148
203
|
gap.push(23, packet(23));
|
|
149
204
|
assert_eq!(gap.next(), PlayoutFrame::Packet(packet(20)));
|
|
150
|
-
assert_eq!(
|
|
205
|
+
assert_eq!(
|
|
206
|
+
gap.next(),
|
|
207
|
+
PlayoutFrame::Missing {
|
|
208
|
+
successor: Some(packet(22))
|
|
209
|
+
}
|
|
210
|
+
);
|
|
151
211
|
assert_eq!(gap.next(), PlayoutFrame::Packet(packet(22)));
|
|
152
212
|
}
|
|
153
213
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
use serde::{Deserialize, Serialize};
|
|
2
2
|
use serde_json::Value;
|
|
3
3
|
|
|
4
|
-
pub const PROTOCOL_VERSION: u8 =
|
|
4
|
+
pub const PROTOCOL_VERSION: u8 = 8;
|
|
5
5
|
pub const MAX_SDP_BYTES: usize = 256 * 1024;
|
|
6
6
|
pub const MAX_DATA_MESSAGE_BYTES: usize = 64 * 1024;
|
|
7
7
|
pub const MAX_PCM_BYTES: usize = 64 * 1024;
|
|
@@ -97,6 +97,9 @@ pub enum Event {
|
|
|
97
97
|
epoch: Option<u64>,
|
|
98
98
|
},
|
|
99
99
|
PlaybackActivity,
|
|
100
|
+
AudioDiagnostics {
|
|
101
|
+
diagnostics: AudioDiagnostics,
|
|
102
|
+
},
|
|
100
103
|
Error {
|
|
101
104
|
message: String,
|
|
102
105
|
},
|
|
@@ -110,6 +113,45 @@ pub struct AudioDevice {
|
|
|
110
113
|
pub is_default: bool,
|
|
111
114
|
}
|
|
112
115
|
|
|
116
|
+
// Interval totals may span epochs; epoch/suppressed describe the final state.
|
|
117
|
+
// Counts and local relative timing only: never audio, captions or provider data.
|
|
118
|
+
#[derive(Clone, Debug, Default, Serialize)]
|
|
119
|
+
pub struct AudioDiagnostics {
|
|
120
|
+
pub epoch: u64,
|
|
121
|
+
pub suppressed: bool,
|
|
122
|
+
pub elapsed_ms: u32,
|
|
123
|
+
pub transitions: u32,
|
|
124
|
+
pub drained_packets: u32,
|
|
125
|
+
pub release_drained_packets: u32,
|
|
126
|
+
pub rejected_packets: u32,
|
|
127
|
+
pub buffering_entries: u32,
|
|
128
|
+
pub tail_flushes: u32,
|
|
129
|
+
pub clock_rebases: u32,
|
|
130
|
+
pub decode_failures: u32,
|
|
131
|
+
pub received_packets: u32,
|
|
132
|
+
pub missing_packets: u32,
|
|
133
|
+
// Successful received-packet decodes only (not PLC), per channel at 48 kHz.
|
|
134
|
+
// Min/max are zero if no packet was decoded in the interval.
|
|
135
|
+
pub decoded_packets: u32,
|
|
136
|
+
pub decoded_packet_samples: u32,
|
|
137
|
+
pub min_decoded_packet_samples: u32,
|
|
138
|
+
pub max_decoded_packet_samples: u32,
|
|
139
|
+
pub late_packets: u32,
|
|
140
|
+
pub duplicate_packets: u32,
|
|
141
|
+
pub reordered_packets: u32,
|
|
142
|
+
pub resyncs: u32,
|
|
143
|
+
pub resync_discarded_packets: u32,
|
|
144
|
+
// Observed read spacing, not network arrival time; includes ordinary pauses.
|
|
145
|
+
pub read_gaps_over_40ms: u32,
|
|
146
|
+
pub max_read_gap_ms: u32,
|
|
147
|
+
pub max_playout_lateness_us: u32,
|
|
148
|
+
pub bridge_frames: u32,
|
|
149
|
+
pub bridge_channel_full: u32,
|
|
150
|
+
pub bridge_sends_over_1ms: u32,
|
|
151
|
+
pub max_bridge_send_us: u32,
|
|
152
|
+
pub first_packet_ms: Option<u32>,
|
|
153
|
+
}
|
|
154
|
+
|
|
113
155
|
impl Command {
|
|
114
156
|
pub fn validate(&self) -> anyhow::Result<()> {
|
|
115
157
|
match self {
|