@markasso/mcp 0.10.1 → 0.10.2
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/markasso-mcp.js +117 -2
- package/package.json +1 -1
package/dist/markasso-mcp.js
CHANGED
|
@@ -5747,7 +5747,7 @@ function escapeXml(str) {
|
|
|
5747
5747
|
}
|
|
5748
5748
|
//#endregion
|
|
5749
5749
|
//#region package.json
|
|
5750
|
-
var version = "0.10.
|
|
5750
|
+
var version = "0.10.2";
|
|
5751
5751
|
//#endregion
|
|
5752
5752
|
//#region ../src/core/layout.ts
|
|
5753
5753
|
/** Space kept on both sides of a label between ranks. */
|
|
@@ -9105,6 +9105,79 @@ function isValidSessionCommand(value) {
|
|
|
9105
9105
|
if (!Object.hasOwn(CHECKS, value.type)) return false;
|
|
9106
9106
|
return CHECKS[value.type](value);
|
|
9107
9107
|
}
|
|
9108
|
+
/**
|
|
9109
|
+
* How late the timeout check may run before it counts as a wake from sleep
|
|
9110
|
+
* (timers do not run while a machine or a background tab sleeps, and run
|
|
9111
|
+
* late in a throttled one): the old ping then proves nothing, and a fresh
|
|
9112
|
+
* one gets a full timeout. Only a check that runs on time can give up.
|
|
9113
|
+
*/
|
|
9114
|
+
var SLEEP_SLACK_MS = 5e3;
|
|
9115
|
+
/** Pings one socket on a period and reports when it stops answering. */
|
|
9116
|
+
var Heartbeat = class {
|
|
9117
|
+
options;
|
|
9118
|
+
intervalMs;
|
|
9119
|
+
timeoutMs;
|
|
9120
|
+
now;
|
|
9121
|
+
nextPing = null;
|
|
9122
|
+
deadline = null;
|
|
9123
|
+
pingSentAt = 0;
|
|
9124
|
+
stopped = true;
|
|
9125
|
+
constructor(options) {
|
|
9126
|
+
this.options = options;
|
|
9127
|
+
this.intervalMs = options.intervalMs ?? 2e4;
|
|
9128
|
+
this.timeoutMs = options.timeoutMs ?? 1e4;
|
|
9129
|
+
this.now = options.now ?? Date.now;
|
|
9130
|
+
}
|
|
9131
|
+
/** Starts, or restarts, the period. */
|
|
9132
|
+
start() {
|
|
9133
|
+
this.stop();
|
|
9134
|
+
this.stopped = false;
|
|
9135
|
+
this.armPing();
|
|
9136
|
+
}
|
|
9137
|
+
/** The socket answered: the next ping waits a full period. */
|
|
9138
|
+
pong() {
|
|
9139
|
+
if (this.stopped) return;
|
|
9140
|
+
this.clear("deadline");
|
|
9141
|
+
this.armPing();
|
|
9142
|
+
}
|
|
9143
|
+
stop() {
|
|
9144
|
+
this.stopped = true;
|
|
9145
|
+
this.clear("nextPing");
|
|
9146
|
+
this.clear("deadline");
|
|
9147
|
+
}
|
|
9148
|
+
armPing() {
|
|
9149
|
+
this.clear("nextPing");
|
|
9150
|
+
this.nextPing = unref(setTimeout(() => this.ping(), this.intervalMs));
|
|
9151
|
+
}
|
|
9152
|
+
ping() {
|
|
9153
|
+
if (this.stopped) return;
|
|
9154
|
+
this.nextPing = null;
|
|
9155
|
+
this.pingSentAt = this.now();
|
|
9156
|
+
this.options.ping();
|
|
9157
|
+
this.clear("deadline");
|
|
9158
|
+
this.deadline = unref(setTimeout(() => this.check(), this.timeoutMs));
|
|
9159
|
+
}
|
|
9160
|
+
check() {
|
|
9161
|
+
if (this.stopped) return;
|
|
9162
|
+
this.deadline = null;
|
|
9163
|
+
if (this.now() - this.pingSentAt - this.timeoutMs > SLEEP_SLACK_MS) {
|
|
9164
|
+
this.ping();
|
|
9165
|
+
return;
|
|
9166
|
+
}
|
|
9167
|
+
this.stop();
|
|
9168
|
+
this.options.onTimeout();
|
|
9169
|
+
}
|
|
9170
|
+
clear(which) {
|
|
9171
|
+
const timer = this[which];
|
|
9172
|
+
if (timer) clearTimeout(timer);
|
|
9173
|
+
this[which] = null;
|
|
9174
|
+
}
|
|
9175
|
+
};
|
|
9176
|
+
/** In Node, a timer must not keep the process alive on its own. */
|
|
9177
|
+
function unref(timer) {
|
|
9178
|
+
timer.unref?.();
|
|
9179
|
+
return timer;
|
|
9180
|
+
}
|
|
9108
9181
|
//#endregion
|
|
9109
9182
|
//#region ../src/io/live_outbox.ts
|
|
9110
9183
|
var LiveOutbox = class {
|
|
@@ -9388,6 +9461,8 @@ var CLOSE_LICENCE_REQUIRED = 4402;
|
|
|
9388
9461
|
var CLOSE_ROOM_FULL = 1013;
|
|
9389
9462
|
/** Close code (with reason "replaced") for a socket a newer one replaced. */
|
|
9390
9463
|
var CLOSE_REPLACED = 1e3;
|
|
9464
|
+
/** How long a socket given up on may take to report its close. */
|
|
9465
|
+
var CLOSE_WAIT_MS = 2e3;
|
|
9391
9466
|
var RECONNECT_BASE_MS = 1e3;
|
|
9392
9467
|
var RECONNECT_MAX_MS = 1e4;
|
|
9393
9468
|
/**
|
|
@@ -9498,6 +9573,8 @@ var LiveLink = class LiveLink {
|
|
|
9498
9573
|
dropClose = null;
|
|
9499
9574
|
/** One-shot notes for the model's next tool answer (see takeNotices). */
|
|
9500
9575
|
notices = [];
|
|
9576
|
+
/** Watches the socket in the room, when the room answers pings. */
|
|
9577
|
+
heartbeat = null;
|
|
9501
9578
|
inbox = [];
|
|
9502
9579
|
/**
|
|
9503
9580
|
* Delivered request ids the agent may answer, each with the elements the
|
|
@@ -9846,7 +9923,9 @@ var LiveLink = class LiveLink {
|
|
|
9846
9923
|
settled = true;
|
|
9847
9924
|
clearTimeout(timer);
|
|
9848
9925
|
resolve(onInit(msg));
|
|
9849
|
-
|
|
9926
|
+
if (msg.heartbeat === true) this.watch(socket, attempt);
|
|
9927
|
+
} else if (msg.type === "pong") this.heartbeat?.pong();
|
|
9928
|
+
else if (msg.type === "apply") {
|
|
9850
9929
|
if (!admitted) return;
|
|
9851
9930
|
if (isSessionCommand(msg.command) && isValidSessionCommand(msg.command)) try {
|
|
9852
9931
|
this.diagram.history.applyRemote(msg.command);
|
|
@@ -9925,8 +10004,42 @@ var LiveLink = class LiveLink {
|
|
|
9925
10004
|
discarded
|
|
9926
10005
|
};
|
|
9927
10006
|
}
|
|
10007
|
+
/**
|
|
10008
|
+
* Pings the socket of this attempt while it is in the room. No answer in
|
|
10009
|
+
* time means the connection died without a close event: it is dropped
|
|
10010
|
+
* right away, as a close would (its own late events no longer count),
|
|
10011
|
+
* instead of waiting for a close that may take long to come.
|
|
10012
|
+
*/
|
|
10013
|
+
watch(socket, attempt) {
|
|
10014
|
+
this.heartbeat?.stop();
|
|
10015
|
+
this.heartbeat = new Heartbeat({
|
|
10016
|
+
ping: () => {
|
|
10017
|
+
if (attempt === this.attemptId) this.send({ type: "ping" });
|
|
10018
|
+
},
|
|
10019
|
+
onTimeout: () => {
|
|
10020
|
+
if (attempt !== this.attemptId || this._state !== "connected") return;
|
|
10021
|
+
try {
|
|
10022
|
+
socket.close();
|
|
10023
|
+
} catch {}
|
|
10024
|
+
setTimeout(() => {
|
|
10025
|
+
if (attempt !== this.attemptId || this._state !== "connected") return;
|
|
10026
|
+
this.attemptId++;
|
|
10027
|
+
this.dropped({
|
|
10028
|
+
code: null,
|
|
10029
|
+
reason: "heartbeat timeout"
|
|
10030
|
+
});
|
|
10031
|
+
}, CLOSE_WAIT_MS).unref?.();
|
|
10032
|
+
}
|
|
10033
|
+
});
|
|
10034
|
+
this.heartbeat.start();
|
|
10035
|
+
}
|
|
10036
|
+
stopWatching() {
|
|
10037
|
+
this.heartbeat?.stop();
|
|
10038
|
+
this.heartbeat = null;
|
|
10039
|
+
}
|
|
9928
10040
|
/** The socket of a joined session closed: retry unless it is final. */
|
|
9929
10041
|
dropped(close) {
|
|
10042
|
+
this.stopWatching();
|
|
9930
10043
|
this._lastClose = close;
|
|
9931
10044
|
this.dropClose = close;
|
|
9932
10045
|
this.outbox.clear();
|
|
@@ -9974,6 +10087,7 @@ var LiveLink = class LiveLink {
|
|
|
9974
10087
|
}
|
|
9975
10088
|
/** Gives up on the room: waiting calls return, nothing is sent anymore. */
|
|
9976
10089
|
lose() {
|
|
10090
|
+
this.stopWatching();
|
|
9977
10091
|
this._state = "lost";
|
|
9978
10092
|
this.cancelReconnect();
|
|
9979
10093
|
this.untrack();
|
|
@@ -9998,6 +10112,7 @@ var LiveLink = class LiveLink {
|
|
|
9998
10112
|
leave() {
|
|
9999
10113
|
if (this.open) this.outbox.drain();
|
|
10000
10114
|
this._state = "left";
|
|
10115
|
+
this.stopWatching();
|
|
10001
10116
|
this.attemptId++;
|
|
10002
10117
|
this.cancelReconnect();
|
|
10003
10118
|
this.wakeWaiters();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markasso/mcp",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"mcpName": "io.github.AlbertoBarrago/markasso",
|
|
5
5
|
"description": "MCP server that lets AI agents create, read and edit Markasso diagrams, offline or live on a shared board",
|
|
6
6
|
"type": "module",
|