@kitman-sh/cli 0.9.0 → 0.10.53

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 (37) hide show
  1. package/dist/chunk-11p4wf6n.js +3551 -0
  2. package/dist/chunk-1mc9vgcr.js +39 -0
  3. package/dist/chunk-30397r95.js +30 -0
  4. package/dist/chunk-3bj7sc3v.js +389 -0
  5. package/dist/chunk-6vns3ej0.js +23 -0
  6. package/dist/chunk-7thnf14y.js +936 -0
  7. package/dist/chunk-arvwar2c.js +141 -0
  8. package/dist/chunk-b6thzgc9.js +32 -0
  9. package/dist/{chunk-8bvf4fh4.js → chunk-ctasxxz5.js} +26 -11
  10. package/dist/{chunk-5gjpv3ax.js → chunk-dzh9e6n2.js} +824 -651
  11. package/dist/{chunk-snn0e1qb.js → chunk-eg8f5ncv.js} +7 -3
  12. package/dist/chunk-g5bs3f6z.js +173 -0
  13. package/dist/chunk-jafetf7z.js +109 -0
  14. package/dist/chunk-jagzz148.js +527 -0
  15. package/dist/{chunk-1d4316hp.js → chunk-jfvq7s24.js} +38 -25
  16. package/dist/chunk-mbctzx7e.js +11436 -0
  17. package/dist/chunk-mej2bx5n.js +100 -0
  18. package/dist/chunk-p6spvbwq.js +6305 -0
  19. package/dist/chunk-pp1p3g6e.js +133 -0
  20. package/dist/chunk-r8p3nxcp.js +231 -0
  21. package/dist/chunk-txwt6r25.js +1731 -0
  22. package/dist/chunk-v290mf51.js +5242 -0
  23. package/dist/chunk-vjmz23rs.js +13 -0
  24. package/dist/chunk-vyv0p5eq.js +3183 -0
  25. package/dist/chunk-wh1pa2aa.js +15322 -0
  26. package/dist/chunk-x0b92bjb.js +222 -0
  27. package/dist/{chunk-8z5b6fpd.js → chunk-x9dhxfts.js} +216 -152
  28. package/dist/chunk-z821b2gp.js +164 -0
  29. package/dist/index.js +13 -5738
  30. package/dist/opencode-reader.main.ts +4 -0
  31. package/package.json +6 -5
  32. package/dist/chunk-3gxahgnq.js +0 -28495
  33. package/dist/chunk-ehzbtavj.js +0 -247
  34. package/dist/chunk-f5z8tgss.js +0 -1214
  35. package/dist/chunk-kdb1cbnx.js +0 -1273
  36. package/dist/chunk-ke1w0hx7.js +0 -5771
  37. package/dist/chunk-z6hc4ew9.js +0 -13
@@ -6,48 +6,53 @@ import {
6
6
  assignProperty,
7
7
  isNone,
8
8
  isSome,
9
- map,
10
- Service,
11
- empty,
9
+ map4,
10
+ Service2,
11
+ empty3,
12
12
  add,
13
13
  getOrUndefinedUnsafe,
14
14
  getUnsafe,
15
- get,
15
+ get4,
16
16
  Reference,
17
- isSuccess,
18
17
  toMillis,
19
- squash,
20
- findError,
21
- hasInterrupts,
22
- interruptors,
23
- failCause,
24
- fail2,
25
- die2,
26
- interrupt,
18
+ isSuccess,
19
+ failCause2,
20
+ fail4,
21
+ die,
22
+ interrupt2,
23
+ void_2,
27
24
  isFailure2,
25
+ makeUnsafe5,
26
+ _await,
27
+ isDoneUnsafe,
28
+ succeed4,
28
29
  Scope,
29
30
  addFinalizerExit,
30
31
  addFinalizer,
31
- succeed4,
32
+ succeed5,
32
33
  effect,
33
- Clock,
34
- min,
34
+ hasInterruptsOnly,
35
+ squash,
36
+ findError,
37
+ hasInterrupts2,
38
+ interruptors,
39
+ min2,
35
40
  exponential,
36
41
  spaced,
37
42
  forEach,
38
43
  whileLoop,
39
- suspend,
40
- sync,
41
- void_2,
42
- callback,
44
+ suspend3,
45
+ sync2,
46
+ void_3,
47
+ callback3,
43
48
  never,
44
49
  gen,
45
- fail4,
46
- withFiber,
47
- flatMap2,
48
- andThen,
49
- map3,
50
- catchCause,
50
+ fail7,
51
+ withFiber2,
52
+ flatMap3,
53
+ andThen2,
54
+ map8,
55
+ catchCause2,
51
56
  catchCauseIf,
52
57
  orDie,
53
58
  tapCause,
@@ -60,17 +65,19 @@ import {
60
65
  matchCauseEffect,
61
66
  context,
62
67
  contextWith,
63
- provideContext,
68
+ provideContext2,
64
69
  serviceOption,
65
70
  updateService,
66
71
  scoped,
67
- ensuring,
72
+ addFinalizer2,
73
+ ensuring2,
68
74
  onError,
69
75
  onExit,
70
- interrupt2,
76
+ interrupt3,
71
77
  interruptible,
72
78
  onInterrupt,
73
- uninterruptibleMask,
79
+ uninterruptible,
80
+ uninterruptibleMask2,
74
81
  forever,
75
82
  makeSpanScoped,
76
83
  useSpan,
@@ -81,37 +88,45 @@ import {
81
88
  fnUntraced,
82
89
  logError,
83
90
  annotateLogs,
84
- interrupt3,
91
+ decodeUnknownEffect2,
92
+ decodeSync,
93
+ encodeEffect,
94
+ Void,
95
+ NonEmptyArray,
96
+ Defect,
97
+ Exit,
98
+ toCodecJson
99
+ } from "./chunk-mbctzx7e.js";
100
+ import {
101
+ interrupt,
85
102
  getCurrent,
86
- makeUnsafe3,
103
+ makeUnsafe2,
87
104
  bounded,
88
105
  offerAll,
89
- failCause3,
106
+ failCause,
90
107
  end,
91
108
  shutdownUnsafe,
92
109
  fromQueue,
93
- unwrap,
94
- empty2,
110
+ unwrap
111
+ } from "./chunk-11p4wf6n.js";
112
+ import {
113
+ Clock,
114
+ empty,
95
115
  fromInput,
96
- merge2,
97
- decodeUnknownEffect,
98
- decodeSync,
99
- encodeEffect,
100
- NonEmptyArray,
101
- Defect,
102
- toCodecJson,
116
+ merge,
103
117
  Socket,
104
118
  SocketReadError,
105
119
  SocketError,
106
120
  isStreamSchema,
107
121
  getStreamSchemas,
108
122
  exitSchema,
123
+ ParseOptions,
109
124
  RpcClientDefect,
110
125
  RpcClientError
111
- } from "./chunk-3gxahgnq.js";
126
+ } from "./chunk-wh1pa2aa.js";
112
127
 
113
- // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/workers/Transferable.js
114
- class Collector extends (/* @__PURE__ */ Service()("effect/workers/Transferable/Collector")) {
128
+ // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/workers/Transferable.js
129
+ class Collector extends (/* @__PURE__ */ Service2()("effect/workers/Transferable/Collector")) {
115
130
  }
116
131
  var makeCollectorUnsafe = () => {
117
132
  let tranferables = [];
@@ -126,15 +141,15 @@ var makeCollectorUnsafe = () => {
126
141
  };
127
142
  return Collector.of({
128
143
  addAllUnsafe: unsafeAddAll,
129
- addAll: (transferables) => sync(() => unsafeAddAll(transferables)),
144
+ addAll: (transferables) => sync2(() => unsafeAddAll(transferables)),
130
145
  readUnsafe: unsafeRead,
131
- read: sync(unsafeRead),
146
+ read: sync2(unsafeRead),
132
147
  clearUnsafe: unsafeClear,
133
- clear: sync(unsafeClear)
148
+ clear: sync2(unsafeClear)
134
149
  });
135
150
  };
136
151
 
137
- // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/internal/tracing.js
152
+ // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/rpc/internal/tracing.js
138
153
  var spanName = (spanPrefix, tag) => spanPrefix === undefined ? tag : `${spanPrefix}.${tag}`;
139
154
  var spanAttributes = (tag, attributes) => ({
140
155
  "rpc.system.name": "effect_rpc",
@@ -142,18 +157,18 @@ var spanAttributes = (tag, attributes) => ({
142
157
  ...attributes
143
158
  });
144
159
 
145
- // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcMessage.js
160
+ // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/rpc/RpcMessage.js
146
161
  var RequestId = (id) => id;
147
162
  var constPing = {
148
163
  _tag: "Ping"
149
164
  };
150
165
 
151
- // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcSerialization.js
166
+ // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/rpc/RpcSerialization.js
152
167
  var codecForJson = toCodecJson;
153
168
  var sharedTextDecoder;
154
169
  var decodeText = (bytes) => (sharedTextDecoder ??= new TextDecoder).decode(bytes);
155
170
 
156
- class RpcSerialization extends (/* @__PURE__ */ Service()("effect/rpc/RpcSerialization")) {
171
+ class RpcSerialization extends (/* @__PURE__ */ Service2()("effect/rpc/RpcSerialization")) {
157
172
  }
158
173
  var defaultMaxBufferSize = 16 * 1024 * 1024;
159
174
  var json = /* @__PURE__ */ RpcSerialization.of({
@@ -169,10 +184,10 @@ var json = /* @__PURE__ */ RpcSerialization.of({
169
184
  })
170
185
  });
171
186
  var defaultSchemaBinaryMaxFrameSize = 16 * 1024 * 1024;
172
- var layerJson = /* @__PURE__ */ succeed4(RpcSerialization)(json);
187
+ var layerJson = /* @__PURE__ */ succeed5(RpcSerialization)(json);
173
188
 
174
- // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/Utils.js
175
- var withRunClient = (f) => suspend(() => {
189
+ // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/rpc/Utils.js
190
+ var withRunClient = (f) => suspend3(() => {
176
191
  const clientIds = new Set;
177
192
  const clientBuffers = new Map;
178
193
  const clientWrites = new Map;
@@ -183,9 +198,9 @@ var withRunClient = (f) => suspend(() => {
183
198
  clientBuffers.set(clientId, buffer);
184
199
  }
185
200
  buffer.push([data, context]);
186
- return void_2;
201
+ return void_3;
187
202
  });
188
- return map3(f((clientId, data) => {
203
+ return map8(f((clientId, data) => {
189
204
  const clientWrite = clientWrites.get(clientId);
190
205
  if (clientWrite) {
191
206
  return clientWrite(data);
@@ -201,20 +216,20 @@ var withRunClient = (f) => suspend(() => {
201
216
  if (buffer) {
202
217
  clientBuffers.delete(clientId);
203
218
  for (const [args, context] of buffer) {
204
- yield* provideContext(suspend(() => f(args)), context);
219
+ yield* provideContext2(suspend3(() => f(args)), context);
205
220
  }
206
221
  }
207
222
  return yield* onExit(never, () => {
208
223
  clientIds.delete(clientId);
209
224
  clientWrites.delete(clientId);
210
- return void_2;
225
+ return void_3;
211
226
  });
212
227
  });
213
228
  }
214
229
  }));
215
230
  });
216
231
 
217
- // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcClient.js
232
+ // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/rpc/RpcClient.js
218
233
  var requestIdCounter = 0;
219
234
  var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options) {
220
235
  const spanPrefix = options.spanPrefix;
@@ -222,29 +237,30 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
222
237
  const disableTracing = options?.disableTracing ?? false;
223
238
  const generateRequestId = options?.generateRequestId ?? (() => requestIdCounter++);
224
239
  const services = yield* context();
225
- const scope = get(services, Scope);
240
+ const scope = get4(services, Scope);
226
241
  const entries = new Map;
227
242
  let isShutdown = false;
228
- yield* addFinalizer(scope, withFiber((parent) => {
243
+ yield* addFinalizer(scope, withFiber2((parent) => {
229
244
  isShutdown = true;
230
- return clearEntries(interrupt(parent.id));
245
+ return clearEntries(interrupt2(parent.id));
231
246
  }));
232
247
  const clearEntries = fnUntraced(function* (exit) {
233
- for (const [id, entry] of entries) {
234
- entries.delete(id);
248
+ const pending = Array.from(entries.values());
249
+ entries.clear();
250
+ for (const entry of pending) {
235
251
  if (entry._tag === "Queue") {
236
- yield* exit._tag === "Success" ? end(entry.queue) : failCause3(entry.queue, exit.cause);
252
+ yield* exit._tag === "Success" ? end(entry.queue) : failCause(entry.queue, exit.cause);
237
253
  } else {
238
254
  entry.resume(exit);
239
255
  }
240
256
  }
241
- });
257
+ }, uninterruptible);
242
258
  const onRequest = (rpc) => {
243
259
  const isStream = isStreamSchema(rpc.successSchema);
244
260
  const middleware = getRpcClientMiddleware(rpc);
245
261
  return (payload, opts) => {
246
- const headers = opts?.headers ? fromInput(opts.headers) : empty2;
247
- const context = opts?.context ?? empty();
262
+ const headers = opts?.headers ? fromInput(opts.headers) : empty;
263
+ const context = opts?.context ?? empty3();
248
264
  if (!isStream) {
249
265
  const onRequest = (span) => onEffectRequest(rpc, middleware, span, rpc.payloadSchema.make(payload), headers, context, opts?.discard ?? false);
250
266
  return disableTracing ? onRequest(undefined) : useSpan(spanName(spanPrefix, rpc._tag), {
@@ -255,18 +271,17 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
255
271
  const queue = onStreamRequest(rpc, middleware, rpc.payloadSchema.make(payload), headers, opts?.streamBufferSize ?? 16, context);
256
272
  if (opts?.asQueue)
257
273
  return queue;
258
- return unwrap(map3(queue, fromQueue));
274
+ return unwrap(map8(queue, fromQueue));
259
275
  };
260
276
  };
261
- const onEffectRequest = (rpc, middleware, span, payload, headers, context, discard) => withFiber((parentFiber) => {
277
+ const onEffectRequest = (rpc, middleware, span, payload, headers, context, discard) => withFiber2((parentFiber) => {
262
278
  if (isShutdown) {
263
- return interrupt2;
279
+ return interrupt3;
264
280
  }
265
281
  const id = generateRequestId();
266
282
  const send = middleware((message) => options.onFromClient({
267
283
  message,
268
- context,
269
- discard
284
+ context
270
285
  }), {
271
286
  _tag: "Request",
272
287
  id,
@@ -277,18 +292,25 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
277
292
  spanId: span.spanId,
278
293
  sampled: span.sampled
279
294
  } : {},
280
- headers: merge2(parentFiber.getRef(CurrentHeaders), headers)
295
+ headers: merge(parentFiber.getRef(CurrentHeaders), headers),
296
+ ...discard ? {
297
+ discard: true
298
+ } : {}
281
299
  });
282
- if (discard) {
283
- return send;
284
- }
285
300
  let fiber;
286
- return onInterrupt(callback((resume) => {
301
+ return onInterrupt(callback3((resume) => {
302
+ let acked = false;
287
303
  const entry = {
288
304
  _tag: "Effect",
289
305
  rpc,
290
306
  context,
291
307
  resume(exit) {
308
+ if (discard && exit._tag === "Success") {
309
+ acked = true;
310
+ if (fiber?.pollUnsafe())
311
+ resume(void_2);
312
+ return;
313
+ }
292
314
  resume(exit);
293
315
  if (fiber && !fiber.pollUnsafe()) {
294
316
  parentFiber.currentDispatcher.scheduleTask(() => {
@@ -303,17 +325,20 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
303
325
  }) : identity, runForkWith(parentFiber.context));
304
326
  fiber.addObserver((exit) => {
305
327
  if (exit._tag === "Failure") {
328
+ entries.delete(id);
306
329
  return resume(exit);
330
+ } else if (acked) {
331
+ return resume(void_2);
307
332
  }
308
333
  });
309
334
  }), (interruptors) => {
310
335
  entries.delete(id);
311
- return andThen(interrupt3(fiber), sendInterrupt(id, Array.from(interruptors), context));
336
+ return andThen2(interrupt(fiber), sendInterrupt(id, Array.from(interruptors), context));
312
337
  });
313
338
  });
314
339
  const onStreamRequest = fnUntraced(function* (rpc, middleware, payload, headers, streamBufferSize, context) {
315
340
  if (isShutdown) {
316
- return yield* interrupt2;
341
+ return yield* interrupt3;
317
342
  }
318
343
  const span = disableTracing ? undefined : yield* makeSpanScoped(spanName(spanPrefix, rpc._tag), {
319
344
  kind: "client",
@@ -326,7 +351,7 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
326
351
  yield* addFinalizerExit(scope, (exit) => {
327
352
  shutdownUnsafe(queue);
328
353
  if (!entries.has(id))
329
- return void_2;
354
+ return void_3;
330
355
  entries.delete(id);
331
356
  return sendInterrupt(id, isFailure2(exit) ? Array.from(interruptors(exit.cause)) : [], context);
332
357
  });
@@ -339,8 +364,7 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
339
364
  });
340
365
  yield* middleware((message) => options.onFromClient({
341
366
  message,
342
- context,
343
- discard: false
367
+ context
344
368
  }), {
345
369
  _tag: "Request",
346
370
  id,
@@ -351,10 +375,14 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
351
375
  spanId: span.spanId,
352
376
  sampled: span.sampled
353
377
  } : {},
354
- headers: merge2(fiber.getRef(CurrentHeaders), headers)
378
+ headers: merge(fiber.getRef(CurrentHeaders), headers)
355
379
  }).pipe(span ? withParentSpan(span, {
356
380
  captureStackTrace: false
357
- }) : identity, onError((cause) => failCause3(queue, cause)), interruptible, forkIn(scope, {
381
+ }) : identity, onError((cause) => {
382
+ if (!hasInterruptsOnly(cause))
383
+ entries.delete(id);
384
+ return failCause(queue, cause);
385
+ }), interruptible, forkIn(scope, {
358
386
  startImmediately: true
359
387
  }));
360
388
  return queue;
@@ -383,7 +411,7 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
383
411
  });
384
412
  };
385
413
  };
386
- const sendInterrupt = (requestId, interruptors, context) => callback((resume) => {
414
+ const sendInterrupt = (requestId, interruptors, context) => callback3((resume) => {
387
415
  const parentFiber = getCurrent();
388
416
  const fiber = options.onFromClient({
389
417
  message: {
@@ -391,11 +419,10 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
391
419
  requestId,
392
420
  interruptors
393
421
  },
394
- context,
395
- discard: false
422
+ context
396
423
  }).pipe(timeout(1000), runForkWith(parentFiber.context));
397
424
  fiber.addObserver(() => {
398
- resume(void_2);
425
+ resume(void_3);
399
426
  });
400
427
  });
401
428
  const write = (message) => {
@@ -404,33 +431,32 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
404
431
  const requestId = message.requestId;
405
432
  const entry = entries.get(requestId);
406
433
  if (!entry || entry._tag !== "Queue")
407
- return void_2;
408
- return offerAll(entry.queue, message.values).pipe(supportsAck ? flatMap2(() => options.onFromClient({
434
+ return void_3;
435
+ return offerAll(entry.queue, message.values).pipe(supportsAck ? flatMap3((dropped) => dropped.length > 0 ? void_3 : options.onFromClient({
409
436
  message: {
410
437
  _tag: "Ack",
411
438
  requestId: message.requestId
412
439
  },
413
- context: entry.context,
414
- discard: false
415
- })) : identity, catchCause((cause) => failCause3(entry.queue, cause)));
440
+ context: entry.context
441
+ })) : identity, catchCause2((cause) => failCause(entry.queue, cause)));
416
442
  }
417
443
  case "Exit": {
418
444
  const requestId = message.requestId;
419
445
  const entry = entries.get(requestId);
420
446
  if (!entry)
421
- return void_2;
447
+ return void_3;
422
448
  entries.delete(requestId);
423
449
  if (entry._tag === "Effect") {
424
450
  entry.resume(message.exit);
425
- return void_2;
451
+ return void_3;
426
452
  }
427
- return message.exit._tag === "Success" ? end(entry.queue) : failCause3(entry.queue, message.exit.cause);
453
+ return message.exit._tag === "Success" ? end(entry.queue) : failCause(entry.queue, message.exit.cause);
428
454
  }
429
455
  case "Defect": {
430
- return clearEntries(die2(message.defect));
456
+ return clearEntries(die(message.defect));
431
457
  }
432
458
  case "ClientEnd": {
433
- return void_2;
459
+ return void_3;
434
460
  }
435
461
  }
436
462
  };
@@ -457,7 +483,7 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
457
483
  };
458
484
  });
459
485
  var clientIdCounter = 0;
460
- var make4 = /* @__PURE__ */ fnUntraced(function* (group, options) {
486
+ var make = /* @__PURE__ */ fnUntraced(function* (group, options) {
461
487
  const clientId = clientIdCounter++;
462
488
  const {
463
489
  codecFor,
@@ -469,9 +495,10 @@ var make4 = /* @__PURE__ */ fnUntraced(function* (group, options) {
469
495
  const rpcSchemas = makeRpcSchemas(codecFor);
470
496
  const decodeDefect = decodeSync(codecFor(Defect()));
471
497
  const entries = new Map;
498
+ const closing = makeUnsafe5();
472
499
  const interruptRequest = (requestId) => {
473
500
  if (!entries.has(requestId))
474
- return void_2;
501
+ return void_3;
475
502
  entries.delete(requestId);
476
503
  return send(clientId, {
477
504
  _tag: "Interrupt",
@@ -495,20 +522,27 @@ var make4 = /* @__PURE__ */ fnUntraced(function* (group, options) {
495
522
  const entry = {
496
523
  rpc,
497
524
  context: collector ? add(fiber.context, Collector, collector) : fiber.context,
498
- schemas: rpcSchemas(rpc)
525
+ schemas: rpcSchemas(rpc),
526
+ discard: message.discard === true
499
527
  };
500
528
  entries.set(message.id, entry);
501
- return entry.schemas.encodePayload(message.payload).pipe(provideContext(entry.context), orDie, flatMap2((payload) => send(clientId, {
502
- ...message,
503
- id: message.id,
504
- payload,
505
- headers: Object.entries(message.headers)
506
- }, collector && collector.readUnsafe())));
529
+ return entry.schemas.encodePayload(message.payload).pipe(provideContext2(entry.context), orDie, flatMap3((payload) => {
530
+ if (isDoneUnsafe(closing)) {
531
+ entries.delete(message.id);
532
+ return interrupt3;
533
+ }
534
+ return send(clientId, {
535
+ ...message,
536
+ id: message.id,
537
+ payload,
538
+ headers: Object.entries(message.headers)
539
+ }, collector && collector.readUnsafe());
540
+ }), onError((cause) => hasInterruptsOnly(cause) ? void_3 : sync2(() => entries.delete(message.id))));
507
541
  }
508
542
  case "Ack": {
509
543
  const entry = entries.get(message.requestId);
510
544
  if (!entry)
511
- return void_2;
545
+ return void_3;
512
546
  return send(clientId, {
513
547
  _tag: "Ack",
514
548
  requestId: message.requestId
@@ -518,7 +552,7 @@ var make4 = /* @__PURE__ */ fnUntraced(function* (group, options) {
518
552
  return interruptRequest(message.requestId);
519
553
  }
520
554
  case "Eof": {
521
- return void_2;
555
+ return void_3;
522
556
  }
523
557
  }
524
558
  }
@@ -529,9 +563,9 @@ var make4 = /* @__PURE__ */ fnUntraced(function* (group, options) {
529
563
  const requestId = RequestId(message.requestId);
530
564
  const entry = entries.get(requestId);
531
565
  if (!entry || isNone(entry.schemas.decodeChunk))
532
- return void_2;
566
+ return void_3;
533
567
  const decodeChunk = entry.schemas.decodeChunk.value;
534
- return uninterruptibleMask((restore) => restore(decodeChunk(message.values).pipe(provideContext(entry.context), orDie, flatMap2((chunk) => write({
568
+ return uninterruptibleMask2((restore) => restore(decodeChunk(message.values).pipe(provideContext2(entry.context), orDie, flatMap3((chunk) => write({
535
569
  _tag: "Chunk",
536
570
  clientId: 0,
537
571
  requestId,
@@ -540,16 +574,25 @@ var make4 = /* @__PURE__ */ fnUntraced(function* (group, options) {
540
574
  _tag: "Exit",
541
575
  clientId: 0,
542
576
  requestId,
543
- exit: failCause(cause)
544
- }).pipe(andThen(hasInterrupts(cause) ? void_2 : ignore(interruptRequest(requestId))))), catchCauseIf((cause) => !hasInterrupts(cause), () => void_2)));
577
+ exit: failCause2(cause)
578
+ }).pipe(andThen2(hasInterrupts2(cause) ? void_3 : raceFirst(ignore(interruptRequest(requestId)), _await(closing))))), catchCauseIf((cause) => !hasInterrupts2(cause), () => void_3)));
545
579
  }
546
580
  case "Exit": {
547
581
  const requestId = RequestId(message.requestId);
548
582
  const entry = entries.get(requestId);
549
583
  if (!entry)
550
- return void_2;
584
+ return void_3;
551
585
  entries.delete(requestId);
552
- return entry.schemas.decodeExit(message.exit).pipe(provideContext(entry.context), orDie, matchCauseEffect({
586
+ if (entry.discard && message.exit._tag === "Success") {
587
+ return write({
588
+ _tag: "Exit",
589
+ clientId: 0,
590
+ requestId,
591
+ exit: void_2
592
+ });
593
+ }
594
+ const decodeExit = entry.discard ? entry.schemas.decodeDiscardExit : entry.schemas.decodeExit;
595
+ return decodeExit(message.exit).pipe(provideContext2(entry.context), orDie, matchCauseEffect({
553
596
  onSuccess: (exit) => write({
554
597
  _tag: "Exit",
555
598
  clientId: 0,
@@ -560,11 +603,12 @@ var make4 = /* @__PURE__ */ fnUntraced(function* (group, options) {
560
603
  _tag: "Exit",
561
604
  clientId: 0,
562
605
  requestId,
563
- exit: failCause(cause)
606
+ exit: failCause2(cause)
564
607
  })
565
608
  }));
566
609
  }
567
610
  case "Defect": {
611
+ entries.clear();
568
612
  return write({
569
613
  _tag: "Defect",
570
614
  clientId: 0,
@@ -572,19 +616,23 @@ var make4 = /* @__PURE__ */ fnUntraced(function* (group, options) {
572
616
  });
573
617
  }
574
618
  case "ClientProtocolError": {
575
- const exit = fail2(message.error);
576
- return forEach(Array.from(entries.keys()), (requestId) => write({
619
+ const exit = fail4(message.error);
620
+ const requestIds = message.requestIds === undefined ? Array.from(entries.keys()) : message.requestIds.map(RequestId).filter((requestId) => entries.has(requestId));
621
+ for (const requestId of requestIds)
622
+ entries.delete(requestId);
623
+ return forEach(requestIds, (requestId) => write({
577
624
  _tag: "Exit",
578
625
  clientId: 0,
579
626
  requestId,
580
627
  exit
581
- }));
628
+ })).pipe(uninterruptible);
582
629
  }
583
630
  default: {
584
- return void_2;
631
+ return void_3;
585
632
  }
586
633
  }
587
- }).pipe(catchCause(logError), interruptible, forkScoped);
634
+ }).pipe(catchCause2(logError), interruptible, forkScoped);
635
+ yield* addFinalizer2(() => succeed4(closing, undefined));
588
636
  return client;
589
637
  });
590
638
  var makeRpcSchemas = (codecFor) => {
@@ -595,21 +643,25 @@ var makeRpcSchemas = (codecFor) => {
595
643
  return entry;
596
644
  }
597
645
  const streamSchemas = getStreamSchemas(rpc.successSchema);
646
+ const parseOptions = get4(rpc.annotations, ParseOptions);
647
+ const exitSchema2 = exitSchema(rpc);
648
+ let decodeDiscardExit;
598
649
  entry = {
599
- decodeChunk: map(streamSchemas, (streamSchemas) => decodeUnknownEffect(codecFor(NonEmptyArray(streamSchemas.success)))),
600
- encodePayload: encodeEffect(codecFor(rpc.payloadSchema)),
601
- decodeExit: decodeUnknownEffect(codecFor(exitSchema(rpc)))
650
+ decodeChunk: map4(streamSchemas, (streamSchemas) => decodeUnknownEffect2(codecFor(NonEmptyArray(streamSchemas.success)), parseOptions)),
651
+ encodePayload: encodeEffect(codecFor(rpc.payloadSchema), parseOptions),
652
+ decodeExit: decodeUnknownEffect2(codecFor(exitSchema2), parseOptions),
653
+ decodeDiscardExit: (encoded) => (decodeDiscardExit ??= decodeUnknownEffect2(codecFor(Exit(Void, exitSchema2.error, exitSchema2.defect)), parseOptions))(encoded)
602
654
  };
603
655
  cache.set(rpc, entry);
604
656
  return entry;
605
657
  };
606
658
  };
607
659
  var CurrentHeaders = /* @__PURE__ */ Reference("effect/rpc/RpcClient/CurrentHeaders", {
608
- defaultValue: () => empty2
660
+ defaultValue: () => empty
609
661
  });
610
- var withHeaders = /* @__PURE__ */ dual(2, (effect, headers) => updateService(effect, CurrentHeaders, merge2(fromInput(headers))));
662
+ var withHeaders = /* @__PURE__ */ dual(2, (effect, headers) => updateService(effect, CurrentHeaders, merge(fromInput(headers))));
611
663
 
612
- class Protocol extends (/* @__PURE__ */ Service()("effect/rpc/RpcClient/Protocol")) {
664
+ class Protocol extends (/* @__PURE__ */ Service2()("effect/rpc/RpcClient/Protocol")) {
613
665
  static make = withRunClient;
614
666
  }
615
667
  var makeProtocolSocket = (options) => Protocol.make(fnUntraced(function* (writeResponse, clientIds) {
@@ -619,13 +671,19 @@ var makeProtocolSocket = (options) => Protocol.make(fnUntraced(function* (writeR
619
671
  const requestClientMap = new Map;
620
672
  const writer = yield* socket.writer;
621
673
  let parser = serialization.makeUnsafe();
622
- const pinger = yield* makePinger(suspend(() => writer.write(parser.encode(constPing))), options);
623
- const onPingTimeout = ignoreCause(options?.onPingTimeout ?? void_2, {
674
+ const pinger = yield* makePinger(suspend3(() => writer.write(parser.encode(constPing))), options);
675
+ const onPingTimeout = ignoreCause(options?.onPingTimeout ?? void_3, {
624
676
  log: true,
625
677
  message: "RpcClient onPingTimeout hook failed"
626
678
  });
627
679
  let currentError;
628
- const broadcast = (response) => forEach(clientIds, (clientId) => writeResponse(clientId, response));
680
+ const broadcast = (response) => {
681
+ const deliver = forEach(Array.from(clientIds), (clientId) => writeResponse(clientId, response));
682
+ if (response._tag !== "Defect" && response._tag !== "ClientProtocolError")
683
+ return deliver;
684
+ requestClientMap.clear();
685
+ return uninterruptible(deliver);
686
+ };
629
687
  const broadcastError = (error) => {
630
688
  currentError = error;
631
689
  return broadcast({
@@ -637,7 +695,7 @@ var makeProtocolSocket = (options) => Protocol.make(fnUntraced(function* (writeR
637
695
  try {
638
696
  const responses = parser.decode(data);
639
697
  if (responses.length === 0)
640
- return void_2;
698
+ return void_3;
641
699
  pinger.onFrame();
642
700
  let i = 0;
643
701
  return whileLoop({
@@ -645,7 +703,7 @@ var makeProtocolSocket = (options) => Protocol.make(fnUntraced(function* (writeR
645
703
  body: () => {
646
704
  const response = responses[i++];
647
705
  if (response._tag === "Pong")
648
- return void_2;
706
+ return void_3;
649
707
  if (Object.hasOwn(response, "requestId")) {
650
708
  const requestId = response.requestId;
651
709
  const clientId = requestClientMap.get(requestId);
@@ -672,7 +730,7 @@ var makeProtocolSocket = (options) => Protocol.make(fnUntraced(function* (writeR
672
730
  });
673
731
  }
674
732
  };
675
- yield* suspend(() => {
733
+ yield* suspend3(() => {
676
734
  parser = serialization.makeUnsafe();
677
735
  pinger.reset();
678
736
  let connected = false;
@@ -691,12 +749,12 @@ var makeProtocolSocket = (options) => Protocol.make(fnUntraced(function* (writeR
691
749
  yield* processData(frames[i]);
692
750
  }
693
751
  }
694
- }).pipe(scoped, raceFirst(pinger.timeout), andThen(() => connected ? onPingTimeout : void_2), andThen(() => fail4(new SocketError({
752
+ }).pipe(scoped, raceFirst(pinger.timeout), andThen2(() => connected ? onPingTimeout : void_3), andThen2(() => fail7(new SocketError({
695
753
  reason: new SocketReadError({
696
754
  cause: new Error("ping timeout")
697
755
  })
698
756
  }))));
699
- }).pipe(isSome(hooks) ? ensuring(hooks.value.onDisconnect) : identity, tapCause((cause) => {
757
+ }).pipe(isSome(hooks) ? ensuring2(hooks.value.onDisconnect) : identity, tapCause((cause) => {
700
758
  const error = findError(cause);
701
759
  const hasError = isSuccess(error);
702
760
  const rpcError = new RpcClientError({
@@ -706,7 +764,7 @@ var makeProtocolSocket = (options) => Protocol.make(fnUntraced(function* (writeR
706
764
  })
707
765
  });
708
766
  if (options?.retryTransientErrors && hasError && error.success.reason._tag === "SocketOpenError") {
709
- return (options.onTransientError?.(rpcError) ?? void_2).pipe(ignoreCause({
767
+ return (options.onTransientError?.(rpcError) ?? void_3).pipe(ignoreCause({
710
768
  log: true,
711
769
  message: "RpcClient onTransientError hook failed"
712
770
  }));
@@ -718,41 +776,47 @@ var makeProtocolSocket = (options) => Protocol.make(fnUntraced(function* (writeR
718
776
  module: "RpcClient",
719
777
  method: "makeProtocolSocket"
720
778
  }), forkScoped);
779
+ const write = (request) => suspend3(() => {
780
+ const encoded = parser.encode(request);
781
+ return encoded === undefined ? void_3 : orDie(writer.write(encoded));
782
+ });
721
783
  return {
722
784
  send(clientId, request) {
723
785
  if (currentError) {
724
- return fail4(currentError);
725
- }
726
- if (request._tag === "Request") {
727
- requestClientMap.set(request.id, clientId);
786
+ return fail7(currentError);
728
787
  }
729
- const encoded = parser.encode(request);
730
- if (encoded === undefined)
731
- return void_2;
732
- return orDie(writer.write(encoded));
788
+ if (request._tag === "Interrupt")
789
+ requestClientMap.delete(request.requestId);
790
+ if (request._tag !== "Request")
791
+ return write(request);
792
+ requestClientMap.set(request.id, clientId);
793
+ return onError(write(request), () => sync2(() => requestClientMap.delete(request.id)));
733
794
  },
734
795
  supportsAck: true,
735
796
  supportsTransferables: false,
736
797
  codecFor: serialization.codecFor
737
798
  };
738
799
  }));
739
- var defaultRetryPolicy = /* @__PURE__ */ min([/* @__PURE__ */ exponential(500, 1.5), /* @__PURE__ */ spaced(5000)]);
800
+ var defaultRetryPolicy = /* @__PURE__ */ min2([/* @__PURE__ */ exponential(500, 1.5), /* @__PURE__ */ spaced(5000)]);
740
801
  var makePinger = /* @__PURE__ */ fnUntraced(function* (writePing, options) {
741
802
  const clock = yield* Clock;
742
803
  const interval = options?.pingInterval ?? "5 seconds";
743
804
  const timeoutMillis = toMillis(options?.pingTimeout ?? interval);
744
805
  let lastSeen = clock.currentTimeMillisUnsafe();
745
- const latch = makeUnsafe3();
806
+ let awaitingResponse = false;
807
+ const latch = makeUnsafe2();
746
808
  const onFrame = () => {
747
809
  lastSeen = clock.currentTimeMillisUnsafe();
810
+ awaitingResponse = false;
748
811
  };
749
812
  const reset = () => {
750
813
  onFrame();
751
814
  latch.closeUnsafe();
752
815
  };
753
- yield* suspend(() => {
754
- if (clock.currentTimeMillisUnsafe() - lastSeen > timeoutMillis)
816
+ yield* suspend3(() => {
817
+ if (awaitingResponse && clock.currentTimeMillisUnsafe() - lastSeen > timeoutMillis)
755
818
  return latch.open;
819
+ awaitingResponse = true;
756
820
  return writePing;
757
821
  }).pipe(delay(interval), ignore, forever, interruptible, forkScoped);
758
822
  return {
@@ -762,7 +826,7 @@ var makePinger = /* @__PURE__ */ fnUntraced(function* (writePing, options) {
762
826
  };
763
827
  });
764
828
  var layerProtocolSocket = (options) => effect(Protocol)(makeProtocolSocket(options));
765
- class ConnectionHooks extends (/* @__PURE__ */ Service()("effect/rpc/RpcClient/ConnectionHooks")) {
829
+ class ConnectionHooks extends (/* @__PURE__ */ Service2()("effect/rpc/RpcClient/ConnectionHooks")) {
766
830
  }
767
831
 
768
- export { layerJson, make4, withHeaders, layerProtocolSocket, ConnectionHooks };
832
+ export { layerJson, make, withHeaders, layerProtocolSocket, ConnectionHooks };