@delali/narsil 0.3.0 → 0.3.1-next.101

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.
Files changed (165) hide show
  1. package/README.md +9 -8
  2. package/dist/adapters/filesystem.d.ts +1 -1
  3. package/dist/adapters/filesystem.mjs +1 -1
  4. package/dist/adapters/indexeddb.d.ts +1 -1
  5. package/dist/adapters/indexeddb.mjs +1 -1
  6. package/dist/adapters/memory.d.ts +1 -1
  7. package/dist/{adapters-79OIa4xm.d.ts → adapters-BQFQ4PRz.d.ts} +27 -1
  8. package/dist/browser/chunk-BDOSMEEP.mjs +493 -0
  9. package/dist/browser/chunk-EJDUFWSO.mjs +602 -0
  10. package/dist/browser/chunk-HOZW3PKP.mjs +9 -0
  11. package/dist/browser/chunk-JOVZ6HMT.mjs +4358 -0
  12. package/dist/browser/chunk-JPTQZWJQ.mjs +10 -0
  13. package/dist/browser/chunk-KPJMDPHG.mjs +24558 -0
  14. package/dist/browser/chunk-PGIM3HIM.mjs +2743 -0
  15. package/dist/browser/chunk-RHG4O77A.mjs +206 -0
  16. package/dist/browser/chunk-RIJSLY2I.mjs +360 -0
  17. package/dist/browser/durability-wiring-SRUYT3VV.mjs +3875 -0
  18. package/dist/browser/module-CBB2ETYP.mjs +3111 -0
  19. package/dist/browser/release-76MXRPGV.mjs +33 -0
  20. package/dist/browser/replace-RURXTGVG.mjs +57 -0
  21. package/dist/browser/restore-queue-EEZQO6RF.mjs +35 -0
  22. package/dist/browser/runtime-7ZAHCHWR.mjs +557 -0
  23. package/dist/browser/snapshot-OAAA5UJ7.mjs +1210 -0
  24. package/dist/browser/write-7D6VIK6O.mjs +208 -0
  25. package/dist/{capabilities-DSsOGz6F.d.ts → capabilities-DiGlB6Sr.d.ts} +68 -7
  26. package/dist/chunk-2RIRGOUL.mjs +113 -0
  27. package/dist/chunk-37CD3OKS.mjs +87 -0
  28. package/dist/chunk-44W3CBNG.mjs +7 -0
  29. package/dist/chunk-46D6JQIG.mjs +426 -0
  30. package/dist/{chunk-VMRR3DQU.mjs → chunk-5JNA5SKS.mjs} +546 -35
  31. package/dist/chunk-747OHOUA.mjs +11 -0
  32. package/dist/chunk-75XIEF6H.mjs +126 -0
  33. package/dist/chunk-7X5JST5L.mjs +114 -0
  34. package/dist/chunk-BOFBLJFZ.mjs +209 -0
  35. package/dist/{chunk-USKFU7J5.mjs → chunk-BWJVNZPR.mjs} +8 -1
  36. package/dist/chunk-C7SLA6CM.mjs +19 -0
  37. package/dist/{chunk-POWOTUKJ.mjs → chunk-CQUMNIIG.mjs} +3 -6
  38. package/dist/chunk-CVXLLEQ3.mjs +1011 -0
  39. package/dist/chunk-DJHHF2L5.mjs +17 -0
  40. package/dist/chunk-E74YLAIG.mjs +24 -0
  41. package/dist/{chunk-UXNWQZST.mjs → chunk-EMRMGYRE.mjs} +236 -18
  42. package/dist/chunk-EWZLIYHV.mjs +57 -0
  43. package/dist/chunk-GBEEG5AN.mjs +35 -0
  44. package/dist/chunk-GES7U2PM.mjs +68 -0
  45. package/dist/chunk-HJSN7UYG.mjs +10 -0
  46. package/dist/chunk-HLPRHOSO.mjs +17 -0
  47. package/dist/chunk-HMFNFVP7.mjs +14 -0
  48. package/dist/chunk-J5QP52HA.mjs +1751 -0
  49. package/dist/{chunk-YNVIUGF5.mjs → chunk-JZVARCRZ.mjs} +3 -28
  50. package/dist/chunk-KOKM4PQN.mjs +52 -0
  51. package/dist/{chunk-B2TFROFX.mjs → chunk-KWTW6VTG.mjs} +465 -250
  52. package/dist/chunk-KZ3NX2P7.mjs +21 -0
  53. package/dist/chunk-L5ORED7V.mjs +25 -0
  54. package/dist/{chunk-THYRHHO2.mjs → chunk-LGAMKHA2.mjs} +2009 -2351
  55. package/dist/chunk-LKOB5COA.mjs +117 -0
  56. package/dist/chunk-LPQOEU5M.mjs +96 -0
  57. package/dist/{chunk-3LHGNRYE.mjs → chunk-LXWDQLTW.mjs} +7 -2
  58. package/dist/{chunk-L6TNPLAR.mjs → chunk-OEYI3KRB.mjs} +270 -108
  59. package/dist/chunk-OM362BRO.mjs +948 -0
  60. package/dist/chunk-OZDFA4WC.mjs +67 -0
  61. package/dist/chunk-P36MUFEJ.mjs +10 -0
  62. package/dist/chunk-PC2G76VW.mjs +2540 -0
  63. package/dist/{chunk-GCM3JFVA.mjs → chunk-PNEYIHA4.mjs} +11 -2
  64. package/dist/chunk-PNFKUCG3.mjs +1130 -0
  65. package/dist/chunk-Q6XWVUZX.mjs +44 -0
  66. package/dist/chunk-R27EMH5M.mjs +617 -0
  67. package/dist/{chunk-YMZCMH5M.mjs → chunk-R6A773WK.mjs} +19 -24
  68. package/dist/chunk-RF7PLG43.mjs +106 -0
  69. package/dist/chunk-RFBLQLLZ.mjs +16 -0
  70. package/dist/{chunk-Y3L5MDRV.mjs → chunk-RFVUDM5E.mjs} +17 -2
  71. package/dist/chunk-S7FL6UAH.mjs +521 -0
  72. package/dist/chunk-S7GNDRPS.mjs +651 -0
  73. package/dist/chunk-SP3NM3ZG.mjs +3537 -0
  74. package/dist/chunk-U476IXKQ.mjs +10 -0
  75. package/dist/chunk-UA3AUGNV.mjs +462 -0
  76. package/dist/chunk-UTG5YNXV.mjs +507 -0
  77. package/dist/chunk-VI4R6W25.mjs +8484 -0
  78. package/dist/chunk-WQBCBKY3.mjs +8 -0
  79. package/dist/{chunk-24RXHMEL.mjs → chunk-WVCOCKBU.mjs} +3794 -7570
  80. package/dist/chunk-X5CV2E2B.mjs +1 -0
  81. package/dist/chunk-XADZPPZI.mjs +614 -0
  82. package/dist/chunk-YEEQHT4V.mjs +212 -0
  83. package/dist/chunk-YTJCGKM4.mjs +56 -0
  84. package/dist/chunk-YYQIODMF.mjs +275 -0
  85. package/dist/chunk-ZI34TVOA.mjs +144 -0
  86. package/dist/{chunk-OOSIDHA3.mjs → chunk-ZKWYWW4Y.mjs} +1 -1
  87. package/dist/chunk-ZM7KU4YW.mjs +35 -0
  88. package/dist/{client-BQK6Tf6A.d.ts → client-BOStAkc5.d.ts} +160 -37
  89. package/dist/client.d.ts +11 -10
  90. package/dist/client.mjs +209 -45
  91. package/dist/{config-DmXULPa-.d.ts → config-Cjvzbs_j.d.ts} +51 -3
  92. package/dist/config-DffQlmRq.d.ts +421 -0
  93. package/dist/direct-executor-ZD64PPEZ.mjs +24 -0
  94. package/dist/distribution/coordinator/etcd.d.ts +79 -18
  95. package/dist/distribution/coordinator/etcd.mjs +553 -109
  96. package/dist/distribution/coordinator/in-memory.d.ts +4 -3
  97. package/dist/distribution/coordinator/in-memory.mjs +22 -3
  98. package/dist/distribution/transport/grpc.d.ts +2 -2
  99. package/dist/distribution/transport/grpc.mjs +79 -14
  100. package/dist/distribution/transport/in-memory.d.ts +2 -2
  101. package/dist/distribution/transport/in-memory.mjs +12 -7
  102. package/dist/distribution/transport/tcp.d.ts +2 -2
  103. package/dist/distribution/transport/tcp.mjs +50 -28
  104. package/dist/distribution.d.ts +144 -23
  105. package/dist/distribution.mjs +14479 -8173
  106. package/dist/durability-wiring-FEUBR5BT.mjs +3330 -0
  107. package/dist/embeddings/openai.d.ts +2 -2
  108. package/dist/embeddings/openai.mjs +22 -133
  109. package/dist/{engine-CIOyFozK.d.ts → engine-rC0vjjY-.d.ts} +165 -141
  110. package/dist/{memory-yFaVn2xZ.d.ts → events-DqOIg5xa.d.ts} +645 -136
  111. package/dist/{types-DAK7mnUZ.d.ts → index-Bkdt8nDw.d.ts} +182 -45
  112. package/dist/index.browser.mjs +4 -32180
  113. package/dist/index.d.ts +91 -20
  114. package/dist/index.mjs +33 -16
  115. package/dist/invalidation/broadcast-channel.d.ts +1 -1
  116. package/dist/invalidation/filesystem.d.ts +1 -1
  117. package/dist/invalidation/filesystem.mjs +2 -1
  118. package/dist/invalidation/noop.d.ts +1 -1
  119. package/dist/module-3S65MVCM.mjs +2151 -0
  120. package/dist/partial-words-DTIHO8G4.d.ts +19 -0
  121. package/dist/partial-words.d.ts +22 -0
  122. package/dist/partial-words.mjs +17 -0
  123. package/dist/pattern-Cledccbl.d.ts +18 -0
  124. package/dist/pattern.d.ts +22 -0
  125. package/dist/pattern.mjs +12 -0
  126. package/dist/persistence/durability/checkpoint-worker.d.ts +119 -72
  127. package/dist/persistence/durability/checkpoint-worker.mjs +51 -18
  128. package/dist/react.d.ts +279 -183
  129. package/dist/react.mjs +201 -48
  130. package/dist/release-BH3DKW3T.mjs +33 -0
  131. package/dist/replace-CEO5KJJ3.mjs +57 -0
  132. package/dist/rerank-K7C4WZFG.mjs +60 -0
  133. package/dist/rerankers/http.d.ts +50 -0
  134. package/dist/rerankers/http.mjs +104 -0
  135. package/dist/restore-queue-KQHA7ZV2.mjs +35 -0
  136. package/dist/runtime-6Y4ZYXOG.mjs +177 -0
  137. package/dist/{schema-d5Afu03A.d.ts → schema-4W_7tk1f.d.ts} +81 -11
  138. package/dist/server.d.ts +13 -12
  139. package/dist/server.mjs +611 -80
  140. package/dist/snapshot-QGZPODM5.mjs +799 -0
  141. package/dist/synonyms-CpOAHPa-.d.ts +52 -0
  142. package/dist/synonyms.d.ts +22 -0
  143. package/dist/synonyms.mjs +12 -0
  144. package/dist/{tasks-CH2Dod8w.d.ts → tasks-CwPTz-tP.d.ts} +10 -3
  145. package/dist/thread-N3IUGUS3.mjs +697 -0
  146. package/dist/{types-BQDlIvfS.d.ts → types-2qoitTXg.d.ts} +1 -1
  147. package/dist/{types-D5OwhtsQ.d.ts → types-Cz5okLml.d.ts} +2 -2
  148. package/dist/vector/search-worker.d.ts +46 -4
  149. package/dist/vector/search-worker.mjs +21 -11
  150. package/dist/workers/entry.mjs +9 -6
  151. package/dist/write-U5RI7MAX.mjs +241 -0
  152. package/package.json +55 -9
  153. package/dist/chunk-3L4U6EJQ.mjs +0 -49
  154. package/dist/chunk-IFBKLBGB.mjs +0 -7
  155. package/dist/chunk-ORBLD3EL.mjs +0 -6
  156. package/dist/chunk-U7KYW4BA.mjs +0 -135
  157. package/dist/chunk-ZJ4CSAB2.mjs +0 -13
  158. package/dist/chunk-ZNZBXMP5.mjs +0 -2117
  159. package/dist/chunk-ZZT3EAUC.mjs +0 -11168
  160. package/dist/config-BhldZgaK.d.ts +0 -194
  161. package/dist/direct-executor-ALAVE7FC.mjs +0 -12
  162. package/dist/serialization/crc32-worker.d.ts +0 -20
  163. package/dist/serialization/crc32-worker.mjs +0 -62
  164. package/dist/simd-DW5AtJ6B.d.ts +0 -41
  165. package/dist/thread-DYHEQRVY.mjs +0 -402
@@ -1,6 +1,7 @@
1
- import { C as ClusterCoordinator } from '../../types-DAK7mnUZ.js';
2
- import '../../schema-d5Afu03A.js';
3
- import '../../adapters-79OIa4xm.js';
1
+ import { C as ClusterCoordinator } from '../../index-Bkdt8nDw.js';
2
+ import '../../schema-4W_7tk1f.js';
3
+ import '../../adapters-BQFQ4PRz.js';
4
+ import '../../synonyms-CpOAHPa-.js';
4
5
 
5
6
  /**
6
7
  * Builds a coordinator that holds the cluster's shared state in one process's
@@ -1,5 +1,6 @@
1
- import { NODE_HEARTBEAT_TTL_MS } from '../../chunk-ORBLD3EL.mjs';
2
- import { compareCodePoints } from '../../chunk-YMZCMH5M.mjs';
1
+ import { CONTROLLER_LEASE_KEY, NODE_HEARTBEAT_TTL_MS } from '../../chunk-44W3CBNG.mjs';
2
+ import '../../chunk-R6A773WK.mjs';
3
+ import { compareCodePoints } from '../../chunk-YTJCGKM4.mjs';
3
4
 
4
5
  // src/distribution/coordinator/in-memory.ts
5
6
  var NODE_HEARTBEAT_PREFIX = "_narsil/node/";
@@ -19,6 +20,7 @@ function createInMemoryCoordinator() {
19
20
  const allocations = /* @__PURE__ */ new Map();
20
21
  const partitionStates = /* @__PURE__ */ new Map();
21
22
  const leases = /* @__PURE__ */ new Map();
23
+ const registrationsHeldUntil = /* @__PURE__ */ new Map();
22
24
  const schemas = /* @__PURE__ */ new Map();
23
25
  const kvStore = /* @__PURE__ */ new Map();
24
26
  const nodeWatchers = /* @__PURE__ */ new Set();
@@ -67,6 +69,7 @@ function createInMemoryCoordinator() {
67
69
  if (key.startsWith(NODE_HEARTBEAT_PREFIX)) {
68
70
  const expiredNodeId = key.slice(NODE_HEARTBEAT_PREFIX.length);
69
71
  nodes.delete(expiredNodeId);
72
+ registrationsHeldUntil.delete(expiredNodeId);
70
73
  emitNodeEvent({ type: "node_left", nodeId: expiredNodeId, registration: null });
71
74
  }
72
75
  }, ttlMs);
@@ -81,8 +84,10 @@ function createInMemoryCoordinator() {
81
84
  const coordinator = {
82
85
  async registerNode(registration) {
83
86
  assertNotShutdown();
87
+ const renewedAt = performance.now();
84
88
  const previous = nodes.get(registration.nodeId);
85
89
  nodes.set(registration.nodeId, registration);
90
+ registrationsHeldUntil.set(registration.nodeId, renewedAt + NODE_HEARTBEAT_TTL_MS);
86
91
  const heartbeatKey = `${NODE_HEARTBEAT_PREFIX}${registration.nodeId}`;
87
92
  clearLeaseEntry(heartbeatKey);
88
93
  const timer = createLeaseTimer(heartbeatKey, NODE_HEARTBEAT_TTL_MS);
@@ -99,12 +104,18 @@ function createInMemoryCoordinator() {
99
104
  async deregisterNode(nodeId) {
100
105
  assertNotShutdown();
101
106
  const existed = nodes.delete(nodeId);
107
+ registrationsHeldUntil.delete(nodeId);
102
108
  const heartbeatKey = `${NODE_HEARTBEAT_PREFIX}${nodeId}`;
103
109
  clearLeaseEntry(heartbeatKey);
104
110
  if (existed) {
105
111
  emitNodeEvent({ type: "node_left", nodeId, registration: null });
106
112
  }
107
113
  },
114
+ registrationLease(nodeId) {
115
+ const heldUntil = registrationsHeldUntil.get(nodeId);
116
+ if (isShutdown || heldUntil === void 0) return null;
117
+ return { remainingMs: heldUntil - performance.now(), ttlMs: NODE_HEARTBEAT_TTL_MS };
118
+ },
108
119
  async listNodes() {
109
120
  assertNotShutdown();
110
121
  return Array.from(nodes.values());
@@ -120,9 +131,12 @@ function createInMemoryCoordinator() {
120
131
  assertNotShutdown();
121
132
  return allocations.get(indexName) ?? null;
122
133
  },
123
- async putAllocation(indexName, table, expectedVersion) {
134
+ async putAllocation(indexName, table, expectedVersion, writerNodeId) {
124
135
  assertNotShutdown();
125
136
  if (expectedVersion !== void 0) {
137
+ if (!isLeaseValid(CONTROLLER_LEASE_KEY) || leases.get(CONTROLLER_LEASE_KEY)?.nodeId !== writerNodeId) {
138
+ return false;
139
+ }
126
140
  const current = allocations.get(indexName);
127
141
  if (expectedVersion === null) {
128
142
  if (current !== void 0) {
@@ -229,6 +243,10 @@ function createInMemoryCoordinator() {
229
243
  kvStore.set(key, new Uint8Array(value));
230
244
  return true;
231
245
  },
246
+ async delete(key) {
247
+ assertNotShutdown();
248
+ kvStore.delete(key);
249
+ },
232
250
  async getSchema(indexName) {
233
251
  assertNotShutdown();
234
252
  return schemas.get(indexName) ?? null;
@@ -274,6 +292,7 @@ function createInMemoryCoordinator() {
274
292
  clearTimeout(entry.timer);
275
293
  }
276
294
  leases.clear();
295
+ registrationsHeldUntil.clear();
277
296
  nodes.clear();
278
297
  allocations.clear();
279
298
  partitionStates.clear();
@@ -1,5 +1,5 @@
1
- import { T as TransportConfig, N as NodeTransport } from '../../types-D5OwhtsQ.js';
2
- import { a as TlsConfig } from '../../types-BQDlIvfS.js';
1
+ import { T as TransportConfig, N as NodeTransport } from '../../types-Cz5okLml.js';
2
+ import { a as TlsConfig } from '../../types-2qoitTXg.js';
3
3
 
4
4
  /**
5
5
  * How the gRPC transport listens and dials.
@@ -1,7 +1,8 @@
1
- import { decodeTransportMessage, encodeTransportMessage } from '../../chunk-OOSIDHA3.mjs';
1
+ import { decodeTransportMessage, encodeTransportMessage } from '../../chunk-ZKWYWW4Y.mjs';
2
+ import { replyDeadlineMs } from '../../chunk-747OHOUA.mjs';
2
3
  import { MAX_MESSAGE_SIZE_BYTES, GRPC_KEEPALIVE_TIMEOUT_MS, GRPC_KEEPALIVE_TIME_MS, GRPC_ENVELOPE_OVERHEAD_BYTES } from '../../chunk-UNEEFTEU.mjs';
3
- import { TransportError, TransportErrorCodes } from '../../chunk-GCM3JFVA.mjs';
4
- import { NarsilError, ErrorCodes } from '../../chunk-USKFU7J5.mjs';
4
+ import { TransportError, TransportErrorCodes } from '../../chunk-PNEYIHA4.mjs';
5
+ import { NarsilError, ErrorCodes } from '../../chunk-BWJVNZPR.mjs';
5
6
 
6
7
  // src/distribution/transport/grpc/codec.ts
7
8
  var FIELD_ONE_LENGTH_DELIMITED_KEY = 10;
@@ -138,6 +139,8 @@ function toCredentialBuffer(material) {
138
139
  }
139
140
 
140
141
  // src/distribution/transport/grpc/client.ts
142
+ var CONNECT_PROBE_PATH = "/narsil.transport.v1.ConnectProbe/LastError";
143
+ var LAST_ERROR_PATTERN = /Last error: (?:Error: )?(.*?)\. Resolution note:/s;
141
144
  var GrpcClientPool = class {
142
145
  grpc;
143
146
  config;
@@ -150,7 +153,13 @@ var GrpcClientPool = class {
150
153
  async send(target, message) {
151
154
  const messageBytes = this.encodeChecked(target, message);
152
155
  const client = await this.getClient(target);
153
- const responseBytes = await this.unaryCall(client, target, message.requestId, messageBytes);
156
+ const responseBytes = await this.unaryCall(
157
+ client,
158
+ target,
159
+ message.requestId,
160
+ messageBytes,
161
+ replyDeadlineMs(message.type, this.config)
162
+ );
154
163
  try {
155
164
  return decodeTransportMessage(responseBytes);
156
165
  } catch (err) {
@@ -170,17 +179,37 @@ var GrpcClientPool = class {
170
179
  openStreamMethod.responseDeserialize,
171
180
  messageBytes,
172
181
  this.metadata(),
173
- this.callOptions(this.config.snapshotTimeout)
182
+ {}
174
183
  );
175
184
  return new Promise((resolve, reject) => {
176
185
  let settled = false;
186
+ const timeoutMs = this.config.snapshotTimeout;
187
+ let idleTimer = null;
177
188
  const settle = (fn) => {
189
+ if (idleTimer !== null) clearTimeout(idleTimer);
178
190
  if (!settled) {
179
191
  settled = true;
180
192
  fn();
181
193
  }
182
194
  };
195
+ const rearm = () => {
196
+ if (idleTimer !== null) clearTimeout(idleTimer);
197
+ idleTimer = setTimeout(() => {
198
+ call.cancel();
199
+ settle(
200
+ () => reject(
201
+ new TransportError(
202
+ TransportErrorCodes.TIMEOUT,
203
+ `No chunk of the stream from '${target}' arrived within ${timeoutMs}ms`,
204
+ { target, requestId: message.requestId, timeoutMs }
205
+ )
206
+ )
207
+ );
208
+ }, timeoutMs);
209
+ };
210
+ rearm();
183
211
  call.on("data", (chunk) => {
212
+ rearm();
184
213
  try {
185
214
  handler(chunk);
186
215
  } catch (err) {
@@ -256,19 +285,55 @@ var GrpcClientPool = class {
256
285
  }
257
286
  connect(target) {
258
287
  const client = new this.grpc.Client(target, this.credentials(), channelOptions());
288
+ const channel = client.getChannel();
289
+ const { READY, SHUTDOWN, TRANSIENT_FAILURE } = this.grpc.connectivityState;
290
+ const deadline = Date.now() + this.config.connectTimeout;
259
291
  return new Promise((resolve, reject) => {
260
- client.waitForReady(Date.now() + this.config.connectTimeout, (err) => {
261
- if (err === void 0) {
262
- resolve(client);
263
- return;
264
- }
292
+ const fail = (reason) => {
265
293
  client.close();
266
294
  reject(
267
- new TransportError(TransportErrorCodes.CONNECT_FAILED, `Failed to connect to '${target}': ${err.message}`, {
295
+ new TransportError(TransportErrorCodes.CONNECT_FAILED, `Failed to connect to '${target}': ${reason}`, {
268
296
  target
269
297
  })
270
298
  );
271
- });
299
+ };
300
+ const check = (deadlinePassed) => {
301
+ if (deadlinePassed !== void 0) {
302
+ fail(`no connection was ready within ${this.config.connectTimeout}ms`);
303
+ return;
304
+ }
305
+ try {
306
+ const state = channel.getConnectivityState(true);
307
+ if (state === READY) {
308
+ resolve(client);
309
+ } else if (state === TRANSIENT_FAILURE) {
310
+ void this.lastConnectError(client, deadline).then(fail);
311
+ } else if (state === SHUTDOWN) {
312
+ fail("the channel shut down");
313
+ } else {
314
+ channel.watchConnectivityState(state, deadline, check);
315
+ }
316
+ } catch {
317
+ fail("the channel closed");
318
+ }
319
+ };
320
+ check();
321
+ });
322
+ }
323
+ lastConnectError(client, deadline) {
324
+ return new Promise((resolve) => {
325
+ client.makeUnaryRequest(
326
+ CONNECT_PROBE_PATH,
327
+ sendMethod.requestSerialize,
328
+ sendMethod.responseDeserialize,
329
+ new Uint8Array(0),
330
+ this.metadata(),
331
+ { deadline },
332
+ (err) => {
333
+ const details = err?.details ?? "";
334
+ resolve(LAST_ERROR_PATTERN.exec(details)?.[1] ?? (details === "" ? "the channel failed to connect" : details));
335
+ }
336
+ );
272
337
  });
273
338
  }
274
339
  credentials() {
@@ -291,7 +356,7 @@ var GrpcClientPool = class {
291
356
  callOptions(timeoutMs) {
292
357
  return { deadline: Date.now() + timeoutMs };
293
358
  }
294
- unaryCall(client, target, requestId, messageBytes) {
359
+ unaryCall(client, target, requestId, messageBytes, timeoutMs) {
295
360
  return new Promise((resolve, reject) => {
296
361
  client.makeUnaryRequest(
297
362
  sendMethod.path,
@@ -299,7 +364,7 @@ var GrpcClientPool = class {
299
364
  sendMethod.responseDeserialize,
300
365
  messageBytes,
301
366
  this.metadata(),
302
- this.callOptions(this.config.requestTimeout),
367
+ this.callOptions(timeoutMs),
303
368
  (err, response) => {
304
369
  if (err !== null) {
305
370
  reject(this.mapCallError(target, requestId, err));
@@ -1,5 +1,5 @@
1
- import { N as NodeTransport, a as TransportMessage, R as RespondFn, T as TransportConfig } from '../../types-D5OwhtsQ.js';
2
- export { L as ListenHandler } from '../../types-D5OwhtsQ.js';
1
+ import { N as NodeTransport, a as TransportMessage, R as RespondFn, T as TransportConfig } from '../../types-Cz5okLml.js';
2
+ export { L as ListenHandler } from '../../types-Cz5okLml.js';
3
3
 
4
4
  /**
5
5
  * Receives a streamed response one chunk at a time.
@@ -1,5 +1,6 @@
1
+ import { replyDeadlineMs } from '../../chunk-747OHOUA.mjs';
1
2
  import { MAX_MESSAGE_SIZE_BYTES } from '../../chunk-UNEEFTEU.mjs';
2
- import { DEFAULT_TRANSPORT_CONFIG, TransportError, TransportErrorCodes } from '../../chunk-GCM3JFVA.mjs';
3
+ import { DEFAULT_TRANSPORT_CONFIG, TransportError, TransportErrorCodes } from '../../chunk-PNEYIHA4.mjs';
3
4
 
4
5
  // src/distribution/transport/in-memory.ts
5
6
  function createInMemoryNetwork() {
@@ -97,6 +98,7 @@ function createInMemoryTransport(nodeId, network, config) {
97
98
  );
98
99
  }
99
100
  const peer = lookupPeer(target);
101
+ const timeoutMs = replyDeadlineMs(message.type, resolvedConfig);
100
102
  return new Promise((resolve, reject) => {
101
103
  let settled = false;
102
104
  const timeoutId = setTimeout(() => {
@@ -105,12 +107,12 @@ function createInMemoryTransport(nodeId, network, config) {
105
107
  reject(
106
108
  new TransportError(
107
109
  TransportErrorCodes.TIMEOUT,
108
- `Request to node '${target}' timed out after ${resolvedConfig.requestTimeout}ms`,
109
- { target, requestId: message.requestId, timeoutMs: resolvedConfig.requestTimeout }
110
+ `Request to node '${target}' timed out after ${timeoutMs}ms`,
111
+ { target, requestId: message.requestId, timeoutMs }
110
112
  )
111
113
  );
112
114
  }
113
- }, resolvedConfig.requestTimeout);
115
+ }, timeoutMs);
114
116
  try {
115
117
  peer.deliverMessage(message, async (response) => {
116
118
  if (!settled) {
@@ -133,18 +135,19 @@ function createInMemoryTransport(nodeId, network, config) {
133
135
  const peer = lookupPeer(target);
134
136
  return new Promise((resolve, reject) => {
135
137
  let settled = false;
136
- const timeoutId = setTimeout(() => {
138
+ const expire = () => {
137
139
  if (!settled) {
138
140
  settled = true;
139
141
  reject(
140
142
  new TransportError(
141
143
  TransportErrorCodes.TIMEOUT,
142
- `Stream to node '${target}' timed out after ${resolvedConfig.snapshotTimeout}ms`,
144
+ `No chunk of the stream from node '${target}' arrived within ${resolvedConfig.snapshotTimeout}ms`,
143
145
  { target, requestId: message.requestId, timeoutMs: resolvedConfig.snapshotTimeout }
144
146
  )
145
147
  );
146
148
  }
147
- }, resolvedConfig.snapshotTimeout);
149
+ };
150
+ let timeoutId = setTimeout(expire, resolvedConfig.snapshotTimeout);
148
151
  const settle = (action) => {
149
152
  if (settled) {
150
153
  return;
@@ -158,6 +161,8 @@ function createInMemoryTransport(nodeId, network, config) {
158
161
  if (settled) {
159
162
  return Promise.resolve();
160
163
  }
164
+ clearTimeout(timeoutId);
165
+ timeoutId = setTimeout(expire, resolvedConfig.snapshotTimeout);
161
166
  try {
162
167
  handler(payload);
163
168
  } catch (error) {
@@ -1,5 +1,5 @@
1
- import { N as NodeTransport } from '../../types-D5OwhtsQ.js';
2
- import { T as TcpTransportConfig, a as TlsConfig } from '../../types-BQDlIvfS.js';
1
+ import { N as NodeTransport } from '../../types-Cz5okLml.js';
2
+ import { T as TcpTransportConfig, a as TlsConfig } from '../../types-2qoitTXg.js';
3
3
 
4
4
  /**
5
5
  * Builds the TCP transport a cluster node reaches its peers through, with
@@ -1,6 +1,7 @@
1
- import { DEFAULT_TCP_CONFIG, encodeTransportMessage, encodeFrame, FRAME_TYPE_REQUEST, FrameParser, FRAME_TYPE_RESPONSE, decodeTransportMessage, FRAME_TYPE_STREAM_CHUNK, FRAME_TYPE_STREAM_END } from '../../chunk-OOSIDHA3.mjs';
1
+ import { DEFAULT_TCP_CONFIG, encodeTransportMessage, encodeFrame, FRAME_TYPE_REQUEST, FrameParser, FRAME_TYPE_RESPONSE, decodeTransportMessage, FRAME_TYPE_STREAM_CHUNK, FRAME_TYPE_STREAM_END } from '../../chunk-ZKWYWW4Y.mjs';
2
+ import { replyDeadlineMs } from '../../chunk-747OHOUA.mjs';
2
3
  import { MAX_MESSAGE_SIZE_BYTES } from '../../chunk-UNEEFTEU.mjs';
3
- import { TransportError, TransportErrorCodes } from '../../chunk-GCM3JFVA.mjs';
4
+ import { TransportError, TransportErrorCodes } from '../../chunk-PNEYIHA4.mjs';
4
5
  import { connect as connect$1, createServer as createServer$1 } from 'net';
5
6
  import { connect, createServer } from 'tls';
6
7
 
@@ -24,6 +25,33 @@ function parseAddress(address) {
24
25
  return [host, port];
25
26
  }
26
27
 
28
+ // src/distribution/transport/tcp/pending-stream.ts
29
+ function createPendingStream(input) {
30
+ const { target, requestId, timeoutMs, reject } = input;
31
+ const expire = () => {
32
+ input.forget();
33
+ reject(
34
+ new TransportError(
35
+ TransportErrorCodes.TIMEOUT,
36
+ `No chunk of the stream from '${target}' arrived within ${timeoutMs}ms`,
37
+ { target, requestId, timeoutMs }
38
+ )
39
+ );
40
+ };
41
+ const pending = {
42
+ target,
43
+ handler: input.handler,
44
+ resolve: input.resolve,
45
+ reject,
46
+ timer: setTimeout(expire, timeoutMs),
47
+ rearm: () => {
48
+ clearTimeout(pending.timer);
49
+ pending.timer = setTimeout(expire, timeoutMs);
50
+ }
51
+ };
52
+ return pending;
53
+ }
54
+
27
55
  // src/distribution/transport/tcp/connection.ts
28
56
  var TcpConnectionPool = class {
29
57
  connections = /* @__PURE__ */ new Map();
@@ -56,21 +84,18 @@ var TcpConnectionPool = class {
56
84
  const socket = await this.getOrCreateConnection(target);
57
85
  const frame = encodeFrame(FRAME_TYPE_REQUEST, message.requestId, messageBytes);
58
86
  const pendingKey = `${target}:${message.requestId}`;
87
+ const timeoutMs = replyDeadlineMs(message.type, this.config);
59
88
  return new Promise((resolve, reject) => {
60
89
  const timer = setTimeout(() => {
61
90
  this.pendingRequests.delete(pendingKey);
62
91
  reject(
63
- new TransportError(
64
- TransportErrorCodes.TIMEOUT,
65
- `Request to '${target}' timed out after ${this.config.requestTimeout}ms`,
66
- {
67
- target,
68
- requestId: message.requestId,
69
- timeoutMs: this.config.requestTimeout
70
- }
71
- )
92
+ new TransportError(TransportErrorCodes.TIMEOUT, `Request to '${target}' timed out after ${timeoutMs}ms`, {
93
+ target,
94
+ requestId: message.requestId,
95
+ timeoutMs
96
+ })
72
97
  );
73
- }, this.config.requestTimeout);
98
+ }, timeoutMs);
74
99
  this.pendingRequests.set(pendingKey, { target, resolve, reject, timer });
75
100
  socket.write(frame, (err) => {
76
101
  if (err) {
@@ -95,24 +120,19 @@ var TcpConnectionPool = class {
95
120
  const frame = encodeFrame(FRAME_TYPE_REQUEST, message.requestId, messageBytes);
96
121
  const pendingKey = `${target}:${message.requestId}`;
97
122
  return new Promise((resolve, reject) => {
98
- const timer = setTimeout(() => {
99
- this.pendingStreams.delete(pendingKey);
100
- reject(
101
- new TransportError(
102
- TransportErrorCodes.TIMEOUT,
103
- `Stream to '${target}' timed out after ${this.config.snapshotTimeout}ms`,
104
- {
105
- target,
106
- requestId: message.requestId,
107
- timeoutMs: this.config.snapshotTimeout
108
- }
109
- )
110
- );
111
- }, this.config.snapshotTimeout);
112
- this.pendingStreams.set(pendingKey, { target, handler, resolve, reject, timer });
123
+ const pending = createPendingStream({
124
+ target,
125
+ requestId: message.requestId,
126
+ timeoutMs: this.config.snapshotTimeout,
127
+ handler,
128
+ resolve,
129
+ reject,
130
+ forget: () => this.pendingStreams.delete(pendingKey)
131
+ });
132
+ this.pendingStreams.set(pendingKey, pending);
113
133
  socket.write(frame, (err) => {
114
134
  if (err) {
115
- clearTimeout(timer);
135
+ clearTimeout(pending.timer);
116
136
  this.pendingStreams.delete(pendingKey);
117
137
  reject(
118
138
  new TransportError(
@@ -239,6 +259,7 @@ var TcpConnectionPool = class {
239
259
  }
240
260
  const pendingStream = this.pendingStreams.get(pendingKey);
241
261
  if (pendingStream !== void 0) {
262
+ pendingStream.rearm();
242
263
  try {
243
264
  const message = decodeTransportMessage(frame.data);
244
265
  pendingStream.handler(message.payload);
@@ -259,6 +280,7 @@ var TcpConnectionPool = class {
259
280
  if (frame.frameType === FRAME_TYPE_STREAM_CHUNK) {
260
281
  const pending = this.pendingStreams.get(pendingKey);
261
282
  if (pending !== void 0) {
283
+ pending.rearm();
262
284
  pending.handler(frame.data);
263
285
  }
264
286
  return;