@thegitai/cli 1.6.0 → 1.8.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 CHANGED
@@ -29,6 +29,8 @@ This package is the CLI. The same agent is also available as a
29
29
  - **Beyond source code** - reads PDF, Word and Excel files, edits Word
30
30
  documents, looks at screenshots, generates images, and searches and fetches
31
31
  the web.
32
+ - **Voice dictation** - run `/voice`, then hold Space and talk. Your words appear in the prompt as you speak, and nothing is sent until you press Enter.
33
+ - **Keyboard shortcuts** - open `/keybindings` to edit the keys for mode switching, image paste, background jobs, notifications, and dictation. Saved changes apply in the current session.
32
34
  - **Steering and recovery** - send corrections while it works, switch between
33
35
  Default, Bypass all permissions and Plan modes, and undo an edit, a turn or a
34
36
  file, or restore a checkpoint.
@@ -0,0 +1,96 @@
1
+ import { createTraceContext, failureCode, failureDetails, failureMessage, normalizeServerUrl, readJsonResponse, ServerApiError, } from './http.js';
2
+ const TRANSCRIBE_TIMEOUT_MS = 90_000;
3
+ export async function transcribeRecording({ config, audio, hints = [], signal, fetchImpl = globalThis.fetch, }) {
4
+ const trace = createTraceContext();
5
+ const timeout = AbortSignal.timeout(TRANSCRIBE_TIMEOUT_MS);
6
+ const response = await fetchImpl(`${normalizeServerUrl(config.serverUrl)}/v1/voice/transcribe`, {
7
+ method: 'POST',
8
+ headers: {
9
+ authorization: `Bearer ${config.token}`,
10
+ ...trace.headers,
11
+ 'content-type': 'audio/wav',
12
+ ...(hints.length ? { 'x-thegitai-voice-hints': encodeURIComponent(JSON.stringify(hints)) } : {}),
13
+ },
14
+ body: new Uint8Array(audio),
15
+ signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
16
+ });
17
+ const data = await readJsonResponse(response);
18
+ if (!response.ok) {
19
+ throw new ServerApiError(failureMessage(data, response.status), response.status, trace.traceId, failureCode(data), failureDetails(data));
20
+ }
21
+ return typeof data?.text === 'string' ? data.text : '';
22
+ }
23
+ export function openVoiceStream({ config, onText, WebSocketImpl = globalThis.WebSocket, }) {
24
+ if (typeof WebSocketImpl !== 'function')
25
+ return null;
26
+ let socket;
27
+ try {
28
+ socket = new WebSocketImpl(`${normalizeServerUrl(config.serverUrl).replace(/^http/i, 'ws')}/v1/voice/stream`);
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ socket.binaryType = 'arraybuffer';
34
+ const queued = [];
35
+ let open = false;
36
+ let ready = false;
37
+ let closed = false;
38
+ socket.addEventListener('open', () => {
39
+ if (closed) {
40
+ socket.close();
41
+ return;
42
+ }
43
+ open = true;
44
+ socket.send(JSON.stringify({ type: 'start', token: config.token }));
45
+ });
46
+ socket.addEventListener('message', (event) => {
47
+ if (closed || typeof event.data !== 'string')
48
+ return;
49
+ let message = null;
50
+ try {
51
+ message = JSON.parse(event.data);
52
+ }
53
+ catch {
54
+ return;
55
+ }
56
+ if (message?.type === 'ready' && !ready) {
57
+ ready = true;
58
+ for (const chunk of queued.splice(0))
59
+ socket.send(chunk);
60
+ }
61
+ else if (message?.type === 'text' && typeof message.text === 'string') {
62
+ onText(message.text);
63
+ }
64
+ });
65
+ socket.addEventListener('error', () => {
66
+ closed = true;
67
+ });
68
+ socket.addEventListener('close', () => {
69
+ closed = true;
70
+ });
71
+ return {
72
+ send(chunk) {
73
+ if (closed)
74
+ return;
75
+ const copy = new Uint8Array(chunk);
76
+ if (ready)
77
+ socket.send(copy);
78
+ else
79
+ queued.push(copy);
80
+ },
81
+ close() {
82
+ if (closed)
83
+ return;
84
+ closed = true;
85
+ if (open) {
86
+ try {
87
+ socket.send(JSON.stringify({ type: 'stop' }));
88
+ }
89
+ catch {
90
+ return;
91
+ }
92
+ }
93
+ socket.close();
94
+ },
95
+ };
96
+ }