@archboard/codex-realtime-voice 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +621 -2
- package/dist/app-server-contract-D4E5bibD.mjs +177 -0
- package/dist/browser.d.mts +10 -0
- package/dist/browser.mjs +475 -0
- package/dist/contract-CZDUvuVt.d.mts +19587 -0
- package/dist/contract-Cupd2jDS.d.mts +131 -0
- package/dist/contract-DTEwX7x-.d.mts +164 -0
- package/dist/contract-qg6q9-vH.d.mts +6905 -0
- package/dist/contract.d.mts +2 -0
- package/dist/contract.mjs +1 -0
- package/dist/controllers.d.mts +588 -0
- package/dist/controllers.mjs +4754 -0
- package/dist/gateway-envelope-CODkg5rz.mjs +43 -0
- package/dist/gateway-envelope-Ch4BsYcK.d.mts +36 -0
- package/dist/instructions-CmBJHqpa.mjs +8980 -0
- package/dist/media-state-CakgDCk4.d.mts +215 -0
- package/dist/model-YHUwnXnC.mjs +2808 -0
- package/dist/react.d.mts +34 -0
- package/dist/react.mjs +49 -0
- package/dist/realtime-contract-DwkCluo2.mjs +1167 -0
- package/dist/realtime-contract-wHmSyUIe.d.mts +150 -0
- package/dist/realtime-state-CTBmCjt1.mjs +182 -0
- package/dist/realtime-state-DT4uvrIV.d.mts +16 -0
- package/dist/realtime.d.mts +3 -0
- package/dist/realtime.mjs +3 -0
- package/dist/runtime.d.mts +93 -0
- package/dist/runtime.mjs +289 -0
- package/dist/schemas.d.mts +7075 -0
- package/dist/schemas.mjs +1 -0
- package/dist/server.d.mts +1374 -0
- package/dist/server.mjs +38224 -0
- package/dist/snapshot-BCrCORmt.d.mts +8597 -0
- package/dist/transport-CqOvXrAE.mjs +5168 -0
- package/package.json +71 -5
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { p as BrowserSnapshot } from "./snapshot-BCrCORmt.mjs";
|
|
2
|
+
import { s as RealtimePhase } from "./realtime-contract-wHmSyUIe.mjs";
|
|
3
|
+
import { n as BrowserWorkbenchCommandIntent, r as BrowserWorkbenchState, t as BrowserCommandDraft } from "./contract-DTEwX7x-.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* How a host connects one page view to the voice server. The tab session id
|
|
6
|
+
* lives in `sessionStorage`, so a reload keeps its conversation and another tab
|
|
7
|
+
* gets its own.
|
|
8
|
+
*/
|
|
9
|
+
interface VoiceClientOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The server's socket path, or a full URL. A path resolves against the page
|
|
12
|
+
* location, and `http:` or `https:` becomes `ws:` or `wss:`.
|
|
13
|
+
*/
|
|
14
|
+
readonly socketPath: string;
|
|
15
|
+
/** The view in the host page that shows this conversation. Defaults to `main`. */
|
|
16
|
+
readonly chatId?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Why the last action failed. */
|
|
19
|
+
interface VoiceClientFailure {
|
|
20
|
+
/** Plain words for the failure. */
|
|
21
|
+
readonly message: string;
|
|
22
|
+
/**
|
|
23
|
+
* The action may have reached the server. Refresh before trying again,
|
|
24
|
+
* because a blind retry could do it twice.
|
|
25
|
+
*/
|
|
26
|
+
readonly uncertain: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** The voice run of the coordinator, as the page shows it. */
|
|
29
|
+
interface VoiceClientVoice {
|
|
30
|
+
/** Where the voice run stands; `idle` when none runs. */
|
|
31
|
+
readonly phase: RealtimePhase;
|
|
32
|
+
/** A new voice run can start in this browser and connection. */
|
|
33
|
+
readonly available: boolean;
|
|
34
|
+
/** Why voice cannot start or why the last run failed, or null. */
|
|
35
|
+
readonly problem: string | null;
|
|
36
|
+
}
|
|
37
|
+
/** One ordinary approval request that the server shows. */
|
|
38
|
+
type VoiceApproval = BrowserSnapshot["approvals"][number];
|
|
39
|
+
/** The answer to one approval, spelled by the app-server method it settles. */
|
|
40
|
+
type VoiceApprovalResponse = Extract<BrowserCommandDraft, {
|
|
41
|
+
readonly command: "approvalRespond";
|
|
42
|
+
}>["response"];
|
|
43
|
+
/** How the account signs in. */
|
|
44
|
+
type VoiceSignIn = Extract<BrowserCommandDraft, {
|
|
45
|
+
readonly command: "accountLogin";
|
|
46
|
+
}>["login"];
|
|
47
|
+
/**
|
|
48
|
+
* What the page showed when it offered an action. Pass the `intent` of the
|
|
49
|
+
* state that rendered an approval back with its answer: the server refuses the
|
|
50
|
+
* answer, rather than retargeting it, if the conversation moved since.
|
|
51
|
+
*/
|
|
52
|
+
type VoiceCommandIntent = BrowserWorkbenchCommandIntent;
|
|
53
|
+
/** The one state the client publishes. Each publication is a new frozen object. */
|
|
54
|
+
interface VoiceClientSnapshot {
|
|
55
|
+
/** The socket to the server. */
|
|
56
|
+
readonly connection: BrowserWorkbenchState["connection"];
|
|
57
|
+
/**
|
|
58
|
+
* What the server last published: the account, the sign-in, the thread
|
|
59
|
+
* link, the workhorse timeline, approvals, queue and the voice transcript.
|
|
60
|
+
* Null before the first publication.
|
|
61
|
+
*/
|
|
62
|
+
readonly server: BrowserSnapshot | null;
|
|
63
|
+
/** The coordinator's voice run. */
|
|
64
|
+
readonly voice: VoiceClientVoice;
|
|
65
|
+
/** An action is running. Only the two stops run during another action. */
|
|
66
|
+
readonly busy: boolean;
|
|
67
|
+
/** Why the last action failed, or null. The next action clears it when it starts. */
|
|
68
|
+
readonly failure: VoiceClientFailure | null;
|
|
69
|
+
/** The intent that binds an answer to the approvals of this state, or null while none can be sent. */
|
|
70
|
+
readonly intent: VoiceCommandIntent | null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* One page view's connection to the voice server. Every action resolves true
|
|
74
|
+
* when it completed. It resolves false when it failed, and the failure is then
|
|
75
|
+
* in the published state. It also resolves false, and changes nothing, after
|
|
76
|
+
* `dispose` or while another action runs; only `stopVoice` and `stopWork` run
|
|
77
|
+
* during another action.
|
|
78
|
+
*/
|
|
79
|
+
interface VoiceClient {
|
|
80
|
+
/**
|
|
81
|
+
* Open the socket with the tab's session id, or open it again. After a
|
|
82
|
+
* socket that was open closes, the client reconnects by itself: `connection`
|
|
83
|
+
* reads `reconnecting`, the client opens a new socket after a short wait,
|
|
84
|
+
* and it tries again after each attempt that fails, until one opens or the
|
|
85
|
+
* client is disposed. A socket that the server closes before its first
|
|
86
|
+
* snapshot also counts as open, and `failure` names the server's reason. The
|
|
87
|
+
* attempts leave an action's failure as it is, so an uncertain delivery stays
|
|
88
|
+
* visible; an attempt that opens clears the failure of a `connect` that did
|
|
89
|
+
* not. A server whose contract this browser cannot read ends them:
|
|
90
|
+
* `connection` reads `stopped`, and `failure` says why unless it already
|
|
91
|
+
* holds another failure. A first `connect` whose socket never opens is not
|
|
92
|
+
* retried; the host calls `connect` again.
|
|
93
|
+
*/
|
|
94
|
+
readonly connect: () => Promise<boolean>;
|
|
95
|
+
/** Read the server's current state again without repeating a command. */
|
|
96
|
+
readonly refresh: () => Promise<boolean>;
|
|
97
|
+
/** Start a sign-in. Defaults to the private ChatGPT sign-in. */
|
|
98
|
+
readonly signIn: (login?: VoiceSignIn) => Promise<boolean>;
|
|
99
|
+
/** Cancel the pending sign-in. */
|
|
100
|
+
readonly cancelSignIn: () => Promise<boolean>;
|
|
101
|
+
/** Sign the account out. */
|
|
102
|
+
readonly signOut: () => Promise<boolean>;
|
|
103
|
+
/** Send a message to the workhorse, creating its conversation on first use. */
|
|
104
|
+
readonly send: (message: string) => Promise<boolean>;
|
|
105
|
+
/** Start the coordinator's voice, creating the conversation on first use. */
|
|
106
|
+
readonly startVoice: () => Promise<boolean>;
|
|
107
|
+
/** Stop voice. The workhorse keeps working. Runs during another action. */
|
|
108
|
+
readonly stopVoice: () => Promise<boolean>;
|
|
109
|
+
/** Silence or restore the microphone of the running voice. */
|
|
110
|
+
readonly setMuted: (muted: boolean) => Promise<boolean>;
|
|
111
|
+
/** Interrupt the workhorse's running turn. Voice keeps running. Runs during another action. */
|
|
112
|
+
readonly stopWork: () => Promise<boolean>;
|
|
113
|
+
/**
|
|
114
|
+
* Answer one approval that the page showed.
|
|
115
|
+
* @param approval The request from the rendered state.
|
|
116
|
+
* @param response The answer.
|
|
117
|
+
* @param intent The `intent` of the state that rendered the request.
|
|
118
|
+
*/
|
|
119
|
+
readonly answerApproval: (approval: VoiceApproval, response: VoiceApprovalResponse, intent: VoiceCommandIntent) => Promise<boolean>;
|
|
120
|
+
/** The current state; the same object until the next publication. */
|
|
121
|
+
readonly snapshot: () => VoiceClientSnapshot;
|
|
122
|
+
/** Hear every publication. Returns the unsubscribe. */
|
|
123
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
124
|
+
/**
|
|
125
|
+
* Stop voice, release the socket and end every subscription. A disposed
|
|
126
|
+
* client never connects again, so a host that mounts twice, as React
|
|
127
|
+
* StrictMode does, creates a client for each mount.
|
|
128
|
+
*/
|
|
129
|
+
readonly dispose: () => Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
export { VoiceClientSnapshot as a, VoiceClientOptions as i, VoiceApprovalResponse as n, VoiceSignIn as o, VoiceClient as r, VoiceApproval as t };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { h as BrowserThreadLink, i as BrowserCommandLease, p as BrowserSnapshot, r as BrowserCommand, u as BrowserReadiness } from "./snapshot-BCrCORmt.mjs";
|
|
2
|
+
import { a as CodexServerResponseByMethod, n as CodexLoginAccountParams } from "./contract-qg6q9-vH.mjs";
|
|
3
|
+
import { a as BrowserGatewaySnapshotMessage, n as BrowserGatewayCommandResult, t as BrowserGatewayAccountReadResult } from "./gateway-envelope-Ch4BsYcK.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* The browser socket as the transport sees it. The application owns opening and closing it.
|
|
6
|
+
*/
|
|
7
|
+
interface BrowserWorkbenchSocket extends EventTarget {
|
|
8
|
+
readonly readyState: number;
|
|
9
|
+
readonly send: (data: string) => void;
|
|
10
|
+
}
|
|
11
|
+
type BrowserWorkbenchSnapshotMessage = BrowserGatewaySnapshotMessage;
|
|
12
|
+
type BrowserWorkbenchCommandResult = BrowserGatewayCommandResult;
|
|
13
|
+
type BrowserWorkbenchAccountReadResult = BrowserGatewayAccountReadResult;
|
|
14
|
+
type SupportedLoginVariant = "apiKey" | "chatgpt" | "amazonBedrock" | "amazonBedrockAccessKeys";
|
|
15
|
+
type BrowserLoginParams = Extract<CodexLoginAccountParams, {
|
|
16
|
+
readonly type: SupportedLoginVariant;
|
|
17
|
+
}>;
|
|
18
|
+
type BrowserApprovalKind = BrowserSnapshot["approvals"][number]["approvalKind"];
|
|
19
|
+
type BrowserApprovalResponseFor<Kind extends BrowserApprovalKind, Method extends keyof CodexServerResponseByMethod> = Readonly<{
|
|
20
|
+
approvalKind: Kind;
|
|
21
|
+
}> & CodexServerResponseByMethod[Method];
|
|
22
|
+
/** The answer to an ordinary approval, spelled by the app-server method it settles. */
|
|
23
|
+
type BrowserApprovalResponse = BrowserApprovalResponseFor<"command_execution", "item/commandExecution/requestApproval"> | BrowserApprovalResponseFor<"file_change", "item/fileChange/requestApproval"> | BrowserApprovalResponseFor<"user_input", "item/tool/requestUserInput"> | BrowserApprovalResponseFor<"elicitation", "mcpServer/elicitation/request"> | BrowserApprovalResponseFor<"permissions", "item/permissions/requestApproval"> | BrowserApprovalResponseFor<"apply_patch", "applyPatchApproval"> | BrowserApprovalResponseFor<"exec_command", "execCommandApproval">;
|
|
24
|
+
type BrowserIntentCommand = Exclude<BrowserCommand, {
|
|
25
|
+
readonly command: "accountLogin" | "approvalRespond";
|
|
26
|
+
}> | (Omit<Extract<BrowserCommand, {
|
|
27
|
+
readonly command: "accountLogin";
|
|
28
|
+
}>, "login"> & {
|
|
29
|
+
readonly login: BrowserLoginParams;
|
|
30
|
+
}) | (Omit<Extract<BrowserCommand, {
|
|
31
|
+
readonly command: "approvalRespond";
|
|
32
|
+
}>, "response"> & {
|
|
33
|
+
readonly response: BrowserApprovalResponse;
|
|
34
|
+
});
|
|
35
|
+
type BrowserCommandName = BrowserIntentCommand["command"];
|
|
36
|
+
/** A command as a caller composes it: the wire command without its authority fields. */
|
|
37
|
+
type BrowserCommandDraft = { [CommandName in BrowserCommandName]: Omit<Extract<BrowserIntentCommand, {
|
|
38
|
+
readonly command: CommandName;
|
|
39
|
+
}>, "kind" | "commandId" | "chatId" | "childId" | "epoch">; }[BrowserCommandName];
|
|
40
|
+
/** The authority fields every wire command carries, taken from the active lease. */
|
|
41
|
+
type BrowserCommandAuthority = Pick<BrowserCommandLease, "commandId" | "chatId" | "childId" | "epoch">;
|
|
42
|
+
/** The lease identity plus the thread link the command was composed against. */
|
|
43
|
+
interface BrowserWorkbenchCommandTarget extends BrowserCommandAuthority {
|
|
44
|
+
readonly capturedThreadLink: BrowserThreadLink;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A displayed action's link, captured without acquiring command authority.
|
|
48
|
+
* Capture and execute through the same transport; copied or invented intents
|
|
49
|
+
* are refused because they cannot prove the socket generation they came from.
|
|
50
|
+
*/
|
|
51
|
+
interface BrowserWorkbenchCommandIntent {
|
|
52
|
+
readonly capturedThreadLink: BrowserThreadLink;
|
|
53
|
+
/** Exact authority, when present, is retained only for request-bound decisions. */
|
|
54
|
+
readonly authority: BrowserWorkbenchCommandTarget | null;
|
|
55
|
+
}
|
|
56
|
+
/** The transport while no socket, or no usable socket, is attached. */
|
|
57
|
+
interface BrowserWorkbenchStoppedState {
|
|
58
|
+
readonly kind: "connection";
|
|
59
|
+
readonly state: "stopped";
|
|
60
|
+
readonly connection: "stopped";
|
|
61
|
+
readonly snapshot: null;
|
|
62
|
+
readonly sequence: null;
|
|
63
|
+
readonly reason: string;
|
|
64
|
+
}
|
|
65
|
+
/** The transport between attach and the subscribe baseline. */
|
|
66
|
+
interface BrowserWorkbenchReconnectingState {
|
|
67
|
+
readonly kind: "connection";
|
|
68
|
+
readonly state: "reconnecting";
|
|
69
|
+
readonly connection: "reconnecting";
|
|
70
|
+
readonly snapshot: BrowserSnapshot | null;
|
|
71
|
+
readonly sequence: number | null;
|
|
72
|
+
readonly reason: string;
|
|
73
|
+
}
|
|
74
|
+
/** The transport after its socket closed, waiting for its owner to attach a new socket. */
|
|
75
|
+
interface BrowserWorkbenchBackoffState {
|
|
76
|
+
readonly kind: "connection";
|
|
77
|
+
readonly state: "backoff";
|
|
78
|
+
readonly connection: "reconnecting";
|
|
79
|
+
readonly snapshot: BrowserSnapshot | null;
|
|
80
|
+
readonly sequence: number | null;
|
|
81
|
+
readonly retryAtMs: number;
|
|
82
|
+
readonly reason: string;
|
|
83
|
+
}
|
|
84
|
+
/** The stream skipped or contradicted itself; a recovery snapshot is on its way. */
|
|
85
|
+
interface BrowserWorkbenchStaleState {
|
|
86
|
+
readonly kind: "stream";
|
|
87
|
+
readonly state: "stale_snapshot";
|
|
88
|
+
readonly connection: "connected";
|
|
89
|
+
readonly snapshot: BrowserSnapshot | null;
|
|
90
|
+
readonly sequence: number | null;
|
|
91
|
+
readonly expectedSequence: number;
|
|
92
|
+
readonly receivedSequence: number;
|
|
93
|
+
readonly reason: string;
|
|
94
|
+
}
|
|
95
|
+
/** The server spoke a contract this browser cannot read; nothing recovers it. */
|
|
96
|
+
interface BrowserWorkbenchIncompatibleState {
|
|
97
|
+
readonly kind: "connection";
|
|
98
|
+
readonly state: "incompatible_contract";
|
|
99
|
+
readonly connection: "stopped";
|
|
100
|
+
readonly snapshot: null;
|
|
101
|
+
readonly sequence: null;
|
|
102
|
+
readonly reason: string;
|
|
103
|
+
}
|
|
104
|
+
/** A published snapshot, named by the server's readiness. */
|
|
105
|
+
interface BrowserWorkbenchReadinessState {
|
|
106
|
+
readonly kind: "readiness";
|
|
107
|
+
readonly state: BrowserReadiness["state"];
|
|
108
|
+
readonly connection: "connected";
|
|
109
|
+
readonly snapshot: BrowserSnapshot;
|
|
110
|
+
readonly sequence: number;
|
|
111
|
+
}
|
|
112
|
+
/** The one state the transport publishes. */
|
|
113
|
+
type BrowserWorkbenchState = BrowserWorkbenchStoppedState | BrowserWorkbenchReconnectingState | BrowserWorkbenchBackoffState | BrowserWorkbenchStaleState | BrowserWorkbenchIncompatibleState | BrowserWorkbenchReadinessState;
|
|
114
|
+
/** What the workbench may ask for right now. */
|
|
115
|
+
interface BrowserWorkbenchCapabilities {
|
|
116
|
+
readonly connected: boolean;
|
|
117
|
+
readonly readiness: BrowserReadiness["state"] | null;
|
|
118
|
+
readonly canReadAccount: boolean;
|
|
119
|
+
readonly canClaimLease: boolean;
|
|
120
|
+
readonly canRenewLease: boolean;
|
|
121
|
+
readonly canReleaseLease: boolean;
|
|
122
|
+
/** The linked workbench can accept a human action and acquire its authority. */
|
|
123
|
+
readonly canCommand: boolean;
|
|
124
|
+
readonly canThreadCommands: boolean;
|
|
125
|
+
readonly canRealtime: boolean;
|
|
126
|
+
/** Human actions include authority acquisition; realtime start and dynamic responses require an exact lease. */
|
|
127
|
+
readonly supportsCommand: (command: BrowserCommandName) => boolean;
|
|
128
|
+
}
|
|
129
|
+
/** One transport over one chat socket at a time. */
|
|
130
|
+
interface BrowserWorkbenchTransport {
|
|
131
|
+
readonly attach: (socket: BrowserWorkbenchSocket) => Promise<BrowserWorkbenchState>;
|
|
132
|
+
readonly detach: (socket?: BrowserWorkbenchSocket) => Promise<void>;
|
|
133
|
+
readonly close: () => Promise<void>;
|
|
134
|
+
readonly refresh: () => Promise<BrowserWorkbenchSnapshotMessage>;
|
|
135
|
+
readonly setMediaReady: (ready: boolean) => Promise<BrowserWorkbenchSnapshotMessage>;
|
|
136
|
+
readonly claimLease: () => Promise<BrowserCommandLease>;
|
|
137
|
+
readonly renewLease: () => Promise<BrowserCommandLease>;
|
|
138
|
+
readonly releaseLease: () => Promise<BrowserCommandLease | null>;
|
|
139
|
+
readonly accountRead: () => Promise<BrowserWorkbenchAccountReadResult>;
|
|
140
|
+
/**
|
|
141
|
+
* Pass the target captured when the action was offered — the approval that
|
|
142
|
+
* was rendered, the queue row that was dragged — and the command is refused
|
|
143
|
+
* rather than retargeted if the workbench has moved since. `queueAdd`
|
|
144
|
+
* requires one: it names neither a thread nor a submission.
|
|
145
|
+
*/
|
|
146
|
+
readonly command: (draft: BrowserCommandDraft, target?: BrowserWorkbenchCommandTarget) => Promise<BrowserWorkbenchCommandResult>;
|
|
147
|
+
/** Human actions acquire fresh authority once, revalidate their intent, then dispatch once. */
|
|
148
|
+
readonly executeCommand: (draft: BrowserCommandDraft, intent?: BrowserWorkbenchCommandIntent) => Promise<BrowserWorkbenchCommandResult>;
|
|
149
|
+
readonly captureCommandIntent: () => BrowserWorkbenchCommandIntent;
|
|
150
|
+
readonly captureCommandTarget: () => BrowserWorkbenchCommandTarget;
|
|
151
|
+
readonly snapshot: () => BrowserSnapshot | null;
|
|
152
|
+
readonly sequence: () => number | null;
|
|
153
|
+
readonly lease: () => BrowserCommandLease | null;
|
|
154
|
+
readonly state: () => BrowserWorkbenchState;
|
|
155
|
+
readonly capabilities: () => BrowserWorkbenchCapabilities;
|
|
156
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
157
|
+
readonly dispose: () => Promise<void>;
|
|
158
|
+
}
|
|
159
|
+
/** Clock and request-id sources, overridable by tests. */
|
|
160
|
+
interface BrowserWorkbenchTransportOptions {
|
|
161
|
+
readonly now?: () => number;
|
|
162
|
+
readonly requestId?: () => string;
|
|
163
|
+
}
|
|
164
|
+
export { BrowserWorkbenchTransportOptions as a, BrowserWorkbenchTransport as i, BrowserWorkbenchCommandIntent as n, BrowserWorkbenchState as r, BrowserCommandDraft as t };
|