dsh-interconnect 0.11.15 → 0.11.16

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.
@@ -840,6 +840,7 @@ var LINK_HANDSHAKE_TIMEOUT_MS = 1e4;
840
840
  var LINK_CHANNEL = "/interconnect/link";
841
841
  var MAX_REQUEST_ID_CHARS = 256;
842
842
  var MAX_LISTED_SESSIONS = 100;
843
+ var frameFitsLink = (frame) => Buffer.byteLength(JSON.stringify(frame), "utf8") <= MAX_LINK_FRAME_BYTES;
843
844
  var rowBytes = (row) => Buffer.byteLength(JSON.stringify(row), "utf8") + 1;
844
845
  var notificationSchema = Schema.union([
845
846
  Schema.object({ kind: Schema.const("agent/created").required(), sessionId: Schema.string().required() }),
@@ -1126,22 +1127,30 @@ var InterconnectService = class extends Service {
1126
1127
  * Send a `msg` frame over the live link to a peer and resolve with its
1127
1128
  * correlated `msg-result`. Undefined when the peer has no live link here
1128
1129
  * (not configured, or the link is down) — sends can only address configured+
1129
- * connected peers by design.
1130
+ * connected peers by design — and a `message-too-large` result when the
1131
+ * encoded frame would not fit the link.
1130
1132
  */
1131
1133
  async msgRequest(instanceId, kind, payload) {
1132
1134
  const state = this.linkStates.get(instanceId);
1133
1135
  if (state === void 0 || !state.writable()) return void 0;
1134
1136
  const reqId = `m${++this.reqIdCounter}-${randomUUID()}`;
1135
- const message = {
1136
- kind,
1137
- sessionId: payload.sessionId,
1138
- text: payload.text,
1139
- ...payload.sender === void 0 ? {} : { sender: payload.sender },
1140
- ...payload.delivery === void 0 ? {} : { delivery: payload.delivery },
1141
- ...payload.resume === void 0 ? {} : { resume: payload.resume }
1137
+ const frame = {
1138
+ type: "msg",
1139
+ reqId,
1140
+ message: {
1141
+ kind,
1142
+ sessionId: payload.sessionId,
1143
+ text: payload.text,
1144
+ ...payload.sender === void 0 ? {} : { sender: payload.sender },
1145
+ ...payload.delivery === void 0 ? {} : { delivery: payload.delivery },
1146
+ ...payload.resume === void 0 ? {} : { resume: payload.resume }
1147
+ }
1142
1148
  };
1149
+ if (!frameFitsLink(frame)) {
1150
+ return { delivered: false, instance: instanceId, reason: "message-too-large" };
1151
+ }
1143
1152
  return this.waitForResult(reqId, "msg", (failure) => {
1144
- const wrote = state.sendFrame({ type: "msg", reqId, message });
1153
+ const wrote = state.sendFrame(frame);
1145
1154
  if (!wrote) failure(new Error(`interconnect: peer link to ${instanceId} closed while sending`));
1146
1155
  });
1147
1156
  }
@@ -1792,7 +1801,7 @@ function apply(ctx) {
1792
1801
  text: {
1793
1802
  type: "string",
1794
1803
  required: true,
1795
- description: "Message text delivered to the peer session."
1804
+ description: 'Message text delivered to the peer session. At most 1 MiB once encoded: a larger message is refused with reason "message-too-large".'
1796
1805
  },
1797
1806
  delivery: {
1798
1807
  type: "string",
@@ -1823,6 +1832,8 @@ function apply(ctx) {
1823
1832
  return `not delivered: could not wake "${_args.sessionId}" on ${value.instance} (no persisted session under that id, or the wake itself failed)`;
1824
1833
  case "session-owned-by-subagent":
1825
1834
  return `not delivered: "${_args.sessionId}" is a subagent's session on ${value.instance} \u2014 its parent agent owns delivery, so reach it through that parent`;
1835
+ case "message-too-large":
1836
+ return "not delivered: the message is too large for the peer link (limit 1 MiB); shorten the text and try again";
1826
1837
  default:
1827
1838
  return `not delivered: no live session "${_args.sessionId}" on ${value.instance}` + (_args.resume === true ? " \u2014 use interconnect_list to see which sessions are live there" : " \u2014 use interconnect_list to see which sessions are live there, or set resume to wake this one");
1828
1839
  }
@@ -1973,6 +1984,9 @@ function apply(ctx) {
1973
1984
  if (value.reason === "no-sender-known") {
1974
1985
  return "not delivered: no sender identity is known to reply to";
1975
1986
  }
1987
+ if (value.reason === "message-too-large") {
1988
+ return "not delivered: the reply is too large for the peer link (limit 1 MiB); shorten the text and try again";
1989
+ }
1976
1990
  if (value.reason === "session-owned-by-subagent") {
1977
1991
  return "not delivered: the recorded sender's session belongs to a subagent and its parent agent owns delivery";
1978
1992
  }