@kitman-sh/cli 0.7.4 → 0.8.0

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.
@@ -3,8 +3,6 @@ import {
3
3
  dual,
4
4
  identity,
5
5
  constVoid,
6
- flow,
7
- hasProperty,
8
6
  assignProperty,
9
7
  isNone,
10
8
  isSome,
@@ -15,7 +13,6 @@ import {
15
13
  getOrUndefinedUnsafe,
16
14
  getUnsafe,
17
15
  get,
18
- merge,
19
16
  Reference,
20
17
  isSuccess,
21
18
  toMillis,
@@ -29,7 +26,6 @@ import {
29
26
  interrupt,
30
27
  isFailure2,
31
28
  Scope,
32
- provide,
33
29
  addFinalizerExit,
34
30
  addFinalizer,
35
31
  succeed4,
@@ -40,7 +36,6 @@ import {
40
36
  spaced,
41
37
  forEach,
42
38
  whileLoop,
43
- succeed5,
44
39
  suspend,
45
40
  sync,
46
41
  void_2,
@@ -60,7 +55,6 @@ import {
60
55
  ignore,
61
56
  ignoreCause,
62
57
  timeout,
63
- timeoutOrElse,
64
58
  delay,
65
59
  raceFirst,
66
60
  matchCauseEffect,
@@ -68,11 +62,8 @@ import {
68
62
  contextWith,
69
63
  provideContext,
70
64
  serviceOption,
71
- updateContext,
72
65
  updateService,
73
- scope,
74
66
  scoped,
75
- acquireRelease,
76
67
  ensuring,
77
68
  onError,
78
69
  onExit,
@@ -100,375 +91,24 @@ import {
100
91
  shutdownUnsafe,
101
92
  fromQueue,
102
93
  unwrap,
103
- empty3,
94
+ empty2,
104
95
  fromInput,
105
- merge3,
96
+ merge2,
106
97
  decodeUnknownEffect,
107
98
  decodeSync,
108
99
  encodeEffect,
109
- optional,
110
- String2,
111
100
  NonEmptyArray,
112
- Union,
113
- Literals,
114
- tag,
115
- Int,
116
101
  Defect,
117
- Error2,
118
- TaggedError2,
119
102
  toCodecJson,
120
- HttpClientErrorSchema,
103
+ Socket,
104
+ SocketReadError,
105
+ SocketError,
121
106
  isStreamSchema,
122
107
  getStreamSchemas,
123
- exitSchema
124
- } from "./chunk-jd09xfx0.js";
125
-
126
- // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/socket/Socket.js
127
- var TypeId = "~effect/socket/Socket";
128
- var Socket = /* @__PURE__ */ Service("effect/socket/Socket");
129
- var make4 = (options) => Socket.of({
130
- [TypeId]: TypeId,
131
- reader: options.reader,
132
- writer: options.writer
133
- });
134
- var encoder = /* @__PURE__ */ new TextEncoder;
135
- var readerString = (self, encoding) => map3(self.reader, ({
136
- pull
137
- }) => {
138
- const decoder = new TextDecoder(encoding);
139
- return map3(pull, (chunk) => {
140
- const out = new Array(chunk.length);
141
- for (let i = 0;i < chunk.length; i++) {
142
- const item = chunk[i];
143
- out[i] = typeof item === "string" ? item : decoder.decode(item);
144
- }
145
- return out;
146
- });
147
- });
148
- var CloseEventTypeId = "~effect/socket/Socket/CloseEvent";
149
- var isCloseEvent = (u) => hasProperty(u, CloseEventTypeId);
150
- var SocketErrorTypeId = "~effect/socket/Socket/SocketError";
151
- var isSocketError = (u) => hasProperty(u, SocketErrorTypeId);
152
-
153
- class SocketReadError extends (/* @__PURE__ */ Error2("effect/socket/Socket/SocketReadError")({
154
- _tag: /* @__PURE__ */ tag("SocketReadError"),
155
- cause: /* @__PURE__ */ Defect()
156
- })) {
157
- message = `An error occurred during Read`;
158
- }
159
-
160
- class SocketWriteError extends (/* @__PURE__ */ Error2("effect/socket/Socket/SocketWriteError")({
161
- _tag: /* @__PURE__ */ tag("SocketWriteError"),
162
- cause: /* @__PURE__ */ Defect()
163
- })) {
164
- message = `An error occurred during Write`;
165
- }
166
-
167
- class SocketOpenError extends (/* @__PURE__ */ Error2("effect/socket/Socket/SocketOpenError")({
168
- _tag: /* @__PURE__ */ tag("SocketOpenError"),
169
- kind: /* @__PURE__ */ Literals(["Unknown", "Timeout"]),
170
- cause: /* @__PURE__ */ Defect()
171
- })) {
172
- get message() {
173
- return this.kind === "Timeout" ? `timeout waiting for "open"` : `An error occurred during Open`;
174
- }
175
- }
176
-
177
- class SocketUpgradeError extends (/* @__PURE__ */ Error2("effect/socket/Socket/SocketUpgradeError")({
178
- _tag: /* @__PURE__ */ tag("SocketUpgradeError"),
179
- cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
180
- })) {
181
- static unsupported = () => fail4(new SocketError({
182
- reason: new SocketUpgradeError({})
183
- }));
184
- get message() {
185
- return this.cause === undefined ? `Socket does not support TLS upgrade` : `An error occurred during TLS upgrade`;
186
- }
187
- }
188
-
189
- class SocketCloseError extends (/* @__PURE__ */ Error2("effect/socket/Socket/SocketCloseError")({
190
- _tag: /* @__PURE__ */ tag("SocketCloseError"),
191
- code: Int,
192
- closeReason: /* @__PURE__ */ optional(String2)
193
- })) {
194
- get message() {
195
- if (this.closeReason) {
196
- return `${this.code}: ${this.closeReason}`;
197
- }
198
- return `${this.code}`;
199
- }
200
- }
201
- var SocketErrorReason = /* @__PURE__ */ Union([SocketReadError, SocketWriteError, SocketOpenError, SocketUpgradeError, SocketCloseError]);
202
-
203
- class SocketError extends (/* @__PURE__ */ TaggedError2(SocketErrorTypeId)("SocketError", {
204
- _tag: /* @__PURE__ */ tag("SocketError"),
205
- reason: SocketErrorReason
206
- })) {
207
- constructor(props) {
208
- if ("cause" in props.reason) {
209
- super({
210
- ...props,
211
- cause: props.reason.cause
212
- });
213
- } else {
214
- super(props);
215
- }
216
- }
217
- [SocketErrorTypeId] = SocketErrorTypeId;
218
- static is(u) {
219
- return isSocketError(u);
220
- }
221
- message = this.reason.message;
222
- }
223
- var closeError = (code, closeReason) => new SocketError({
224
- reason: new SocketCloseError({
225
- code,
226
- closeReason
227
- })
228
- });
229
- class WebSocketConstructor extends (/* @__PURE__ */ Service()("@effect/platform/Socket/WebSocketConstructor")) {
230
- }
231
- var layerWebSocketConstructorGlobal = /* @__PURE__ */ succeed4(WebSocketConstructor)((url, options) => {
232
- if (options !== undefined && typeof options !== "string" && !Array.isArray(options)) {
233
- throw new TypeError("WebSocket client options are not supported by the global WebSocket constructor");
234
- }
235
- return new globalThis.WebSocket(url, options);
236
- });
237
- var makeWebSocket = (url, options) => WebSocketConstructor.use((makeWs) => fromWebSocket(acquireRelease((typeof url === "string" ? succeed5(url) : url).pipe(map3((url) => makeWs(url, options?.headers === undefined ? options?.protocols : {
238
- protocols: options.protocols,
239
- headers: options.headers
240
- }))), (ws) => sync(() => ws.close(1000))), options));
241
- var isPausable = (ws) => ("pause" in ws) && typeof ws.pause === "function";
242
- var fromWebSocket = (acquire, options) => withFiber((fiber) => {
243
- let currentWS;
244
- const latch = makeUnsafe3(false);
245
- const acquireContext = fiber.context;
246
- const reader = gen(function* () {
247
- const scope2 = yield* scope;
248
- const ws = yield* provide(acquire, scope2);
249
- if ("binaryType" in ws) {
250
- ws.binaryType = "arraybuffer";
251
- }
252
- const pausable = isPausable(ws);
253
- const highWaterMark = options?.highWaterMark ?? (pausable ? defaultHighWaterMark : undefined);
254
- let open = ws.readyState === 1;
255
- let paused = pausable && "isPaused" in ws && ws.isPaused === true;
256
- let buffer = [];
257
- let bufferSize = 0;
258
- let error;
259
- let waiter;
260
- let openWaiter;
261
- function pauseWebSocket() {
262
- if (!pausable || paused)
263
- return;
264
- ws.pause();
265
- paused = true;
266
- }
267
- function resumeWebSocket() {
268
- if (!pausable || !paused)
269
- return;
270
- ws.resume();
271
- paused = false;
272
- }
273
- function takeBuffer() {
274
- const chunk = buffer;
275
- buffer = [];
276
- bufferSize = 0;
277
- if (error === undefined)
278
- resumeWebSocket();
279
- return chunk;
280
- }
281
- function deliver() {
282
- if (waiter === undefined || buffer.length === 0)
283
- return;
284
- const resume = waiter;
285
- waiter = undefined;
286
- resume(succeed5(takeBuffer()));
287
- }
288
- function push(data) {
289
- buffer.push(data);
290
- if (highWaterMark !== undefined) {
291
- bufferSize += typeof data === "string" ? encoder.encode(data).byteLength : data.byteLength;
292
- }
293
- if (waiter !== undefined)
294
- deliver();
295
- if (pausable && bufferSize >= highWaterMark) {
296
- pauseWebSocket();
297
- } else if (!pausable && !waiter && highWaterMark !== undefined && bufferSize > highWaterMark) {
298
- fail(new SocketError({
299
- reason: new SocketReadError({
300
- cause: new Error(`Socket highWaterMark of ${highWaterMark} bytes exceeded`)
301
- })
302
- }));
303
- }
304
- }
305
- function fail(err) {
306
- if (error === undefined)
307
- error = err;
308
- if (openWaiter !== undefined) {
309
- const {
310
- cleanup,
311
- resume
312
- } = openWaiter;
313
- openWaiter = undefined;
314
- cleanup();
315
- resume(fail4(error));
316
- }
317
- if (waiter !== undefined) {
318
- const resume = waiter;
319
- waiter = undefined;
320
- resume(buffer.length > 0 ? succeed5(takeBuffer()) : fail4(error));
321
- }
322
- }
323
- function onMessage(event) {
324
- const data = event.data;
325
- if (typeof Blob !== "undefined" && data instanceof Blob) {
326
- data.arrayBuffer().then((buf) => push(new Uint8Array(buf)), (cause) => {
327
- fail(new SocketError({
328
- reason: new SocketReadError({
329
- cause
330
- })
331
- }));
332
- });
333
- return;
334
- }
335
- push(data instanceof ArrayBuffer ? new Uint8Array(data) : data);
336
- }
337
- function onError(event) {
338
- fail(new SocketError({
339
- reason: open ? new SocketReadError({
340
- cause: event
341
- }) : new SocketOpenError({
342
- kind: "Unknown",
343
- cause: event
344
- })
345
- }));
346
- }
347
- function onClose(event) {
348
- fail(closeError(typeof event.code === "number" ? event.code : 1006, event.reason));
349
- }
350
- ws.addEventListener("message", onMessage);
351
- ws.addEventListener("error", onError, {
352
- once: true
353
- });
354
- ws.addEventListener("close", onClose, {
355
- once: true
356
- });
357
- yield* addFinalizer(scope2, sync(() => {
358
- fail(closeError(1006));
359
- ws.removeEventListener("message", onMessage);
360
- ws.removeEventListener("error", onError);
361
- ws.removeEventListener("close", onClose);
362
- if (pausable) {
363
- try {
364
- resumeWebSocket();
365
- } catch {}
366
- }
367
- latch.closeUnsafe();
368
- currentWS = undefined;
369
- }));
370
- if (ws.readyState >= 2) {
371
- return yield* fail4(error ?? closeError(1006));
372
- }
373
- if (!open) {
374
- yield* callback((resume) => {
375
- const onOpen = () => {
376
- if (openWaiter?.resume !== resume)
377
- return;
378
- openWaiter = undefined;
379
- ws.removeEventListener("open", onOpen);
380
- resume(void_2);
381
- };
382
- const cleanup = () => ws.removeEventListener("open", onOpen);
383
- openWaiter = {
384
- resume,
385
- cleanup
386
- };
387
- ws.addEventListener("open", onOpen, {
388
- once: true
389
- });
390
- return sync(() => {
391
- if (openWaiter?.resume === resume)
392
- openWaiter = undefined;
393
- cleanup();
394
- });
395
- }).pipe(timeoutOrElse({
396
- duration: options?.openTimeout ?? 1e4,
397
- orElse: () => fail4(new SocketError({
398
- reason: new SocketOpenError({
399
- kind: "Timeout",
400
- cause: new Error('timeout waiting for "open"')
401
- })
402
- }))
403
- }));
404
- open = true;
405
- }
406
- if (error === undefined && bufferSize < highWaterMark)
407
- resumeWebSocket();
408
- currentWS = ws;
409
- latch.openUnsafe();
410
- return {
411
- pull: callback((resume) => {
412
- if (buffer.length > 0)
413
- return resume(succeed5(takeBuffer()));
414
- if (error !== undefined)
415
- return resume(fail4(error));
416
- waiter = resume;
417
- return sync(() => {
418
- if (waiter === resume)
419
- waiter = undefined;
420
- });
421
- }),
422
- upgrade: SocketUpgradeError.unsupported
423
- };
424
- }).pipe(updateContext((input) => merge(acquireContext, input)));
425
- const write = (chunk) => suspend(() => {
426
- const ws = currentWS;
427
- if (ws === undefined)
428
- return latch.whenOpen(write(chunk));
429
- try {
430
- if (isCloseEvent(chunk)) {
431
- ws.close(chunk.code, chunk.reason);
432
- } else {
433
- ws.send(chunk);
434
- }
435
- return void_2;
436
- } catch (cause) {
437
- return fail4(new SocketError({
438
- reason: new SocketWriteError({
439
- cause
440
- })
441
- }));
442
- }
443
- });
444
- const writeAll = (chunks) => suspend(() => {
445
- const ws = currentWS;
446
- if (ws === undefined)
447
- return latch.whenOpen(writeAll(chunks));
448
- try {
449
- for (let i = 0;i < chunks.length; i++) {
450
- ws.send(chunks[i]);
451
- }
452
- return void_2;
453
- } catch (cause) {
454
- return fail4(new SocketError({
455
- reason: new SocketWriteError({
456
- cause
457
- })
458
- }));
459
- }
460
- });
461
- const writer = succeed5({
462
- write,
463
- writeAll
464
- });
465
- return succeed5(make4({
466
- reader,
467
- writer
468
- }));
469
- });
470
- var defaultHighWaterMark = 64 * 1024;
471
- var layerWebSocket = /* @__PURE__ */ flow(makeWebSocket, /* @__PURE__ */ effect(Socket));
108
+ exitSchema,
109
+ RpcClientDefect,
110
+ RpcClientError
111
+ } from "./chunk-fpyy4rpd.js";
472
112
 
473
113
  // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/workers/Transferable.js
474
114
  class Collector extends (/* @__PURE__ */ Service()("effect/workers/Transferable/Collector")) {
@@ -494,36 +134,6 @@ var makeCollectorUnsafe = () => {
494
134
  });
495
135
  };
496
136
 
497
- // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/workers/WorkerError.js
498
- class WorkerSpawnError extends (/* @__PURE__ */ Error2("effect/workers/WorkerError/WorkerSpawnError")({
499
- _tag: /* @__PURE__ */ tag("WorkerSpawnError"),
500
- message: String2,
501
- cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
502
- })) {
503
- }
504
-
505
- class WorkerSendError extends (/* @__PURE__ */ Error2("effect/workers/WorkerError/WorkerSendError")({
506
- _tag: /* @__PURE__ */ tag("WorkerSendError"),
507
- message: String2,
508
- cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
509
- })) {
510
- }
511
-
512
- class WorkerReceiveError extends (/* @__PURE__ */ Error2("effect/workers/WorkerError/WorkerReceiveError")({
513
- _tag: /* @__PURE__ */ tag("WorkerReceiveError"),
514
- message: String2,
515
- cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
516
- })) {
517
- }
518
-
519
- class WorkerUnknownError extends (/* @__PURE__ */ Error2("effect/workers/WorkerError/WorkerUnknownError")({
520
- _tag: /* @__PURE__ */ tag("WorkerUnknownError"),
521
- message: String2,
522
- cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
523
- })) {
524
- }
525
- var WorkerErrorReason = /* @__PURE__ */ Union([WorkerSpawnError, WorkerSendError, WorkerReceiveError, WorkerUnknownError]);
526
-
527
137
  // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/internal/tracing.js
528
138
  var spanName = (spanPrefix, tag) => spanPrefix === undefined ? tag : `${spanPrefix}.${tag}`;
529
139
  var spanAttributes = (tag, attributes) => ({
@@ -532,26 +142,6 @@ var spanAttributes = (tag, attributes) => ({
532
142
  ...attributes
533
143
  });
534
144
 
535
- // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcClientError.js
536
- var TypeId2 = "~effect/rpc/RpcClientError";
537
-
538
- class RpcClientDefect extends (/* @__PURE__ */ Error2("effect/rpc/RpcClientError/RpcClientDefect")({
539
- _tag: /* @__PURE__ */ tag("RpcClientDefect"),
540
- message: String2,
541
- cause: /* @__PURE__ */ Defect()
542
- })) {
543
- }
544
-
545
- class RpcClientError extends (/* @__PURE__ */ Error2(TypeId2)({
546
- _tag: /* @__PURE__ */ tag("RpcClientError"),
547
- reason: /* @__PURE__ */ Union([WorkerErrorReason, SocketErrorReason, HttpClientErrorSchema, RpcClientDefect])
548
- })) {
549
- [TypeId2] = TypeId2;
550
- get message() {
551
- return `${this.reason._tag}: ${this.reason.message}`;
552
- }
553
- }
554
-
555
145
  // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/rpc/RpcMessage.js
556
146
  var RequestId = (id) => id;
557
147
  var constPing = {
@@ -653,7 +243,7 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
653
243
  const isStream = isStreamSchema(rpc.successSchema);
654
244
  const middleware = getRpcClientMiddleware(rpc);
655
245
  return (payload, opts) => {
656
- const headers = opts?.headers ? fromInput(opts.headers) : empty3;
246
+ const headers = opts?.headers ? fromInput(opts.headers) : empty2;
657
247
  const context = opts?.context ?? empty();
658
248
  if (!isStream) {
659
249
  const onRequest = (span) => onEffectRequest(rpc, middleware, span, rpc.payloadSchema.make(payload), headers, context, opts?.discard ?? false);
@@ -687,7 +277,7 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
687
277
  spanId: span.spanId,
688
278
  sampled: span.sampled
689
279
  } : {},
690
- headers: merge3(parentFiber.getRef(CurrentHeaders), headers)
280
+ headers: merge2(parentFiber.getRef(CurrentHeaders), headers)
691
281
  });
692
282
  if (discard) {
693
283
  return send;
@@ -761,7 +351,7 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
761
351
  spanId: span.spanId,
762
352
  sampled: span.sampled
763
353
  } : {},
764
- headers: merge3(fiber.getRef(CurrentHeaders), headers)
354
+ headers: merge2(fiber.getRef(CurrentHeaders), headers)
765
355
  }).pipe(span ? withParentSpan(span, {
766
356
  captureStackTrace: false
767
357
  }) : identity, onError((cause) => failCause3(queue, cause)), interruptible, forkIn(scope, {
@@ -867,7 +457,7 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
867
457
  };
868
458
  });
869
459
  var clientIdCounter = 0;
870
- var make5 = /* @__PURE__ */ fnUntraced(function* (group, options) {
460
+ var make4 = /* @__PURE__ */ fnUntraced(function* (group, options) {
871
461
  const clientId = clientIdCounter++;
872
462
  const {
873
463
  codecFor,
@@ -1015,9 +605,9 @@ var makeRpcSchemas = (codecFor) => {
1015
605
  };
1016
606
  };
1017
607
  var CurrentHeaders = /* @__PURE__ */ Reference("effect/rpc/RpcClient/CurrentHeaders", {
1018
- defaultValue: () => empty3
608
+ defaultValue: () => empty2
1019
609
  });
1020
- var withHeaders = /* @__PURE__ */ dual(2, (effect, headers) => updateService(effect, CurrentHeaders, merge3(fromInput(headers))));
610
+ var withHeaders = /* @__PURE__ */ dual(2, (effect, headers) => updateService(effect, CurrentHeaders, merge2(fromInput(headers))));
1021
611
 
1022
612
  class Protocol extends (/* @__PURE__ */ Service()("effect/rpc/RpcClient/Protocol")) {
1023
613
  static make = withRunClient;
@@ -1175,4 +765,4 @@ var layerProtocolSocket = (options) => effect(Protocol)(makeProtocolSocket(optio
1175
765
  class ConnectionHooks extends (/* @__PURE__ */ Service()("effect/rpc/RpcClient/ConnectionHooks")) {
1176
766
  }
1177
767
 
1178
- export { make4, readerString, isCloseEvent, SocketReadError, SocketWriteError, SocketOpenError, SocketUpgradeError, SocketCloseError, SocketError, WebSocketConstructor, layerWebSocketConstructorGlobal, layerWebSocket, layerJson, make5, withHeaders, layerProtocolSocket, ConnectionHooks };
768
+ export { layerJson, make4, withHeaders, layerProtocolSocket, ConnectionHooks };
@@ -0,0 +1,132 @@
1
+ // @bun
2
+ import {
3
+ getOrElse,
4
+ TaggedError,
5
+ currentTimeMillis,
6
+ forEach,
7
+ tryPromise,
8
+ sync,
9
+ gen,
10
+ flatMap2,
11
+ andThen,
12
+ map3,
13
+ scoped,
14
+ runForEach,
15
+ FileSystem,
16
+ is,
17
+ encodeEffect,
18
+ optionalKey,
19
+ String2,
20
+ Record,
21
+ ArraySchema,
22
+ Union,
23
+ TaggedStruct,
24
+ fromJsonString,
25
+ TaggedError2,
26
+ toCodecJson,
27
+ Json,
28
+ guard,
29
+ ProgramWorkUnit,
30
+ RunFileRefused,
31
+ runFileContentType,
32
+ sha256Hasher,
33
+ put,
34
+ setHeaders,
35
+ bodyUint8Array,
36
+ filterStatusOk,
37
+ HttpClient,
38
+ RunnerRpcError
39
+ } from "./chunk-fpyy4rpd.js";
40
+ import {
41
+ LoopManifest,
42
+ ManifestInvalid,
43
+ make,
44
+ Suspended,
45
+ LoopCheckError
46
+ } from "./chunk-2npvts4c.js";
47
+
48
+ // packages/sdk/src/program/engine.ts
49
+ class JournalWriteFailed extends TaggedError("JournalWriteFailed") {
50
+ get message() {
51
+ return `Journal write failed: ${this.cause.message}`;
52
+ }
53
+ }
54
+ var JournalEntries = Record(String2, Json);
55
+ var isSuspended = is(Suspended);
56
+ var emptyWorkflow = make("kitman-loop/none", { payload: {}, idempotencyKey: () => "none" });
57
+ var replayStatuses = new Set([401, 403, 409, 429]);
58
+ var isRunnerRpcError = is(RunnerRpcError);
59
+ var isRunFileRefused = is(RunFileRefused);
60
+ var put2 = (target, contentType, body) => gen(function* () {
61
+ const response = yield* (yield* HttpClient).execute(put(target.url).pipe(bodyUint8Array(body, contentType), setHeaders(target.headers ?? {})));
62
+ return (yield* filterStatusOk(response)).headers.etag ?? "";
63
+ });
64
+ var readRange = (path, offset, size) => scoped(gen(function* () {
65
+ const file = yield* (yield* FileSystem).open(path);
66
+ return getOrElse(yield* file.readAlloc(size, { position: BigInt(offset) }), () => new Uint8Array);
67
+ }));
68
+ var partUrlMarginMillis = 60000;
69
+ var uploadParts = (files, path, contentType, fileId, upload) => forEach(upload.parts, (part) => gen(function* () {
70
+ const now = yield* currentTimeMillis;
71
+ const fresh = Date.parse(part.expiresAt) - now > partUrlMarginMillis ? part : (yield* files.runFileParts({ fileId, partNumbers: [part.partNumber] }))[0] ?? part;
72
+ const body = yield* readRange(path, (part.partNumber - 1) * upload.partSize, upload.partSize);
73
+ return { partNumber: part.partNumber, etag: yield* put2(fresh, contentType, body) };
74
+ }));
75
+ var uploadRunFile = (files, file) => gen(function* () {
76
+ const fs = yield* FileSystem;
77
+ const contentType = runFileContentType(file.name);
78
+ const byteSize = Number((yield* fs.stat(file.path)).size);
79
+ const hash = sha256Hasher();
80
+ yield* runForEach(fs.stream(file.path), (chunk) => sync(() => hash.update(chunk)));
81
+ const { file: slotted, upload } = yield* files.createRunFile({
82
+ step: file.step,
83
+ name: file.name,
84
+ ...file.caption === undefined ? undefined : { caption: file.caption },
85
+ contentType,
86
+ byteSize,
87
+ sha256: hash.digest("hex")
88
+ });
89
+ if (upload === undefined)
90
+ return slotted;
91
+ return yield* upload.kind === "single" ? readRange(file.path, 0, byteSize).pipe(flatMap2((body) => put2(upload, contentType, body)), andThen(files.completeRunFile({ fileId: slotted.id }))) : flatMap2(uploadParts(files, file.path, contentType, slotted.id, upload), (parts) => files.completeRunFile({ fileId: slotted.id, parts }));
92
+ });
93
+ var programLease = (work) => ({
94
+ workUnitId: work.id,
95
+ leaseOwnerId: work.lease.leaseOwnerId,
96
+ runnerReplicaId: work.lease.runnerReplicaId,
97
+ leaseId: work.lease.leaseId,
98
+ attempt: work.lease.attempt,
99
+ fencingToken: work.lease.fencingToken,
100
+ capacitySlot: work.lease.capacitySlot
101
+ });
102
+ var rpcRunFiles = (rpc, lease) => ({
103
+ createRunFile: (file) => rpc.createRunFile({ lease, ...file }),
104
+ runFileParts: (request) => map3(rpc.runFileParts({ lease, ...request, partNumbers: [...request.partNumbers] }), ({ parts }) => parts),
105
+ completeRunFile: ({ parts, ...request }) => rpc.completeRunFile({ lease, ...request, ...parts === undefined ? undefined : { parts: [...parts] } })
106
+ });
107
+
108
+ // packages/sdk/src/program/host.ts
109
+ var describeFlag = "--kitman-describe";
110
+ var Described = Union([
111
+ TaggedStruct("Described", {
112
+ loops: ArraySchema(LoopManifest),
113
+ agents: Record(String2, Json),
114
+ schedules: optionalKey(Record(String2, Json)),
115
+ kits: optionalKey(Record(String2, Json))
116
+ }),
117
+ TaggedStruct("Refused", { error: Union([ManifestInvalid, LoopCheckError]) })
118
+ ]);
119
+ var encodeDescribed = encodeEffect(fromJsonString(toCodecJson(Described)));
120
+
121
+ class ProgramRefused extends TaggedError2()("ProgramRefused", { reason: String2 }) {
122
+ get message() {
123
+ return this.reason;
124
+ }
125
+ }
126
+ var programHostsEnv = "KITMAN_PROGRAM_HOSTS";
127
+ var undeclaredHostsEnv = "KITMAN_UNDECLARED_HOSTS";
128
+ var redirectStatuses = new Set([301, 302, 303, 307, 308]);
129
+ var readStdin = tryPromise(() => Bun.stdin.text());
130
+ var isWorkUnit = guard(ProgramWorkUnit);
131
+
132
+ export { uploadRunFile, programLease, rpcRunFiles, describeFlag, Described, programHostsEnv, undeclaredHostsEnv };
@@ -3,7 +3,7 @@ import {
3
3
  Random,
4
4
  succeed5,
5
5
  withFiber
6
- } from "./chunk-jd09xfx0.js";
6
+ } from "./chunk-fpyy4rpd.js";
7
7
 
8
8
  // node_modules/.bun/effect@4.0.4/node_modules/effect/dist/Random.js
9
9
  var Random2 = Random;