@yieldfabric/terminal 1.1.2 → 1.2.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/dist/index.cjs +1120 -3
- package/dist/index.d.cts +366 -2
- package/dist/index.d.ts +366 -2
- package/dist/index.js +1107 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -818,11 +818,11 @@ var AVATAR_COLORS = [
|
|
|
818
818
|
"#ef4444"
|
|
819
819
|
];
|
|
820
820
|
function avatarColor(entityId) {
|
|
821
|
-
let
|
|
821
|
+
let hash2 = 0;
|
|
822
822
|
for (let i = 0; i < entityId.length; i++) {
|
|
823
|
-
|
|
823
|
+
hash2 = entityId.charCodeAt(i) + ((hash2 << 5) - hash2);
|
|
824
824
|
}
|
|
825
|
-
return AVATAR_COLORS[Math.abs(
|
|
825
|
+
return AVATAR_COLORS[Math.abs(hash2) % AVATAR_COLORS.length];
|
|
826
826
|
}
|
|
827
827
|
function initials(name) {
|
|
828
828
|
return name.split(" ").map((w) => w[0]).join("").toUpperCase().slice(0, 2);
|
|
@@ -3389,6 +3389,7 @@ function TerminalInputBar({
|
|
|
3389
3389
|
selectedPaletteItem,
|
|
3390
3390
|
onSelectPaletteItem,
|
|
3391
3391
|
inputBarExtra,
|
|
3392
|
+
leading,
|
|
3392
3393
|
modeSelector,
|
|
3393
3394
|
compactToolbar = false,
|
|
3394
3395
|
submitTitle = "Send",
|
|
@@ -3667,6 +3668,7 @@ function TerminalInputBar({
|
|
|
3667
3668
|
})(),
|
|
3668
3669
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { ref: toolbarRef, className: "flex items-center justify-between pt-2.5 gap-2", children: [
|
|
3669
3670
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 text-[11px] min-w-0 flex-wrap", children: [
|
|
3671
|
+
leading,
|
|
3670
3672
|
chipsVisible && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3671
3673
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3672
3674
|
"button",
|
|
@@ -5547,6 +5549,7 @@ Path: ${parsed.endpoint.path}`);
|
|
|
5547
5549
|
core.setCommandPaletteItems([]);
|
|
5548
5550
|
},
|
|
5549
5551
|
inputBarExtra: slots?.inputBarExtra,
|
|
5552
|
+
leading: slots?.inputBarLeading,
|
|
5550
5553
|
modeSelector: slots?.modeSelector
|
|
5551
5554
|
}
|
|
5552
5555
|
),
|
|
@@ -6219,6 +6222,7 @@ function ChatTerminal({
|
|
|
6219
6222
|
core.setCommandPaletteItems([]);
|
|
6220
6223
|
},
|
|
6221
6224
|
inputBarExtra: slots?.inputBarExtra,
|
|
6225
|
+
leading: slots?.inputBarLeading,
|
|
6222
6226
|
modeSelector: slots?.modeSelector
|
|
6223
6227
|
}
|
|
6224
6228
|
),
|
|
@@ -7622,6 +7626,1104 @@ function agentStepTraceExtra(entry) {
|
|
|
7622
7626
|
const working = meta?.agentStepsLive ?? entry.content.endsWith("\u258B");
|
|
7623
7627
|
return /* @__PURE__ */ jsxRuntime.jsx(AgentStepTrace, { steps, working });
|
|
7624
7628
|
}
|
|
7629
|
+
var BAR_SHAPE = [0.55, 1, 0.8, 0.45];
|
|
7630
|
+
function tintOf(color, alpha) {
|
|
7631
|
+
return `color-mix(in srgb, ${color} ${Math.round(alpha * 100)}%, transparent)`;
|
|
7632
|
+
}
|
|
7633
|
+
function useCoarsePointer() {
|
|
7634
|
+
const [coarse, setCoarse] = React15.useState(
|
|
7635
|
+
() => typeof window !== "undefined" && !!window.matchMedia?.("(pointer: coarse)").matches
|
|
7636
|
+
);
|
|
7637
|
+
React15.useEffect(() => {
|
|
7638
|
+
const mq = window.matchMedia?.("(pointer: coarse)");
|
|
7639
|
+
if (!mq) return void 0;
|
|
7640
|
+
const on = () => setCoarse(mq.matches);
|
|
7641
|
+
mq.addEventListener?.("change", on);
|
|
7642
|
+
return () => mq.removeEventListener?.("change", on);
|
|
7643
|
+
}, []);
|
|
7644
|
+
return coarse;
|
|
7645
|
+
}
|
|
7646
|
+
function VoiceInputButton({
|
|
7647
|
+
state,
|
|
7648
|
+
onToggle,
|
|
7649
|
+
disabled = false,
|
|
7650
|
+
level,
|
|
7651
|
+
startTitle = "Talk",
|
|
7652
|
+
stopTitle = "End voice"
|
|
7653
|
+
}) {
|
|
7654
|
+
const t = useTheme();
|
|
7655
|
+
const coarse = useCoarsePointer();
|
|
7656
|
+
const isLight = t.mode ? t.mode === "light" : t.bgRaised === "#ffffff";
|
|
7657
|
+
const on = state !== "off";
|
|
7658
|
+
const tint = (a) => tintOf(t.primary, a);
|
|
7659
|
+
const bars = React15.useRef([]);
|
|
7660
|
+
const levelRef = React15.useRef(level);
|
|
7661
|
+
levelRef.current = level;
|
|
7662
|
+
React15.useEffect(() => {
|
|
7663
|
+
if (state !== "live") return void 0;
|
|
7664
|
+
let raf = 0;
|
|
7665
|
+
let smooth = 0;
|
|
7666
|
+
const tick = (now) => {
|
|
7667
|
+
const raw = levelRef.current ? Math.min(1, Math.max(0, levelRef.current())) : 0;
|
|
7668
|
+
smooth = raw > smooth ? smooth + (raw - smooth) * 0.55 : smooth + (raw - smooth) * 0.12;
|
|
7669
|
+
bars.current.forEach((bar, i) => {
|
|
7670
|
+
if (!bar) return;
|
|
7671
|
+
const idle = 0.18 + 0.1 * Math.sin(now / 320 + i * 1.3);
|
|
7672
|
+
const h = Math.max(idle, smooth * BAR_SHAPE[i] * (0.85 + 0.15 * Math.sin(now / 90 + i * 2.1)));
|
|
7673
|
+
bar.style.transform = `scaleY(${Math.min(1, h).toFixed(3)})`;
|
|
7674
|
+
});
|
|
7675
|
+
raf = window.requestAnimationFrame(tick);
|
|
7676
|
+
};
|
|
7677
|
+
raf = window.requestAnimationFrame(tick);
|
|
7678
|
+
return () => window.cancelAnimationFrame(raf);
|
|
7679
|
+
}, [state]);
|
|
7680
|
+
const size = coarse ? 32 : 22;
|
|
7681
|
+
const title = on ? stopTitle : startTitle;
|
|
7682
|
+
const style = on ? {
|
|
7683
|
+
backgroundColor: t.primary,
|
|
7684
|
+
border: `1px solid ${t.primary}`,
|
|
7685
|
+
color: t.textInverse,
|
|
7686
|
+
boxShadow: `0 0 0 3px ${tint(0.18)}, 0 6px 18px -6px ${tint(0.75)}`
|
|
7687
|
+
} : {
|
|
7688
|
+
backgroundColor: isLight ? tint(0.07) : tint(0.1),
|
|
7689
|
+
border: `1px solid ${tint(isLight ? 0.35 : 0.3)}`,
|
|
7690
|
+
color: t.primary
|
|
7691
|
+
};
|
|
7692
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
7693
|
+
"button",
|
|
7694
|
+
{
|
|
7695
|
+
type: "button",
|
|
7696
|
+
disabled: disabled && !on,
|
|
7697
|
+
"aria-pressed": on,
|
|
7698
|
+
"aria-label": title,
|
|
7699
|
+
title,
|
|
7700
|
+
className: `relative flex items-center justify-center disabled:opacity-30 disabled:cursor-not-allowed transition-all duration-200 active:scale-95 ${coarse ? "rounded-full" : "rounded-lg px-1.5"}`,
|
|
7701
|
+
style: { ...style, height: size, minWidth: size, WebkitTapHighlightColor: "transparent" },
|
|
7702
|
+
onClick: onToggle,
|
|
7703
|
+
children: [
|
|
7704
|
+
state === "live" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
7705
|
+
"span",
|
|
7706
|
+
{
|
|
7707
|
+
"aria-hidden": "true",
|
|
7708
|
+
className: `pointer-events-none absolute inset-0 animate-ping ${coarse ? "rounded-full" : "rounded-lg"}`,
|
|
7709
|
+
style: { backgroundColor: tint(0.35), animationDuration: "1.8s" }
|
|
7710
|
+
}
|
|
7711
|
+
) : null,
|
|
7712
|
+
state === "connecting" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: coarse ? "w-4 h-4 animate-spin" : "w-3.5 h-3.5 animate-spin" }) : state === "live" ? /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", className: "relative flex items-center gap-[2px]", style: { height: coarse ? 14 : 11 }, children: BAR_SHAPE.map((_, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
7713
|
+
"span",
|
|
7714
|
+
{
|
|
7715
|
+
ref: (el) => {
|
|
7716
|
+
bars.current[i] = el;
|
|
7717
|
+
},
|
|
7718
|
+
className: "block rounded-full",
|
|
7719
|
+
style: {
|
|
7720
|
+
width: coarse ? 2.5 : 2,
|
|
7721
|
+
height: "100%",
|
|
7722
|
+
backgroundColor: "currentColor",
|
|
7723
|
+
transform: "scaleY(0.25)",
|
|
7724
|
+
transformOrigin: "center",
|
|
7725
|
+
transition: "transform 60ms linear"
|
|
7726
|
+
}
|
|
7727
|
+
},
|
|
7728
|
+
i
|
|
7729
|
+
)) }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Mic, { className: coarse ? "w-4 h-4" : "w-3.5 h-3.5" })
|
|
7730
|
+
]
|
|
7731
|
+
}
|
|
7732
|
+
);
|
|
7733
|
+
}
|
|
7734
|
+
|
|
7735
|
+
// src/voice/askQueue.ts
|
|
7736
|
+
var REPLACED_OUTPUT = "Replaced by their corrected question, which is being answered instead. Say nothing about this one.";
|
|
7737
|
+
var AskQueue = class {
|
|
7738
|
+
/**
|
|
7739
|
+
* `run` asks the host (resolves with what the voice speaks from; a
|
|
7740
|
+
* rejection is reported as a failure). `finish` sends the result: `speak`
|
|
7741
|
+
* false for a replaced question.
|
|
7742
|
+
*/
|
|
7743
|
+
constructor(run, finish) {
|
|
7744
|
+
this.run = run;
|
|
7745
|
+
this.finish = finish;
|
|
7746
|
+
this.waiting = [];
|
|
7747
|
+
this.running = null;
|
|
7748
|
+
}
|
|
7749
|
+
/** Questions being worked on or waiting. */
|
|
7750
|
+
get size() {
|
|
7751
|
+
return this.waiting.length + (this.running ? 1 : 0);
|
|
7752
|
+
}
|
|
7753
|
+
add(ask) {
|
|
7754
|
+
if (ask.replaces && this.size > 0) {
|
|
7755
|
+
for (const dropped of this.waiting) this.finish(dropped, REPLACED_OUTPUT, false);
|
|
7756
|
+
this.waiting = [ask];
|
|
7757
|
+
this.running?.controller.abort();
|
|
7758
|
+
} else {
|
|
7759
|
+
this.waiting.push(ask);
|
|
7760
|
+
}
|
|
7761
|
+
this.next();
|
|
7762
|
+
}
|
|
7763
|
+
next() {
|
|
7764
|
+
if (this.running) return;
|
|
7765
|
+
const ask = this.waiting.shift();
|
|
7766
|
+
if (!ask) return;
|
|
7767
|
+
const controller = new AbortController();
|
|
7768
|
+
this.running = { ask, controller };
|
|
7769
|
+
this.run(ask, controller.signal).catch((e) => `The assistant could not answer: ${e?.message || "unknown error"}. Tell them it failed; do not guess.`).then((output) => {
|
|
7770
|
+
this.running = null;
|
|
7771
|
+
if (controller.signal.aborted) this.finish(ask, REPLACED_OUTPUT, false);
|
|
7772
|
+
else this.finish(ask, output, true);
|
|
7773
|
+
this.next();
|
|
7774
|
+
});
|
|
7775
|
+
}
|
|
7776
|
+
};
|
|
7777
|
+
|
|
7778
|
+
// src/voice/pcm.ts
|
|
7779
|
+
var WIRE_RATE = 24e3;
|
|
7780
|
+
var FRAME_SAMPLES = 2400;
|
|
7781
|
+
var Downsampler = class {
|
|
7782
|
+
constructor(inputRate, outputRate = WIRE_RATE) {
|
|
7783
|
+
/** Input samples not yet consumed. */
|
|
7784
|
+
this.carry = new Float32Array(0);
|
|
7785
|
+
/** Fractional read position into `carry`. */
|
|
7786
|
+
this.pos = 0;
|
|
7787
|
+
if (!(inputRate > 0) || !(outputRate > 0)) throw new Error("Sample rates must be positive");
|
|
7788
|
+
this.ratio = inputRate / outputRate;
|
|
7789
|
+
}
|
|
7790
|
+
push(input) {
|
|
7791
|
+
const buf = new Float32Array(this.carry.length + input.length);
|
|
7792
|
+
buf.set(this.carry, 0);
|
|
7793
|
+
buf.set(input, this.carry.length);
|
|
7794
|
+
const out = [];
|
|
7795
|
+
let pos = this.pos;
|
|
7796
|
+
while (pos + this.ratio <= buf.length) {
|
|
7797
|
+
const start = Math.floor(pos);
|
|
7798
|
+
const end = Math.max(start + 1, Math.floor(pos + this.ratio));
|
|
7799
|
+
let sum = 0;
|
|
7800
|
+
for (let i = start; i < end; i += 1) sum += buf[i];
|
|
7801
|
+
out.push(floatToInt16(sum / (end - start)));
|
|
7802
|
+
pos += this.ratio;
|
|
7803
|
+
}
|
|
7804
|
+
const consumed = Math.floor(pos);
|
|
7805
|
+
this.carry = buf.slice(consumed);
|
|
7806
|
+
this.pos = pos - consumed;
|
|
7807
|
+
return Int16Array.from(out);
|
|
7808
|
+
}
|
|
7809
|
+
};
|
|
7810
|
+
function floatToInt16(sample) {
|
|
7811
|
+
const s = Math.max(-1, Math.min(1, Number.isFinite(sample) ? sample : 0));
|
|
7812
|
+
return s < 0 ? Math.round(s * 32768) : Math.round(s * 32767);
|
|
7813
|
+
}
|
|
7814
|
+
var FrameBuffer = class {
|
|
7815
|
+
constructor() {
|
|
7816
|
+
this.pending = [];
|
|
7817
|
+
}
|
|
7818
|
+
push(samples) {
|
|
7819
|
+
for (let i = 0; i < samples.length; i += 1) this.pending.push(samples[i]);
|
|
7820
|
+
const frames = [];
|
|
7821
|
+
while (this.pending.length >= FRAME_SAMPLES) {
|
|
7822
|
+
frames.push(toLittleEndian(this.pending.splice(0, FRAME_SAMPLES)));
|
|
7823
|
+
}
|
|
7824
|
+
return frames;
|
|
7825
|
+
}
|
|
7826
|
+
};
|
|
7827
|
+
function toLittleEndian(samples) {
|
|
7828
|
+
const view = new DataView(new ArrayBuffer(samples.length * 2));
|
|
7829
|
+
samples.forEach((s, i) => view.setInt16(i * 2, s, true));
|
|
7830
|
+
return view.buffer;
|
|
7831
|
+
}
|
|
7832
|
+
function pcm16ToFloat32(bytes) {
|
|
7833
|
+
const view = new DataView(bytes);
|
|
7834
|
+
const out = new Float32Array(Math.floor(bytes.byteLength / 2));
|
|
7835
|
+
for (let i = 0; i < out.length; i += 1) out[i] = view.getInt16(i * 2, true) / 32768;
|
|
7836
|
+
return out;
|
|
7837
|
+
}
|
|
7838
|
+
|
|
7839
|
+
// src/voice/persona.ts
|
|
7840
|
+
var VOICE_NAMES = [
|
|
7841
|
+
"alloy",
|
|
7842
|
+
"ash",
|
|
7843
|
+
"ballad",
|
|
7844
|
+
"cedar",
|
|
7845
|
+
"coral",
|
|
7846
|
+
"echo",
|
|
7847
|
+
"marin",
|
|
7848
|
+
"sage",
|
|
7849
|
+
"shimmer",
|
|
7850
|
+
"verse"
|
|
7851
|
+
];
|
|
7852
|
+
var VOICE_LANGUAGES = ["en", "es", "pt", "fr", "de", "it", "nl", "ar", "hi", "ja", "ko", "zh"];
|
|
7853
|
+
function encodePersona(persona) {
|
|
7854
|
+
if (!persona) return null;
|
|
7855
|
+
const fields = Object.fromEntries(Object.entries(persona).filter(([, v]) => v !== void 0));
|
|
7856
|
+
return Object.keys(fields).length ? JSON.stringify(fields) : null;
|
|
7857
|
+
}
|
|
7858
|
+
|
|
7859
|
+
// src/voice/worklet.ts
|
|
7860
|
+
var VOICE_CAPTURE_WORKLET_SOURCE = `class YfVoiceCapture extends AudioWorkletProcessor {
|
|
7861
|
+
constructor() {
|
|
7862
|
+
super();
|
|
7863
|
+
this.batch = new Float32Array(2048);
|
|
7864
|
+
this.filled = 0;
|
|
7865
|
+
}
|
|
7866
|
+
process(inputs) {
|
|
7867
|
+
const channel = inputs[0] && inputs[0][0];
|
|
7868
|
+
if (channel) {
|
|
7869
|
+
let offset = 0;
|
|
7870
|
+
while (offset < channel.length) {
|
|
7871
|
+
const n = Math.min(channel.length - offset, this.batch.length - this.filled);
|
|
7872
|
+
this.batch.set(channel.subarray(offset, offset + n), this.filled);
|
|
7873
|
+
this.filled += n;
|
|
7874
|
+
offset += n;
|
|
7875
|
+
if (this.filled === this.batch.length) {
|
|
7876
|
+
this.port.postMessage(this.batch, [this.batch.buffer]);
|
|
7877
|
+
this.batch = new Float32Array(2048);
|
|
7878
|
+
this.filled = 0;
|
|
7879
|
+
}
|
|
7880
|
+
}
|
|
7881
|
+
}
|
|
7882
|
+
return true;
|
|
7883
|
+
}
|
|
7884
|
+
}
|
|
7885
|
+
registerProcessor('yf-voice-capture', YfVoiceCapture);
|
|
7886
|
+
`;
|
|
7887
|
+
var VOICE_CAPTURE_PROCESSOR = "yf-voice-capture";
|
|
7888
|
+
|
|
7889
|
+
// src/voice/session.ts
|
|
7890
|
+
function socketBase(base) {
|
|
7891
|
+
return base.replace(/^http/i, "ws").replace(/\/+$/, "");
|
|
7892
|
+
}
|
|
7893
|
+
var OFF = { enabled: false, blocked: null, maxSessionSecs: 0, persona: null };
|
|
7894
|
+
async function getVoiceStatus(connection, signal) {
|
|
7895
|
+
const token = await connection.getToken();
|
|
7896
|
+
if (!token) return OFF;
|
|
7897
|
+
try {
|
|
7898
|
+
const res = await fetch(`${connection.baseUrl.replace(/\/+$/, "")}/voice/status`, {
|
|
7899
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
7900
|
+
signal
|
|
7901
|
+
});
|
|
7902
|
+
if (!res.ok) return OFF;
|
|
7903
|
+
const body = await res.json();
|
|
7904
|
+
return {
|
|
7905
|
+
enabled: body?.enabled === true,
|
|
7906
|
+
blocked: typeof body?.blocked === "string" ? body.blocked : null,
|
|
7907
|
+
maxSessionSecs: Number(body?.max_session_secs) || 0,
|
|
7908
|
+
persona: body?.persona && typeof body.persona.name === "string" ? body.persona : null
|
|
7909
|
+
};
|
|
7910
|
+
} catch {
|
|
7911
|
+
return OFF;
|
|
7912
|
+
}
|
|
7913
|
+
}
|
|
7914
|
+
var SILENT = { input: 0, output: 0 };
|
|
7915
|
+
function rms(analyser, buf) {
|
|
7916
|
+
if (!analyser || !buf) return 0;
|
|
7917
|
+
analyser.getFloatTimeDomainData(buf);
|
|
7918
|
+
let sum = 0;
|
|
7919
|
+
for (let i = 0; i < buf.length; i += 1) sum += buf[i] * buf[i];
|
|
7920
|
+
return Math.sqrt(sum / buf.length);
|
|
7921
|
+
}
|
|
7922
|
+
var PcmPlayer = class {
|
|
7923
|
+
constructor(ctx, out, onIdle) {
|
|
7924
|
+
this.ctx = ctx;
|
|
7925
|
+
this.out = out;
|
|
7926
|
+
this.onIdle = onIdle;
|
|
7927
|
+
this.next = 0;
|
|
7928
|
+
this.live = /* @__PURE__ */ new Set();
|
|
7929
|
+
}
|
|
7930
|
+
get playing() {
|
|
7931
|
+
return this.live.size > 0;
|
|
7932
|
+
}
|
|
7933
|
+
enqueue(bytes) {
|
|
7934
|
+
const samples = pcm16ToFloat32(bytes);
|
|
7935
|
+
if (samples.length === 0) return;
|
|
7936
|
+
const buffer = this.ctx.createBuffer(1, samples.length, WIRE_RATE);
|
|
7937
|
+
buffer.getChannelData(0).set(samples);
|
|
7938
|
+
const source = this.ctx.createBufferSource();
|
|
7939
|
+
source.buffer = buffer;
|
|
7940
|
+
source.connect(this.out);
|
|
7941
|
+
const at = Math.max(this.ctx.currentTime + 0.02, this.next);
|
|
7942
|
+
source.start(at);
|
|
7943
|
+
this.next = at + buffer.duration;
|
|
7944
|
+
this.live.add(source);
|
|
7945
|
+
source.onended = () => {
|
|
7946
|
+
this.live.delete(source);
|
|
7947
|
+
if (this.live.size === 0) this.onIdle();
|
|
7948
|
+
};
|
|
7949
|
+
}
|
|
7950
|
+
stop() {
|
|
7951
|
+
this.live.forEach((source) => {
|
|
7952
|
+
source.onended = null;
|
|
7953
|
+
try {
|
|
7954
|
+
source.stop();
|
|
7955
|
+
} catch {
|
|
7956
|
+
}
|
|
7957
|
+
});
|
|
7958
|
+
this.live.clear();
|
|
7959
|
+
this.next = 0;
|
|
7960
|
+
}
|
|
7961
|
+
};
|
|
7962
|
+
var FINISH_GRACE_MS = 800;
|
|
7963
|
+
var FINISH_MAX_WAIT_MS = 15e3;
|
|
7964
|
+
var CLOSE_REASONS = {
|
|
7965
|
+
time_limit: "time_limit",
|
|
7966
|
+
replaced: "replaced",
|
|
7967
|
+
upstream_closed: "lost",
|
|
7968
|
+
upstream_error: "lost"
|
|
7969
|
+
};
|
|
7970
|
+
function voiceSocketUrl(connection, token) {
|
|
7971
|
+
const params = new URLSearchParams({ access_token: token });
|
|
7972
|
+
if (connection.threadId) params.set("thread_id", connection.threadId);
|
|
7973
|
+
if (connection.workingGroupId) params.set("working_group_id", connection.workingGroupId);
|
|
7974
|
+
const persona = encodePersona(connection.persona);
|
|
7975
|
+
if (persona) params.set("persona", persona);
|
|
7976
|
+
return `${socketBase(connection.baseUrl)}/voice/realtime?${params.toString()}`;
|
|
7977
|
+
}
|
|
7978
|
+
var VoiceSession = class {
|
|
7979
|
+
constructor(h, connection) {
|
|
7980
|
+
this.h = h;
|
|
7981
|
+
this.connection = connection;
|
|
7982
|
+
this.ctx = null;
|
|
7983
|
+
this.stream = null;
|
|
7984
|
+
this.node = null;
|
|
7985
|
+
this.ws = null;
|
|
7986
|
+
this.player = null;
|
|
7987
|
+
this.inputAnalyser = null;
|
|
7988
|
+
this.outputAnalyser = null;
|
|
7989
|
+
this.inputBuf = null;
|
|
7990
|
+
this.outputBuf = null;
|
|
7991
|
+
this.ready = false;
|
|
7992
|
+
this.ended = false;
|
|
7993
|
+
this.phase = null;
|
|
7994
|
+
/** The voice's questions to the host, one at a time (see `askQueue.ts`). */
|
|
7995
|
+
this.asks = new AskQueue(
|
|
7996
|
+
(ask, signal) => {
|
|
7997
|
+
let open = true;
|
|
7998
|
+
const progress = (line, kind) => {
|
|
7999
|
+
if (open && !signal.aborted && line.trim()) this.send({ type: "progress", kind, text: line.slice(0, 240) });
|
|
8000
|
+
};
|
|
8001
|
+
return this.h.onAsk(ask.question, ask.heard, ask.utterance, progress, signal).finally(() => {
|
|
8002
|
+
open = false;
|
|
8003
|
+
});
|
|
8004
|
+
},
|
|
8005
|
+
(ask, output, speak) => {
|
|
8006
|
+
if (this.ended) return;
|
|
8007
|
+
this.send({ type: "tool_result", call_id: ask.callId, output, ...speak ? {} : { speak: false } });
|
|
8008
|
+
this.settle();
|
|
8009
|
+
}
|
|
8010
|
+
);
|
|
8011
|
+
this.heard = null;
|
|
8012
|
+
this.partialHeard = "";
|
|
8013
|
+
this.saying = "";
|
|
8014
|
+
this.endingReason = null;
|
|
8015
|
+
this.finishTimer = null;
|
|
8016
|
+
this.blobUrl = null;
|
|
8017
|
+
}
|
|
8018
|
+
/** Call from the tap itself: iOS only lets audio start inside a gesture,
|
|
8019
|
+
* so the AudioContext is created before the first `await`. */
|
|
8020
|
+
async start() {
|
|
8021
|
+
const Ctx = window.AudioContext ?? window.webkitAudioContext;
|
|
8022
|
+
if (!Ctx || !navigator.mediaDevices?.getUserMedia || typeof AudioWorkletNode === "undefined") {
|
|
8023
|
+
this.end("unavailable", "This browser cannot do live voice.");
|
|
8024
|
+
return;
|
|
8025
|
+
}
|
|
8026
|
+
const ctx = new Ctx();
|
|
8027
|
+
this.ctx = ctx;
|
|
8028
|
+
void ctx.resume();
|
|
8029
|
+
this.setPhase("connecting");
|
|
8030
|
+
const status = await getVoiceStatus(this.connection);
|
|
8031
|
+
if (this.ended) return;
|
|
8032
|
+
if (status.blocked) {
|
|
8033
|
+
this.end("blocked", status.blocked);
|
|
8034
|
+
return;
|
|
8035
|
+
}
|
|
8036
|
+
if (!status.enabled) {
|
|
8037
|
+
this.end("unavailable", "Voice is not switched on.");
|
|
8038
|
+
return;
|
|
8039
|
+
}
|
|
8040
|
+
try {
|
|
8041
|
+
this.stream = await navigator.mediaDevices.getUserMedia({
|
|
8042
|
+
audio: { channelCount: 1, echoCancellation: true, noiseSuppression: true, autoGainControl: true }
|
|
8043
|
+
});
|
|
8044
|
+
} catch (e) {
|
|
8045
|
+
this.end("mic_denied", e?.message);
|
|
8046
|
+
return;
|
|
8047
|
+
}
|
|
8048
|
+
if (this.ended) {
|
|
8049
|
+
this.release();
|
|
8050
|
+
return;
|
|
8051
|
+
}
|
|
8052
|
+
try {
|
|
8053
|
+
let url = this.connection.workletUrl;
|
|
8054
|
+
if (!url) {
|
|
8055
|
+
this.blobUrl = URL.createObjectURL(new Blob([VOICE_CAPTURE_WORKLET_SOURCE], { type: "application/javascript" }));
|
|
8056
|
+
url = this.blobUrl;
|
|
8057
|
+
}
|
|
8058
|
+
await ctx.audioWorklet.addModule(url);
|
|
8059
|
+
} catch (e) {
|
|
8060
|
+
this.end("unavailable", e?.message);
|
|
8061
|
+
return;
|
|
8062
|
+
}
|
|
8063
|
+
if (this.ended) return;
|
|
8064
|
+
const down = new Downsampler(ctx.sampleRate);
|
|
8065
|
+
const frames = new FrameBuffer();
|
|
8066
|
+
const node = new AudioWorkletNode(ctx, VOICE_CAPTURE_PROCESSOR);
|
|
8067
|
+
this.node = node;
|
|
8068
|
+
node.port.onmessage = (e) => {
|
|
8069
|
+
const ws2 = this.ws;
|
|
8070
|
+
if (!this.ready || !ws2 || ws2.readyState !== WebSocket.OPEN) return;
|
|
8071
|
+
for (const frame of frames.push(down.push(e.data))) ws2.send(frame);
|
|
8072
|
+
};
|
|
8073
|
+
const mic = ctx.createMediaStreamSource(this.stream);
|
|
8074
|
+
const inputAnalyser = ctx.createAnalyser();
|
|
8075
|
+
inputAnalyser.fftSize = 1024;
|
|
8076
|
+
const outputAnalyser = ctx.createAnalyser();
|
|
8077
|
+
outputAnalyser.fftSize = 1024;
|
|
8078
|
+
this.inputAnalyser = inputAnalyser;
|
|
8079
|
+
this.outputAnalyser = outputAnalyser;
|
|
8080
|
+
this.inputBuf = new Float32Array(inputAnalyser.fftSize);
|
|
8081
|
+
this.outputBuf = new Float32Array(outputAnalyser.fftSize);
|
|
8082
|
+
const mute = ctx.createGain();
|
|
8083
|
+
mute.gain.value = 0;
|
|
8084
|
+
mic.connect(inputAnalyser);
|
|
8085
|
+
inputAnalyser.connect(node);
|
|
8086
|
+
node.connect(mute);
|
|
8087
|
+
mute.connect(ctx.destination);
|
|
8088
|
+
outputAnalyser.connect(ctx.destination);
|
|
8089
|
+
this.player = new PcmPlayer(ctx, outputAnalyser, () => this.settle());
|
|
8090
|
+
const token = await this.connection.getToken();
|
|
8091
|
+
if (this.ended) return;
|
|
8092
|
+
if (!token) {
|
|
8093
|
+
this.end("unavailable", "Sign in again to use voice.");
|
|
8094
|
+
return;
|
|
8095
|
+
}
|
|
8096
|
+
const ws = new WebSocket(voiceSocketUrl(this.connection, token));
|
|
8097
|
+
ws.binaryType = "arraybuffer";
|
|
8098
|
+
this.ws = ws;
|
|
8099
|
+
ws.onmessage = (e) => {
|
|
8100
|
+
if (typeof e.data === "string") this.onEvent(e.data);
|
|
8101
|
+
else this.onAudio(e.data);
|
|
8102
|
+
};
|
|
8103
|
+
ws.onclose = (e) => {
|
|
8104
|
+
if (this.ended) return;
|
|
8105
|
+
if (!this.ready) {
|
|
8106
|
+
this.end("unavailable");
|
|
8107
|
+
return;
|
|
8108
|
+
}
|
|
8109
|
+
this.end(this.endingReason ?? CLOSE_REASONS[e.reason] ?? "lost");
|
|
8110
|
+
};
|
|
8111
|
+
}
|
|
8112
|
+
stop() {
|
|
8113
|
+
this.end("stopped");
|
|
8114
|
+
}
|
|
8115
|
+
/** Cheap enough to call every animation frame. */
|
|
8116
|
+
levels() {
|
|
8117
|
+
if (this.ended) return SILENT;
|
|
8118
|
+
return {
|
|
8119
|
+
input: rms(this.inputAnalyser, this.inputBuf),
|
|
8120
|
+
output: this.player?.playing ? rms(this.outputAnalyser, this.outputBuf) : 0
|
|
8121
|
+
};
|
|
8122
|
+
}
|
|
8123
|
+
setPhase(phase) {
|
|
8124
|
+
if (this.ended || this.phase === phase) return;
|
|
8125
|
+
this.phase = phase;
|
|
8126
|
+
this.h.onPhase(phase);
|
|
8127
|
+
}
|
|
8128
|
+
settle() {
|
|
8129
|
+
if (this.asks.size > 0) this.setPhase("thinking");
|
|
8130
|
+
else if (this.player?.playing) this.setPhase("speaking");
|
|
8131
|
+
else this.setPhase("listening");
|
|
8132
|
+
}
|
|
8133
|
+
send(message) {
|
|
8134
|
+
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(JSON.stringify(message));
|
|
8135
|
+
}
|
|
8136
|
+
onAudio(bytes) {
|
|
8137
|
+
if (this.ended || !this.player) return;
|
|
8138
|
+
this.player.enqueue(bytes);
|
|
8139
|
+
this.setPhase("speaking");
|
|
8140
|
+
}
|
|
8141
|
+
onEvent(raw) {
|
|
8142
|
+
let ev;
|
|
8143
|
+
try {
|
|
8144
|
+
ev = JSON.parse(raw);
|
|
8145
|
+
} catch {
|
|
8146
|
+
return;
|
|
8147
|
+
}
|
|
8148
|
+
const text = (k) => typeof ev[k] === "string" ? ev[k] : "";
|
|
8149
|
+
switch (ev.type) {
|
|
8150
|
+
case "session.ready":
|
|
8151
|
+
this.ready = true;
|
|
8152
|
+
this.setPhase("listening");
|
|
8153
|
+
break;
|
|
8154
|
+
case "input_audio_buffer.speech_started":
|
|
8155
|
+
this.cancelFinish();
|
|
8156
|
+
this.player?.stop();
|
|
8157
|
+
this.saying = "";
|
|
8158
|
+
this.partialHeard = "";
|
|
8159
|
+
this.heard = null;
|
|
8160
|
+
this.setPhase("hearing");
|
|
8161
|
+
break;
|
|
8162
|
+
case "input_audio_buffer.speech_stopped":
|
|
8163
|
+
this.setPhase("thinking");
|
|
8164
|
+
break;
|
|
8165
|
+
case "conversation.item.input_audio_transcription.delta":
|
|
8166
|
+
this.partialHeard += text("delta");
|
|
8167
|
+
this.h.onHeard(this.partialHeard, false);
|
|
8168
|
+
break;
|
|
8169
|
+
case "conversation.item.input_audio_transcription.completed":
|
|
8170
|
+
this.heard = text("transcript").trim() || null;
|
|
8171
|
+
this.partialHeard = "";
|
|
8172
|
+
this.h.onHeard(this.heard ?? "", true);
|
|
8173
|
+
if (this.heard && text("message_id")) {
|
|
8174
|
+
this.h.onUtterance?.({ itemId: text("item_id"), messageId: text("message_id"), text: this.heard });
|
|
8175
|
+
}
|
|
8176
|
+
break;
|
|
8177
|
+
case "voice.reply":
|
|
8178
|
+
if (text("message_id") && text("text")) {
|
|
8179
|
+
this.h.onReply?.({
|
|
8180
|
+
messageId: text("message_id"),
|
|
8181
|
+
itemId: text("item_id") || null,
|
|
8182
|
+
text: text("text"),
|
|
8183
|
+
interrupted: ev.interrupted === true
|
|
8184
|
+
});
|
|
8185
|
+
}
|
|
8186
|
+
break;
|
|
8187
|
+
case "response.audio_transcript.delta":
|
|
8188
|
+
this.saying += text("delta");
|
|
8189
|
+
this.h.onSaying(this.saying, false);
|
|
8190
|
+
break;
|
|
8191
|
+
case "response.audio_transcript.done":
|
|
8192
|
+
this.h.onSaying(text("transcript") || this.saying, true);
|
|
8193
|
+
this.saying = "";
|
|
8194
|
+
break;
|
|
8195
|
+
case "tool_call":
|
|
8196
|
+
this.asks.add({
|
|
8197
|
+
callId: text("call_id"),
|
|
8198
|
+
question: text("question"),
|
|
8199
|
+
replaces: ev.replaces_earlier === true,
|
|
8200
|
+
heard: this.heard,
|
|
8201
|
+
utterance: text("message_id") ? { itemId: text("item_id"), messageId: text("message_id") } : null
|
|
8202
|
+
});
|
|
8203
|
+
this.setPhase("thinking");
|
|
8204
|
+
break;
|
|
8205
|
+
case "response.done":
|
|
8206
|
+
if (!this.player?.playing) this.settle();
|
|
8207
|
+
break;
|
|
8208
|
+
case "session.ending":
|
|
8209
|
+
this.endingReason = CLOSE_REASONS[text("reason")] ?? "lost";
|
|
8210
|
+
break;
|
|
8211
|
+
case "session.finish":
|
|
8212
|
+
this.finishAfterGoodbye();
|
|
8213
|
+
break;
|
|
8214
|
+
case "error":
|
|
8215
|
+
console.warn("[voice]", ev.code, ev.message);
|
|
8216
|
+
break;
|
|
8217
|
+
}
|
|
8218
|
+
}
|
|
8219
|
+
/** They are done: end once the goodbye has finished playing. */
|
|
8220
|
+
finishAfterGoodbye() {
|
|
8221
|
+
this.cancelFinish();
|
|
8222
|
+
const deadline = Date.now() + FINISH_MAX_WAIT_MS;
|
|
8223
|
+
const check = () => {
|
|
8224
|
+
if (this.ended) return;
|
|
8225
|
+
if (this.player?.playing && Date.now() < deadline) {
|
|
8226
|
+
this.finishTimer = setTimeout(check, 200);
|
|
8227
|
+
return;
|
|
8228
|
+
}
|
|
8229
|
+
this.finishTimer = setTimeout(() => this.end("finished"), FINISH_GRACE_MS);
|
|
8230
|
+
};
|
|
8231
|
+
check();
|
|
8232
|
+
}
|
|
8233
|
+
cancelFinish() {
|
|
8234
|
+
if (this.finishTimer) clearTimeout(this.finishTimer);
|
|
8235
|
+
this.finishTimer = null;
|
|
8236
|
+
}
|
|
8237
|
+
release() {
|
|
8238
|
+
this.node?.port.close();
|
|
8239
|
+
this.node?.disconnect();
|
|
8240
|
+
this.stream?.getTracks().forEach((t) => t.stop());
|
|
8241
|
+
this.player?.stop();
|
|
8242
|
+
void this.ctx?.close().catch(() => void 0);
|
|
8243
|
+
if (this.blobUrl) URL.revokeObjectURL(this.blobUrl);
|
|
8244
|
+
this.blobUrl = null;
|
|
8245
|
+
this.inputAnalyser = null;
|
|
8246
|
+
this.outputAnalyser = null;
|
|
8247
|
+
this.node = null;
|
|
8248
|
+
this.stream = null;
|
|
8249
|
+
this.ctx = null;
|
|
8250
|
+
}
|
|
8251
|
+
end(reason, detail) {
|
|
8252
|
+
if (this.ended) return;
|
|
8253
|
+
this.ended = true;
|
|
8254
|
+
this.cancelFinish();
|
|
8255
|
+
const ws = this.ws;
|
|
8256
|
+
this.ws = null;
|
|
8257
|
+
if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) ws.close(1e3);
|
|
8258
|
+
this.release();
|
|
8259
|
+
this.h.onEnd(reason, detail);
|
|
8260
|
+
}
|
|
8261
|
+
};
|
|
8262
|
+
|
|
8263
|
+
// src/voice/voiceprint.ts
|
|
8264
|
+
var GLYPHS = "\uFF71\uFF72\uFF73\uFF74\uFF75\uFF76\uFF77\uFF78\uFF79\uFF7A\uFF7B\uFF7C\uFF7D\uFF7E\uFF7F\uFF80\uFF81\uFF82\uFF83\uFF84\uFF85\uFF86\uFF87\uFF88\uFF89\uFF8A\uFF8B\uFF8C\uFF8D\uFF8E\uFF8F\uFF90\uFF91\uFF92\uFF93\uFF94\uFF95\uFF96\uFF97\uFF98\uFF99\uFF9A\uFF9B\uFF9C\uFF9D01".split("");
|
|
8265
|
+
var STEP_MS = 42;
|
|
8266
|
+
function loudness(rms2) {
|
|
8267
|
+
const v = Math.max(0, rms2 - 4e-3);
|
|
8268
|
+
return Math.min(1, Math.sqrt(v * 7));
|
|
8269
|
+
}
|
|
8270
|
+
function nextColumn(levels, phase, t, seed) {
|
|
8271
|
+
const you = loudness(levels.input);
|
|
8272
|
+
const javier = loudness(levels.output);
|
|
8273
|
+
if (javier > 0.05 && javier >= you * 0.8) return { amp: javier, voice: 2 /* Javier */, seed };
|
|
8274
|
+
if (you > 0.12) return { amp: you, voice: 1 /* You */, seed };
|
|
8275
|
+
if (phase === "thinking" || phase === "connecting") {
|
|
8276
|
+
const swell = 0.24 + 0.17 * Math.sin(t / 170) * Math.sin(t / 530);
|
|
8277
|
+
return { amp: Math.max(0.06, swell), voice: 3 /* Working */, seed };
|
|
8278
|
+
}
|
|
8279
|
+
return { amp: 0.06 + 0.035 * Math.sin(t / 650), voice: 0 /* Quiet */, seed };
|
|
8280
|
+
}
|
|
8281
|
+
function cellIntensity(amp, rows, row) {
|
|
8282
|
+
const half = rows / 2;
|
|
8283
|
+
const d = Math.abs(row + 0.5 - half) / half;
|
|
8284
|
+
const reach = Math.max(amp, 0);
|
|
8285
|
+
if (reach <= 0 || d > reach) return 0;
|
|
8286
|
+
return 0.5 + 0.5 * Math.pow(1 - d / reach, 0.8);
|
|
8287
|
+
}
|
|
8288
|
+
function hash(a, b) {
|
|
8289
|
+
let h = Math.imul(a | 0, 374761393) + Math.imul(b | 0, 668265263) | 0;
|
|
8290
|
+
h = Math.imul(h ^ h >>> 13, 1274126177);
|
|
8291
|
+
return (h ^ h >>> 16) >>> 0;
|
|
8292
|
+
}
|
|
8293
|
+
function glyphFor(seed, row) {
|
|
8294
|
+
return GLYPHS[hash(seed, row) % GLYPHS.length];
|
|
8295
|
+
}
|
|
8296
|
+
function ageFade(x, width) {
|
|
8297
|
+
const span = width * 0.42;
|
|
8298
|
+
if (span <= 0) return 1;
|
|
8299
|
+
const k = Math.min(1, Math.max(0, x / span));
|
|
8300
|
+
return k * k * (3 - 2 * k);
|
|
8301
|
+
}
|
|
8302
|
+
function clock(ms) {
|
|
8303
|
+
const s = Math.max(0, Math.floor(ms / 1e3));
|
|
8304
|
+
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
|
|
8305
|
+
}
|
|
8306
|
+
function captionTail(text, max) {
|
|
8307
|
+
const t = text.trim();
|
|
8308
|
+
if (t.length <= max) return t;
|
|
8309
|
+
const cut = t.slice(t.length - max);
|
|
8310
|
+
const space = cut.indexOf(" ");
|
|
8311
|
+
return `\u2026${space > 0 && space < 24 ? cut.slice(space + 1) : cut}`;
|
|
8312
|
+
}
|
|
8313
|
+
function parseCssColor(value, fallback) {
|
|
8314
|
+
const v = value.trim();
|
|
8315
|
+
const srgb = /^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/i.exec(v);
|
|
8316
|
+
if (srgb) return [srgb[1], srgb[2], srgb[3]].map((n) => Math.round(Math.min(1, Math.max(0, Number(n))) * 255));
|
|
8317
|
+
const rgb = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(v);
|
|
8318
|
+
if (rgb) return [Number(rgb[1]), Number(rgb[2]), Number(rgb[3])].map((n) => Math.round(n));
|
|
8319
|
+
return fallback;
|
|
8320
|
+
}
|
|
8321
|
+
|
|
8322
|
+
// src/voice/useVoiceSession.ts
|
|
8323
|
+
function useVoiceSession(host, connection) {
|
|
8324
|
+
const [available, setAvailable] = React15.useState(false);
|
|
8325
|
+
const [defaultName, setDefaultName] = React15.useState(null);
|
|
8326
|
+
const [maxSessionSecs, setMaxSessionSecs] = React15.useState(0);
|
|
8327
|
+
const [phase, setPhase] = React15.useState("off");
|
|
8328
|
+
const [heard, setHeard] = React15.useState("");
|
|
8329
|
+
const [saying, setSaying] = React15.useState("");
|
|
8330
|
+
const [ended, setEnded] = React15.useState(null);
|
|
8331
|
+
const [startedAt, setStartedAt] = React15.useState(null);
|
|
8332
|
+
const session = React15.useRef(null);
|
|
8333
|
+
const hostRef = React15.useRef(host);
|
|
8334
|
+
hostRef.current = host;
|
|
8335
|
+
const connectionRef = React15.useRef(connection);
|
|
8336
|
+
connectionRef.current = connection;
|
|
8337
|
+
const { baseUrl } = connection;
|
|
8338
|
+
React15.useEffect(() => {
|
|
8339
|
+
const controller = new AbortController();
|
|
8340
|
+
void getVoiceStatus(connectionRef.current, controller.signal).then((s) => {
|
|
8341
|
+
if (controller.signal.aborted) return;
|
|
8342
|
+
setAvailable(s.enabled);
|
|
8343
|
+
setMaxSessionSecs(s.maxSessionSecs);
|
|
8344
|
+
setDefaultName(s.persona?.name ?? null);
|
|
8345
|
+
});
|
|
8346
|
+
return () => controller.abort();
|
|
8347
|
+
}, [baseUrl]);
|
|
8348
|
+
const start = React15.useCallback(() => {
|
|
8349
|
+
if (session.current) return;
|
|
8350
|
+
setEnded(null);
|
|
8351
|
+
setHeard("");
|
|
8352
|
+
setSaying("");
|
|
8353
|
+
setStartedAt(null);
|
|
8354
|
+
const s = new VoiceSession(
|
|
8355
|
+
{
|
|
8356
|
+
onPhase: (p) => {
|
|
8357
|
+
setPhase(p);
|
|
8358
|
+
if (p !== "connecting") setStartedAt((at) => at ?? Date.now());
|
|
8359
|
+
},
|
|
8360
|
+
onHeard: (text) => setHeard(text),
|
|
8361
|
+
onSaying: (text) => setSaying(text),
|
|
8362
|
+
onAsk: (question, h, utterance, progress, signal) => hostRef.current.onAsk(question, h, utterance, progress, signal),
|
|
8363
|
+
onUtterance: (u) => hostRef.current.onUtterance?.(u),
|
|
8364
|
+
onReply: (r) => hostRef.current.onReply?.(r),
|
|
8365
|
+
onEnd: (reason, detail) => {
|
|
8366
|
+
if (session.current === s) session.current = null;
|
|
8367
|
+
setPhase("off");
|
|
8368
|
+
setStartedAt(null);
|
|
8369
|
+
setEnded(reason === "stopped" || reason === "finished" ? null : { reason, detail });
|
|
8370
|
+
}
|
|
8371
|
+
},
|
|
8372
|
+
{ ...connectionRef.current }
|
|
8373
|
+
);
|
|
8374
|
+
session.current = s;
|
|
8375
|
+
void s.start();
|
|
8376
|
+
}, []);
|
|
8377
|
+
const stop = React15.useCallback(() => session.current?.stop(), []);
|
|
8378
|
+
const toggle = React15.useCallback(() => session.current ? stop() : start(), [start, stop]);
|
|
8379
|
+
const dismiss = React15.useCallback(() => setEnded(null), []);
|
|
8380
|
+
const levels = React15.useCallback(() => session.current?.levels() ?? SILENT, []);
|
|
8381
|
+
const level = React15.useCallback(() => {
|
|
8382
|
+
const l = levels();
|
|
8383
|
+
return Math.max(loudness(l.input), loudness(l.output));
|
|
8384
|
+
}, [levels]);
|
|
8385
|
+
React15.useEffect(() => () => session.current?.stop(), []);
|
|
8386
|
+
return {
|
|
8387
|
+
available,
|
|
8388
|
+
defaultName,
|
|
8389
|
+
phase,
|
|
8390
|
+
heard,
|
|
8391
|
+
saying,
|
|
8392
|
+
ended,
|
|
8393
|
+
startedAt,
|
|
8394
|
+
maxSessionSecs,
|
|
8395
|
+
levels,
|
|
8396
|
+
level,
|
|
8397
|
+
buttonState: phase === "off" ? "off" : phase === "connecting" ? "connecting" : "live",
|
|
8398
|
+
start,
|
|
8399
|
+
stop,
|
|
8400
|
+
toggle,
|
|
8401
|
+
dismiss
|
|
8402
|
+
};
|
|
8403
|
+
}
|
|
8404
|
+
function voiceEndedMessage(ended, name = "the assistant") {
|
|
8405
|
+
if (!ended) return null;
|
|
8406
|
+
switch (ended.reason) {
|
|
8407
|
+
case "time_limit":
|
|
8408
|
+
return "Voice ends after a while to keep costs in check. Tap the microphone to keep talking.";
|
|
8409
|
+
case "replaced":
|
|
8410
|
+
return "Voice moved to your other window.";
|
|
8411
|
+
case "blocked":
|
|
8412
|
+
return ended.detail === "card_required" ? "Add a card to use voice." : ended.detail === "credit_exhausted" ? "You are out of credit. Top up to use voice." : "Voice needs an active billing plan.";
|
|
8413
|
+
case "mic_denied":
|
|
8414
|
+
return `Allow microphone access to talk to ${name}.`;
|
|
8415
|
+
case "unavailable":
|
|
8416
|
+
return ended.detail && !/^[a-z_]+$/.test(ended.detail) ? ended.detail : "Voice could not connect. Try again in a moment.";
|
|
8417
|
+
case "lost":
|
|
8418
|
+
return "Voice disconnected. Tap the microphone to reconnect.";
|
|
8419
|
+
default:
|
|
8420
|
+
return null;
|
|
8421
|
+
}
|
|
8422
|
+
}
|
|
8423
|
+
|
|
8424
|
+
// src/voice/styles.ts
|
|
8425
|
+
var VOICE_DECK_CSS = `
|
|
8426
|
+
@property --yf-voice-angle { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
|
|
8427
|
+
@keyframes yf-voice-orbit { to { --yf-voice-angle: 360deg; } }
|
|
8428
|
+
@keyframes yf-voice-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
|
|
8429
|
+
@keyframes yf-voice-beacon {
|
|
8430
|
+
0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--yf-voice-live) 55%, transparent); }
|
|
8431
|
+
70% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--yf-voice-live) 0%, transparent); }
|
|
8432
|
+
100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--yf-voice-live) 0%, transparent); }
|
|
8433
|
+
}
|
|
8434
|
+
.yf-voice-deck {
|
|
8435
|
+
--yf-voice-live: var(--yf-voice-accent);
|
|
8436
|
+
position: relative;
|
|
8437
|
+
border-radius: 16px;
|
|
8438
|
+
padding: 1px;
|
|
8439
|
+
background:
|
|
8440
|
+
conic-gradient(
|
|
8441
|
+
from var(--yf-voice-angle),
|
|
8442
|
+
transparent 0deg,
|
|
8443
|
+
color-mix(in srgb, var(--yf-voice-live) 95%, transparent) 50deg,
|
|
8444
|
+
color-mix(in srgb, var(--yf-voice-live) 15%, transparent) 110deg,
|
|
8445
|
+
transparent 180deg,
|
|
8446
|
+
transparent 360deg
|
|
8447
|
+
),
|
|
8448
|
+
linear-gradient(color-mix(in srgb, var(--yf-voice-live) 22%, transparent), color-mix(in srgb, var(--yf-voice-live) 22%, transparent));
|
|
8449
|
+
box-shadow: 0 24px 60px -32px color-mix(in srgb, var(--yf-voice-live) 65%, transparent);
|
|
8450
|
+
animation: yf-voice-orbit 5s linear infinite;
|
|
8451
|
+
transition: box-shadow 0.5s ease;
|
|
8452
|
+
}
|
|
8453
|
+
.yf-voice-deck[data-phase='hearing'] { --yf-voice-live: var(--yf-voice-ink); animation-duration: 2.6s; }
|
|
8454
|
+
.yf-voice-deck[data-phase='thinking'] { animation-duration: 1.4s; }
|
|
8455
|
+
.yf-voice-deck[data-phase='speaking'] { animation-duration: 3.2s; }
|
|
8456
|
+
.yf-voice-deck[data-phase='listening'],
|
|
8457
|
+
.yf-voice-deck[data-phase='connecting'] { animation-duration: 9s; }
|
|
8458
|
+
.yf-voice-deck__panel {
|
|
8459
|
+
position: relative;
|
|
8460
|
+
overflow: hidden;
|
|
8461
|
+
border-radius: 15px;
|
|
8462
|
+
background:
|
|
8463
|
+
radial-gradient(120% 160% at 100% 0%, color-mix(in srgb, var(--yf-voice-live) 13%, transparent), transparent 58%),
|
|
8464
|
+
radial-gradient(90% 120% at 0% 100%, color-mix(in srgb, var(--yf-voice-live) 5%, transparent), transparent 60%),
|
|
8465
|
+
color-mix(in srgb, var(--yf-voice-panel) 90%, transparent);
|
|
8466
|
+
-webkit-backdrop-filter: blur(14px) saturate(1.2);
|
|
8467
|
+
backdrop-filter: blur(14px) saturate(1.2);
|
|
8468
|
+
animation: yf-voice-rise 0.32s cubic-bezier(0.2, 0.7, 0.2, 1) both;
|
|
8469
|
+
}
|
|
8470
|
+
.yf-voice-beacon {
|
|
8471
|
+
width: 8px;
|
|
8472
|
+
height: 8px;
|
|
8473
|
+
flex-shrink: 0;
|
|
8474
|
+
border-radius: 999px;
|
|
8475
|
+
background: var(--yf-voice-live);
|
|
8476
|
+
animation: yf-voice-beacon 1.8s ease-out infinite;
|
|
8477
|
+
transition: background-color 0.3s ease;
|
|
8478
|
+
}
|
|
8479
|
+
.yf-voice-deck[data-phase='listening'] .yf-voice-beacon { animation-duration: 3.2s; }
|
|
8480
|
+
.yf-voice-phase {
|
|
8481
|
+
font-size: 10.5px;
|
|
8482
|
+
font-weight: 600;
|
|
8483
|
+
letter-spacing: 0.14em;
|
|
8484
|
+
text-transform: uppercase;
|
|
8485
|
+
color: var(--yf-voice-live);
|
|
8486
|
+
transition: color 0.3s ease;
|
|
8487
|
+
}
|
|
8488
|
+
.yf-voice-clock { font-size: 11px; font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--yf-voice-muted); }
|
|
8489
|
+
.yf-voice-clock[data-soon] { color: var(--yf-voice-accent); }
|
|
8490
|
+
.yf-voice-end {
|
|
8491
|
+
display: inline-flex;
|
|
8492
|
+
align-items: center;
|
|
8493
|
+
gap: 7px;
|
|
8494
|
+
height: 28px;
|
|
8495
|
+
padding: 0 12px 0 10px;
|
|
8496
|
+
border-radius: 999px;
|
|
8497
|
+
border: 1px solid color-mix(in srgb, var(--yf-voice-ink) 16%, transparent);
|
|
8498
|
+
background: color-mix(in srgb, var(--yf-voice-ink) 5%, transparent);
|
|
8499
|
+
color: color-mix(in srgb, var(--yf-voice-ink) 85%, transparent);
|
|
8500
|
+
font-size: 12px;
|
|
8501
|
+
font-weight: 500;
|
|
8502
|
+
transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
|
|
8503
|
+
-webkit-tap-highlight-color: transparent;
|
|
8504
|
+
}
|
|
8505
|
+
.yf-voice-end:hover { background: color-mix(in srgb, var(--yf-voice-ink) 10%, transparent); border-color: color-mix(in srgb, var(--yf-voice-ink) 28%, transparent); color: var(--yf-voice-ink); }
|
|
8506
|
+
.yf-voice-end:active { transform: scale(0.97); }
|
|
8507
|
+
.yf-voice-end__mark { width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
|
|
8508
|
+
.yf-voice-print {
|
|
8509
|
+
-webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12%, #000 100%);
|
|
8510
|
+
mask-image: linear-gradient(90deg, transparent 0, #000 12%, #000 100%);
|
|
8511
|
+
}
|
|
8512
|
+
.yf-voice-caption { display: flex; min-width: 0; align-items: baseline; gap: 8px; color: color-mix(in srgb, var(--yf-voice-ink) 72%, transparent); }
|
|
8513
|
+
.yf-voice-caption--javier { display: block; color: var(--yf-voice-ink); font-weight: 450; text-wrap: pretty; }
|
|
8514
|
+
.yf-voice-hint { color: var(--yf-voice-muted); }
|
|
8515
|
+
.yf-voice-who {
|
|
8516
|
+
flex-shrink: 0;
|
|
8517
|
+
font-size: 9.5px;
|
|
8518
|
+
font-weight: 600;
|
|
8519
|
+
letter-spacing: 0.14em;
|
|
8520
|
+
text-transform: uppercase;
|
|
8521
|
+
color: var(--yf-voice-muted);
|
|
8522
|
+
}
|
|
8523
|
+
.yf-voice-deck[data-phone] { border-radius: 20px; }
|
|
8524
|
+
.yf-voice-deck[data-phone] .yf-voice-deck__panel { border-radius: 19px; }
|
|
8525
|
+
.yf-voice-deck[data-phone] .yf-voice-end { height: 40px; padding: 0 16px 0 14px; font-size: 14px; }
|
|
8526
|
+
.yf-voice-deck[data-phone] .yf-voice-phase { font-size: 11.5px; }
|
|
8527
|
+
@media (prefers-reduced-motion: reduce) {
|
|
8528
|
+
.yf-voice-deck, .yf-voice-beacon, .yf-voice-deck__panel { animation: none; }
|
|
8529
|
+
}
|
|
8530
|
+
`;
|
|
8531
|
+
var STYLE_ID = "yf-voice-deck-styles";
|
|
8532
|
+
function ensureVoiceDeckStyles(doc = typeof document === "undefined" ? void 0 : document) {
|
|
8533
|
+
if (!doc || doc.getElementById(STYLE_ID)) return;
|
|
8534
|
+
const style = doc.createElement("style");
|
|
8535
|
+
style.id = STYLE_ID;
|
|
8536
|
+
style.textContent = VOICE_DECK_CSS;
|
|
8537
|
+
doc.head.appendChild(style);
|
|
8538
|
+
}
|
|
8539
|
+
function VoiceDeck({ voice, name, phone = false, hint }) {
|
|
8540
|
+
const t = useTheme();
|
|
8541
|
+
React15.useEffect(() => ensureVoiceDeckStyles(), []);
|
|
8542
|
+
const now = useClock(voice.startedAt !== null);
|
|
8543
|
+
if (voice.phase === "off") return null;
|
|
8544
|
+
const speaker = name ?? voice.defaultName ?? "Assistant";
|
|
8545
|
+
const phaseWords = {
|
|
8546
|
+
connecting: "Connecting",
|
|
8547
|
+
listening: "Listening",
|
|
8548
|
+
hearing: "Hearing you",
|
|
8549
|
+
thinking: "Working on it",
|
|
8550
|
+
speaking: speaker
|
|
8551
|
+
};
|
|
8552
|
+
const { startedAt, maxSessionSecs } = voice;
|
|
8553
|
+
const elapsed = startedAt === null ? 0 : now - startedAt;
|
|
8554
|
+
const remaining = maxSessionSecs > 0 && startedAt !== null ? maxSessionSecs * 1e3 - elapsed : Infinity;
|
|
8555
|
+
const endingSoon = remaining < 6e4;
|
|
8556
|
+
const said = captionTail(voice.saying, phone ? 170 : 240);
|
|
8557
|
+
const words = captionTail(voice.heard, phone ? 90 : 140);
|
|
8558
|
+
const vars = {
|
|
8559
|
+
"--yf-voice-accent": t.primary,
|
|
8560
|
+
"--yf-voice-ink": t.text,
|
|
8561
|
+
"--yf-voice-muted": t.textMuted,
|
|
8562
|
+
"--yf-voice-panel": t.bgRaised
|
|
8563
|
+
};
|
|
8564
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "yf-voice-deck", "data-phase": voice.phase, "data-phone": phone ? "" : void 0, style: vars, children: [
|
|
8565
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "yf-voice-deck__panel", children: [
|
|
8566
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex items-center gap-2.5 ${phone ? "px-4 pt-3.5" : "px-4 pt-3"}`, children: [
|
|
8567
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "yf-voice-beacon", "aria-hidden": "true" }),
|
|
8568
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { role: "status", "aria-live": "polite", className: "yf-voice-phase", children: phaseWords[voice.phase] }),
|
|
8569
|
+
startedAt !== null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "yf-voice-clock", "data-soon": endingSoon ? "" : void 0, title: endingSoon ? "Voice ends soon" : "Time in this voice session", children: endingSoon && Number.isFinite(remaining) ? `ends in ${clock(remaining)}` : clock(elapsed) }) : null,
|
|
8570
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1" }),
|
|
8571
|
+
/* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", onClick: voice.stop, className: "yf-voice-end", "aria-label": "End voice", children: [
|
|
8572
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "yf-voice-end__mark", "aria-hidden": "true" }),
|
|
8573
|
+
"End"
|
|
8574
|
+
] })
|
|
8575
|
+
] }),
|
|
8576
|
+
/* @__PURE__ */ jsxRuntime.jsx(Voiceprint, { phase: voice.phase, levels: voice.levels, height: phone ? 104 : 76, cell: phone ? 13 : 11 }),
|
|
8577
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex flex-col gap-1.5 ${phone ? "px-4 pb-4" : "px-4 pb-3.5"}`, style: { minHeight: "1.25rem" }, "aria-live": "off", children: [
|
|
8578
|
+
words ? /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "yf-voice-caption", style: { fontSize: phone ? 13.5 : 12.5 }, children: [
|
|
8579
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "yf-voice-who", children: "You" }),
|
|
8580
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "min-w-0 truncate", children: words })
|
|
8581
|
+
] }) : null,
|
|
8582
|
+
said ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "yf-voice-caption yf-voice-caption--javier", style: { fontSize: phone ? 16 : 14, lineHeight: phone ? 1.45 : 1.5 }, children: said }) : !words ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "yf-voice-hint", style: { fontSize: phone ? 14 : 12.5 }, children: voice.phase === "connecting" ? "Opening the line\u2026" : hint ?? "Ask anything. Talk over me to interrupt." }) : null
|
|
8583
|
+
] })
|
|
8584
|
+
] }),
|
|
8585
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "data-voice-probe": "ink", hidden: true, style: { color: "var(--yf-voice-ink)" } }),
|
|
8586
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "data-voice-probe": "accent", hidden: true, style: { color: "var(--yf-voice-accent)" } }),
|
|
8587
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "data-voice-probe": "muted", hidden: true, style: { color: "var(--yf-voice-muted)" } })
|
|
8588
|
+
] });
|
|
8589
|
+
}
|
|
8590
|
+
function useClock(running) {
|
|
8591
|
+
const [now, setNow] = React15.useState(() => Date.now());
|
|
8592
|
+
React15.useEffect(() => {
|
|
8593
|
+
if (!running) return void 0;
|
|
8594
|
+
setNow(Date.now());
|
|
8595
|
+
const id = window.setInterval(() => setNow(Date.now()), 1e3);
|
|
8596
|
+
return () => window.clearInterval(id);
|
|
8597
|
+
}, [running]);
|
|
8598
|
+
return now;
|
|
8599
|
+
}
|
|
8600
|
+
function Voiceprint({ phase, levels, height, cell }) {
|
|
8601
|
+
const canvasRef = React15.useRef(null);
|
|
8602
|
+
const phaseRef = React15.useRef(phase);
|
|
8603
|
+
phaseRef.current = phase;
|
|
8604
|
+
const levelsRef = React15.useRef(levels);
|
|
8605
|
+
levelsRef.current = levels;
|
|
8606
|
+
React15.useEffect(() => {
|
|
8607
|
+
const canvas = canvasRef.current;
|
|
8608
|
+
const ctx = canvas?.getContext("2d");
|
|
8609
|
+
if (!canvas || !ctx) return void 0;
|
|
8610
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
|
|
8611
|
+
const cellW = Math.round(cell * 0.8);
|
|
8612
|
+
const cellH = Math.round(cell * 0.95);
|
|
8613
|
+
let width = 0;
|
|
8614
|
+
let dpr = 1;
|
|
8615
|
+
let rows = 1;
|
|
8616
|
+
let columns = [];
|
|
8617
|
+
let colors = { ink: [236, 232, 225], accent: [255, 140, 66], muted: [140, 140, 140] };
|
|
8618
|
+
let seed = 1;
|
|
8619
|
+
let last = performance.now();
|
|
8620
|
+
let colorsAt = 0;
|
|
8621
|
+
let raf = 0;
|
|
8622
|
+
const readColors = () => {
|
|
8623
|
+
const deck = canvas.closest(".yf-voice-deck");
|
|
8624
|
+
const probe = (which, fallback) => {
|
|
8625
|
+
const el = deck?.querySelector(`[data-voice-probe="${which}"]`);
|
|
8626
|
+
return el ? parseCssColor(getComputedStyle(el).color, fallback) : fallback;
|
|
8627
|
+
};
|
|
8628
|
+
colors = { ink: probe("ink", colors.ink), accent: probe("accent", colors.accent), muted: probe("muted", colors.muted) };
|
|
8629
|
+
};
|
|
8630
|
+
const resize = () => {
|
|
8631
|
+
dpr = Math.min(window.devicePixelRatio || 1, 3);
|
|
8632
|
+
width = canvas.clientWidth;
|
|
8633
|
+
canvas.width = Math.round(width * dpr);
|
|
8634
|
+
canvas.height = Math.round(height * dpr);
|
|
8635
|
+
rows = Math.max(3, Math.floor(height / cellH));
|
|
8636
|
+
const need = Math.ceil(width / cellW) + 3;
|
|
8637
|
+
columns = columns.slice(-need);
|
|
8638
|
+
while (columns.length < need) columns.unshift({ amp: 0.05, voice: 0 /* Quiet */, seed: seed++ });
|
|
8639
|
+
};
|
|
8640
|
+
const rgba = (c, a) => `rgba(${c[0]},${c[1]},${c[2]},${a.toFixed(3)})`;
|
|
8641
|
+
const colorOf = (v) => v === 1 /* You */ ? colors.ink : v === 0 /* Quiet */ ? colors.muted : colors.accent;
|
|
8642
|
+
const draw = (time) => {
|
|
8643
|
+
if (time - colorsAt > 1e3) {
|
|
8644
|
+
readColors();
|
|
8645
|
+
colorsAt = time;
|
|
8646
|
+
}
|
|
8647
|
+
const step = reduced ? STEP_MS * 2.5 : STEP_MS;
|
|
8648
|
+
while (time - last >= step) {
|
|
8649
|
+
columns.shift();
|
|
8650
|
+
columns.push(nextColumn(levelsRef.current(), phaseRef.current, time, seed++));
|
|
8651
|
+
last += step;
|
|
8652
|
+
}
|
|
8653
|
+
if (time - last > step * 4) last = time;
|
|
8654
|
+
const frac = reduced ? 0 : (time - last) / step;
|
|
8655
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
8656
|
+
ctx.clearRect(0, 0, width, height);
|
|
8657
|
+
ctx.font = `500 ${cell}px "Hiragino Kaku Gothic ProN", "Noto Sans JP", ui-monospace, monospace`;
|
|
8658
|
+
ctx.textAlign = "center";
|
|
8659
|
+
ctx.textBaseline = "middle";
|
|
8660
|
+
const n = columns.length;
|
|
8661
|
+
const top = (height - rows * cellH) / 2 + cellH / 2;
|
|
8662
|
+
for (let i = 0; i < n; i += 1) {
|
|
8663
|
+
const col = columns[i];
|
|
8664
|
+
const x = width - (n - 1 - i + frac) * cellW + cellW / 2 - cellW;
|
|
8665
|
+
if (x < -cellW || x > width + cellW) continue;
|
|
8666
|
+
const fade = ageFade(x, width);
|
|
8667
|
+
const fresh = n - 1 - i < 3;
|
|
8668
|
+
const color = colorOf(col.voice);
|
|
8669
|
+
const reach = Math.min(1, col.amp * 1.15);
|
|
8670
|
+
for (let r = 0; r < rows; r += 1) {
|
|
8671
|
+
const k = cellIntensity(reach, rows, r);
|
|
8672
|
+
const s = fresh && !reduced ? col.seed + Math.floor(time / 90) : col.seed;
|
|
8673
|
+
const y = top + r * cellH;
|
|
8674
|
+
if (k <= 0.02) {
|
|
8675
|
+
ctx.fillStyle = rgba(colors.muted, 0.07 * (0.25 + 0.75 * fade));
|
|
8676
|
+
ctx.fillText(glyphFor(s + 7, r), x, y);
|
|
8677
|
+
continue;
|
|
8678
|
+
}
|
|
8679
|
+
const alpha = Math.min(1, k * (col.voice === 0 /* Quiet */ ? 0.45 : 0.95) * (0.12 + 0.88 * fade) * (fresh ? 1.3 : 1));
|
|
8680
|
+
const bright = k > 0.8 && col.voice !== 0 /* Quiet */ && !reduced;
|
|
8681
|
+
if (bright) {
|
|
8682
|
+
ctx.shadowColor = rgba(color, 0.9);
|
|
8683
|
+
ctx.shadowBlur = 7;
|
|
8684
|
+
}
|
|
8685
|
+
ctx.fillStyle = rgba(color, alpha);
|
|
8686
|
+
ctx.fillText(glyphFor(s, r), x, y);
|
|
8687
|
+
if (bright) ctx.shadowBlur = 0;
|
|
8688
|
+
}
|
|
8689
|
+
}
|
|
8690
|
+
const head = columns[n - 1];
|
|
8691
|
+
if (head) {
|
|
8692
|
+
const c = colorOf(head.voice);
|
|
8693
|
+
const radius = height * 0.48;
|
|
8694
|
+
ctx.save();
|
|
8695
|
+
ctx.translate(width, height / 2);
|
|
8696
|
+
ctx.scale(1.9, 1);
|
|
8697
|
+
const glow = ctx.createRadialGradient(0, 0, 0, 0, 0, radius);
|
|
8698
|
+
glow.addColorStop(0, rgba(c, 0.1 + 0.3 * head.amp));
|
|
8699
|
+
glow.addColorStop(1, rgba(c, 0));
|
|
8700
|
+
ctx.fillStyle = glow;
|
|
8701
|
+
ctx.beginPath();
|
|
8702
|
+
ctx.arc(0, 0, radius, 0, Math.PI * 2);
|
|
8703
|
+
ctx.fill();
|
|
8704
|
+
ctx.restore();
|
|
8705
|
+
const reach = Math.max(6, Math.min(1, head.amp * 1.15) * height * 0.9);
|
|
8706
|
+
const line = ctx.createLinearGradient(0, (height - reach) / 2, 0, (height + reach) / 2);
|
|
8707
|
+
line.addColorStop(0, rgba(c, 0));
|
|
8708
|
+
line.addColorStop(0.5, rgba(c, 0.5 + 0.5 * head.amp));
|
|
8709
|
+
line.addColorStop(1, rgba(c, 0));
|
|
8710
|
+
ctx.fillStyle = line;
|
|
8711
|
+
ctx.fillRect(width - 1.5, (height - reach) / 2, 1.5, reach);
|
|
8712
|
+
}
|
|
8713
|
+
raf = window.requestAnimationFrame(draw);
|
|
8714
|
+
};
|
|
8715
|
+
readColors();
|
|
8716
|
+
resize();
|
|
8717
|
+
const observer = new ResizeObserver(resize);
|
|
8718
|
+
observer.observe(canvas);
|
|
8719
|
+
raf = window.requestAnimationFrame(draw);
|
|
8720
|
+
return () => {
|
|
8721
|
+
window.cancelAnimationFrame(raf);
|
|
8722
|
+
observer.disconnect();
|
|
8723
|
+
};
|
|
8724
|
+
}, [height, cell]);
|
|
8725
|
+
return /* @__PURE__ */ jsxRuntime.jsx("canvas", { ref: canvasRef, className: "yf-voice-print block w-full", style: { height }, "aria-hidden": "true" });
|
|
8726
|
+
}
|
|
7625
8727
|
|
|
7626
8728
|
// src/knowledge/graphTheme.ts
|
|
7627
8729
|
var NODE_TYPE_COLORS = {
|
|
@@ -14661,6 +15763,7 @@ exports.AgentAvatar = AgentAvatar;
|
|
|
14661
15763
|
exports.AgentPresenceBar = AgentPresenceBar;
|
|
14662
15764
|
exports.AgentStepTrace = AgentStepTrace;
|
|
14663
15765
|
exports.AnnotationThread = AnnotationThread;
|
|
15766
|
+
exports.AskQueue = AskQueue;
|
|
14664
15767
|
exports.CLAIM_STATUS_COLORS = CLAIM_STATUS_COLORS;
|
|
14665
15768
|
exports.ChatTerminal = ChatTerminal;
|
|
14666
15769
|
exports.CheckpointCard = CheckpointCard;
|
|
@@ -14689,9 +15792,11 @@ exports.NODE_TYPE_LABELS = NODE_TYPE_LABELS;
|
|
|
14689
15792
|
exports.NodeDetailDrawer = NodeDetailDrawer;
|
|
14690
15793
|
exports.PROGRESS_EVENT_NAME = PROGRESS_EVENT_NAME;
|
|
14691
15794
|
exports.PipelineProgressBar = PipelineProgressBar;
|
|
15795
|
+
exports.REPLACED_OUTPUT = REPLACED_OUTPUT;
|
|
14692
15796
|
exports.ReasoningHistoryCard = ReasoningHistoryCard;
|
|
14693
15797
|
exports.ReasoningOverlay = ReasoningOverlay;
|
|
14694
15798
|
exports.ReasoningView = ReasoningView;
|
|
15799
|
+
exports.SILENT = SILENT;
|
|
14695
15800
|
exports.SSE_KEEPALIVE_MS = SSE_KEEPALIVE_MS;
|
|
14696
15801
|
exports.SSE_STALL_MS = SSE_STALL_MS;
|
|
14697
15802
|
exports.SYNTHESIS_DONE_SIGNAL = SYNTHESIS_DONE_SIGNAL;
|
|
@@ -14702,6 +15807,12 @@ exports.StageCanvas = StageCanvas;
|
|
|
14702
15807
|
exports.StandardTerminal = StandardTerminal;
|
|
14703
15808
|
exports.TerminalInputBar = TerminalInputBar;
|
|
14704
15809
|
exports.TerminalThemeProvider = TerminalThemeProvider;
|
|
15810
|
+
exports.VOICE_CAPTURE_WORKLET_SOURCE = VOICE_CAPTURE_WORKLET_SOURCE;
|
|
15811
|
+
exports.VOICE_LANGUAGES = VOICE_LANGUAGES;
|
|
15812
|
+
exports.VOICE_NAMES = VOICE_NAMES;
|
|
15813
|
+
exports.VoiceDeck = VoiceDeck;
|
|
15814
|
+
exports.VoiceInputButton = VoiceInputButton;
|
|
15815
|
+
exports.VoiceSession = VoiceSession;
|
|
14705
15816
|
exports.agentSeed = agentSeed;
|
|
14706
15817
|
exports.agentStepTraceExtra = agentStepTraceExtra;
|
|
14707
15818
|
exports.avatarColor = avatarColor;
|
|
@@ -14715,6 +15826,7 @@ exports.dispatchProgressEvent = dispatchProgressEvent;
|
|
|
14715
15826
|
exports.documentEventToActivity = documentEventToActivity;
|
|
14716
15827
|
exports.emeraldCollab = emeraldCollab;
|
|
14717
15828
|
exports.emeraldRevised = emeraldRevised;
|
|
15829
|
+
exports.encodePersona = encodePersona;
|
|
14718
15830
|
exports.eventToActivity = eventToActivity;
|
|
14719
15831
|
exports.extractKGSources = extractKGSources;
|
|
14720
15832
|
exports.extractKgId = extractKgId;
|
|
@@ -14731,6 +15843,7 @@ exports.getNodeColors = getNodeColors;
|
|
|
14731
15843
|
exports.getNodeTypeLabel = getNodeTypeLabel;
|
|
14732
15844
|
exports.getVocabTypeColors = getVocabTypeColors;
|
|
14733
15845
|
exports.getVocabTypeLabel = getVocabTypeLabel;
|
|
15846
|
+
exports.getVoiceStatus = getVoiceStatus;
|
|
14734
15847
|
exports.greenAction = greenAction;
|
|
14735
15848
|
exports.handleSSEStream = handleSSEStream;
|
|
14736
15849
|
exports.handleStreamingResponse = handleStreamingResponse;
|
|
@@ -14750,10 +15863,14 @@ exports.reduceProgress = reduceProgress;
|
|
|
14750
15863
|
exports.renderMarkdownBlock = renderMarkdownBlock;
|
|
14751
15864
|
exports.resolvePaymentAssetDisplay = resolvePaymentAssetDisplay;
|
|
14752
15865
|
exports.snapshotToSubgraph = snapshotToSubgraph;
|
|
15866
|
+
exports.socketBase = socketBase;
|
|
14753
15867
|
exports.terminalClassNames = terminalClassNames;
|
|
14754
15868
|
exports.terminalColors = terminalColors;
|
|
14755
15869
|
exports.useScopedProgressEvent = useScopedProgressEvent;
|
|
14756
15870
|
exports.useSlashMentionPicker = useSlashMentionPicker;
|
|
14757
15871
|
exports.useTheme = useTheme;
|
|
15872
|
+
exports.useVoiceSession = useVoiceSession;
|
|
15873
|
+
exports.voiceEndedMessage = voiceEndedMessage;
|
|
15874
|
+
exports.voiceSocketUrl = voiceSocketUrl;
|
|
14758
15875
|
exports.warmBg = warmBg;
|
|
14759
15876
|
exports.withStallTimeout = withStallTimeout;
|