agent-loft 0.2.113 → 0.2.115
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 +1 -1
- package/package.json +3 -1
- package/src/agents/codex/session.ts +31 -3
- package/src/channels/web/server.ts +69 -11
- package/src/core/hub.ts +3 -2
- package/src/core/realtime-relay.ts +142 -0
- package/src/core/types.ts +4 -1
- package/web/css/composer.css +4 -159
- package/web/css/voice-call.css +196 -0
- package/web/index.html +1 -0
- package/web/lib/rt-worklet.js +110 -0
- package/web/lib/ws.js +5 -2
- package/web/views/composer.js +10 -4
- package/web/views/voice-call.js +343 -83
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/* 语音对话:沉浸式光球与收起后的通话条。音频逻辑共用 views/voice-call.js。 */
|
|
2
|
+
.call-btn[hidden] { display: none; }
|
|
3
|
+
|
|
4
|
+
.call-dialog {
|
|
5
|
+
position: fixed;
|
|
6
|
+
inset: 0;
|
|
7
|
+
width: 100%;
|
|
8
|
+
max-width: none;
|
|
9
|
+
height: 100%;
|
|
10
|
+
height: 100dvh;
|
|
11
|
+
max-height: none;
|
|
12
|
+
margin: 0;
|
|
13
|
+
padding: 0;
|
|
14
|
+
border: 0;
|
|
15
|
+
background: var(--bg);
|
|
16
|
+
color: var(--fg);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.call-dialog::backdrop { background: var(--bg); }
|
|
20
|
+
|
|
21
|
+
.call-panel {
|
|
22
|
+
--call-blue: #2686ec;
|
|
23
|
+
position: relative;
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-direction: column;
|
|
26
|
+
align-items: center;
|
|
27
|
+
width: 100%;
|
|
28
|
+
height: 100%;
|
|
29
|
+
overflow-y: auto;
|
|
30
|
+
overscroll-behavior: contain;
|
|
31
|
+
padding: max(24px, env(safe-area-inset-top)) 40px max(28px, env(safe-area-inset-bottom));
|
|
32
|
+
background: radial-gradient(ellipse at 50% 40%, color-mix(in srgb, #8bc8ff 7%, transparent), transparent 60%), var(--bg);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.call-header {
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
gap: 16px;
|
|
39
|
+
width: 100%;
|
|
40
|
+
flex-shrink: 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.call-brand { display: flex; align-items: center; gap: 12px; font-size: 17px; font-weight: 600; line-height: 1.3; }
|
|
44
|
+
.call-brand small { display: block; margin-top: 4px; font-size: 11px; font-weight: 400; color: var(--fg-faint); letter-spacing: 0.12em; }
|
|
45
|
+
.call-brand-icon { display: grid; place-items: center; width: 40px; height: 40px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 14px; }
|
|
46
|
+
.call-brand-icon svg { width: 22px; height: 22px; }
|
|
47
|
+
.call-session { display: flex; align-items: center; gap: 7px; margin-left: auto; color: var(--fg-soft); font-size: 12px; font-variant-numeric: tabular-nums; }
|
|
48
|
+
.call-live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--call-blue); }
|
|
49
|
+
.connecting .call-live-dot { animation: call-dot 1.4s ease-in-out infinite; }
|
|
50
|
+
.call-minimize { border: 1px solid var(--border); border-radius: 50%; width: 40px; height: 40px; }
|
|
51
|
+
|
|
52
|
+
.call-main { flex: 1 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; min-height: 310px; padding: 24px 0; }
|
|
53
|
+
.call-stage { display: grid; place-items: center; width: 100%; padding: 30px 0 42px; }
|
|
54
|
+
|
|
55
|
+
/* 叠加的云层在球面内流动,用 transform 合成动画,实际音量控制整个球的缩放。 */
|
|
56
|
+
.call-orb {
|
|
57
|
+
--voice-scale: 1;
|
|
58
|
+
position: relative;
|
|
59
|
+
width: clamp(170px, 28vh, 280px);
|
|
60
|
+
aspect-ratio: 1;
|
|
61
|
+
flex-shrink: 0;
|
|
62
|
+
transform: scale(var(--voice-scale));
|
|
63
|
+
transition: transform 160ms ease-out, opacity 0.5s, filter 0.5s;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.call-orb::before {
|
|
67
|
+
content: "";
|
|
68
|
+
position: absolute;
|
|
69
|
+
inset: -12%;
|
|
70
|
+
border-radius: 50%;
|
|
71
|
+
background: radial-gradient(circle, #56b7ff33, #80c8ff0d 60%, transparent 72%);
|
|
72
|
+
filter: blur(12px);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.call-orb-surface {
|
|
76
|
+
position: absolute;
|
|
77
|
+
inset: 0;
|
|
78
|
+
isolation: isolate;
|
|
79
|
+
overflow: hidden;
|
|
80
|
+
border-radius: 50%;
|
|
81
|
+
background: radial-gradient(circle at 30% 20%, #f7fcff 5%, #dbf4ff 22%, #79c9ff 52%, #2588ed 78%, #1b68c5 100%);
|
|
82
|
+
box-shadow: inset 0 0 28px #ffffff80, inset -10px -16px 30px #276bd833, 0 10px 60px #3697ef1c;
|
|
83
|
+
animation: call-float 7s ease-in-out infinite;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.call-orb-surface::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: radial-gradient(ellipse at 32% 12%, #fff9, transparent 55%); box-shadow: inset 0 0 3px #fff8; }
|
|
87
|
+
.call-orb-cloud { position: absolute; inset: -35%; border-radius: 44% 56% 62% 38%; filter: blur(16px); will-change: transform; }
|
|
88
|
+
.cloud-a { background: conic-gradient(from 40deg, transparent 8%, #f8fdff 28%, #dbf5ffb3 38%, transparent 55%, #1976e8cc 76%, transparent); animation: call-flow 14s linear infinite; }
|
|
89
|
+
.cloud-b { inset: -25%; background: conic-gradient(from 160deg, #fff0 10%, #e4faffcc 22%, #fff0 40%, #2787e9b3 60%, #fff0 82%); animation: call-flow 19s linear infinite reverse; }
|
|
90
|
+
.cloud-c { inset: 14% -35% -40%; background: radial-gradient(ellipse, #006ce7b3 10%, #3da7ff80 35%, transparent 64%); animation: call-drift 8s ease-in-out infinite alternate; }
|
|
91
|
+
.speaking .cloud-a { animation-duration: 5s; }
|
|
92
|
+
.speaking .cloud-b { animation-duration: 7s; }
|
|
93
|
+
.connecting .call-orb { opacity: 0.55; }
|
|
94
|
+
.muted .call-orb { filter: saturate(0.3); }
|
|
95
|
+
.processing .call-orb-surface { animation-duration: 3s; }
|
|
96
|
+
|
|
97
|
+
.call-info { text-align: center; }
|
|
98
|
+
.call-status { display: block; font-size: 23px; font-weight: 500; letter-spacing: -0.02em; }
|
|
99
|
+
.call-hint { margin: 8px 0 0; color: var(--fg-faint); font-size: 13px; }
|
|
100
|
+
.call-caption { width: min(620px, 100%); min-height: 88px; max-height: min(22vh, 180px); overflow-y: auto; text-align: center; padding: 8px 12px 20px; scrollbar-width: thin; flex-shrink: 0; }
|
|
101
|
+
.call-who { display: block; color: var(--fg-faint); font-size: 12px; margin-bottom: 8px; }
|
|
102
|
+
.call-text { font-size: clamp(17px, 2.3vw, 22px); line-height: 1.7; overflow-wrap: anywhere; white-space: pre-wrap; }
|
|
103
|
+
.call-footer { display: flex; flex-direction: column; align-items: center; gap: 22px; padding-top: 22px; flex-shrink: 0; }
|
|
104
|
+
.call-ctls { display: flex; align-items: flex-start; justify-content: center; gap: 24px; }
|
|
105
|
+
.call-control { display: flex; flex-direction: column; align-items: center; gap: 9px; }
|
|
106
|
+
.call-control > span { font-size: 11px; color: var(--fg-faint); }
|
|
107
|
+
.call-ctl { display: inline-grid; place-items: center; width: 56px; height: 56px; flex-shrink: 0; border: 1px solid var(--border); border-radius: 50%; background: var(--bg-soft); color: var(--fg); transition: background 0.18s, transform 0.18s; }
|
|
108
|
+
.call-ctl:hover { background: var(--bg-hover); transform: translateY(-2px); }
|
|
109
|
+
.call-ctl svg { width: 22px; height: 22px; }
|
|
110
|
+
.call-ctl.on { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--bg)); border-color: color-mix(in srgb, var(--danger) 20%, var(--border)); }
|
|
111
|
+
.call-ctl.active { color: var(--call-blue); border-color: var(--call-blue); }
|
|
112
|
+
.call-end { background: color-mix(in srgb, var(--danger) 10%, var(--bg)); color: var(--danger); border-color: transparent; }
|
|
113
|
+
.call-end:hover { background: color-mix(in srgb, var(--danger) 18%, var(--bg)); }
|
|
114
|
+
.call-panel :is(button, select):focus-visible { outline: 2px solid var(--call-blue); outline-offset: 4px; }
|
|
115
|
+
.call-footer-note { color: var(--fg-faint); font-size: 11px; }
|
|
116
|
+
.call-expand { display: none; }
|
|
117
|
+
|
|
118
|
+
.call-opts { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 20px; width: min(620px, 100%); padding: 16px; flex-shrink: 0; border: 1px solid var(--border); background: var(--bg-soft); border-radius: 18px; }
|
|
119
|
+
.call-opts[hidden] { display: none; }
|
|
120
|
+
.call-opt { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 13px; color: var(--fg-soft); }
|
|
121
|
+
.call-opt > span { flex-shrink: 0; }
|
|
122
|
+
.call-opt select { max-width: 205px; min-width: 0; border: 1px solid var(--border); border-radius: 9px; padding: 7px; background: var(--bg-input); font-size: 13px; }
|
|
123
|
+
.call-opts-hint { width: 100%; text-align: center; font-size: 11px; color: var(--fg-faint); }
|
|
124
|
+
|
|
125
|
+
/* 展开设置时给字幕和操作留出空间,小屏上挂断按钮始终留在视口内。 */
|
|
126
|
+
.call-panel:not(.compact):has(.call-opts:not([hidden])) .call-main { min-height: 210px; padding: 12px 0; }
|
|
127
|
+
.call-panel:not(.compact):has(.call-opts:not([hidden])) .call-stage { padding: 8px 0 20px; }
|
|
128
|
+
.call-panel:not(.compact):has(.call-opts:not([hidden])) .call-orb { width: clamp(100px, 16vh, 160px); }
|
|
129
|
+
.call-panel:not(.compact):has(.call-opts:not([hidden])) .call-caption { min-height: 48px; max-height: 100px; }
|
|
130
|
+
|
|
131
|
+
/* 收起时继续通话,保留光球、状态、字幕和全部操作。 */
|
|
132
|
+
.call-panel.compact { display: grid; grid-template-columns: minmax(0, 1fr) auto; height: auto; overflow: visible; padding: 14px 16px; border: 1px solid var(--border); border-radius: 24px; background: var(--bg-input); box-shadow: var(--shadow); }
|
|
133
|
+
.compact .call-header, .compact .call-hint, .compact .call-footer-note, .compact .call-control > span { display: none; }
|
|
134
|
+
.compact .call-main { grid-column: 1; grid-row: 1; min-height: 0; padding: 0; flex-direction: row; justify-content: flex-start; gap: 14px; }
|
|
135
|
+
.compact .call-stage { width: auto; padding: 0; }
|
|
136
|
+
.compact .call-orb { width: 42px; }
|
|
137
|
+
.compact .call-orb-cloud { filter: blur(4px); }
|
|
138
|
+
.compact .call-info { min-width: 0; text-align: left; }
|
|
139
|
+
.compact .call-status { font-size: 13px; }
|
|
140
|
+
.compact .call-footer { grid-column: 2; grid-row: 1; padding: 0; }
|
|
141
|
+
.compact .call-ctls { gap: 6px; align-items: center; }
|
|
142
|
+
.compact .call-ctl { width: 36px; height: 36px; }
|
|
143
|
+
.compact .call-ctl svg { width: 17px; height: 17px; }
|
|
144
|
+
.compact .call-expand { display: inline-grid; }
|
|
145
|
+
.compact .call-caption { display: none; grid-column: 1 / -1; padding: 12px 0 0; margin-top: 12px; min-height: 0; max-height: 100px; border-top: 1px solid var(--border); text-align: left; }
|
|
146
|
+
.compact.has-caption .call-caption { display: block; }
|
|
147
|
+
.compact .call-who { display: inline; margin-right: 8px; }
|
|
148
|
+
.compact .call-text { font-size: 13px; }
|
|
149
|
+
.compact .call-opts { grid-column: 1 / -1; grid-row: 3; width: 100%; margin-top: 12px; }
|
|
150
|
+
|
|
151
|
+
@keyframes call-flow { to { transform: rotate(360deg); } }
|
|
152
|
+
@keyframes call-float { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }
|
|
153
|
+
@keyframes call-drift { from { transform: translate(-10%, 6%) rotate(-20deg); } to { transform: translate(16%, -15%) rotate(30deg); } }
|
|
154
|
+
@keyframes call-dot { 50% { opacity: 0.3; } }
|
|
155
|
+
|
|
156
|
+
@media (prefers-color-scheme: dark) {
|
|
157
|
+
.call-panel { background: radial-gradient(ellipse at 50% 40%, #123e6526, transparent 60%), var(--bg); }
|
|
158
|
+
.call-orb-surface { box-shadow: inset 0 0 28px #ffffff70, inset -10px -16px 30px #276bd855, 0 0 80px #3697ef26; }
|
|
159
|
+
.call-panel.compact { background: var(--bg-input); }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@media (max-width: 640px) {
|
|
163
|
+
.call-panel { padding: max(18px, env(safe-area-inset-top)) 20px max(22px, env(safe-area-inset-bottom)); }
|
|
164
|
+
.call-main { min-height: 270px; }
|
|
165
|
+
.call-stage { padding: 20px 0 36px; }
|
|
166
|
+
.call-status { font-size: 21px; }
|
|
167
|
+
.call-caption { min-height: 90px; }
|
|
168
|
+
.call-ctls { gap: 22px; }
|
|
169
|
+
.call-opts { gap: 12px; }
|
|
170
|
+
.call-opt { width: 100%; justify-content: space-between; }
|
|
171
|
+
.call-opt select { flex: 1; max-width: 240px; }
|
|
172
|
+
.call-panel.compact { padding: 12px; }
|
|
173
|
+
.compact .call-main { gap: 10px; }
|
|
174
|
+
.compact .call-status { font-size: 12px; }
|
|
175
|
+
.compact .call-orb { width: 30px; }
|
|
176
|
+
.compact .call-ctls { gap: 4px; }
|
|
177
|
+
.compact .call-ctl { width: 36px; height: 36px; }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@media (max-height: 600px) {
|
|
181
|
+
.call-panel:not(.compact) { padding-top: 12px; padding-bottom: 12px; }
|
|
182
|
+
.call-main { min-height: 170px; padding: 8px 0; }
|
|
183
|
+
.call-orb { width: 110px; }
|
|
184
|
+
.call-stage { padding: 12px 0 16px; }
|
|
185
|
+
.call-caption { min-height: 40px; max-height: 80px; padding-bottom: 8px; }
|
|
186
|
+
.call-footer { padding-top: 8px; gap: 8px; }
|
|
187
|
+
.call-ctl { width: 44px; height: 44px; }
|
|
188
|
+
.call-panel:not(.compact):has(.call-opts:not([hidden])) .call-main { display: none; }
|
|
189
|
+
.call-panel:not(.compact):has(.call-opts:not([hidden])) .call-caption { min-height: 0; max-height: 50px; padding: 4px; }
|
|
190
|
+
.call-panel:not(.compact):has(.call-opts:not([hidden])) .call-opts { margin-top: auto; padding: 10px; gap: 8px 16px; }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@media (prefers-reduced-motion: reduce) {
|
|
194
|
+
.call-panel *, .call-panel *::before, .call-panel *::after { animation: none !important; transition: none !important; }
|
|
195
|
+
.call-orb { transform: none; }
|
|
196
|
+
}
|
package/web/index.html
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
<link rel="stylesheet" href="/css/albums.css" />
|
|
23
23
|
<link rel="stylesheet" href="/css/loader.css" />
|
|
24
24
|
<link rel="stylesheet" href="/css/composer.css" />
|
|
25
|
+
<link rel="stylesheet" href="/css/voice-call.css" />
|
|
25
26
|
<link rel="stylesheet" href="/css/overlay.css" />
|
|
26
27
|
<link rel="stylesheet" href="/css/search.css" />
|
|
27
28
|
<link rel="stylesheet" href="/css/settings.css" />
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// 语音对话的音频处理(AudioWorklet,跑在音频线程里)。声音经服务器中转:两头都是 24kHz、16 位、单声道的 PCM。
|
|
2
|
+
// rt-capture:麦克风 → 重采样到 24kHz → 每 20ms 一块 Int16 发给主线程(主线程走 WebSocket 发给服务器)
|
|
3
|
+
// rt-play:服务器发来的 Int16 24kHz → 攒一点缓冲 → 重采样到 AudioContext 的采样率放出来
|
|
4
|
+
|
|
5
|
+
const RATE = 24000;
|
|
6
|
+
const CHUNK = 480; // 20ms
|
|
7
|
+
|
|
8
|
+
class Capture extends AudioWorkletProcessor {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.step = sampleRate / RATE; // 每出一个 24kHz 采样,输入前进多少
|
|
12
|
+
this.pos = 0; // 下一个输出采样在输入里的位置(相对 prev 之后)
|
|
13
|
+
this.prev = 0; // 上一块的最后一个采样,插值跨块用
|
|
14
|
+
this.out = new Int16Array(CHUNK);
|
|
15
|
+
this.n = 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
process(inputs) {
|
|
19
|
+
const input = inputs[0]?.[0];
|
|
20
|
+
if (!input) return true;
|
|
21
|
+
// 多声道输入只取第一路就够(getUserMedia 一般是单声道)
|
|
22
|
+
const len = input.length;
|
|
23
|
+
// 位置 -1 对应 prev,0..len-1 对应 input
|
|
24
|
+
while (this.pos < len) {
|
|
25
|
+
const i = Math.floor(this.pos);
|
|
26
|
+
const f = this.pos - i;
|
|
27
|
+
const a = i < 0 ? this.prev : input[i];
|
|
28
|
+
const b = i + 1 < len ? input[i + 1] : input[len - 1];
|
|
29
|
+
let v = a + (b - a) * f;
|
|
30
|
+
v = v < -1 ? -1 : v > 1 ? 1 : v;
|
|
31
|
+
this.out[this.n++] = v < 0 ? v * 0x8000 : v * 0x7fff;
|
|
32
|
+
if (this.n === CHUNK) {
|
|
33
|
+
this.port.postMessage(this.out.buffer, [this.out.buffer]);
|
|
34
|
+
this.out = new Int16Array(CHUNK);
|
|
35
|
+
this.n = 0;
|
|
36
|
+
}
|
|
37
|
+
this.pos += this.step;
|
|
38
|
+
}
|
|
39
|
+
this.pos -= len;
|
|
40
|
+
this.prev = input[len - 1];
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class Play extends AudioWorkletProcessor {
|
|
46
|
+
constructor() {
|
|
47
|
+
super();
|
|
48
|
+
this.step = RATE / sampleRate; // 每出一个输出采样,24kHz 的缓冲前进多少
|
|
49
|
+
this.size = RATE * 4; // 环形缓冲最多 4 秒
|
|
50
|
+
this.buf = new Float32Array(this.size);
|
|
51
|
+
this.read = 0; // 读位置(小数)
|
|
52
|
+
this.avail = 0; // 还没放的采样数
|
|
53
|
+
this.write = 0;
|
|
54
|
+
this.playing = false;
|
|
55
|
+
this.port.onmessage = (e) => {
|
|
56
|
+
if (e.data === "flush") {
|
|
57
|
+
this.avail = 0;
|
|
58
|
+
this.playing = false;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const pcm = new Int16Array(e.data);
|
|
62
|
+
// 放不下(网络卡了一阵又一下子涌来):丢掉最旧的,宁可跳一下也不越放越晚
|
|
63
|
+
const over = this.avail + pcm.length - this.size;
|
|
64
|
+
if (over > 0) {
|
|
65
|
+
this.read = (this.read + over) % this.size;
|
|
66
|
+
this.avail -= over;
|
|
67
|
+
}
|
|
68
|
+
for (let i = 0; i < pcm.length; i++) {
|
|
69
|
+
this.buf[this.write] = pcm[i] / 0x8000;
|
|
70
|
+
this.write = (this.write + 1) % this.size;
|
|
71
|
+
}
|
|
72
|
+
this.avail += pcm.length;
|
|
73
|
+
// 太多了(超过 1 秒)说明延迟越积越大,追到只剩 0.2 秒
|
|
74
|
+
if (this.avail > RATE) {
|
|
75
|
+
const skip = this.avail - RATE / 5;
|
|
76
|
+
this.read = (this.read + skip) % this.size;
|
|
77
|
+
this.avail -= skip;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
process(_inputs, outputs) {
|
|
83
|
+
const out = outputs[0];
|
|
84
|
+
const ch = out[0];
|
|
85
|
+
if (!ch) return true;
|
|
86
|
+
// 先攒 60ms 再开始放,扛一点网络抖动;放空了就停下来重新攒
|
|
87
|
+
if (!this.playing && this.avail >= RATE * 0.06) this.playing = true;
|
|
88
|
+
for (let i = 0; i < ch.length; i++) {
|
|
89
|
+
if (!this.playing || this.avail < 2) {
|
|
90
|
+
ch[i] = 0;
|
|
91
|
+
this.playing = false;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const i0 = Math.floor(this.read);
|
|
95
|
+
const f = this.read - i0;
|
|
96
|
+
const a = this.buf[i0 % this.size];
|
|
97
|
+
const b = this.buf[(i0 + 1) % this.size];
|
|
98
|
+
ch[i] = a + (b - a) * f;
|
|
99
|
+
const next = this.read + this.step;
|
|
100
|
+
const used = Math.floor(next) - i0;
|
|
101
|
+
this.avail -= used;
|
|
102
|
+
this.read = next % this.size;
|
|
103
|
+
}
|
|
104
|
+
for (let c = 1; c < out.length; c++) out[c].set(ch);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
registerProcessor("rt-capture", Capture);
|
|
110
|
+
registerProcessor("rt-play", Play);
|
package/web/lib/ws.js
CHANGED
|
@@ -11,7 +11,7 @@ import { setBusy } from "../views/composer.js";
|
|
|
11
11
|
import { SH, shownHere } from "./shell.js";
|
|
12
12
|
import { currentPushSub } from "./push.js";
|
|
13
13
|
import { renderScheduled } from "../views/schedule.js";
|
|
14
|
-
import { onRealtimeEvent } from "../views/voice-call.js";
|
|
14
|
+
import { onRealtimeAudio, onRealtimeEvent, onSocketLost } from "../views/voice-call.js";
|
|
15
15
|
import { reloadExperts } from "../views/experts.js";
|
|
16
16
|
|
|
17
17
|
// ---------- WebSocket ----------
|
|
@@ -34,6 +34,8 @@ export const WS = {
|
|
|
34
34
|
if (this.sock && (this.sock.readyState === 0 || this.sock.readyState === 1)) return;
|
|
35
35
|
const proto = location.protocol === "https:" ? "wss" : "ws";
|
|
36
36
|
const sock = new WebSocket(`${proto}://${location.host}/ws`);
|
|
37
|
+
// 二进制帧只有语音对话的声音
|
|
38
|
+
sock.binaryType = "arraybuffer";
|
|
37
39
|
this.sock = sock;
|
|
38
40
|
sock.onopen = () => {
|
|
39
41
|
this.connected = true;
|
|
@@ -42,10 +44,11 @@ export const WS = {
|
|
|
42
44
|
clearInterval(this.pingTimer);
|
|
43
45
|
this.pingTimer = setInterval(() => this.raw({ t: "ping" }), 25000);
|
|
44
46
|
};
|
|
45
|
-
sock.onmessage = (e) => onWsMessage(JSON.parse(e.data));
|
|
47
|
+
sock.onmessage = (e) => (typeof e.data === "string" ? onWsMessage(JSON.parse(e.data)) : onRealtimeAudio(e.data));
|
|
46
48
|
sock.onclose = async (e) => {
|
|
47
49
|
this.connected = false;
|
|
48
50
|
clearInterval(this.pingTimer);
|
|
51
|
+
if (this.sock === sock) onSocketLost();
|
|
49
52
|
for (const w of this.waiters.values()) w.reject(new Error("连接已断开"));
|
|
50
53
|
this.waiters.clear();
|
|
51
54
|
if (this.sock !== sock) return;
|
package/web/views/composer.js
CHANGED
|
@@ -8,7 +8,7 @@ import { addItem, openConversation, openLightbox, renderEmpty, scrollToBottom }
|
|
|
8
8
|
import { renderScheduled } from "./schedule.js";
|
|
9
9
|
import { renderTodos } from "./todos.js";
|
|
10
10
|
import { cancelVoice, SpeechRec, toggleVoice } from "./voice.js";
|
|
11
|
-
import { callButton } from "./voice-call.js";
|
|
11
|
+
import { callButton, canCall } from "./voice-call.js";
|
|
12
12
|
import { closeSlashMenu, commandUsage, oneLine, slashKeydown, updateSlashMenu } from "./slash.js";
|
|
13
13
|
import { doAction, openModelPicker, openSessions } from "./conv-actions.js";
|
|
14
14
|
|
|
@@ -155,7 +155,13 @@ function hasDraft() {
|
|
|
155
155
|
|
|
156
156
|
export function updateSendBtn() {
|
|
157
157
|
if (!ui.sendBtn) return;
|
|
158
|
-
|
|
158
|
+
// 最右侧共用一个位置:空闲且没有草稿时通话,有文字/附件时发送;回复中仍保留停止。
|
|
159
|
+
const draft = hasDraft();
|
|
160
|
+
const editing = S.editingMessage === S.current && !!S.current;
|
|
161
|
+
const showCall = canCall() && !draft && !S.busy && !S.sending && !editing;
|
|
162
|
+
if (ui.callBtn) ui.callBtn.hidden = !showCall;
|
|
163
|
+
ui.sendBtn.hidden = showCall;
|
|
164
|
+
if (editing) {
|
|
159
165
|
ui.sendBtn.disabled = true;
|
|
160
166
|
ui.sendBtn.title = "正在恢复消息…";
|
|
161
167
|
return;
|
|
@@ -167,10 +173,10 @@ export function updateSendBtn() {
|
|
|
167
173
|
ui.sendBtn.disabled = true;
|
|
168
174
|
return;
|
|
169
175
|
}
|
|
170
|
-
const stop = S.busy && !
|
|
176
|
+
const stop = S.busy && !draft;
|
|
171
177
|
ui.sendBtn.innerHTML = stop ? ICON.stop : ICON.send;
|
|
172
178
|
ui.sendBtn.title = stop ? "停止" : "发送";
|
|
173
|
-
ui.sendBtn.disabled = !stop && !
|
|
179
|
+
ui.sendBtn.disabled = !stop && !draft;
|
|
174
180
|
}
|
|
175
181
|
|
|
176
182
|
export function setBusy(busy) {
|