Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "qryptchat-web",
"private": true,
"version": "0.13.2",
"version": "0.13.3",
"type": "module",
"bin": {
"qc": "./bin/qc.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/qryptchat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@profullstack/qryptchat",
"version": "0.9.1",
"version": "0.9.2",
"description": "qc: qrypt.chat in your terminal. A full-screen end-to-end encrypted chat client (ML-KEM-1024), plus a scriptable CLI and an MCP server.",
"type": "module",
"bin": {
Expand Down
13 changes: 10 additions & 3 deletions src/cli/voice-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export const e2eeOptions = (key) => ({
});

export const JOIN_RECENT_MS = 30 * 60 * 1000; // on start-up, join calls started this recently
const ALONE_LEAVE_MS = 30 * 1000; // leave once no person has been in the call this long
const ALONE_LEAVE_MS = 30 * 1000; // leave once the people have gone for this long
export const FIRST_WAIT_MS = 10 * 60 * 1000; // wait this long for the first person to join
const MAX_CALL_MS = 3 * 60 * 60 * 1000;
const RATE = 16000; // what we listen at
const SPEAK_RATE = 24000; // what /api/voice/speak returns
Expand Down Expand Up @@ -131,6 +132,7 @@ export class CallSession {
this.closed = false;
this.started = Date.now();
this.lastHuman = Date.now();
this.humanSeen = false;
}

get id() {
Expand Down Expand Up @@ -163,8 +165,13 @@ export class CallSession {
}

checkAlone() {
if (this.humansPresent()) this.lastHuman = Date.now();
if (Date.now() - this.lastHuman > ALONE_LEAVE_MS) return this.close('everyone left');
if (this.humansPresent()) {
this.lastHuman = Date.now();
this.humanSeen = true;
}
// Whoever started the call may still be on their way in: wait for them before giving up.
const limit = this.humanSeen ? ALONE_LEAVE_MS : FIRST_WAIT_MS;
if (Date.now() - this.lastHuman > limit) return this.close(this.humanSeen ? 'everyone left' : 'nobody came');
if (Date.now() - this.started > MAX_CALL_MS) return this.close('call too long');
}

Expand Down
37 changes: 37 additions & 0 deletions src/cli/voice-agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,43 @@ describe('CallSession', () => {
expect(frames).toEqual([]);
});

it('waits for the first person, then leaves 30 s after the last one goes', () => {
const { s } = make('echo PASS');
const closed = [];
s.close = (why) => closed.push(why);
let people = false;
s.humansPresent = () => people;
const t0 = Date.now();
const at = (ms) => vi.spyOn(Date, 'now').mockReturnValue(t0 + ms);
s.lastHuman = t0;
at(5 * 60 * 1000);
s.checkAlone();
expect(closed).toEqual([]); // nobody yet, but well inside 10 minutes
people = true;
s.checkAlone();
people = false;
at(5 * 60 * 1000 + 20 * 1000);
s.checkAlone();
expect(closed).toEqual([]);
at(5 * 60 * 1000 + 31 * 1000);
s.checkAlone();
expect(closed).toEqual(['everyone left']);
vi.restoreAllMocks();
});

it('gives up when nobody comes within 10 minutes', () => {
const { s } = make('echo PASS');
const closed = [];
s.close = (why) => closed.push(why);
s.humansPresent = () => false;
const t0 = Date.now();
s.lastHuman = t0;
vi.spyOn(Date, 'now').mockReturnValue(t0 + 10 * 60 * 1000 + 1000);
s.checkAlone();
expect(closed).toEqual(['nobody came']);
vi.restoreAllMocks();
});

it('stays quiet on PASS and stops talking when interrupted', async () => {
const { s, frames, sent } = make('echo PASS');
await s.heard(new Float32Array(1600), 'chovy', 'h');
Expand Down
10 changes: 2 additions & 8 deletions src/lib/components/chat/MessageInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { newVoiceRoomLink, parseSlashCommand, voiceMessage } from '@/lib/chat/vo
import EmojiPicker, { Icon } from './EmojiPicker.jsx';
import { IRC_COMMANDS, listLines, namesLines } from '@/lib/chat/irc.js';
import { agentsIn } from '@/lib/chat/voice-mode.js';
import { CALL_TYPE, isJoinable, parseCall } from '@/lib/chat/calls.js';
import { useVoiceMode } from '@/lib/hooks/useVoiceMode.js';
import VoiceBar from './VoiceBar.jsx';
import { setBusy } from '@/lib/app-update.js';
Expand Down Expand Up @@ -82,15 +81,10 @@ export default function MessageInput({ conversationId, disabled = false }) {
const voiceOn = voice.phase !== 'off';

// With AI agents in the chat the mic is a real voice call: they join it, hear
// you and talk back in their own voices (qc agent call). Join the call that is
// already going, if any, else start one.
// you and talk back in their own voices (qc agent call). Always a fresh call: a
// new call message is what brings the agents in, and they may have left an old one.
const chatAgents = agentsIn(activeConversation, user?.id);
function talkToAgents() {
const recent = [...messages].reverse().find((m) => m.conversation_id === conversationId && m.message_type === CALL_TYPE);
const call = recent && parseCall(recent.content);
if (call && isJoinable(call, recent.created_at) && Date.now() - Date.parse(call.at ?? recent.created_at) < 30 * 60 * 1000) {
return useChatStore.getState().joinCall(conversationId, call.key, false);
}
return useChatStore.getState().startCall(conversationId, { video: false });
}

Expand Down
Loading