@archboard/codex-realtime-voice 0.4.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 +32 -41
- package/dist/browser.d.mts +1 -3
- package/dist/browser.mjs +67 -66
- package/dist/{contract-DTEwX7x-.d.mts → contract-B2ILifH5.d.mts} +3 -3
- package/dist/{contract-qg6q9-vH.d.mts → contract-CkitFygd.d.mts} +97 -3054
- package/dist/{contract-Cupd2jDS.d.mts → contract-D9_WuSxD.d.mts} +3 -3
- package/dist/contract.d.mts +1 -1
- package/dist/controllers.d.mts +221 -6
- package/dist/controllers.mjs +6 -4
- package/dist/{gateway-envelope-Ch4BsYcK.d.mts → gateway-envelope-O67wCRD7.d.mts} +4 -3
- package/dist/{realtime-state-CTBmCjt1.mjs → gateway-envelope-jUP82Pq1.mjs} +71 -3
- package/dist/identity-capabilities-3Q_2tJiT.d.mts +147 -0
- package/dist/instructions-B-6HVmoD.mjs +1024 -0
- package/dist/{contract-CZDUvuVt.d.mts → instructions-C6TkBWcp.d.mts} +14 -984
- package/dist/{model-YHUwnXnC.mjs → model-MSyAviwx.mjs} +1658 -78
- package/dist/react.d.mts +1 -1
- package/dist/{realtime-contract-wHmSyUIe.d.mts → realtime-contract-C-1bMn-F.d.mts} +1 -22
- package/dist/realtime.d.mts +2 -3
- package/dist/realtime.mjs +1 -3
- package/dist/runtime.d.mts +3 -18
- package/dist/runtime.mjs +2 -2
- package/dist/schemas.d.mts +3 -13
- package/dist/schemas.mjs +1 -1
- package/dist/server.d.mts +1082 -252
- package/dist/server.mjs +18278 -9849
- package/dist/{snapshot-BCrCORmt.d.mts → snapshot-DCl2vsJl.d.mts} +9 -154
- package/dist/{transport-CqOvXrAE.mjs → transport-DVUz3EK0.mjs} +17 -13
- package/package.json +2 -2
- package/dist/app-server-contract-D4E5bibD.mjs +0 -177
- package/dist/gateway-envelope-CODkg5rz.mjs +0 -43
- package/dist/instructions-CmBJHqpa.mjs +0 -8980
- package/dist/media-state-CakgDCk4.d.mts +0 -215
- package/dist/realtime-contract-DwkCluo2.mjs +0 -1167
- package/dist/realtime-state-DT4uvrIV.d.mts +0 -16
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { s as RealtimePhase } from "./realtime-contract-
|
|
3
|
-
import { n as BrowserWorkbenchCommandIntent, r as BrowserWorkbenchState, t as BrowserCommandDraft } from "./contract-
|
|
1
|
+
import { s as BrowserSnapshot } from "./snapshot-DCl2vsJl.mjs";
|
|
2
|
+
import { s as RealtimePhase } from "./realtime-contract-C-1bMn-F.mjs";
|
|
3
|
+
import { n as BrowserWorkbenchCommandIntent, r as BrowserWorkbenchState, t as BrowserCommandDraft } from "./contract-B2ILifH5.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* How a host connects one page view to the voice server. The tab session id
|
|
6
6
|
* lives in `sessionStorage`, so a reload keeps its conversation and another tab
|
package/dist/contract.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as BrowserSpokenApproval, d as BrowserWorkhorses, m as BrowserDynamicApproval, s as BrowserSnapshot, t as BrowserApproval, u as BrowserTimeline } from "./snapshot-DCl2vsJl.mjs";
|
|
2
2
|
export type { BrowserApproval, BrowserDynamicApproval, BrowserSnapshot, BrowserSpokenApproval, BrowserTimeline, BrowserWorkhorses };
|
package/dist/controllers.d.mts
CHANGED
|
@@ -1,14 +1,229 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as CodexLoginAccountParams, t as CodexCommandExecutionApprovalDecision } from "./contract-
|
|
3
|
-
import { r as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { m as LoginId, v as ThreadId } from "./identity-capabilities-3Q_2tJiT.mjs";
|
|
2
|
+
import { n as CodexLoginAccountParams, t as CodexCommandExecutionApprovalDecision } from "./contract-CkitFygd.mjs";
|
|
3
|
+
import { b as DYNAMIC_APPROVAL_DECISIONS, f as DeliveryOutcome, i as BrowserQueue, l as BrowserThreadLink, m as BrowserDynamicApproval, p as VoiceNarrative, r as BrowserCommandLease, s as BrowserSnapshot, t as BrowserApproval, u as BrowserTimeline } from "./snapshot-DCl2vsJl.mjs";
|
|
4
|
+
import { d as RealtimeState, i as RealtimeCorrelation, l as RealtimeServer, n as AppendOutcome, p as RealtimeUnsubscribe } from "./realtime-contract-C-1bMn-F.mjs";
|
|
5
|
+
import { r as BrowserGatewayErrorCode } from "./gateway-envelope-O67wCRD7.mjs";
|
|
6
|
+
import { a as BrowserWorkbenchTransportOptions, i as BrowserWorkbenchTransport, r as BrowserWorkbenchState } from "./contract-B2ILifH5.mjs";
|
|
6
7
|
/**
|
|
7
8
|
* Adapt one chat's server socket to the browser workbench gateway.
|
|
8
9
|
* @param transportOptions Clock and request-id sources.
|
|
9
10
|
* @returns The transport.
|
|
10
11
|
*/
|
|
11
12
|
declare function createBrowserWorkbenchTransport(transportOptions?: BrowserWorkbenchTransportOptions): BrowserWorkbenchTransport;
|
|
13
|
+
/** A playback stream is anything carrying audio tracks: a MediaStream, or the realtime module's remote stream port. */
|
|
14
|
+
interface VoiceOutputPlayback {
|
|
15
|
+
readonly getAudioTracks: () => ReadonlyArray<Pick<MediaStreamTrack, "readyState">>;
|
|
16
|
+
}
|
|
17
|
+
/** Whether the audio graph behind a meter is producing samples. */
|
|
18
|
+
type VoiceOutputPlaybackState = "running" | "suspended" | "closed";
|
|
19
|
+
/** One measured playback stream. `read` is called once per animation frame. */
|
|
20
|
+
interface VoiceOutputMeter {
|
|
21
|
+
/** The playback state right now; `suspended` means autoplay policy holds the graph. */
|
|
22
|
+
readonly playback: () => VoiceOutputPlaybackState;
|
|
23
|
+
/** Asks the graph to run; resolves whatever the resulting state is. */
|
|
24
|
+
readonly resume: () => Promise<void>;
|
|
25
|
+
/** The root-mean-square level of the latest output frame, 0..1. */
|
|
26
|
+
readonly read: () => number;
|
|
27
|
+
/** Releases the graph. Idempotent. */
|
|
28
|
+
readonly close: () => void;
|
|
29
|
+
}
|
|
30
|
+
/** Builds a meter over one playback stream, or null when the browser cannot analyse audio. */
|
|
31
|
+
type VoiceOutputMeterFactory = (playback: VoiceOutputPlayback) => VoiceOutputMeter | null;
|
|
32
|
+
/**
|
|
33
|
+
* Whether a published level counts as the model speaking.
|
|
34
|
+
* @param level The RMS level, 0..1.
|
|
35
|
+
* @returns True at or above the speaking level.
|
|
36
|
+
*/
|
|
37
|
+
declare function isSpeakingLevel(level: number): boolean;
|
|
38
|
+
/** Frame scheduling, injectable so a test can step frames by hand. */
|
|
39
|
+
interface VoiceOutputFrameScheduler {
|
|
40
|
+
readonly requestFrame: (callback: () => void) => number;
|
|
41
|
+
readonly cancelFrame: (handle: number) => void;
|
|
42
|
+
}
|
|
43
|
+
/** Receives every published level. */
|
|
44
|
+
type VoiceOutputLevelListener = (level: number) => void;
|
|
45
|
+
/** The measured model output level as an external store. */
|
|
46
|
+
interface VoiceOutputLevelSource {
|
|
47
|
+
/** The latest published level, 0..1. */
|
|
48
|
+
readonly current: () => number;
|
|
49
|
+
readonly subscribe: (listener: VoiceOutputLevelListener) => () => void;
|
|
50
|
+
/** Follows one playback meter, releasing any previous one. */
|
|
51
|
+
readonly follow: (meter: VoiceOutputMeter) => void;
|
|
52
|
+
/** Stops following, closes the meter, and settles the level to 0. */
|
|
53
|
+
readonly settle: () => void;
|
|
54
|
+
/** Settles and refuses further followers and subscribers. */
|
|
55
|
+
readonly dispose: () => void;
|
|
56
|
+
}
|
|
57
|
+
/** Something that raises named events; the DOM's EventTarget satisfies it. */
|
|
58
|
+
interface RealtimeEventSource {
|
|
59
|
+
addEventListener(type: string, listener: () => void): void;
|
|
60
|
+
removeEventListener(type: string, listener: () => void): void;
|
|
61
|
+
}
|
|
62
|
+
/** One captured or received audio track. */
|
|
63
|
+
interface RealtimeMediaTrack extends Pick<MediaStreamTrack, "enabled" | "readyState" | "stop">, RealtimeEventSource {}
|
|
64
|
+
/** A stream of tracks: the captured microphone, or the remote playback. */
|
|
65
|
+
interface RealtimeMediaStream {
|
|
66
|
+
getTracks(): readonly RealtimeMediaTrack[];
|
|
67
|
+
getAudioTracks(): readonly RealtimeMediaTrack[];
|
|
68
|
+
}
|
|
69
|
+
/** The realtime events channel. */
|
|
70
|
+
interface RealtimeDataChannel extends RealtimeEventSource {
|
|
71
|
+
readonly readyState: RTCDataChannelState;
|
|
72
|
+
close(): void;
|
|
73
|
+
}
|
|
74
|
+
/** One outbound sender on the peer. */
|
|
75
|
+
interface RealtimeSender {
|
|
76
|
+
readonly track: RealtimeMediaTrack | null;
|
|
77
|
+
replaceTrack(track: null): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
/** One inbound receiver on the peer. */
|
|
80
|
+
interface RealtimeReceiver {
|
|
81
|
+
readonly track: RealtimeMediaTrack;
|
|
82
|
+
}
|
|
83
|
+
/** The peer connection. */
|
|
84
|
+
interface RealtimePeer extends RealtimeEventSource {
|
|
85
|
+
readonly connectionState: RTCPeerConnectionState;
|
|
86
|
+
readonly iceConnectionState: RTCIceConnectionState;
|
|
87
|
+
readonly localDescription: Pick<RTCSessionDescription, "sdp"> | null;
|
|
88
|
+
addTransceiver(track: RealtimeMediaTrack, stream: RealtimeMediaStream): void;
|
|
89
|
+
createDataChannel(label: string): RealtimeDataChannel;
|
|
90
|
+
createOffer(): Promise<RTCSessionDescriptionInit>;
|
|
91
|
+
setLocalDescription(description: RTCSessionDescriptionInit): Promise<void>;
|
|
92
|
+
setRemoteDescription(description: RTCSessionDescriptionInit): Promise<void>;
|
|
93
|
+
getSenders(): readonly RealtimeSender[];
|
|
94
|
+
getReceivers(): readonly RealtimeReceiver[];
|
|
95
|
+
removeTrack(sender: RealtimeSender): void;
|
|
96
|
+
close(): void;
|
|
97
|
+
}
|
|
98
|
+
/** The microphone source. */
|
|
99
|
+
interface RealtimeMediaDevices extends RealtimeEventSource {
|
|
100
|
+
getUserMedia(constraints: MediaStreamConstraints): Promise<RealtimeMediaStream>;
|
|
101
|
+
}
|
|
102
|
+
/** One scheduled timer; cancelling one that already fired is harmless. */
|
|
103
|
+
interface RealtimeTimer {
|
|
104
|
+
readonly cancel: () => void;
|
|
105
|
+
}
|
|
106
|
+
/** Everything the media session needs from the browser. */
|
|
107
|
+
interface RealtimeMediaEnvironment {
|
|
108
|
+
/** Null when the browser cannot request a microphone at all. */
|
|
109
|
+
readonly mediaDevices: () => RealtimeMediaDevices | null;
|
|
110
|
+
/** True when WebRTC, MediaStream, Web Audio and animation frames all exist. */
|
|
111
|
+
readonly realtimeSupported: () => boolean;
|
|
112
|
+
readonly createPeerConnection: () => RealtimePeer;
|
|
113
|
+
readonly createMediaStream: (tracks: readonly RealtimeMediaTrack[]) => RealtimeMediaStream;
|
|
114
|
+
/** Makes the remote stream the element's source; the one place a stream meets an element. */
|
|
115
|
+
readonly attachPlayback: (element: HTMLMediaElement, stream: RealtimeMediaStream) => void;
|
|
116
|
+
/** Builds the output meter over the remote playback stream. */
|
|
117
|
+
readonly analysePlayback: VoiceOutputMeterFactory;
|
|
118
|
+
readonly frames: VoiceOutputFrameScheduler;
|
|
119
|
+
/** A monotonic clock in milliseconds. */
|
|
120
|
+
readonly now: () => number;
|
|
121
|
+
readonly schedule: (callback: () => void, delayMs: number) => RealtimeTimer;
|
|
122
|
+
}
|
|
123
|
+
/** The published view of the session: which run, and where it stands. */
|
|
124
|
+
interface RealtimeMediaSnapshot {
|
|
125
|
+
readonly correlation: RealtimeCorrelation | null;
|
|
126
|
+
readonly state: RealtimeState;
|
|
127
|
+
}
|
|
128
|
+
/** Receives every published snapshot. */
|
|
129
|
+
type RealtimeMediaListener = (snapshot: RealtimeMediaSnapshot) => void;
|
|
130
|
+
/** The session. There is one per media owner and no second voice backend. */
|
|
131
|
+
interface RealtimeMediaSession {
|
|
132
|
+
readonly getSnapshot: () => RealtimeMediaSnapshot;
|
|
133
|
+
readonly subscribe: (listener: RealtimeMediaListener) => RealtimeUnsubscribe;
|
|
134
|
+
readonly start: (correlation: RealtimeCorrelation) => Promise<RealtimeMediaSnapshot>;
|
|
135
|
+
/**
|
|
136
|
+
* Silences the captured microphone without touching the negotiated
|
|
137
|
+
* connection: every local audio track is disabled and the run publishes
|
|
138
|
+
* `muted`. The server receives nothing. A run that is not `listening` is left
|
|
139
|
+
* exactly as it is.
|
|
140
|
+
*/
|
|
141
|
+
readonly mute: () => Promise<RealtimeMediaSnapshot>;
|
|
142
|
+
/** The exact inverse of `mute`, from `muted` only. */
|
|
143
|
+
readonly unmute: () => Promise<RealtimeMediaSnapshot>;
|
|
144
|
+
readonly stop: () => Promise<RealtimeMediaSnapshot>;
|
|
145
|
+
readonly dispose: () => Promise<void>;
|
|
146
|
+
/** The measured model output level, on its own channel. Never the microphone. */
|
|
147
|
+
readonly outputLevel: VoiceOutputLevelSource;
|
|
148
|
+
}
|
|
149
|
+
/** Construction options; the browser environment is the default. */
|
|
150
|
+
interface RealtimeMediaSessionOptions {
|
|
151
|
+
readonly environment?: RealtimeMediaEnvironment;
|
|
152
|
+
/**
|
|
153
|
+
* Hears the voice's receivers once its remote audio is built, so a host can tune or measure
|
|
154
|
+
* how the voice is received: a recording buffers more of it than a conversation can.
|
|
155
|
+
*/
|
|
156
|
+
readonly receivers?: (receivers: readonly RealtimeReceiver[]) => void;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Creates the session.
|
|
160
|
+
* @param server The neutral realtime server.
|
|
161
|
+
* @param options The environment, when not the browser's own, and who hears the voice's receivers.
|
|
162
|
+
* @returns The session.
|
|
163
|
+
*/
|
|
164
|
+
declare function createRealtimeMediaSession(server: RealtimeServer, options?: RealtimeMediaSessionOptions): RealtimeMediaSession;
|
|
165
|
+
/** Where the owner stands: installing, ready to start, or why it cannot. */
|
|
166
|
+
type BrowserWorkbenchMediaState = {
|
|
167
|
+
readonly state: "attaching";
|
|
168
|
+
} | {
|
|
169
|
+
readonly state: "ready";
|
|
170
|
+
} | {
|
|
171
|
+
readonly state: "unavailable";
|
|
172
|
+
readonly reason: "detached" | "socket_closed" | "media_api_unavailable" | "permission_denied" | "negotiation_failed";
|
|
173
|
+
readonly message: string;
|
|
174
|
+
};
|
|
175
|
+
/** Owns local realtime media while the workbench transport owns the server socket. */
|
|
176
|
+
interface BrowserWorkbenchMediaOwner {
|
|
177
|
+
readonly attach: (transport: BrowserWorkbenchTransport) => Promise<BrowserWorkbenchMediaState>;
|
|
178
|
+
readonly detach: (transport: BrowserWorkbenchTransport) => Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Starts realtime media, as an ordinary session or one that presents a host narrative.
|
|
181
|
+
* @param narrative The narrative the session presents, when there is one.
|
|
182
|
+
*/
|
|
183
|
+
readonly start: (narrative?: VoiceNarrative | null) => Promise<RealtimeMediaSnapshot>;
|
|
184
|
+
readonly appendText: (text: string) => Promise<AppendOutcome>;
|
|
185
|
+
/**
|
|
186
|
+
* Silences and restores the captured microphone. Neither claims a lease nor
|
|
187
|
+
* sends a command: the realtime session disables the local audio track it
|
|
188
|
+
* already owns, so there is no wire operation to authorize. The forwarded
|
|
189
|
+
* subscription is what publishes the resulting phase.
|
|
190
|
+
*/
|
|
191
|
+
readonly mute: () => Promise<RealtimeMediaSnapshot>;
|
|
192
|
+
readonly unmute: () => Promise<RealtimeMediaSnapshot>;
|
|
193
|
+
readonly stop: () => Promise<RealtimeMediaSnapshot>;
|
|
194
|
+
readonly snapshot: () => RealtimeMediaSnapshot | null;
|
|
195
|
+
readonly state: () => BrowserWorkbenchMediaState;
|
|
196
|
+
/** The active session's measured model output level, or null between sessions. */
|
|
197
|
+
readonly outputLevel: () => RealtimeMediaSession["outputLevel"] | null;
|
|
198
|
+
/**
|
|
199
|
+
* Fires whenever `snapshot()` or `state()` may have changed, including the
|
|
200
|
+
* browser-originated realtime publications that reach only the inner
|
|
201
|
+
* realtime session: a lost microphone, a dropped ICE connection, a closed
|
|
202
|
+
* data channel, and every in-start phase.
|
|
203
|
+
*/
|
|
204
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
205
|
+
readonly dispose: () => Promise<void>;
|
|
206
|
+
}
|
|
207
|
+
/** Construction options; every default is the real browser. */
|
|
208
|
+
interface BrowserWorkbenchMediaOwnerOptions {
|
|
209
|
+
readonly createMediaSession?: typeof createRealtimeMediaSession;
|
|
210
|
+
readonly environment?: RealtimeMediaEnvironment;
|
|
211
|
+
/** Where the remote audio element comes from and is mounted. */
|
|
212
|
+
readonly audioElements?: BrowserAudioElementPort;
|
|
213
|
+
/** Hears the voice's receivers once its remote audio is built. */
|
|
214
|
+
readonly receivers?: RealtimeMediaSessionOptions["receivers"];
|
|
215
|
+
/** Whether this browser can carry realtime media at all. */
|
|
216
|
+
readonly mediaSupported?: () => boolean;
|
|
217
|
+
}
|
|
218
|
+
/** Creates and mounts the remote audio element. */
|
|
219
|
+
interface BrowserAudioElementPort {
|
|
220
|
+
readonly create: () => HTMLAudioElement;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The real browser's audio elements.
|
|
224
|
+
* @returns The port.
|
|
225
|
+
*/
|
|
226
|
+
declare function browserAudioElements(): BrowserAudioElementPort;
|
|
12
227
|
/**
|
|
13
228
|
* Creates the owner.
|
|
14
229
|
* @param options The construction options.
|
|
@@ -585,4 +800,4 @@ declare function projectTimelineTurns(timeline: BrowserTimeline, owner: Conversa
|
|
|
585
800
|
* @returns The turns, with each delegated one told whether its delegating turn is among them.
|
|
586
801
|
*/
|
|
587
802
|
declare function mergeConversation(workhorse: readonly ConversationTurn[], coordinator: readonly ConversationTurn[]): readonly ConversationTurn[];
|
|
588
|
-
export { type ApprovalChoice, type BrowserAudioElementPort, type BrowserWorkbenchMediaOwner, type BrowserWorkbenchState, type BrowserWorkbenchTransport, type ConversationControllers, type ConversationTurn,
|
|
803
|
+
export { type ApprovalChoice, type BrowserAudioElementPort, type BrowserWorkbenchMediaOwner, type BrowserWorkbenchState, type BrowserWorkbenchTransport, type ConversationControllers, type ConversationTurn, type VoiceOutputLevelSource, browserAudioElements, createBrowserWorkbenchMediaOwner, createBrowserWorkbenchTransport, createConversationControllers, isSpeakingLevel, mergeConversation, projectTimelineTurns };
|
package/dist/controllers.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
1
|
+
import { t as BROWSER_GATEWAY_ERROR_CODES } from "./gateway-envelope-jUP82Pq1.mjs";
|
|
2
|
+
import { a as isSpeakingLevel, i as browserAudioElements, n as BrowserWorkbenchTransportError, r as createBrowserWorkbenchMediaOwner, t as createBrowserWorkbenchTransport } from "./transport-DVUz3EK0.mjs";
|
|
3
3
|
// src/ui/approval-forms/rules/fields.ts
|
|
4
4
|
const QUESTION_PREFIX = "question:";
|
|
5
5
|
const ELICITATION_PREFIX = "field:";
|
|
@@ -2439,7 +2439,9 @@ const TRANSPORT_REFUSALS = {
|
|
|
2439
2439
|
response_lost: "The server never answered, so the command's outcome is unknown.",
|
|
2440
2440
|
replaced: "Another workbench connection replaced this one before the command was sent.",
|
|
2441
2441
|
invalid_command: "The server refused this command for the workhorse's current state. Read the timeline, then send again.",
|
|
2442
|
-
gateway_error: "The server refused this command."
|
|
2442
|
+
gateway_error: "The server refused this command.",
|
|
2443
|
+
work_stopping: "The workhorse is stopping, or its last stop did not show that all work ended. Before you send new work, press Stop while it shows, or ask the voice coordinator to stop the work.",
|
|
2444
|
+
stop_unconfirmed: "Some work of this workhorse or its sub-agents still runs or could not be read. Press Stop again while it shows, or ask the voice coordinator to stop the work."
|
|
2443
2445
|
};
|
|
2444
2446
|
const GENERIC_TRANSPORT_REFUSAL = "The server refused this workhorse command.";
|
|
2445
2447
|
/**
|
|
@@ -4751,4 +4753,4 @@ function mergeConversation(workhorse, coordinator) {
|
|
|
4751
4753
|
const shown = new Set(coordinator.map((turn) => turn.turnId));
|
|
4752
4754
|
return [...placed(coordinator), ...placed(workhorse)].toSorted(byTime).map(({ turn }) => withDelegationShown(turn, shown));
|
|
4753
4755
|
}
|
|
4754
|
-
export {
|
|
4756
|
+
export { browserAudioElements, createBrowserWorkbenchMediaOwner, createBrowserWorkbenchTransport, createConversationControllers, isSpeakingLevel, mergeConversation, projectTimelineTurns };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { c as BrowserCommandId, y as TurnId } from "./identity-capabilities-3Q_2tJiT.mjs";
|
|
2
|
+
import { f as DeliveryOutcome, s as BrowserSnapshot } from "./snapshot-DCl2vsJl.mjs";
|
|
3
|
+
import { t as AnswerSdp } from "./realtime-contract-C-1bMn-F.mjs";
|
|
4
|
+
declare const BROWSER_GATEWAY_ERROR_CODES: readonly ["disposed", "invalid_input", "invalid_command", "invalid_projection", "not_ready", "thread_capability_required", "link_required", "link_changed", "lease_required", "lease_expired", "lease_released", "lease_transferred", "child_disconnected", "approval_not_pending", "dynamic_approval_not_pending", "unsupported_command", "command_failed", "outcome_unknown", "work_stopping", "stop_unconfirmed"];
|
|
4
5
|
type BrowserGatewayErrorCode = (typeof BROWSER_GATEWAY_ERROR_CODES)[number];
|
|
5
6
|
interface BrowserGatewaySnapshotMessage {
|
|
6
7
|
readonly kind: "snapshot";
|
|
@@ -1,5 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { c as WAITS, l as lengthOf } from "./model-MSyAviwx.mjs";
|
|
2
|
+
// ../timing/src/shared/operations/timers.ts
|
|
3
|
+
/**
|
|
4
|
+
* Let the process exit while a background timer is pending.
|
|
5
|
+
* @param wait The delay or cadence.
|
|
6
|
+
* @param timer The timer.
|
|
7
|
+
*/
|
|
8
|
+
function unrefBackground(wait, timer) {
|
|
9
|
+
if (!("background" in WAITS[wait])) return;
|
|
10
|
+
if (typeof timer === "object" && timer !== null && "unref" in timer) {
|
|
11
|
+
if (typeof timer.unref === "function") timer.unref();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Run something once after a declared delay. The timer carries the delay's name, so a test
|
|
16
|
+
* preload can shorten it by name. A background delay lets its process exit.
|
|
17
|
+
* @param wait The delay.
|
|
18
|
+
* @param run What to run.
|
|
19
|
+
* @returns Cancels the run, if it has not happened.
|
|
20
|
+
*/
|
|
21
|
+
function after(wait, run) {
|
|
22
|
+
const timer = setTimeout(() => run(), lengthOf(wait), wait);
|
|
23
|
+
unrefBackground(wait, timer);
|
|
24
|
+
return () => clearTimeout(timer);
|
|
25
|
+
}
|
|
26
|
+
Object.freeze([
|
|
3
27
|
"idle",
|
|
4
28
|
"requesting_permission",
|
|
5
29
|
"negotiating",
|
|
@@ -179,4 +203,48 @@ function transitionRealtimeState(current, next) {
|
|
|
179
203
|
assertRealtimeTransition(current, next);
|
|
180
204
|
return Object.freeze({ ...next });
|
|
181
205
|
}
|
|
182
|
-
|
|
206
|
+
// src/shared/protocol/gateway-envelope.ts
|
|
207
|
+
const BROWSER_GATEWAY_ERROR_CODES = [
|
|
208
|
+
"disposed",
|
|
209
|
+
"invalid_input",
|
|
210
|
+
"invalid_command",
|
|
211
|
+
"invalid_projection",
|
|
212
|
+
"not_ready",
|
|
213
|
+
"thread_capability_required",
|
|
214
|
+
"link_required",
|
|
215
|
+
"link_changed",
|
|
216
|
+
"lease_required",
|
|
217
|
+
"lease_expired",
|
|
218
|
+
"lease_released",
|
|
219
|
+
"lease_transferred",
|
|
220
|
+
"child_disconnected",
|
|
221
|
+
"approval_not_pending",
|
|
222
|
+
"dynamic_approval_not_pending",
|
|
223
|
+
"unsupported_command",
|
|
224
|
+
"command_failed",
|
|
225
|
+
"outcome_unknown",
|
|
226
|
+
"work_stopping",
|
|
227
|
+
"stop_unconfirmed"
|
|
228
|
+
];
|
|
229
|
+
/** Every snapshot field a delta may carry, in snapshot order. */
|
|
230
|
+
const BROWSER_SNAPSHOT_DELTA_KEYS = [
|
|
231
|
+
"readiness",
|
|
232
|
+
"account",
|
|
233
|
+
"login",
|
|
234
|
+
"threadLink",
|
|
235
|
+
"timeline",
|
|
236
|
+
"queue",
|
|
237
|
+
"settings",
|
|
238
|
+
"approvals",
|
|
239
|
+
"dynamicApprovals",
|
|
240
|
+
"contextDelivery",
|
|
241
|
+
"coordinator",
|
|
242
|
+
"voice",
|
|
243
|
+
"spokenApproval",
|
|
244
|
+
"voiceContext",
|
|
245
|
+
"coordinatorTimeline",
|
|
246
|
+
"workhorses",
|
|
247
|
+
"lease",
|
|
248
|
+
"operation"
|
|
249
|
+
];
|
|
250
|
+
export { transitionRealtimeState as a, canTransitionRealtimeState as i, BROWSER_SNAPSHOT_DELTA_KEYS as n, after as o, INITIAL_REALTIME_STATE as r, BROWSER_GATEWAY_ERROR_CODES as t };
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
declare const identityBrand: unique symbol;
|
|
2
|
+
type IdentityDomain = "child" | "epoch" | "browser-command" | "thread" | "turn" | "item" | "queued-submission" | "login" | "json-rpc-request" | "dynamic-tool-call" | "realtime-session" | "approval" | "operation";
|
|
3
|
+
type BrandedIdentity<Domain extends IdentityDomain> = string & {
|
|
4
|
+
readonly [identityBrand]: Domain;
|
|
5
|
+
};
|
|
6
|
+
type JsonRpcRequestIdWireValue = string | number;
|
|
7
|
+
type ChildId = BrandedIdentity<"child">;
|
|
8
|
+
type ChildEpoch = BrandedIdentity<"epoch">;
|
|
9
|
+
type BrowserCommandId = BrandedIdentity<"browser-command">;
|
|
10
|
+
type ThreadId = BrandedIdentity<"thread">;
|
|
11
|
+
type TurnId = BrandedIdentity<"turn">;
|
|
12
|
+
type ItemId = BrandedIdentity<"item">;
|
|
13
|
+
type QueuedSubmissionId = BrandedIdentity<"queued-submission">;
|
|
14
|
+
type LoginId = BrandedIdentity<"login">;
|
|
15
|
+
type JsonRpcRequestId = BrandedIdentity<"json-rpc-request">;
|
|
16
|
+
type DynamicToolCallId = BrandedIdentity<"dynamic-tool-call">;
|
|
17
|
+
type RealtimeSessionId = BrandedIdentity<"realtime-session">;
|
|
18
|
+
type ApprovalId = BrandedIdentity<"approval">;
|
|
19
|
+
/** A server-issued workbench mutation correlation, bound to one child epoch. */
|
|
20
|
+
type OperationId = BrandedIdentity<"operation">;
|
|
21
|
+
type AnyIdentity = ChildId | ChildEpoch | BrowserCommandId | ThreadId | TurnId | ItemId | QueuedSubmissionId | LoginId | JsonRpcRequestId | DynamicToolCallId | RealtimeSessionId | ApprovalId | OperationId;
|
|
22
|
+
/** Identities that may appear in Codex requests or reverse requests. */
|
|
23
|
+
type CodexIdentity = ThreadId | TurnId | ItemId | QueuedSubmissionId | LoginId | JsonRpcRequestId | DynamicToolCallId | ApprovalId;
|
|
24
|
+
interface WireRequestCorrelation {
|
|
25
|
+
readonly child: ChildId;
|
|
26
|
+
readonly epoch: ChildEpoch;
|
|
27
|
+
readonly requestId: JsonRpcRequestId;
|
|
28
|
+
}
|
|
29
|
+
interface LogicalToolCallCorrelation {
|
|
30
|
+
readonly child: ChildId;
|
|
31
|
+
readonly epoch: ChildEpoch;
|
|
32
|
+
readonly threadId: ThreadId;
|
|
33
|
+
readonly turnId: TurnId;
|
|
34
|
+
readonly callId: DynamicToolCallId;
|
|
35
|
+
readonly namespace: string;
|
|
36
|
+
readonly tool: string;
|
|
37
|
+
readonly manifestHash: string;
|
|
38
|
+
}
|
|
39
|
+
interface WireRequestCorrelationInput {
|
|
40
|
+
readonly requestId: JsonRpcRequestId;
|
|
41
|
+
}
|
|
42
|
+
interface LogicalToolCallCorrelationInput {
|
|
43
|
+
readonly threadId: ThreadId;
|
|
44
|
+
readonly turnId: TurnId;
|
|
45
|
+
readonly callId: DynamicToolCallId;
|
|
46
|
+
readonly namespace: string;
|
|
47
|
+
readonly tool: string;
|
|
48
|
+
readonly manifestHash: string;
|
|
49
|
+
}
|
|
50
|
+
/** Raw server identities collected from one decoded app-server response. */
|
|
51
|
+
interface CodexResponseIdentityBatch {
|
|
52
|
+
readonly threadIds?: readonly unknown[];
|
|
53
|
+
readonly turnIds?: readonly unknown[];
|
|
54
|
+
readonly itemIds?: readonly unknown[];
|
|
55
|
+
readonly queuedSubmissionIds?: readonly unknown[];
|
|
56
|
+
readonly loginIds?: readonly unknown[];
|
|
57
|
+
}
|
|
58
|
+
/** Branded identities returned in the same order as one response batch. */
|
|
59
|
+
interface AdoptedCodexResponseIdentityBatch {
|
|
60
|
+
readonly threadIds: readonly ThreadId[];
|
|
61
|
+
readonly turnIds: readonly TurnId[];
|
|
62
|
+
readonly itemIds: readonly ItemId[];
|
|
63
|
+
readonly queuedSubmissionIds: readonly QueuedSubmissionId[];
|
|
64
|
+
readonly loginIds: readonly LoginId[];
|
|
65
|
+
}
|
|
66
|
+
interface IdentityValidator {
|
|
67
|
+
readonly childId: ChildId;
|
|
68
|
+
readonly epoch: ChildEpoch;
|
|
69
|
+
readonly isCurrentEpoch: (child: ChildId, epoch: ChildEpoch) => boolean;
|
|
70
|
+
readonly assertCurrentEpoch: (child: ChildId, epoch: ChildEpoch) => void;
|
|
71
|
+
}
|
|
72
|
+
/** The only capability ordinary mutation owners need to validate an OperationId. */
|
|
73
|
+
interface OperationIdValidator {
|
|
74
|
+
readonly isCurrentOperationId: (operationId: OperationId) => boolean;
|
|
75
|
+
readonly assertCurrentOperationId: (operationId: OperationId) => void;
|
|
76
|
+
}
|
|
77
|
+
/** Server-owned IDs are minted here; app-server-owned IDs can only enter via the trusted decoder. */
|
|
78
|
+
interface IdentityIssuer {
|
|
79
|
+
readonly mintBrowserCommandId: () => BrowserCommandId;
|
|
80
|
+
readonly mintJsonRpcRequestId: () => JsonRpcRequestId;
|
|
81
|
+
readonly mintRealtimeSessionId: () => RealtimeSessionId;
|
|
82
|
+
readonly mintChildEpoch: () => ChildEpoch;
|
|
83
|
+
}
|
|
84
|
+
/** The only capability that can issue a server-owned OperationId. */
|
|
85
|
+
interface OperationIdIssuer {
|
|
86
|
+
readonly mintOperationId: () => OperationId;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* This capability is passed only to protocol decoders. Its adoption methods
|
|
90
|
+
* are deliberately absent from IdentityValidator and IdentityIssuer.
|
|
91
|
+
*/
|
|
92
|
+
interface TrustedIdentityDecoder {
|
|
93
|
+
readonly parseChildId: (value: unknown) => ChildId;
|
|
94
|
+
readonly parseChildEpoch: (value: unknown) => ChildEpoch;
|
|
95
|
+
readonly parseBrowserCommandId: (value: unknown) => BrowserCommandId;
|
|
96
|
+
readonly parseThreadId: (value: unknown) => ThreadId;
|
|
97
|
+
readonly parseTurnId: (value: unknown) => TurnId;
|
|
98
|
+
readonly parseItemId: (value: unknown) => ItemId;
|
|
99
|
+
readonly parseQueuedSubmissionId: (value: unknown) => QueuedSubmissionId;
|
|
100
|
+
readonly parseLoginId: (value: unknown) => LoginId;
|
|
101
|
+
readonly parseJsonRpcRequestId: (value: unknown) => JsonRpcRequestId;
|
|
102
|
+
readonly parseDynamicToolCallId: (value: unknown) => DynamicToolCallId;
|
|
103
|
+
readonly parseRealtimeSessionId: (value: unknown) => RealtimeSessionId;
|
|
104
|
+
readonly parseApprovalId: (value: unknown) => ApprovalId;
|
|
105
|
+
/** Resolves a raw Codex thread id only when this authority already issued it. */
|
|
106
|
+
readonly resolveThreadId: (raw: unknown) => ThreadId;
|
|
107
|
+
/** Resolves a raw Codex item id only when this authority already issued it. */
|
|
108
|
+
readonly resolveItemId: (raw: unknown) => ItemId;
|
|
109
|
+
readonly adoptThreadId: (raw: unknown) => ThreadId;
|
|
110
|
+
readonly adoptTurnId: (raw: unknown) => TurnId;
|
|
111
|
+
readonly adoptItemId: (raw: unknown) => ItemId;
|
|
112
|
+
readonly adoptQueuedSubmissionId: (raw: unknown) => QueuedSubmissionId;
|
|
113
|
+
readonly adoptLoginId: (raw: unknown) => LoginId;
|
|
114
|
+
readonly adoptJsonRpcRequestId: (raw: unknown) => JsonRpcRequestId;
|
|
115
|
+
readonly adoptDynamicToolCallId: (raw: unknown) => DynamicToolCallId;
|
|
116
|
+
readonly adoptApprovalId: (raw: unknown) => ApprovalId;
|
|
117
|
+
/** Validates a complete decoded response before adopting any identity from it. */
|
|
118
|
+
readonly adoptCodexResponseIdentities: (batch: CodexResponseIdentityBatch) => AdoptedCodexResponseIdentityBatch;
|
|
119
|
+
readonly serializeCodexIdentity: (identity: CodexIdentity) => string;
|
|
120
|
+
readonly serializeJsonRpcRequestId: (identity: JsonRpcRequestId) => JsonRpcRequestIdWireValue;
|
|
121
|
+
readonly createWireRequestCorrelation: (input: WireRequestCorrelationInput) => WireRequestCorrelation;
|
|
122
|
+
readonly parseWireRequestCorrelation: (value: unknown) => WireRequestCorrelation;
|
|
123
|
+
readonly createLogicalToolCallCorrelation: (input: LogicalToolCallCorrelationInput) => LogicalToolCallCorrelation;
|
|
124
|
+
readonly parseLogicalToolCallCorrelation: (value: unknown) => LogicalToolCallCorrelation;
|
|
125
|
+
}
|
|
126
|
+
/** Trusted protocol code may parse and serialize, but never adopt, OperationIds. */
|
|
127
|
+
interface TrustedOperationIdDecoder {
|
|
128
|
+
readonly parseOperationId: (value: unknown) => OperationId;
|
|
129
|
+
readonly serializeOperationId: (identity: OperationId) => string;
|
|
130
|
+
}
|
|
131
|
+
/** The complete operation capability is composed only at the authority boundary. */
|
|
132
|
+
interface OperationAuthority {
|
|
133
|
+
readonly validator: OperationIdValidator;
|
|
134
|
+
readonly issuer: OperationIdIssuer;
|
|
135
|
+
readonly decoder: TrustedOperationIdDecoder;
|
|
136
|
+
}
|
|
137
|
+
interface IdentityAuthority {
|
|
138
|
+
readonly validator: IdentityValidator;
|
|
139
|
+
readonly issuer: IdentityIssuer;
|
|
140
|
+
readonly decoder: TrustedIdentityDecoder;
|
|
141
|
+
}
|
|
142
|
+
/** The factory return type composes legacy identity capabilities with operation capabilities. */
|
|
143
|
+
interface IdentityAuthorities {
|
|
144
|
+
readonly identity: IdentityAuthority;
|
|
145
|
+
readonly operation: OperationAuthority;
|
|
146
|
+
}
|
|
147
|
+
export { RealtimeSessionId as _, WireRequestCorrelation as a, BrowserCommandId as c, DynamicToolCallId as d, ItemId as f, QueuedSubmissionId as g, OperationId as h, LogicalToolCallCorrelation as i, ChildEpoch as l, LoginId as m, IdentityAuthority as n, AnyIdentity as o, JsonRpcRequestId as p, OperationAuthority as r, ApprovalId as s, IdentityAuthorities as t, ChildId as u, ThreadId as v, TurnId as y };
|