@monoclaw/machine 1.0.19 → 1.0.20
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/cli.js +53 -17
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3846,9 +3846,22 @@ function formatUseResult(name, r, cwd) {
|
|
|
3846
3846
|
if (r.error) return { content: [{ type: "text", text: r.error }], isError: true };
|
|
3847
3847
|
return formatToolResult({ name }, r, cwd);
|
|
3848
3848
|
}
|
|
3849
|
+
var READ_ONLY_TOOLS = /* @__PURE__ */ new Set(["find_tools", "list_agents", "image_view", "agents_options", "agents_read_profile"]);
|
|
3850
|
+
var RESTART_PLAIN = "The service restarted while this ran; call it again.";
|
|
3851
|
+
function restartMessage(call) {
|
|
3852
|
+
switch (call.kind) {
|
|
3853
|
+
case "find":
|
|
3854
|
+
case "list":
|
|
3855
|
+
return RESTART_PLAIN;
|
|
3856
|
+
case "use":
|
|
3857
|
+
return READ_ONLY_TOOLS.has(call.name) ? RESTART_PLAIN : `The service restarted while ${call.name} ran. It may have run anyway: anything it made would be in your steps for the people in the project, and it may have cost money. Ask the person before calling it again.`;
|
|
3858
|
+
case "send":
|
|
3859
|
+
return `The service restarted while this message was being sent to ${call.to}. It may have arrived. If it matters, ask ${call.to} whether it did before sending it again.`;
|
|
3860
|
+
}
|
|
3861
|
+
}
|
|
3849
3862
|
var ToolWaits = class {
|
|
3850
3863
|
waits = /* @__PURE__ */ new Map();
|
|
3851
|
-
wait(id, timeoutMs = TOOL_TIMEOUT_MS) {
|
|
3864
|
+
wait(id, timeoutMs = TOOL_TIMEOUT_MS, lost = RESTART_PLAIN) {
|
|
3852
3865
|
return new Promise((resolve) => {
|
|
3853
3866
|
const timer = setTimeout(() => finish({ error: `No result within ${Math.round(timeoutMs / 1e3)} seconds.`, files: [] }), timeoutMs);
|
|
3854
3867
|
const finish = (r) => {
|
|
@@ -3856,14 +3869,18 @@ var ToolWaits = class {
|
|
|
3856
3869
|
this.waits.delete(id);
|
|
3857
3870
|
resolve(r);
|
|
3858
3871
|
};
|
|
3859
|
-
this.waits.set(id, finish);
|
|
3872
|
+
this.waits.set(id, { finish, lost });
|
|
3860
3873
|
});
|
|
3861
3874
|
}
|
|
3862
3875
|
resolve(id, r) {
|
|
3863
|
-
this.waits.get(id)?.(r);
|
|
3876
|
+
this.waits.get(id)?.finish(r);
|
|
3864
3877
|
}
|
|
3865
3878
|
closeAll(reason = "Session closed.") {
|
|
3866
|
-
for (const
|
|
3879
|
+
for (const w of [...this.waits.values()]) w.finish({ error: reason, files: [] });
|
|
3880
|
+
}
|
|
3881
|
+
/** The connection to the service closed: every waiting call ends now with its own message. */
|
|
3882
|
+
failWaiting() {
|
|
3883
|
+
for (const w of [...this.waits.values()]) w.finish({ error: w.lost, files: [] });
|
|
3867
3884
|
}
|
|
3868
3885
|
};
|
|
3869
3886
|
var SessionToolRunner = class {
|
|
@@ -3889,7 +3906,7 @@ var SessionToolRunner = class {
|
|
|
3889
3906
|
if (!ok) return formatToolResult(t, { error: "The user declined this tool call.", files: [] });
|
|
3890
3907
|
}
|
|
3891
3908
|
const id = newId();
|
|
3892
|
-
const wait = this.waits.wait(id, t.capability === "tts" && this.timeoutMs === TOOL_TIMEOUT_MS ? TTS_TOOL_TIMEOUT_MS : this.timeoutMs);
|
|
3909
|
+
const wait = this.waits.wait(id, t.capability === "tts" && this.timeoutMs === TOOL_TIMEOUT_MS ? TTS_TOOL_TIMEOUT_MS : this.timeoutMs, restartMessage({ kind: "use", name: t.name }));
|
|
3893
3910
|
this.push({ kind: "tool.call", id, toolId: t.id, prompt, args: callArgs });
|
|
3894
3911
|
return formatToolResult(t, await wait, this.cwd);
|
|
3895
3912
|
}
|
|
@@ -3901,7 +3918,7 @@ var SessionToolRunner = class {
|
|
|
3901
3918
|
const callArgs2 = toolCallArgs(t, args2);
|
|
3902
3919
|
if (t.askBeforeUse && !await this.approve(toolMcpName(t), { file: given, ...callArgs2 }, `${t.name}: ${given}`)) return formatToolResult(t, { error: "The user declined this tool call.", files: [] });
|
|
3903
3920
|
const id2 = newId();
|
|
3904
|
-
const wait2 = this.waits.wait(id2, this.timeoutMs === TOOL_TIMEOUT_MS ? STT_TOOL_TIMEOUT_MS : this.timeoutMs);
|
|
3921
|
+
const wait2 = this.waits.wait(id2, this.timeoutMs === TOOL_TIMEOUT_MS ? STT_TOOL_TIMEOUT_MS : this.timeoutMs, restartMessage({ kind: "use", name: t.name }));
|
|
3905
3922
|
this.push({ kind: "tool.call", id: id2, toolId: t.id, prompt: "", args: callArgs2, attachmentId: attachment });
|
|
3906
3923
|
return formatToolResult(t, await wait2, this.cwd);
|
|
3907
3924
|
}
|
|
@@ -3913,14 +3930,14 @@ var SessionToolRunner = class {
|
|
|
3913
3930
|
if (!ok) return formatToolResult(t, { error: "The user declined this tool call.", files: [] });
|
|
3914
3931
|
}
|
|
3915
3932
|
const id = newId();
|
|
3916
|
-
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? STT_TOOL_TIMEOUT_MS : this.timeoutMs);
|
|
3933
|
+
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? STT_TOOL_TIMEOUT_MS : this.timeoutMs, restartMessage({ kind: "use", name: t.name }));
|
|
3917
3934
|
this.push({ kind: "tool.call", id, toolId: t.id, prompt: "", args: callArgs, file: file.path });
|
|
3918
3935
|
return formatToolResult(t, await wait, this.cwd);
|
|
3919
3936
|
}
|
|
3920
3937
|
/** `find_tools`: the server's list, as the JSON text it sent. */
|
|
3921
3938
|
async find(args2) {
|
|
3922
3939
|
const id = newId();
|
|
3923
|
-
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? FIND_TOOLS_TIMEOUT_MS : this.timeoutMs);
|
|
3940
|
+
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? FIND_TOOLS_TIMEOUT_MS : this.timeoutMs, restartMessage({ kind: "find" }));
|
|
3924
3941
|
this.push({ kind: "tools.find", id, ...args2.query?.trim() ? { query: args2.query.trim() } : {}, ...typeof args2.limit === "number" ? { limit: args2.limit } : {} });
|
|
3925
3942
|
const r = await wait;
|
|
3926
3943
|
return r.error ? { content: [{ type: "text", text: r.error }], isError: true } : { content: [{ type: "text", text: r.text ?? "" }] };
|
|
@@ -3944,7 +3961,7 @@ var SessionToolRunner = class {
|
|
|
3944
3961
|
let file;
|
|
3945
3962
|
for (let round2 = 0; round2 < 3; round2++) {
|
|
3946
3963
|
const id = newId();
|
|
3947
|
-
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? USE_TOOL_TIMEOUT_MS : this.timeoutMs);
|
|
3964
|
+
const wait = this.waits.wait(id, this.timeoutMs === TOOL_TIMEOUT_MS ? USE_TOOL_TIMEOUT_MS : this.timeoutMs, restartMessage({ kind: "use", name }));
|
|
3948
3965
|
this.push({ kind: "tool.use", id, name, input, ...approved ? { approved } : {}, ...file ? { file } : {} });
|
|
3949
3966
|
const r = await wait;
|
|
3950
3967
|
if (!r.next) return formatUseResult(name, r, this.cwd);
|
|
@@ -3964,6 +3981,10 @@ var SessionToolRunner = class {
|
|
|
3964
3981
|
result(id, r) {
|
|
3965
3982
|
this.waits.resolve(id, r);
|
|
3966
3983
|
}
|
|
3984
|
+
/** The connection to the service closed: every waiting call ends now (bug: a tool call lost in a server restart). */
|
|
3985
|
+
failWaiting() {
|
|
3986
|
+
this.waits.failWaiting();
|
|
3987
|
+
}
|
|
3967
3988
|
close() {
|
|
3968
3989
|
this.waits.closeAll();
|
|
3969
3990
|
}
|
|
@@ -4324,6 +4345,10 @@ var SessionManager = class {
|
|
|
4324
4345
|
this.emit(groupId, { kind: "error", message: e.message, fatal: false });
|
|
4325
4346
|
}
|
|
4326
4347
|
}
|
|
4348
|
+
/** The connection to the service closed: every session's waiting calls end now (bug: a tool call lost in a server restart). */
|
|
4349
|
+
connectionLost() {
|
|
4350
|
+
for (const l of this.live.values()) l.session.connectionLost?.();
|
|
4351
|
+
}
|
|
4327
4352
|
/** The server's answer to an `agent.send` or `agents.list` event. */
|
|
4328
4353
|
agentResult(groupId, id, result) {
|
|
4329
4354
|
this.live.get(groupId)?.session.agentResult?.(id, result);
|
|
@@ -4665,7 +4690,7 @@ function guessMime(name) {
|
|
|
4665
4690
|
}
|
|
4666
4691
|
|
|
4667
4692
|
// src/version.ts
|
|
4668
|
-
var APP_VERSION = true ? "1.0.
|
|
4693
|
+
var APP_VERSION = true ? "1.0.20" : fromPackage();
|
|
4669
4694
|
|
|
4670
4695
|
// src/diag.ts
|
|
4671
4696
|
var MAX_HELD = 200;
|
|
@@ -4939,6 +4964,7 @@ var HostClient = class {
|
|
|
4939
4964
|
ws.on("close", (code, reason) => {
|
|
4940
4965
|
if (this.ws !== ws) return;
|
|
4941
4966
|
this.onState("offline");
|
|
4967
|
+
this.sessions.connectionLost();
|
|
4942
4968
|
if (this.heartbeat) clearInterval(this.heartbeat);
|
|
4943
4969
|
this.clearTimers();
|
|
4944
4970
|
if (code === 4001) {
|
|
@@ -5942,7 +5968,7 @@ var EchoSession = class {
|
|
|
5942
5968
|
const id = newId();
|
|
5943
5969
|
const r = await new Promise((res) => {
|
|
5944
5970
|
const t = setTimeout(() => res({ error: "no answer from the router" }), 5e3);
|
|
5945
|
-
this.agentWaits.set(id, (x) => (clearTimeout(t), res(x)));
|
|
5971
|
+
this.agentWaits.set(id, { finish: (x) => (clearTimeout(t), res(x)), lost: restartMessage({ kind: "send", to: to.trim() }) });
|
|
5946
5972
|
this.q.push({ kind: "agent.send", id, to: to.trim(), text: rest.join(":").trim() });
|
|
5947
5973
|
});
|
|
5948
5974
|
this.agentWaits.delete(id);
|
|
@@ -5954,7 +5980,7 @@ var EchoSession = class {
|
|
|
5954
5980
|
const id = newId();
|
|
5955
5981
|
const r = await new Promise((res) => {
|
|
5956
5982
|
const t = setTimeout(() => res({ error: "no answer from the router" }), 5e3);
|
|
5957
|
-
this.agentWaits.set(id, (x) => (clearTimeout(t), res(x)));
|
|
5983
|
+
this.agentWaits.set(id, { finish: (x) => (clearTimeout(t), res(x)), lost: restartMessage({ kind: "list" }) });
|
|
5958
5984
|
this.q.push({ kind: "agents.list", id });
|
|
5959
5985
|
});
|
|
5960
5986
|
this.agentWaits.delete(id);
|
|
@@ -6054,11 +6080,15 @@ ${r.text}`, final: true });
|
|
|
6054
6080
|
this.pending.delete(id);
|
|
6055
6081
|
}
|
|
6056
6082
|
agentResult(id, result) {
|
|
6057
|
-
this.agentWaits.get(id)?.(result);
|
|
6083
|
+
this.agentWaits.get(id)?.finish(result);
|
|
6058
6084
|
}
|
|
6059
6085
|
toolResult(id, result) {
|
|
6060
6086
|
this.tools.result(id, result);
|
|
6061
6087
|
}
|
|
6088
|
+
connectionLost() {
|
|
6089
|
+
for (const w of [...this.agentWaits.values()]) w.finish({ error: w.lost });
|
|
6090
|
+
this.tools.failWaiting();
|
|
6091
|
+
}
|
|
6062
6092
|
async interrupt() {
|
|
6063
6093
|
this.abort?.abort();
|
|
6064
6094
|
}
|
|
@@ -6409,6 +6439,7 @@ var ClaudeSession = class {
|
|
|
6409
6439
|
/** tool_use id → tool name, so a result can be named. */
|
|
6410
6440
|
toolNames = /* @__PURE__ */ new Map();
|
|
6411
6441
|
/** `send` and `list_agents` calls waiting for the server's `agent.send.result`. */
|
|
6442
|
+
/** `send` and `list_agents` calls waiting for the service, each with what to say if the connection is lost meanwhile. */
|
|
6412
6443
|
agentWaits = /* @__PURE__ */ new Map();
|
|
6413
6444
|
/** The agent's tools: calls waiting for the server's `tool.result`. */
|
|
6414
6445
|
tools;
|
|
@@ -6482,7 +6513,7 @@ var ClaudeSession = class {
|
|
|
6482
6513
|
this.agentWaits.delete(id);
|
|
6483
6514
|
resolve(r2);
|
|
6484
6515
|
};
|
|
6485
|
-
this.agentWaits.set(id, finish);
|
|
6516
|
+
this.agentWaits.set(id, { finish, lost: restartMessage({ kind: "list" }) });
|
|
6486
6517
|
});
|
|
6487
6518
|
this.q.push({ kind: "agents.list", id });
|
|
6488
6519
|
const r = await result;
|
|
@@ -6503,7 +6534,7 @@ var ClaudeSession = class {
|
|
|
6503
6534
|
this.agentWaits.delete(id);
|
|
6504
6535
|
resolve(r);
|
|
6505
6536
|
};
|
|
6506
|
-
this.agentWaits.set(id, finish);
|
|
6537
|
+
this.agentWaits.set(id, { finish, lost: restartMessage({ kind: "send", to: args2.to }) });
|
|
6507
6538
|
});
|
|
6508
6539
|
this.q.push({ kind: "agent.send", id, to: args2.to, text: args2.text });
|
|
6509
6540
|
return sendToolResult(args2, await result);
|
|
@@ -6721,11 +6752,16 @@ ${files.map((a) => `- ${a.localPath} (${a.mime}, ${a.size} bytes)${a.note ? `: $
|
|
|
6721
6752
|
f(allow ? { behavior: "allow", updatedInput } : { behavior: "deny", message: "The user declined this action in the chat." });
|
|
6722
6753
|
}
|
|
6723
6754
|
agentResult(id, result) {
|
|
6724
|
-
this.agentWaits.get(id)?.(result);
|
|
6755
|
+
this.agentWaits.get(id)?.finish(result);
|
|
6725
6756
|
}
|
|
6726
6757
|
toolResult(id, result) {
|
|
6727
6758
|
this.tools.result(id, result);
|
|
6728
6759
|
}
|
|
6760
|
+
/** The machine's connection to the service closed: what was waiting for it ends now, each call with its own words. */
|
|
6761
|
+
connectionLost() {
|
|
6762
|
+
for (const w of [...this.agentWaits.values()]) w.finish({ error: w.lost });
|
|
6763
|
+
this.tools.failWaiting();
|
|
6764
|
+
}
|
|
6729
6765
|
/**
|
|
6730
6766
|
* When we last asked the run to stop. The result that follows within a minute is a stop, whatever it calls itself
|
|
6731
6767
|
* (a stop asked for while nothing ran must not hide a later run's real error, hence the limit).
|
|
@@ -6760,7 +6796,7 @@ ${files.map((a) => `- ${a.localPath} (${a.mime}, ${a.size} bytes)${a.note ? `: $
|
|
|
6760
6796
|
this.closed = true;
|
|
6761
6797
|
liveBackground.delete(this.opts.groupId);
|
|
6762
6798
|
for (const f of this.pending.values()) f({ behavior: "deny", message: "Session closed." });
|
|
6763
|
-
for (const
|
|
6799
|
+
for (const w of this.agentWaits.values()) w.finish({ error: "Session closed." });
|
|
6764
6800
|
this.tools.close();
|
|
6765
6801
|
this.prompts.close();
|
|
6766
6802
|
await this.query?.interrupt().catch(() => {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monoclaw/machine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@monoclaw/machine",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.20",
|
|
10
10
|
"license": "UNLICENSED",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/claude-agent-sdk": "0.3.302",
|
|
@@ -789,9 +789,9 @@
|
|
|
789
789
|
}
|
|
790
790
|
},
|
|
791
791
|
"node_modules/hono": {
|
|
792
|
-
"version": "4.13.
|
|
793
|
-
"resolved": "https://registry.npmjs.org/hono/-/hono-4.13.
|
|
794
|
-
"integrity": "sha512-
|
|
792
|
+
"version": "4.13.23",
|
|
793
|
+
"resolved": "https://registry.npmjs.org/hono/-/hono-4.13.23.tgz",
|
|
794
|
+
"integrity": "sha512-OS90dj7dcsftEEWCOef8jRbnHE5lbrOq0hNRqjSyPsOnaGZvvfof1KS05hQNb4kUOCfDq1mG3PmHoX37DMnHQg==",
|
|
795
795
|
"license": "MIT",
|
|
796
796
|
"engines": {
|
|
797
797
|
"node": ">=16.9.0"
|
package/package.json
CHANGED