talon-agent 4.2.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/cli/setup.ts +8 -2
- package/src/core/engine/cross-chat-relay.ts +125 -0
- package/src/core/engine/dispatcher.ts +10 -1
- package/src/core/engine/gateway-actions/cross-send.ts +9 -0
- package/src/core/mesh/device-files.ts +58 -5
- package/src/core/mesh/service.ts +52 -0
- package/src/core/types.ts +7 -0
- package/src/frontend/whatsapp/actions/index.ts +7 -1
- package/src/frontend/whatsapp/inbound.ts +7 -0
- package/src/plugins/github/provision.ts +1 -1
- package/src/plugins/mempalace/provision.ts +1 -1
package/README.md
CHANGED
|
@@ -328,7 +328,7 @@ On first boot Talon creates a venv at `~/.talon/mempalace-venv` and installs the
|
|
|
328
328
|
"backend": "mempalace",
|
|
329
329
|
"mempalace": {
|
|
330
330
|
"palacePath": "~/.talon/workspace/palace",
|
|
331
|
-
"version": "3.
|
|
331
|
+
"version": "3.10.0",
|
|
332
332
|
"autoUpdate": true,
|
|
333
333
|
"autoProvision": true
|
|
334
334
|
}
|
package/package.json
CHANGED
package/src/cli/setup.ts
CHANGED
|
@@ -29,14 +29,20 @@ const trimmedOrUndefined = (raw: string) => raw.trim() || undefined;
|
|
|
29
29
|
* the unguarded remainder still needed an `as string` cast. clack only
|
|
30
30
|
* ever resolves a symbol to mean "cancelled", so narrowing on `typeof`
|
|
31
31
|
* here removes both.
|
|
32
|
+
*
|
|
33
|
+
* The answer type is subtracted with `Exclude` rather than inferred from a
|
|
34
|
+
* `Promise<T | symbol>` parameter: clack 1.8.1 retyped `CANCEL_SYMBOL` as a
|
|
35
|
+
* `unique symbol`, which no longer cancels out against a plain `symbol` in
|
|
36
|
+
* the target, so every caller inferred `T` as the whole `answer | symbol`
|
|
37
|
+
* union and leaked the symbol into the config.
|
|
32
38
|
*/
|
|
33
|
-
async function askOrExit<T>(prompt: Promise<T
|
|
39
|
+
async function askOrExit<T>(prompt: Promise<T>): Promise<Exclude<T, symbol>> {
|
|
34
40
|
const value = await prompt;
|
|
35
41
|
if (typeof value === "symbol") {
|
|
36
42
|
p.cancel("Cancelled.");
|
|
37
43
|
process.exit(0);
|
|
38
44
|
}
|
|
39
|
-
return value
|
|
45
|
+
return value as Exclude<T, symbol>;
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
// ── Steps: each prompts for one section and returns its slice of the answers ──
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-chat relay — keeps the session that sent a message somewhere
|
|
3
|
+
* else aware of what came back.
|
|
4
|
+
*
|
|
5
|
+
* `send_via` lets a Telegram session message a WhatsApp number. The
|
|
6
|
+
* reply, though, lands in the WhatsApp chat: a different chat id, a
|
|
7
|
+
* different session, a different history. The session that started the
|
|
8
|
+
* exchange never learns how it went, so the next thing it says about
|
|
9
|
+
* it is a guess — it "sent the message" and then goes blind.
|
|
10
|
+
*
|
|
11
|
+
* So a cross-send subscribes the sending chat to the target chat for a
|
|
12
|
+
* while. Inbound messages on the target are queued for each subscriber
|
|
13
|
+
* and folded into the front of that chat's next turn, the same way a
|
|
14
|
+
* person glancing at their other phone would have seen the reply before
|
|
15
|
+
* answering you.
|
|
16
|
+
*
|
|
17
|
+
* Deliberately passive: the queued reply waits for the origin chat's
|
|
18
|
+
* next turn rather than waking it. The target chat usually has its own
|
|
19
|
+
* live session already handling that message — waking the origin too
|
|
20
|
+
* would mean two sessions independently reacting to one reply, and an
|
|
21
|
+
* unprompted Telegram message every time someone answers on WhatsApp.
|
|
22
|
+
*
|
|
23
|
+
* State is in-memory on purpose. A subscription is a fact about a
|
|
24
|
+
* conversation in flight; after a restart there is no turn waiting for
|
|
25
|
+
* the reply, and a relayed line from before the restart would arrive
|
|
26
|
+
* with no context to attach to.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** How long a cross-send keeps the sender subscribed to replies. */
|
|
30
|
+
export const RELAY_TTL_MS = 6 * 60 * 60 * 1000;
|
|
31
|
+
|
|
32
|
+
/** Most queued lines held for one chat — a burst can't flood a prompt. */
|
|
33
|
+
export const RELAY_MAX_PENDING = 20;
|
|
34
|
+
|
|
35
|
+
/** Longest single relayed message; the rest is elided. */
|
|
36
|
+
export const RELAY_MAX_TEXT = 600;
|
|
37
|
+
|
|
38
|
+
/** target chat id → origin chat id → time of the last cross-send. */
|
|
39
|
+
const subscribers = new Map<string, Map<string, number>>();
|
|
40
|
+
|
|
41
|
+
/** origin chat id → relayed lines waiting for its next turn. */
|
|
42
|
+
const pending = new Map<string, string[]>();
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Record that `origin` sent into `target`, subscribing it to replies.
|
|
46
|
+
* A repeat send refreshes the window rather than adding a second entry.
|
|
47
|
+
*/
|
|
48
|
+
export function noteCrossSend(origin: string, target: string): void {
|
|
49
|
+
// Sending into your own chat is not a cross-send; subscribing would
|
|
50
|
+
// relay a chat's own inbound messages back into itself.
|
|
51
|
+
if (!origin || !target || origin === target) return;
|
|
52
|
+
const forTarget = subscribers.get(target) ?? new Map<string, number>();
|
|
53
|
+
forTarget.set(origin, Date.now());
|
|
54
|
+
subscribers.set(target, forTarget);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* An inbound message arrived on `target`. Queue it for every chat still
|
|
59
|
+
* subscribed, and return how many were notified (0 when nobody is
|
|
60
|
+
* listening, which is the overwhelmingly common case).
|
|
61
|
+
*/
|
|
62
|
+
export function relayInbound(
|
|
63
|
+
target: string,
|
|
64
|
+
senderName: string,
|
|
65
|
+
text: string,
|
|
66
|
+
): number {
|
|
67
|
+
const forTarget = subscribers.get(target);
|
|
68
|
+
if (!forTarget?.size) return 0;
|
|
69
|
+
const now = Date.now();
|
|
70
|
+
const body =
|
|
71
|
+
text.length > RELAY_MAX_TEXT
|
|
72
|
+
? `${text.slice(0, RELAY_MAX_TEXT)}… (truncated)`
|
|
73
|
+
: text;
|
|
74
|
+
let notified = 0;
|
|
75
|
+
for (const [origin, at] of forTarget) {
|
|
76
|
+
// Expiry is evaluated here rather than on a timer: the map is small,
|
|
77
|
+
// and a sweep that never runs can't leak a stale subscription.
|
|
78
|
+
if (now - at > RELAY_TTL_MS) {
|
|
79
|
+
forTarget.delete(origin);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const queue = pending.get(origin) ?? [];
|
|
83
|
+
queue.push(`${senderName} (in ${target}): ${body}`);
|
|
84
|
+
if (queue.length > RELAY_MAX_PENDING) {
|
|
85
|
+
queue.splice(0, queue.length - RELAY_MAX_PENDING);
|
|
86
|
+
}
|
|
87
|
+
pending.set(origin, queue);
|
|
88
|
+
notified++;
|
|
89
|
+
}
|
|
90
|
+
if (!forTarget.size) subscribers.delete(target);
|
|
91
|
+
return notified;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Drain everything queued for `chatId`. Draining is the point: each
|
|
96
|
+
* relayed line is folded into exactly one turn, so a long conversation
|
|
97
|
+
* doesn't re-read the same reply on every subsequent prompt.
|
|
98
|
+
*/
|
|
99
|
+
export function takePendingRelay(chatId: string): string[] {
|
|
100
|
+
const queue = pending.get(chatId);
|
|
101
|
+
if (!queue?.length) return [];
|
|
102
|
+
pending.delete(chatId);
|
|
103
|
+
return queue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Render drained lines as the block that goes in front of a prompt.
|
|
108
|
+
* Returns "" when there is nothing, so callers can concatenate blindly.
|
|
109
|
+
*/
|
|
110
|
+
export function formatRelayBlock(lines: readonly string[]): string {
|
|
111
|
+
if (!lines.length) return "";
|
|
112
|
+
return (
|
|
113
|
+
`[Cross-chat: ${lines.length} new message(s) arrived in a chat this ` +
|
|
114
|
+
`session messaged. You have not replied to these — decide whether they ` +
|
|
115
|
+
`need one.]\n` +
|
|
116
|
+
lines.map((l) => `- ${l}`).join("\n") +
|
|
117
|
+
"\n\n"
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Test seam: drop all subscriptions and queued lines. */
|
|
122
|
+
export function resetCrossChatRelay(): void {
|
|
123
|
+
subscribers.clear();
|
|
124
|
+
pending.clear();
|
|
125
|
+
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { ExecuteParams, ExecuteResult } from "../types.js";
|
|
12
|
+
import { formatRelayBlock, takePendingRelay } from "./cross-chat-relay.js";
|
|
12
13
|
import { log } from "../../util/log.js";
|
|
13
14
|
import { taskTable, type KillOutcome } from "../tasks/index.js";
|
|
14
15
|
import { initWeaver, type Weaver, type WeaverDeps } from "../weaver/index.js";
|
|
@@ -66,8 +67,16 @@ export function stopAllTurns(): number {
|
|
|
66
67
|
* Execute an AI query with full lifecycle management.
|
|
67
68
|
* Same-chat queries are serialized (FIFO) to avoid session conflicts.
|
|
68
69
|
* Different-chat queries run in true parallel.
|
|
70
|
+
*
|
|
71
|
+
* Every turn for every frontend and every source funnels through here,
|
|
72
|
+
* which makes it the one place a cross-chat reply can be folded in
|
|
73
|
+
* without teaching each frontend about the relay.
|
|
69
74
|
*/
|
|
70
75
|
export async function execute(params: ExecuteParams): Promise<ExecuteResult> {
|
|
71
76
|
if (!weaver) throw new Error("Dispatcher not initialized");
|
|
72
|
-
|
|
77
|
+
const relayed = takePendingRelay(params.chatId);
|
|
78
|
+
const prompt = relayed.length
|
|
79
|
+
? formatRelayBlock(relayed) + params.prompt
|
|
80
|
+
: params.prompt;
|
|
81
|
+
return weaver.runTurn(relayed.length ? { ...params, prompt } : params);
|
|
73
82
|
}
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
import type { FrontendActionHandler } from "../../types.js";
|
|
29
|
+
import { noteCrossSend } from "../cross-chat-relay.js";
|
|
29
30
|
import type { SharedActionHandlers } from "./types.js";
|
|
30
31
|
|
|
31
32
|
const targets = new Map<string, FrontendActionHandler>();
|
|
@@ -188,6 +189,14 @@ export const crossSendHandlers: SharedActionHandlers = {
|
|
|
188
189
|
error: `send_via: the ${frontend} frontend does not implement ${action}`,
|
|
189
190
|
};
|
|
190
191
|
}
|
|
192
|
+
// Subscribe the calling session to whatever comes back. `_chatId` is
|
|
193
|
+
// the bridge's own caller tag, and the frontend reports the canonical
|
|
194
|
+
// id it resolved — a phone number is not a chat id, so without that
|
|
195
|
+
// report there would be nothing to subscribe to.
|
|
196
|
+
if (result.ok) {
|
|
197
|
+
const origin = body._chatId ? String(body._chatId) : "";
|
|
198
|
+
noteCrossSend(origin, result.chat_id ?? target);
|
|
199
|
+
}
|
|
191
200
|
return result;
|
|
192
201
|
},
|
|
193
202
|
};
|
|
@@ -61,8 +61,53 @@ export interface DeviceFilesHost {
|
|
|
61
61
|
* fallback tolerable without bloating a single SSE frame too far.
|
|
62
62
|
*/
|
|
63
63
|
const FILE_CHUNK_BYTES = 1024 * 1024;
|
|
64
|
-
/**
|
|
65
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Wall-clock budget for one streamed transfer (command dispatch → done).
|
|
66
|
+
*
|
|
67
|
+
* A device that accepts the transfer command and then goes silent answers
|
|
68
|
+
* never: a stalled body stream on a flaky mobile link delivers neither
|
|
69
|
+
* bytes nor a FIN, so the device-side `await` for the body never completes
|
|
70
|
+
* and never throws, and the command result it would have posted afterwards
|
|
71
|
+
* is never posted. The dispatch timeout is the only thing that ends that
|
|
72
|
+
* wait — and since turns serialize per chat, the whole chat's message loop
|
|
73
|
+
* queues behind it. A flat hour therefore takes a chat offline for an hour
|
|
74
|
+
* over one dropped TCP connection.
|
|
75
|
+
*
|
|
76
|
+
* So the budget is sized to the payload instead: a fixed grace for the
|
|
77
|
+
* handshake and device-side setup, plus the body at a deliberately
|
|
78
|
+
* pessimistic floor throughput, clamped at both ends. A genuinely slow
|
|
79
|
+
* link still finishes; a dead one gives up in minutes.
|
|
80
|
+
*/
|
|
81
|
+
const STREAM_TRANSFER_GRACE_MS = 60_000;
|
|
82
|
+
const STREAM_TRANSFER_FLOOR_BYTES_PER_SEC = 32 * 1024;
|
|
83
|
+
/**
|
|
84
|
+
* Ceiling, so a payload large enough to out-scale the formula still can't
|
|
85
|
+
* block a chat indefinitely. Deliberately well above what a big transfer
|
|
86
|
+
* over a slow link needs — the common wedge is a SMALL transfer that used
|
|
87
|
+
* to inherit the same budget as a huge one, and that case now resolves in
|
|
88
|
+
* about a minute.
|
|
89
|
+
*/
|
|
90
|
+
const STREAM_TRANSFER_MAX_MS = 30 * 60 * 1000;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Budget for streaming `bytes` to or from a device. An unknown size — a
|
|
94
|
+
* pull whose caller has not already paid for a `stat` — takes the ceiling
|
|
95
|
+
* rather than an extra mesh round trip to size a budget with: still
|
|
96
|
+
* bounded, just less tightly. Either way the device-side idle timeout
|
|
97
|
+
* normally answers long before this fires; this is the backstop for a
|
|
98
|
+
* device that has stopped answering altogether.
|
|
99
|
+
*/
|
|
100
|
+
export function streamTransferTimeoutMs(bytes?: number): number {
|
|
101
|
+
if (bytes === undefined || !Number.isFinite(bytes)) {
|
|
102
|
+
return STREAM_TRANSFER_MAX_MS;
|
|
103
|
+
}
|
|
104
|
+
const forBody =
|
|
105
|
+
(Math.max(0, bytes) / STREAM_TRANSFER_FLOOR_BYTES_PER_SEC) * 1000;
|
|
106
|
+
return Math.min(
|
|
107
|
+
Math.round(STREAM_TRANSFER_GRACE_MS + forBody),
|
|
108
|
+
STREAM_TRANSFER_MAX_MS,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
66
111
|
/** readFileBytes switches to the streaming path above this size. */
|
|
67
112
|
const STREAM_READ_THRESHOLD_BYTES = 4 * 1024 * 1024;
|
|
68
113
|
/**
|
|
@@ -134,13 +179,14 @@ export class DeviceFiles {
|
|
|
134
179
|
target: DeviceInfo,
|
|
135
180
|
remote: string,
|
|
136
181
|
dest: string,
|
|
182
|
+
sizeHint?: number,
|
|
137
183
|
): Promise<{ bytes: number } | { error: string }> {
|
|
138
184
|
const { token, done } = this.transfers.createPull(target.id, dest);
|
|
139
185
|
const dispatched = await this.host.dispatchCommand(
|
|
140
186
|
target.id,
|
|
141
187
|
"upload_file",
|
|
142
188
|
{ token, path: remote },
|
|
143
|
-
|
|
189
|
+
streamTransferTimeoutMs(sizeHint),
|
|
144
190
|
);
|
|
145
191
|
if ("error" in dispatched) {
|
|
146
192
|
this.transfers.cancel(token);
|
|
@@ -203,7 +249,7 @@ export class DeviceFiles {
|
|
|
203
249
|
const size = await this.statSize(target.id, p);
|
|
204
250
|
if (size !== undefined && size > STREAM_READ_THRESHOLD_BYTES) {
|
|
205
251
|
const tmp = join(tmpdir(), `talon-pull-${randomUUID()}-${basename(p)}`);
|
|
206
|
-
const pulled = await this.pullViaStream(target, p, tmp);
|
|
252
|
+
const pulled = await this.pullViaStream(target, p, tmp, size);
|
|
207
253
|
if ("error" in pulled) return { error: pulled.error };
|
|
208
254
|
try {
|
|
209
255
|
const data = await readFile(tmp);
|
|
@@ -338,12 +384,19 @@ export class DeviceFiles {
|
|
|
338
384
|
const target = resolved.target;
|
|
339
385
|
if (this.canStream(target, "download_file")) {
|
|
340
386
|
const started = Date.now();
|
|
387
|
+
// The source is on this host, so sizing the budget costs a local stat
|
|
388
|
+
// rather than a mesh round trip. A source we cannot stat still gets a
|
|
389
|
+
// bounded (if looser) budget — this decides a timeout, not whether
|
|
390
|
+
// the transfer is allowed to start.
|
|
391
|
+
const localSize = await stat(local)
|
|
392
|
+
.then((s) => s.size)
|
|
393
|
+
.catch(() => undefined);
|
|
341
394
|
const { token } = this.transfers.createPush(target.id, local);
|
|
342
395
|
const dispatched = await this.host.dispatchCommand(
|
|
343
396
|
target.id,
|
|
344
397
|
"download_file",
|
|
345
398
|
{ token, path: remote },
|
|
346
|
-
|
|
399
|
+
streamTransferTimeoutMs(localSize),
|
|
347
400
|
);
|
|
348
401
|
if ("error" in dispatched) {
|
|
349
402
|
this.transfers.cancel(token);
|
package/src/core/mesh/service.ts
CHANGED
|
@@ -82,6 +82,8 @@ export type MeshServiceOptions = {
|
|
|
82
82
|
pollIntervalMs?: number;
|
|
83
83
|
/** How long a device command waits for its result before timing out. */
|
|
84
84
|
commandTimeoutMs?: number;
|
|
85
|
+
/** How often a long command re-checks that its device is still present. */
|
|
86
|
+
presenceWatchIntervalMs?: number;
|
|
85
87
|
/** Node-binary resolver override (tests — the real one builds/downloads). */
|
|
86
88
|
nodeBinaryResolver?: NodeBinaryResolver;
|
|
87
89
|
};
|
|
@@ -100,6 +102,8 @@ const MAX_HISTORY_LINES = 24;
|
|
|
100
102
|
const DEFAULT_EXEC_TIMEOUT_MS = 60_000;
|
|
101
103
|
/** Hard ceiling on a caller-requested exec timeout. */
|
|
102
104
|
const MAX_EXEC_TIMEOUT_MS = 300_000;
|
|
105
|
+
/** How often a long-running command re-checks that its device is still up. */
|
|
106
|
+
const PRESENCE_WATCH_INTERVAL_MS = 15_000;
|
|
103
107
|
export class MeshService {
|
|
104
108
|
private readonly waiters = new Set<() => void>();
|
|
105
109
|
private readonly transports = new Set<MeshTransport>();
|
|
@@ -126,6 +130,7 @@ export class MeshService {
|
|
|
126
130
|
private readonly freshFixTimeoutMs: number;
|
|
127
131
|
private readonly pollIntervalMs: number;
|
|
128
132
|
private readonly commandTimeoutMs: number;
|
|
133
|
+
private readonly presenceWatchIntervalMs: number;
|
|
129
134
|
private loading: Promise<void> | null = null;
|
|
130
135
|
|
|
131
136
|
constructor(
|
|
@@ -137,6 +142,8 @@ export class MeshService {
|
|
|
137
142
|
this.pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
138
143
|
this.commandTimeoutMs =
|
|
139
144
|
options.commandTimeoutMs ?? DEFAULT_COMMAND_TIMEOUT_MS;
|
|
145
|
+
this.presenceWatchIntervalMs =
|
|
146
|
+
options.presenceWatchIntervalMs ?? PRESENCE_WATCH_INTERVAL_MS;
|
|
140
147
|
this.resolveNode = options.nodeBinaryResolver ?? resolveNodeBinary;
|
|
141
148
|
this.files = new DeviceFiles({
|
|
142
149
|
load: () => this.load(),
|
|
@@ -264,6 +271,38 @@ export class MeshService {
|
|
|
264
271
|
return true;
|
|
265
272
|
}
|
|
266
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Fail a pending command early when its device stops heartbeating.
|
|
276
|
+
*
|
|
277
|
+
* A device that drops mid-command will never answer, so waiting out the
|
|
278
|
+
* remaining budget only buys silence — and on a transfer budget that
|
|
279
|
+
* silence is minutes of a tool call, and therefore a chat, wedged behind
|
|
280
|
+
* a device that is plainly gone. Presence is derived from `lastSeen`, so
|
|
281
|
+
* this reports one presence grace period after the device goes quiet
|
|
282
|
+
* rather than instantly; short budgets aren't watched at all, since their
|
|
283
|
+
* own timeout lands first. Returns a stop function.
|
|
284
|
+
*/
|
|
285
|
+
private watchPresence(
|
|
286
|
+
deviceId: string,
|
|
287
|
+
timeoutMs: number,
|
|
288
|
+
onGone: (device: DeviceInfo) => void,
|
|
289
|
+
): () => void {
|
|
290
|
+
const every = this.presenceWatchIntervalMs;
|
|
291
|
+
if (timeoutMs <= every) return () => {};
|
|
292
|
+
const timer = setInterval(() => {
|
|
293
|
+
const current = this.registry
|
|
294
|
+
.list()
|
|
295
|
+
.devices.find((d) => d.id === deviceId);
|
|
296
|
+
// Unknown device: leave it to the timeout — an entry evicted from the
|
|
297
|
+
// registry is not evidence that the device stopped answering.
|
|
298
|
+
if (!current || current.online) return;
|
|
299
|
+
clearInterval(timer);
|
|
300
|
+
onGone(current);
|
|
301
|
+
}, every);
|
|
302
|
+
timer.unref?.();
|
|
303
|
+
return () => clearInterval(timer);
|
|
304
|
+
}
|
|
305
|
+
|
|
267
306
|
/**
|
|
268
307
|
* Push one command to a device and await its result (or time out). The
|
|
269
308
|
* low-level primitive under every command tool; exposed for tests and
|
|
@@ -282,8 +321,10 @@ export class MeshService {
|
|
|
282
321
|
params,
|
|
283
322
|
};
|
|
284
323
|
return new Promise<DeviceCommandResult>((resolve) => {
|
|
324
|
+
let stopWatch: () => void = () => {};
|
|
285
325
|
const timer = setTimeout(() => {
|
|
286
326
|
this.pendingCommands.delete(command.id);
|
|
327
|
+
stopWatch();
|
|
287
328
|
resolve({
|
|
288
329
|
commandId: command.id,
|
|
289
330
|
deviceId: device.id,
|
|
@@ -292,10 +333,21 @@ export class MeshService {
|
|
|
292
333
|
});
|
|
293
334
|
}, timeoutMs);
|
|
294
335
|
timer.unref?.();
|
|
336
|
+
stopWatch = this.watchPresence(device.id, timeoutMs, (current) => {
|
|
337
|
+
if (!this.pendingCommands.delete(command.id)) return;
|
|
338
|
+
clearTimeout(timer);
|
|
339
|
+
resolve({
|
|
340
|
+
commandId: command.id,
|
|
341
|
+
deviceId: device.id,
|
|
342
|
+
ok: false,
|
|
343
|
+
message: `${device.name} went offline (last seen ${age(Date.now() - current.lastSeen)}) before answering "${name}".`,
|
|
344
|
+
});
|
|
345
|
+
});
|
|
295
346
|
this.pendingCommands.set(command.id, {
|
|
296
347
|
deviceId: device.id,
|
|
297
348
|
resolve: (result) => {
|
|
298
349
|
clearTimeout(timer);
|
|
350
|
+
stopWatch();
|
|
299
351
|
resolve(result);
|
|
300
352
|
},
|
|
301
353
|
});
|
package/src/core/types.ts
CHANGED
|
@@ -257,6 +257,13 @@ export type ActionResult = {
|
|
|
257
257
|
* tool calls (react/edit/delete) that target this message.
|
|
258
258
|
*/
|
|
259
259
|
message_id?: number | string;
|
|
260
|
+
/**
|
|
261
|
+
* The canonical Talon chat id the action actually addressed. Set when
|
|
262
|
+
* a frontend resolved an explicit `target` (a phone number, a JID) to
|
|
263
|
+
* one of its chats, so the caller learns where its message landed —
|
|
264
|
+
* the cross-chat relay needs it to subscribe to the replies.
|
|
265
|
+
*/
|
|
266
|
+
chat_id?: string;
|
|
260
267
|
/**
|
|
261
268
|
* Set by tools that return a viewable image (e.g. `read` on a photo). The
|
|
262
269
|
* MCP layer turns this into an image content block so the model sees the
|
|
@@ -110,6 +110,12 @@ export function createWhatsAppActionHandler(
|
|
|
110
110
|
chat,
|
|
111
111
|
scheduledMessages,
|
|
112
112
|
};
|
|
113
|
-
|
|
113
|
+
const result = await handler(body, chatId, ctx);
|
|
114
|
+
// An explicitly targeted action resolved a chat the caller could not
|
|
115
|
+
// name itself (a phone number is not a chat id). Report where the
|
|
116
|
+
// message landed so cross-frontend callers can follow the thread.
|
|
117
|
+
return result && chat && body.target !== undefined
|
|
118
|
+
? { ...result, chat_id: chat.chatId }
|
|
119
|
+
: result;
|
|
114
120
|
};
|
|
115
121
|
}
|
|
@@ -11,6 +11,7 @@ import { execute } from "../../core/engine/dispatcher.js";
|
|
|
11
11
|
import { toolInputToRecord } from "../../core/agent-runtime/events.js";
|
|
12
12
|
import { appendDailyLog } from "../../storage/daily-log.js";
|
|
13
13
|
import { pushMessage } from "../../storage/history.js";
|
|
14
|
+
import { relayInbound } from "../../core/engine/cross-chat-relay.js";
|
|
14
15
|
import {
|
|
15
16
|
recordMessageProcessed,
|
|
16
17
|
recordMessageReceived,
|
|
@@ -175,6 +176,12 @@ async function recordInbound(
|
|
|
175
176
|
...(replyTo ? { replyToMsgId: replyTo.msgId } : {}),
|
|
176
177
|
...(media ? { mediaType: media.type, filePath: media.filePath } : {}),
|
|
177
178
|
});
|
|
179
|
+
|
|
180
|
+
// If another chat's session messaged this one via send_via, it is
|
|
181
|
+
// waiting to hear back — hand it the reply for its next turn. A no-op
|
|
182
|
+
// (and one Map miss) for every chat nobody cross-sent into.
|
|
183
|
+
relayInbound(chat.chatId, senderName, text || `[${media?.type ?? "media"}]`);
|
|
184
|
+
|
|
178
185
|
return { ...admitted, chat, msgId, text, media, senderName, platformTs };
|
|
179
186
|
}
|
|
180
187
|
|
|
@@ -26,7 +26,7 @@ import { dirs } from "../../util/paths.js";
|
|
|
26
26
|
* The github-mcp-server image tag Talon runs. Bump deliberately, with
|
|
27
27
|
* the canary workflow green — see .github/workflows/native-provision.yml.
|
|
28
28
|
*/
|
|
29
|
-
export const GITHUB_MCP_PINNED_TAG = "v1.12.
|
|
29
|
+
export const GITHUB_MCP_PINNED_TAG = "v1.12.2";
|
|
30
30
|
|
|
31
31
|
const GITHUB_MCP_IMAGE = "ghcr.io/github/github-mcp-server";
|
|
32
32
|
|
|
@@ -47,7 +47,7 @@ import { dirs, files } from "../../util/paths.js";
|
|
|
47
47
|
* to. Bump deliberately, with the canary workflow green — see
|
|
48
48
|
* .github/workflows/native-provision.yml.
|
|
49
49
|
*/
|
|
50
|
-
export const MEMPALACE_PINNED_VERSION = "3.
|
|
50
|
+
export const MEMPALACE_PINNED_VERSION = "3.10.0";
|
|
51
51
|
|
|
52
52
|
/** Minimum python for the managed venv (matches mempalace's supported floor). */
|
|
53
53
|
const PYTHON_MIN = { major: 3, minor: 10 };
|