@hyperwindmill/caretaker-cli 0.28.0 → 0.30.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/agents/dispatch.d.ts.map +1 -1
- package/dist/agents/dispatch.js +4 -1
- package/dist/cli/web/scheduler/telegram.d.ts +27 -0
- package/dist/cli/web/scheduler/telegram.d.ts.map +1 -1
- package/dist/cli/web/scheduler/telegram.js +133 -78
- package/dist/cli/web/scheduler/telegram_media.d.ts +73 -0
- package/dist/cli/web/scheduler/telegram_media.d.ts.map +1 -0
- package/dist/cli/web/scheduler/telegram_media.js +90 -0
- package/dist/cli/web/scheduler/telegram_window.d.ts +68 -0
- package/dist/cli/web/scheduler/telegram_window.d.ts.map +1 -0
- package/dist/cli/web/scheduler/telegram_window.js +144 -0
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +29 -7
- package/dist/cli/web/session_scope.d.ts +11 -0
- package/dist/cli/web/session_scope.d.ts.map +1 -0
- package/dist/cli/web/session_scope.js +13 -0
- package/dist/cli/web/turn_guard.d.ts +9 -0
- package/dist/cli/web/turn_guard.d.ts.map +1 -0
- package/dist/cli/web/turn_guard.js +18 -0
- package/dist/cli/web/voice_builtin.d.ts +3 -0
- package/dist/cli/web/voice_builtin.d.ts.map +1 -0
- package/dist/cli/web/voice_builtin.js +55 -0
- package/dist/cli/web/voice_proxy.d.ts +33 -1
- package/dist/cli/web/voice_proxy.d.ts.map +1 -1
- package/dist/cli/web/voice_proxy.js +173 -27
- package/dist/commands/loader.js +2 -2
- package/dist/harness/tools/builtin/index.d.ts.map +1 -1
- package/dist/harness/tools/builtin/index.js +4 -0
- package/dist/harness/tools/builtin/set_workspace.d.ts +3 -0
- package/dist/harness/tools/builtin/set_workspace.d.ts.map +1 -0
- package/dist/harness/tools/builtin/set_workspace.js +49 -0
- package/dist/plugins/manifest.d.ts +1 -1
- package/dist/plugins/manifest.js +1 -1
- package/dist/session/store.d.ts +6 -0
- package/dist/session/store.d.ts.map +1 -1
- package/dist/session/store.js +8 -0
- package/dist/session/types.d.ts +4 -0
- package/dist/session/types.d.ts.map +1 -1
- package/dist/voice/pocket/catalog.d.ts +24 -0
- package/dist/voice/pocket/catalog.d.ts.map +1 -0
- package/dist/voice/pocket/catalog.js +152 -0
- package/dist/voice/pocket/engine.d.ts +17 -0
- package/dist/voice/pocket/engine.d.ts.map +1 -0
- package/dist/voice/pocket/engine.js +145 -0
- package/dist/voice/pocket/inference.d.ts +36 -0
- package/dist/voice/pocket/inference.d.ts.map +1 -0
- package/dist/voice/pocket/inference.js +228 -0
- package/dist/voice/pocket/install.d.ts +54 -0
- package/dist/voice/pocket/install.d.ts.map +1 -0
- package/dist/voice/pocket/install.js +275 -0
- package/dist/voice/pocket/tokenizer.d.ts +42 -0
- package/dist/voice/pocket/tokenizer.d.ts.map +1 -0
- package/dist/voice/pocket/tokenizer.js +279 -0
- package/dist/voice/pocket/voices.d.ts +9 -0
- package/dist/voice/pocket/voices.d.ts.map +1 -0
- package/dist/voice/pocket/voices.js +88 -0
- package/dist/voice/pronunciation.d.ts +16 -0
- package/dist/voice/pronunciation.d.ts.map +1 -0
- package/dist/voice/pronunciation.js +51 -0
- package/dist/webview/standalone.js +1508 -701
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +3 -3
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { writeFile, readFile, rename } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { schedulerLogsDir, ensureSchedulerLogsDir } from './logs.js';
|
|
5
|
+
/** How long a caption-less image waits for text in a cold chat. */
|
|
6
|
+
export const HOLD_MS = 180_000;
|
|
7
|
+
/** How recently the chat must have flushed to count as warm. */
|
|
8
|
+
export const WARM_MS = 120_000;
|
|
9
|
+
export const MAX_ENTRIES = 20;
|
|
10
|
+
/** A Telegram media group holds up to 10 items; a full album must survive. */
|
|
11
|
+
export const MAX_IMAGES = 10;
|
|
12
|
+
/** The session every message of a chat lands in, on every surface that touches it. */
|
|
13
|
+
export function telegramSessionId(chatId) {
|
|
14
|
+
return `telegram_${chatId}`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Whether the window should be delivered now. Text always goes straight
|
|
18
|
+
* through; an image on its own waits for a caption, unless the chat flushed
|
|
19
|
+
* recently enough that the agent already has the context in its history.
|
|
20
|
+
*/
|
|
21
|
+
export function decideFlush(chat, now) {
|
|
22
|
+
if (chat.entries.length === 0)
|
|
23
|
+
return 'idle';
|
|
24
|
+
if (chat.entries.some((e) => !!e.text))
|
|
25
|
+
return 'flush';
|
|
26
|
+
if (chat.lastFlushAt !== undefined && now - chat.lastFlushAt < WARM_MS)
|
|
27
|
+
return 'flush';
|
|
28
|
+
if (now - chat.firstAt >= HOLD_MS)
|
|
29
|
+
return 'flush';
|
|
30
|
+
return 'hold';
|
|
31
|
+
}
|
|
32
|
+
function imageCount(chat) {
|
|
33
|
+
return chat.entries.reduce((n, e) => n + e.attachments.length, 0);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether one more message would overflow the window. The image cap applies
|
|
37
|
+
* only to a message that carries an image: refusing the text typed under a
|
|
38
|
+
* full album would drop the very question that flushes the window.
|
|
39
|
+
*/
|
|
40
|
+
export function isAtCapacity(chat, incomingHasImage) {
|
|
41
|
+
if (chat.entries.length >= MAX_ENTRIES)
|
|
42
|
+
return true;
|
|
43
|
+
return incomingHasImage && imageCount(chat) >= MAX_IMAGES;
|
|
44
|
+
}
|
|
45
|
+
export function noTextLine(count) {
|
|
46
|
+
return count === 1
|
|
47
|
+
? "(L'utente ha inviato un'immagine senza scrivere nulla.)"
|
|
48
|
+
: `(L'utente ha inviato ${count} immagini senza scrivere nulla.)`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The single user turn a flushed window becomes. One entry from one sender
|
|
52
|
+
* reproduces the legacy format byte for byte.
|
|
53
|
+
*/
|
|
54
|
+
export function buildMergedPrompt(chat, isNewSession) {
|
|
55
|
+
const chatBlock = `Chat: ${chat.chatLabel} (id: ${chat.chatId}, type: ${chat.chatType})`;
|
|
56
|
+
const senders = new Set(chat.entries.map((e) => e.fromLabel));
|
|
57
|
+
if (senders.size <= 1) {
|
|
58
|
+
const from = chat.entries[0]?.fromLabel ?? 'unknown';
|
|
59
|
+
const header = isNewSession ? `From: ${from}\n${chatBlock}` : `From: ${from}`;
|
|
60
|
+
const texts = chat.entries.map((e) => e.text).filter((t) => !!t);
|
|
61
|
+
const body = texts.length > 0 ? texts.join('\n\n') : noTextLine(imageCount(chat));
|
|
62
|
+
return `${header}\n\n${body}`;
|
|
63
|
+
}
|
|
64
|
+
// Mixed senders: the agent needs to know who said what, so each entry
|
|
65
|
+
// carries its own From line and the chat block moves to the top.
|
|
66
|
+
const blocks = chat.entries.map((e) => `From: ${e.fromLabel}\n\n${e.text || noTextLine(e.attachments.length || 1)}`);
|
|
67
|
+
return (isNewSession ? `${chatBlock}\n\n` : '') + blocks.join('\n\n');
|
|
68
|
+
}
|
|
69
|
+
export function pendingStatePath(taskId) {
|
|
70
|
+
return join(schedulerLogsDir(), `${taskId}.pending.json`);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* tmp + rename, with the Windows-style transient lock retry. Shared with
|
|
74
|
+
* saveTelegramOffset so the retry policy lives in one place.
|
|
75
|
+
*/
|
|
76
|
+
export async function atomicWriteFile(path, contents) {
|
|
77
|
+
const tmpPath = `${path}.tmp.${process.pid}.${Date.now()}`;
|
|
78
|
+
await writeFile(tmpPath, contents, 'utf8');
|
|
79
|
+
const maxAttempts = process.platform === 'win32' ? 5 : 1;
|
|
80
|
+
let lastErr;
|
|
81
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
82
|
+
try {
|
|
83
|
+
await rename(tmpPath, path);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
lastErr = err;
|
|
88
|
+
const code = err.code;
|
|
89
|
+
const retryable = code === 'EACCES' || code === 'EPERM' || code === 'EBUSY';
|
|
90
|
+
if (attempt === maxAttempts || !retryable)
|
|
91
|
+
break;
|
|
92
|
+
await new Promise((r) => setTimeout(r, 50 * 2 ** (attempt - 1)));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
throw lastErr;
|
|
96
|
+
}
|
|
97
|
+
function isUsableChat(chat) {
|
|
98
|
+
const c = chat;
|
|
99
|
+
return (!!c &&
|
|
100
|
+
typeof c === 'object' &&
|
|
101
|
+
typeof c.chatId === 'number' &&
|
|
102
|
+
typeof c.firstAt === 'number' &&
|
|
103
|
+
Array.isArray(c.entries) &&
|
|
104
|
+
c.entries.every((e) => !!e && Array.isArray(e.attachments)));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The buffer must survive a restart: the Telegram offset is committed before
|
|
108
|
+
* an entry is buffered, so losing the file loses the message. Anything
|
|
109
|
+
* unreadable degrades to an empty window rather than wedging the poller.
|
|
110
|
+
*/
|
|
111
|
+
export async function loadPendingState(taskId) {
|
|
112
|
+
const path = pendingStatePath(taskId);
|
|
113
|
+
if (!existsSync(path))
|
|
114
|
+
return { v: 1, chats: {} };
|
|
115
|
+
try {
|
|
116
|
+
const parsed = JSON.parse(await readFile(path, 'utf8'));
|
|
117
|
+
if (!parsed || parsed.v !== 1 || typeof parsed.chats !== 'object' || parsed.chats === null) {
|
|
118
|
+
console.error(`[scheduler/telegram] Unusable pending state at ${path}, starting empty`);
|
|
119
|
+
return { v: 1, chats: {} };
|
|
120
|
+
}
|
|
121
|
+
// A structurally valid file can still hold a broken chat record. Dropping
|
|
122
|
+
// the bad ones self-heals on the next save; letting one through throws on
|
|
123
|
+
// every tick, and since the offset is already committed that loses every
|
|
124
|
+
// incoming message silently and forever.
|
|
125
|
+
const chats = {};
|
|
126
|
+
for (const [key, chat] of Object.entries(parsed.chats)) {
|
|
127
|
+
if (isUsableChat(chat)) {
|
|
128
|
+
chats[key] = chat;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
console.error(`[scheduler/telegram] Dropping malformed chat record ${key} in ${path}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { v: 1, chats };
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
console.error(`[scheduler/telegram] Failed to read pending state ${path}:`, err);
|
|
138
|
+
return { v: 1, chats: {} };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export async function savePendingState(taskId, state) {
|
|
142
|
+
await ensureSchedulerLogsDir();
|
|
143
|
+
await atomicWriteFile(pendingStatePath(taskId), JSON.stringify(state));
|
|
144
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AA8ClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAgC,MAAM,gBAAgB,CAAC;AAChG,OAAO,KAAK,EAAe,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAsC9F,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9D,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,Q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refreshSource, } from '../../p
|
|
|
20
20
|
import { createMcpServer, deleteMcpServer, patchMcpServer, readOAuthBlob } from '../../mcp/server_manager.js';
|
|
21
21
|
import { authenticateMcpServer, revokeMcpAuth } from '../../mcp/oauth.js';
|
|
22
22
|
import { listForAgent, readSession, deleteSession, computeContextUsage, createSession, userMessage, appendMessage, saveAttachment, attachmentsDir, } from '../../session/index.js';
|
|
23
|
+
import { sessionRunScope } from './session_scope.js';
|
|
24
|
+
import { guardTurnCallbacks } from './turn_guard.js';
|
|
23
25
|
import { watchCycleStream } from './scheduler/cycle_events.js';
|
|
24
26
|
import { startBackgroundScheduler, loadTaskRuns } from './scheduler.js';
|
|
25
27
|
import { fsRouter } from './fs.js';
|
|
26
28
|
import { activationStatus, resolvePlanningEnabled } from './scheduler/task_roles.js';
|
|
27
|
-
import { registerVoiceProxy, voiceClientConfig, fetchVoiceCatalog } from './voice_proxy.js';
|
|
29
|
+
import { registerVoiceProxy, voiceClientConfig, fetchVoiceCatalog, formKeyFor, KEY_WITHHELD_HINT, } from './voice_proxy.js';
|
|
28
30
|
import { registerVoiceBackend, maybeAutoStartBackend } from './voice_backend.js';
|
|
31
|
+
import { registerVoiceBuiltin } from './voice_builtin.js';
|
|
29
32
|
import { fetchAcpRegistry, installAcpAgent } from '../../acp/index.js';
|
|
30
33
|
// Resolve Webview static files path.
|
|
31
34
|
// Published npm package ships the assets under dist/webview (see scripts/copy-webview.mjs);
|
|
@@ -86,7 +89,13 @@ export class WebSessionController {
|
|
|
86
89
|
this.history = [];
|
|
87
90
|
}
|
|
88
91
|
}
|
|
92
|
+
else {
|
|
93
|
+
// Re-read the latest session_meta every turn: `set_workspace` may have
|
|
94
|
+
// appended a workspace override during the previous turn.
|
|
95
|
+
this.metaRecord = (await readSession(this.opts.agent.id, this.metaRecord.id)).meta;
|
|
96
|
+
}
|
|
89
97
|
const meta = this.metaRecord;
|
|
98
|
+
const scope = sessionRunScope(meta, this.opts.workingDir);
|
|
90
99
|
const attachmentRecords = [];
|
|
91
100
|
if (rawAttachments && rawAttachments.length > 0) {
|
|
92
101
|
for (const att of rawAttachments) {
|
|
@@ -109,7 +118,8 @@ export class WebSessionController {
|
|
|
109
118
|
prompt,
|
|
110
119
|
history: priorHistory,
|
|
111
120
|
signal: ac.signal,
|
|
112
|
-
workingDir:
|
|
121
|
+
workingDir: scope.workingDir,
|
|
122
|
+
memoryProjectId: scope.memoryProjectId,
|
|
113
123
|
sessionId: meta.id,
|
|
114
124
|
promptAttachments: attachmentRecords.length > 0 ? attachmentRecords : undefined,
|
|
115
125
|
voiceConversation,
|
|
@@ -149,6 +159,7 @@ export async function startServer(port, host) {
|
|
|
149
159
|
registerTaskBridge(app);
|
|
150
160
|
registerVoiceProxy(app);
|
|
151
161
|
registerVoiceBackend(app);
|
|
162
|
+
registerVoiceBuiltin(app);
|
|
152
163
|
// Pure-Node static serving with absolute path validation and fallback
|
|
153
164
|
app.get('/', (c) => {
|
|
154
165
|
try {
|
|
@@ -863,6 +874,10 @@ export async function startServer(port, host) {
|
|
|
863
874
|
controller = null;
|
|
864
875
|
post({ type: 'contextUsage', usage: null });
|
|
865
876
|
await loadSessionsAndSend(agent.id);
|
|
877
|
+
// Ack: the switch is complete server-side. The desktop assistant waits
|
|
878
|
+
// for it before opening the mic, so a `start` cannot reach the previous
|
|
879
|
+
// agent while this one's MCP servers are still connecting.
|
|
880
|
+
post({ type: 'agentSelected', agentId: agent.id });
|
|
866
881
|
};
|
|
867
882
|
const loadSessionsAndSend = async (agentId) => {
|
|
868
883
|
try {
|
|
@@ -990,7 +1005,8 @@ export async function startServer(port, host) {
|
|
|
990
1005
|
sessionId: currentSessionId ?? undefined,
|
|
991
1006
|
});
|
|
992
1007
|
}
|
|
993
|
-
|
|
1008
|
+
const turnController = controller;
|
|
1009
|
+
await controller.start(msg.prompt, guardTurnCallbacks({
|
|
994
1010
|
onChunk: (text) => post({ type: 'chunk', text }),
|
|
995
1011
|
onThinking: (text) => post({ type: 'thinking', text }),
|
|
996
1012
|
onToolCall: (id, name, args) => post({ type: 'tool_call', id, name, args }),
|
|
@@ -1015,7 +1031,7 @@ export async function startServer(port, host) {
|
|
|
1015
1031
|
currentSessionId = sessionId;
|
|
1016
1032
|
void loadSessionsAndSend(currentAgent.id);
|
|
1017
1033
|
},
|
|
1018
|
-
}, msg.attachments, msg.voice);
|
|
1034
|
+
}, () => controller === turnController), msg.attachments, msg.voice);
|
|
1019
1035
|
return;
|
|
1020
1036
|
}
|
|
1021
1037
|
case 'abort':
|
|
@@ -1048,6 +1064,9 @@ export async function startServer(port, host) {
|
|
|
1048
1064
|
return;
|
|
1049
1065
|
}
|
|
1050
1066
|
case 'createSession': {
|
|
1067
|
+
// A confirm card of the superseded turn can no longer be answered
|
|
1068
|
+
// (the view was cleared); reject it so that run can wind down.
|
|
1069
|
+
resolveAllPending('reject');
|
|
1051
1070
|
currentSessionId = null;
|
|
1052
1071
|
controller = null;
|
|
1053
1072
|
post({ type: 'contextUsage', usage: null });
|
|
@@ -1275,15 +1294,18 @@ export async function startServer(port, host) {
|
|
|
1275
1294
|
post({ type: 'acpInstallResult', agentId: msg.agentId, ok: false, error: String(err) });
|
|
1276
1295
|
}
|
|
1277
1296
|
return;
|
|
1278
|
-
case 'fetchVoiceModels':
|
|
1297
|
+
case 'fetchVoiceModels': {
|
|
1298
|
+
const { key, withheld } = formKeyFor(msg.endpoint, msg.apiKey, (await loadConfig()).voice);
|
|
1279
1299
|
try {
|
|
1280
|
-
const catalog = await fetchVoiceCatalog(msg.endpoint,
|
|
1300
|
+
const catalog = await fetchVoiceCatalog(msg.endpoint, key);
|
|
1281
1301
|
post({ type: 'voiceModelsFetched', result: { ok: true, catalog }, target: msg.target });
|
|
1282
1302
|
}
|
|
1283
1303
|
catch (err) {
|
|
1284
|
-
|
|
1304
|
+
const error = withheld && /\b40[13]\b/.test(String(err)) ? `${KEY_WITHHELD_HINT} (${err})` : String(err);
|
|
1305
|
+
post({ type: 'voiceModelsFetched', result: { ok: false, error }, target: msg.target });
|
|
1285
1306
|
}
|
|
1286
1307
|
return;
|
|
1308
|
+
}
|
|
1287
1309
|
case 'watchCycle': {
|
|
1288
1310
|
// Ids name files on disk; the same rule as the bridge parser.
|
|
1289
1311
|
if (!/^[A-Za-z0-9_-]+$/.test(msg.agentId) || !/^[A-Za-z0-9_-]+$/.test(msg.sessionId))
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SessionMetaRecord } from '../../session/types.js';
|
|
2
|
+
/** Working dir + memory scope for one chat turn. The `set_workspace` override
|
|
3
|
+
* on the session meta wins over the agent's own workingDir and brings its
|
|
4
|
+
* projectId along (passed explicitly: a managed clone's blank
|
|
5
|
+
* `projects[].workingDir` never prefix-matches, so dir-based resolution
|
|
6
|
+
* would degrade the turn to global-only memories). */
|
|
7
|
+
export declare function sessionRunScope(meta: Pick<SessionMetaRecord, 'workingDir' | 'projectId'> | undefined, agentWorkingDir: string): {
|
|
8
|
+
workingDir: string;
|
|
9
|
+
memoryProjectId?: string;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=session_scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session_scope.d.ts","sourceRoot":"","sources":["../../../src/cli/web/session_scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;uDAIuD;AACvD,wBAAgB,eAAe,CAC7B,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,WAAW,CAAC,GAAG,SAAS,EACrE,eAAe,EAAE,MAAM,GACtB;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,CAOlD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Working dir + memory scope for one chat turn. The `set_workspace` override
|
|
2
|
+
* on the session meta wins over the agent's own workingDir and brings its
|
|
3
|
+
* projectId along (passed explicitly: a managed clone's blank
|
|
4
|
+
* `projects[].workingDir` never prefix-matches, so dir-based resolution
|
|
5
|
+
* would degrade the turn to global-only memories). */
|
|
6
|
+
export function sessionRunScope(meta, agentWorkingDir) {
|
|
7
|
+
if (meta?.workingDir) {
|
|
8
|
+
return meta.projectId
|
|
9
|
+
? { workingDir: meta.workingDir, memoryProjectId: meta.projectId }
|
|
10
|
+
: { workingDir: meta.workingDir };
|
|
11
|
+
}
|
|
12
|
+
return { workingDir: agentWorkingDir };
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ChatCallbacks } from './server.js';
|
|
2
|
+
/** Silence a chat turn once it is superseded. Dropping the controller
|
|
3
|
+
* (new session, agent switch) does not stop its run, and the run's callbacks
|
|
4
|
+
* post straight to the socket — without this, a still-streaming turn keeps
|
|
5
|
+
* writing chunks, `done` and confirm cards into the session that replaced
|
|
6
|
+
* it. The old run keeps going; only its output is cut. A superseded turn's
|
|
7
|
+
* confirmations resolve `reject`: nobody can answer them any more. */
|
|
8
|
+
export declare function guardTurnCallbacks(cb: ChatCallbacks, isCurrent: () => boolean): ChatCallbacks;
|
|
9
|
+
//# sourceMappingURL=turn_guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn_guard.d.ts","sourceRoot":"","sources":["../../../src/cli/web/turn_guard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;uEAKuE;AACvE,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,GAAG,aAAa,CAY7F"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Silence a chat turn once it is superseded. Dropping the controller
|
|
2
|
+
* (new session, agent switch) does not stop its run, and the run's callbacks
|
|
3
|
+
* post straight to the socket — without this, a still-streaming turn keeps
|
|
4
|
+
* writing chunks, `done` and confirm cards into the session that replaced
|
|
5
|
+
* it. The old run keeps going; only its output is cut. A superseded turn's
|
|
6
|
+
* confirmations resolve `reject`: nobody can answer them any more. */
|
|
7
|
+
export function guardTurnCallbacks(cb, isCurrent) {
|
|
8
|
+
return {
|
|
9
|
+
onChunk: (t) => isCurrent() && cb.onChunk(t),
|
|
10
|
+
onThinking: (t) => isCurrent() && cb.onThinking(t),
|
|
11
|
+
onToolCall: (id, name, args) => isCurrent() && cb.onToolCall(id, name, args),
|
|
12
|
+
onToolResult: (id, content) => isCurrent() && cb.onToolResult(id, content),
|
|
13
|
+
askConfirm: (id, toolName, args) => isCurrent() ? cb.askConfirm(id, toolName, args) : Promise.resolve('reject'),
|
|
14
|
+
onError: (m) => isCurrent() && cb.onError(m),
|
|
15
|
+
onDone: () => isCurrent() && cb.onDone(),
|
|
16
|
+
onSessionCreated: (id) => isCurrent() && cb.onSessionCreated?.(id),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voice_builtin.d.ts","sourceRoot":"","sources":["../../../src/cli/web/voice_builtin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAwBjC,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAgCpD"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Routes for the built-in voice installer. The in-flight guard is per language so a
|
|
2
|
+
// second install of the same language cannot start a parallel download.
|
|
3
|
+
import { stream } from 'hono/streaming';
|
|
4
|
+
import { POCKET_LANGUAGES } from '../../voice/pocket/catalog.js';
|
|
5
|
+
import { builtinVoiceStatus, deleteBuiltinVoice, installBuiltinVoice, } from '../../voice/pocket/install.js';
|
|
6
|
+
import { releasePocketModels, runtimeLoadError, runtimeLoaded, speakBuiltin } from '../../voice/pocket/engine.js';
|
|
7
|
+
import { setBuiltinSpeaker } from './voice_proxy.js';
|
|
8
|
+
// One install or delete at a time: languages share the runtime directory.
|
|
9
|
+
let busy = null;
|
|
10
|
+
function reqLanguage(q) {
|
|
11
|
+
return q && Object.hasOwn(POCKET_LANGUAGES, q) ? q : null;
|
|
12
|
+
}
|
|
13
|
+
async function statusWithLoadError() {
|
|
14
|
+
const status = await builtinVoiceStatus();
|
|
15
|
+
const loadError = runtimeLoadError();
|
|
16
|
+
return loadError ? { ...status, runtime: { ...status.runtime, loadError } } : status;
|
|
17
|
+
}
|
|
18
|
+
export function registerVoiceBuiltin(app) {
|
|
19
|
+
setBuiltinSpeaker(speakBuiltin);
|
|
20
|
+
app.get('/api/voice/builtin', async (c) => c.json(await statusWithLoadError()));
|
|
21
|
+
app.post('/api/voice/builtin/install', async (c) => {
|
|
22
|
+
const lang = reqLanguage(c.req.query('language'));
|
|
23
|
+
if (!lang)
|
|
24
|
+
return c.text('Unknown language.', 400);
|
|
25
|
+
if (busy)
|
|
26
|
+
return c.text(`An install of ${busy} is already in progress.`, 409);
|
|
27
|
+
busy = lang;
|
|
28
|
+
c.header('Content-Type', 'application/x-ndjson');
|
|
29
|
+
return stream(c, async (s) => {
|
|
30
|
+
try {
|
|
31
|
+
for await (const p of installBuiltinVoice(lang))
|
|
32
|
+
await s.writeln(JSON.stringify(p));
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
busy = null;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
app.post('/api/voice/builtin/delete', async (c) => {
|
|
40
|
+
const lang = reqLanguage(c.req.query('language'));
|
|
41
|
+
if (!lang)
|
|
42
|
+
return c.text('Unknown language.', 400);
|
|
43
|
+
if (busy)
|
|
44
|
+
return c.text('An install is in progress; wait for it to finish.', 409);
|
|
45
|
+
busy = lang;
|
|
46
|
+
try {
|
|
47
|
+
await releasePocketModels();
|
|
48
|
+
await deleteBuiltinVoice(lang, { keepRuntime: runtimeLoaded() });
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
busy = null;
|
|
52
|
+
}
|
|
53
|
+
return c.json(await statusWithLoadError());
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Hono } from 'hono';
|
|
2
|
-
import type { CaretakerConfig, VoiceConfig } from 'caretaker-types';
|
|
2
|
+
import type { CaretakerConfig, PronunciationEntry, VoiceConfig } from 'caretaker-types';
|
|
3
3
|
import type { VoiceCatalog, VoiceClientConfig } from 'webview-ui/bridge';
|
|
4
4
|
export declare function voiceClientConfig(config: CaretakerConfig): VoiceClientConfig | null;
|
|
5
5
|
/** Resolve the usable voice config, or a reason it cannot be used. Shared with
|
|
@@ -22,6 +22,38 @@ export declare function ttsTarget(voice: VoiceConfig): {
|
|
|
22
22
|
apiKey?: string;
|
|
23
23
|
};
|
|
24
24
|
export declare function registerVoiceProxy(app: Hono): void;
|
|
25
|
+
export type SynthesisSettings = Pick<VoiceConfig, 'ttsEngine' | 'ttsLanguage' | 'ttsVoice' | 'ttsModel' | 'ttsSpeed' | 'ttsEndpoint' | 'pronunciationEnabled'> & {
|
|
26
|
+
pronunciation?: PronunciationEntry[];
|
|
27
|
+
};
|
|
28
|
+
/** The saved voice config if synthesis can run: voice enabled, and (for the
|
|
29
|
+
* endpoint engine) some endpoint to talk to. The built-in engine needs none. */
|
|
30
|
+
export declare function resolveSynthesis(): Promise<{
|
|
31
|
+
voice: VoiceConfig;
|
|
32
|
+
} | {
|
|
33
|
+
error: string;
|
|
34
|
+
}>;
|
|
35
|
+
/** Same server: scheme, host and port. A different path or a trailing slash is
|
|
36
|
+
* not a different host, so it keeps the saved key. */
|
|
37
|
+
export declare function sameHost(a?: string, b?: string): boolean;
|
|
38
|
+
export declare const KEY_WITHHELD_HINT = "The endpoint changed: enter the API key again, or save first, to use it with the new endpoint.";
|
|
39
|
+
/** The key to send to `endpoint` for a request built from the settings form. A key
|
|
40
|
+
* typed in the form is the user's own, for that endpoint. The stored key (the form
|
|
41
|
+
* round-trips its encrypted blob) goes only to the host it was saved for;
|
|
42
|
+
* otherwise it is withheld and the request goes without a key. */
|
|
43
|
+
export declare function formKeyFor(endpoint: string, formKey: string | null | undefined, saved: VoiceConfig | undefined): {
|
|
44
|
+
key: string | null;
|
|
45
|
+
withheld: boolean;
|
|
46
|
+
};
|
|
47
|
+
/** Overlay the form's unsaved synthesis settings on the saved config. The saved
|
|
48
|
+
* `ttsApiKey` is dropped when the previewed `ttsEndpoint` is on another host than
|
|
49
|
+
* the saved one, so editing the URL can never send the stored key to a new host. */
|
|
50
|
+
export declare function mergePreview(saved: VoiceConfig, s: SynthesisSettings): VoiceConfig;
|
|
51
|
+
export type BuiltinSpeaker = (voice: VoiceConfig, text: string, signal: AbortSignal) => Promise<Response>;
|
|
52
|
+
/** The built-in engine registers itself here; null unregisters. */
|
|
53
|
+
export declare function setBuiltinSpeaker(fn: BuiltinSpeaker | null): void;
|
|
54
|
+
/** Synthesize `text` with the configured engine, dictionary applied, streaming
|
|
55
|
+
* the audio back. Failures are Responses (status + readable body), not throws. */
|
|
56
|
+
export declare function synthesize(voice: VoiceConfig, text: string, signal: AbortSignal): Promise<Response>;
|
|
25
57
|
/**
|
|
26
58
|
* Read a speech endpoint's installed models so the settings form can offer real
|
|
27
59
|
* choices instead of free text.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"voice_proxy.d.ts","sourceRoot":"","sources":["../../../src/cli/web/voice_proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"voice_proxy.d.ts","sourceRoot":"","sources":["../../../src/cli/web/voice_proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGxF,OAAO,KAAK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