stitchkit 0.66.1 → 0.68.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.
Files changed (93) hide show
  1. package/dist/agent-runtime.js +5 -6
  2. package/dist/application/admission.d.ts +131 -0
  3. package/dist/application/admission.d.ts.map +1 -0
  4. package/dist/application/channel.d.ts +106 -0
  5. package/dist/application/channel.d.ts.map +1 -0
  6. package/dist/application/graph.d.ts +1 -1
  7. package/dist/application/graph.d.ts.map +1 -1
  8. package/dist/application/kernel.d.ts.map +1 -1
  9. package/dist/application/latest-sink.d.ts.map +1 -1
  10. package/dist/application/resource.d.ts +72 -1
  11. package/dist/application/resource.d.ts.map +1 -1
  12. package/dist/application/server-resource.d.ts +26 -5
  13. package/dist/application/server-resource.d.ts.map +1 -1
  14. package/dist/application-grammy.js +2 -2
  15. package/dist/application-opentelemetry.js +1 -1
  16. package/dist/application.d.ts +4 -2
  17. package/dist/application.d.ts.map +1 -1
  18. package/dist/application.js +408 -24
  19. package/dist/browser/client.d.ts +2 -3
  20. package/dist/browser/client.d.ts.map +1 -1
  21. package/dist/browser/contract-stream.d.ts +5 -0
  22. package/dist/browser/contract-stream.d.ts.map +1 -0
  23. package/dist/browser/http.d.ts +3 -0
  24. package/dist/browser/http.d.ts.map +1 -1
  25. package/dist/browser/stream.d.ts +4 -1
  26. package/dist/browser/stream.d.ts.map +1 -1
  27. package/dist/browser/transport.d.ts +3 -0
  28. package/dist/browser/transport.d.ts.map +1 -0
  29. package/dist/cli.js +6 -7
  30. package/dist/contract/define.d.ts +34 -2
  31. package/dist/contract/define.d.ts.map +1 -1
  32. package/dist/contract/errors.d.ts +4 -0
  33. package/dist/contract/errors.d.ts.map +1 -1
  34. package/dist/contract/index.d.ts +2 -1
  35. package/dist/contract/index.d.ts.map +1 -1
  36. package/dist/contract/index.js +5 -1
  37. package/dist/contract/stream.d.ts +19 -0
  38. package/dist/contract/stream.d.ts.map +1 -0
  39. package/dist/{index-xxye8j3k.js → index-0w9abg87.js} +4 -0
  40. package/dist/index-2k4yrqkc.js +9 -0
  41. package/dist/index-69m2278y.js +115 -0
  42. package/dist/{index-eabpd4tb.js → index-6wzr93cg.js} +21 -2
  43. package/dist/{index-1pgeyyee.js → index-7pn02bgv.js} +4 -6
  44. package/dist/index-9ky9hhg3.js +484 -0
  45. package/dist/{index-wrhf06ak.js → index-avjd67h6.js} +8 -8
  46. package/dist/{index-413xk7ga.js → index-cq9q73nf.js} +50 -1
  47. package/dist/{index-6taryy00.js → index-dafax5md.js} +1 -1
  48. package/dist/{index-s1tywej8.js → index-nymn7wbg.js} +1103 -20
  49. package/dist/{index-y91zd0ch.js → index-pr0qsmjy.js} +3 -2
  50. package/dist/index-v5bayx1z.js +138 -0
  51. package/dist/{index-mfw1pec7.js → index-wqyrvhzz.js} +3 -3
  52. package/dist/{index-svqhcrrj.js → index-zd4v31v2.js} +156 -10
  53. package/dist/{index-x8v8b7rc.js → index-zpyj7hsv.js} +330 -58
  54. package/dist/index.js +270 -105
  55. package/dist/internal/bounded-lines.d.ts +4 -0
  56. package/dist/internal/bounded-lines.d.ts.map +1 -0
  57. package/dist/node.d.ts +1 -0
  58. package/dist/node.d.ts.map +1 -1
  59. package/dist/node.js +11 -8
  60. package/dist/observability/index.js +6 -7
  61. package/dist/remote.js +5 -6
  62. package/dist/server/contract-stream.d.ts +5 -0
  63. package/dist/server/contract-stream.d.ts.map +1 -0
  64. package/dist/server/create.d.ts.map +1 -1
  65. package/dist/server/implement.d.ts.map +1 -1
  66. package/dist/server/index.d.ts +1 -0
  67. package/dist/server/index.d.ts.map +1 -1
  68. package/dist/server/index.js +41 -283
  69. package/dist/server/openapi.d.ts.map +1 -1
  70. package/dist/server/process-signals.d.ts.map +1 -1
  71. package/dist/server/stream.d.ts +3 -1
  72. package/dist/server/stream.d.ts.map +1 -1
  73. package/dist/server/streaming-route.d.ts +2 -0
  74. package/dist/server/streaming-route.d.ts.map +1 -1
  75. package/dist/server/types.d.ts +13 -3
  76. package/dist/server/types.d.ts.map +1 -1
  77. package/dist/server/unix-client-body.d.ts +4 -0
  78. package/dist/server/unix-client-body.d.ts.map +1 -0
  79. package/dist/server/unix-client-bun.d.ts +13 -0
  80. package/dist/server/unix-client-bun.d.ts.map +1 -0
  81. package/dist/server/unix-client-error.d.ts +9 -0
  82. package/dist/server/unix-client-error.d.ts.map +1 -0
  83. package/dist/server/unix-client.d.ts +25 -0
  84. package/dist/server/unix-client.d.ts.map +1 -0
  85. package/dist/testing.js +7 -5
  86. package/dist/tools.js +14 -16
  87. package/llms-full.txt +594 -29
  88. package/package.json +1 -1
  89. package/dist/index-48ffdxgk.js +0 -6
  90. package/dist/index-pzyt11ch.js +0 -127
  91. package/dist/index-tvwcrx2d.js +0 -224
  92. package/dist/index-wd8g8z6e.js +0 -206
  93. package/dist/index-yr276yz0.js +0 -6
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  ALL_TRANSPORTS,
3
3
  AppError,
4
+ ContractStreamFrameSchema,
5
+ DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
4
6
  ManagedFilePathSchema,
5
7
  ManagedFileRefSchema,
6
8
  STITCH_ERROR_STATUS,
@@ -19,7 +21,7 @@ import {
19
21
  parseTrailingWildcard,
20
22
  rateLimited,
21
23
  unauthorized
22
- } from "./index-413xk7ga.js";
24
+ } from "./index-cq9q73nf.js";
23
25
  import {
24
26
  isRecord,
25
27
  mapObject,
@@ -296,6 +298,102 @@ function joinClientBaseUrl(baseUrl, relativeUrl) {
296
298
  return `${base}${path}`;
297
299
  }
298
300
 
301
+ // src/internal/bounded-lines.ts
302
+ var DEFAULT_STREAM_LINE_BYTES = 1024 * 1024;
303
+ function lineLimit(value) {
304
+ const resolved = value ?? DEFAULT_STREAM_LINE_BYTES;
305
+ if (!Number.isSafeInteger(resolved) || resolved <= 0) {
306
+ throw new TypeError("maxLineBytes must be a positive safe integer");
307
+ }
308
+ return resolved;
309
+ }
310
+ function joinBytes(left, right) {
311
+ if (left.byteLength === 0)
312
+ return right.slice();
313
+ const result = new Uint8Array(left.byteLength + right.byteLength);
314
+ result.set(left);
315
+ result.set(right, left.byteLength);
316
+ return result;
317
+ }
318
+ async function* readBoundedUtf8Lines(response, maxLineBytes) {
319
+ const reader = response.body?.getReader();
320
+ if (!reader)
321
+ return;
322
+ const limit = lineLimit(maxLineBytes);
323
+ const decoder = new TextDecoder("utf-8", { fatal: true });
324
+ let pending = new Uint8Array;
325
+ try {
326
+ for (;; ) {
327
+ const chunk = await reader.read();
328
+ if (chunk.done)
329
+ break;
330
+ let start = 0;
331
+ for (let index = 0;index < chunk.value.byteLength; index += 1) {
332
+ if (chunk.value[index] !== 10)
333
+ continue;
334
+ const lineBytes = joinBytes(pending, chunk.value.slice(start, index));
335
+ if (lineBytes.byteLength > limit) {
336
+ throw new RangeError(`Stream line exceeds the ${limit} byte limit`);
337
+ }
338
+ yield decoder.decode(lineBytes);
339
+ pending = new Uint8Array;
340
+ start = index + 1;
341
+ }
342
+ pending = joinBytes(pending, chunk.value.slice(start));
343
+ if (pending.byteLength > limit) {
344
+ throw new RangeError(`Stream line exceeds the ${limit} byte limit`);
345
+ }
346
+ }
347
+ if (pending.byteLength > 0)
348
+ yield decoder.decode(pending);
349
+ } finally {
350
+ await reader.cancel().catch(() => {
351
+ return;
352
+ });
353
+ reader.releaseLock();
354
+ }
355
+ }
356
+
357
+ // src/internal/errors.ts
358
+ import { z } from "zod";
359
+ function issuePath(path) {
360
+ return path.length > 0 ? path.map(String).join(".") : "(root)";
361
+ }
362
+ function zodIssues(error) {
363
+ return error.issues.map((issue) => ({
364
+ path: issuePath(issue.path),
365
+ code: issue.code,
366
+ message: issue.message
367
+ }));
368
+ }
369
+
370
+ // src/server/stream.ts
371
+ async function* parseSSE(response, options) {
372
+ try {
373
+ for await (const rawLine of readBoundedUtf8Lines(response, options?.maxLineBytes ?? DEFAULT_STREAM_LINE_BYTES)) {
374
+ const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
375
+ if (!line.startsWith("data:"))
376
+ continue;
377
+ const data = line.slice(5).replace(/^ /, "");
378
+ if (data === "[DONE]")
379
+ return;
380
+ try {
381
+ yield JSON.parse(data);
382
+ } catch (error) {
383
+ const failure = error instanceof Error ? error : new Error(String(error));
384
+ if (!options?.onParseError)
385
+ throw failure;
386
+ options.onParseError(data, failure);
387
+ }
388
+ }
389
+ } catch (error) {
390
+ const failure = error instanceof Error ? error : new Error(String(error));
391
+ if (!options?.onParseError)
392
+ throw failure;
393
+ options.onParseError("", failure);
394
+ }
395
+ }
396
+
299
397
  // src/browser/http.ts
300
398
  import ky, {
301
399
  isHTTPError,
@@ -402,8 +500,8 @@ function parseApiErrorBody(body) {
402
500
  hint: typeof error.hint === "string" ? error.hint : undefined
403
501
  };
404
502
  }
405
- function createRetryAwareFetch(unix) {
406
- const runtimeFetch = globalThis.fetch.bind(globalThis);
503
+ function createRetryAwareFetch(transportFetch, unix) {
504
+ const runtimeFetch = transportFetch;
407
505
  let attempt = 0;
408
506
  return (input, init) => {
409
507
  attempt += 1;
@@ -411,10 +509,13 @@ function createRetryAwareFetch(unix) {
411
509
  return runtimeFetch(input, init);
412
510
  }
413
511
  if (!(input instanceof Request)) {
414
- return runtimeFetch(input, unix === undefined ? init : { ...init, unix });
512
+ if (unix === undefined)
513
+ return runtimeFetch(input, init);
514
+ const unixInit = { ...init, unix };
515
+ return runtimeFetch(input, unixInit);
415
516
  }
416
517
  const streamedBody = input.body ? { body: input.body, duplex: "half" } : {};
417
- return runtimeFetch(input.url, {
518
+ const materialized = {
418
519
  ...init,
419
520
  ...unix !== undefined && { unix },
420
521
  method: input.method,
@@ -429,10 +530,22 @@ function createRetryAwareFetch(unix) {
429
530
  referrer: input.referrer,
430
531
  referrerPolicy: input.referrerPolicy,
431
532
  signal: input.signal
432
- });
533
+ };
534
+ return runtimeFetch(input.url, materialized);
433
535
  };
434
536
  }
435
537
  function createHttpClient(config) {
538
+ if (config.fetch && config.unix) {
539
+ throw new TypeError("HttpClientConfig.fetch and unix are mutually exclusive");
540
+ }
541
+ if (config.unix !== undefined) {
542
+ if (!config.unix.startsWith("/") || config.unix.includes("\x00")) {
543
+ throw new TypeError("HttpClientConfig.unix must be an absolute Unix socket path");
544
+ }
545
+ if (typeof Reflect.get(globalThis, "Bun") !== "object") {
546
+ throw new TypeError("HttpClientConfig.unix requires Bun; on Bun or Node use createUnixClientTransport().fetch for an explicit portable transport");
547
+ }
548
+ }
436
549
  let ssrCookies = null;
437
550
  let isLoggedOut = false;
438
551
  const listeners = new Set;
@@ -497,7 +610,7 @@ function createHttpClient(config) {
497
610
  async function request(method, url, data, options = {}) {
498
611
  const cancellation = createRequestCancellation(options.signal, options.timeout ?? config.timeout ?? 30000);
499
612
  const kyOptions = {
500
- fetch: createRetryAwareFetch(config.unix),
613
+ fetch: createRetryAwareFetch(config.fetch ?? globalThis.fetch.bind(globalThis), config.unix),
501
614
  timeout: false,
502
615
  signal: cancellation.signal
503
616
  };
@@ -579,10 +692,103 @@ function createHttpClient(config) {
579
692
  }
580
693
  };
581
694
  }
695
+ // src/browser/stream.ts
696
+ function parseFailure(raw, error, onParseError) {
697
+ const failure = error instanceof Error ? error : new Error(String(error));
698
+ if (!onParseError)
699
+ throw failure;
700
+ onParseError(raw, failure);
701
+ }
702
+ async function* parseNDJSON(response, options) {
703
+ try {
704
+ for await (const rawLine of readBoundedUtf8Lines(response, options?.maxLineBytes ?? DEFAULT_STREAM_LINE_BYTES)) {
705
+ const line = (rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine).trim();
706
+ if (line === "")
707
+ continue;
708
+ try {
709
+ yield JSON.parse(line);
710
+ } catch (error) {
711
+ parseFailure(line, error, options?.onParseError);
712
+ }
713
+ }
714
+ } catch (error) {
715
+ parseFailure("", error, options?.onParseError);
716
+ }
717
+ }
718
+
719
+ // src/browser/contract-stream.ts
720
+ function sourceFor(response, descriptor) {
721
+ const options = {
722
+ maxLineBytes: descriptor.maxFrameBytes ?? DEFAULT_CONTRACT_STREAM_FRAME_BYTES
723
+ };
724
+ return descriptor.format === "sse" ? parseSSE(response, options) : parseNDJSON(response, options);
725
+ }
726
+ async function* readContractStream(response, descriptor, abort) {
727
+ let ended = false;
728
+ let terminalSeen = descriptor.terminal === undefined;
729
+ try {
730
+ for await (const raw of sourceFor(response, descriptor)) {
731
+ const parsedFrame = ContractStreamFrameSchema.safeParse(raw);
732
+ if (!parsedFrame.success) {
733
+ throw new ApiError("STREAM_PROTOCOL_ERROR", 0, undefined, "Stream frame did not match the protocol envelope");
734
+ }
735
+ const frame = parsedFrame.data;
736
+ if (frame.type === "error") {
737
+ throw new ApiError(frame.error.code, 0, frame.error.details, frame.error.message, frame.error.hint);
738
+ }
739
+ if (frame.type === "end") {
740
+ if (!terminalSeen) {
741
+ throw new ApiError("STREAM_TERMINAL_MISSING", 0, undefined, "Stream completed before its declared terminal item");
742
+ }
743
+ ended = true;
744
+ return;
745
+ }
746
+ const parsedItem = descriptor.item.safeParse(frame.data);
747
+ if (!parsedItem.success) {
748
+ throw new ApiError("STREAM_ITEM_INVALID", 0, undefined, "Stream item did not match its contract");
749
+ }
750
+ const item = parsedItem.data;
751
+ if (descriptor.terminal?.safeParse(item).success)
752
+ terminalSeen = true;
753
+ yield item;
754
+ }
755
+ if (!ended) {
756
+ throw new ApiError("STREAM_TRUNCATED", 0, undefined, "Stream ended without its protocol terminal frame");
757
+ }
758
+ } finally {
759
+ abort();
760
+ }
761
+ }
762
+
763
+ class OwnedContractStream {
764
+ #inner;
765
+ #abort;
766
+ constructor(inner, abort) {
767
+ this.#inner = inner;
768
+ this.#abort = abort;
769
+ }
770
+ [Symbol.asyncIterator]() {
771
+ return this;
772
+ }
773
+ next() {
774
+ return this.#inner.next();
775
+ }
776
+ return() {
777
+ this.#abort();
778
+ return this.#inner.return(undefined);
779
+ }
780
+ throw(error) {
781
+ this.#abort();
782
+ return this.#inner.throw(error);
783
+ }
784
+ }
785
+ function parseContractStream(response, descriptor, abort) {
786
+ return new OwnedContractStream(readContractStream(response, descriptor, abort), abort);
787
+ }
582
788
 
583
789
  // src/browser/client.ts
584
790
  function withTimeout(options, endpoint) {
585
- const responseType = endpoint.rawResponse ? "response" : endpoint.output ? undefined : "void";
791
+ const responseType = endpoint.rawResponse || "stream" in endpoint ? "response" : endpoint.output ? undefined : "void";
586
792
  if (endpoint.timeout === undefined && responseType === undefined)
587
793
  return options;
588
794
  return {
@@ -591,9 +797,23 @@ function withTimeout(options, endpoint) {
591
797
  ...responseType && { responseType }
592
798
  };
593
799
  }
594
- function withOutput(endpoint, result) {
800
+ function withOutput(endpoint, result, abortStream) {
595
801
  if (endpoint.rawResponse)
596
802
  return result;
803
+ if ("stream" in endpoint && endpoint.stream) {
804
+ return result.then((value) => {
805
+ if (!(value instanceof Response)) {
806
+ abortStream?.();
807
+ throw new Error("Streaming endpoint did not return a Response");
808
+ }
809
+ return parseContractStream(value, endpoint.stream, abortStream ?? (() => {
810
+ return;
811
+ }));
812
+ }, (error) => {
813
+ abortStream?.();
814
+ throw error;
815
+ });
816
+ }
597
817
  const schema = endpoint.output;
598
818
  return result.then((value) => {
599
819
  if (!schema) {
@@ -690,20 +910,26 @@ function createHttpExecutor(endpoint, prefix, client, config) {
690
910
  const httpMethod = endpoint.method.toLowerCase();
691
911
  return (requestArgs, options) => {
692
912
  const plan = planClientRequest(endpoint, prefix, requestArgs, config);
913
+ const streamAbort = "stream" in endpoint ? new AbortController : undefined;
914
+ const requestOptions = streamAbort ? {
915
+ ...options,
916
+ signal: options?.signal ? AbortSignal.any([options.signal, streamAbort.signal]) : streamAbort.signal
917
+ } : options;
918
+ const finishStream = streamAbort ? () => streamAbort.abort() : undefined;
693
919
  if (endpoint.multipart) {
694
920
  if (httpMethod === "get" || httpMethod === "head" || httpMethod === "delete") {
695
921
  throw new Error(`Multipart endpoint ${endpoint.method} ${endpoint.path} must be POST / PUT / PATCH`);
696
922
  }
697
923
  const formData = buildMultipartForm(endpoint.multipart, plan.remainingArgs);
698
- return withOutput(endpoint, client[httpMethod](plan.relativeUrl, formData, withTimeout(options, endpoint)));
924
+ return withOutput(endpoint, client[httpMethod](plan.relativeUrl, formData, withTimeout(requestOptions, endpoint)), finishStream);
699
925
  }
700
926
  if (httpMethod === "get" || httpMethod === "head") {
701
- return withOutput(endpoint, client[httpMethod](plan.relativeUrl, withTimeout(options, endpoint)));
927
+ return withOutput(endpoint, client[httpMethod](plan.relativeUrl, withTimeout(requestOptions, endpoint)), finishStream);
702
928
  }
703
929
  if (httpMethod === "delete") {
704
- return withOutput(endpoint, client.delete(plan.relativeUrl, withTimeout(options, endpoint)));
930
+ return withOutput(endpoint, client.delete(plan.relativeUrl, withTimeout(requestOptions, endpoint)), finishStream);
705
931
  }
706
- return withOutput(endpoint, client[httpMethod](plan.relativeUrl, Object.keys(plan.remainingArgs).length > 0 ? plan.remainingArgs : undefined, withTimeout(options, endpoint)));
932
+ return withOutput(endpoint, client[httpMethod](plan.relativeUrl, Object.keys(plan.remainingArgs).length > 0 ? plan.remainingArgs : undefined, withTimeout(requestOptions, endpoint)), finishStream);
707
933
  };
708
934
  }
709
935
  function createFetchExecutor(endpoint, prefix, config, contractConfig) {
@@ -715,7 +941,32 @@ function createFetchExecutor(endpoint, prefix, config, contractConfig) {
715
941
  Accept: "application/json",
716
942
  ...typeof config.headers === "function" ? config.headers() : config.headers
717
943
  };
718
- const cancellation = createRequestCancellation(options?.signal, endpoint.timeout ?? config.timeout ?? 30000);
944
+ const streamAbort = "stream" in endpoint ? new AbortController : undefined;
945
+ const requestSignal = streamAbort ? options?.signal ? AbortSignal.any([options.signal, streamAbort.signal]) : streamAbort.signal : options?.signal;
946
+ const openTimeoutMs = endpoint.timeout ?? config.timeout ?? 30000;
947
+ const cancellation = streamAbort ? {
948
+ signal: requestSignal,
949
+ async run(operation) {
950
+ let timedOut = false;
951
+ const timer = setTimeout(() => {
952
+ timedOut = true;
953
+ streamAbort.abort(new DOMException("Request timed out", "TimeoutError"));
954
+ }, openTimeoutMs);
955
+ try {
956
+ if (options?.signal?.aborted)
957
+ throw new RequestCancellationError("caller");
958
+ return await operation(requestSignal);
959
+ } catch (error) {
960
+ if (timedOut)
961
+ throw new RequestCancellationError("timeout");
962
+ if (options?.signal?.aborted)
963
+ throw new RequestCancellationError("caller");
964
+ throw error;
965
+ } finally {
966
+ clearTimeout(timer);
967
+ }
968
+ }
969
+ } : createRequestCancellation(requestSignal, openTimeoutMs);
719
970
  const hasBody = endpoint.method !== "GET" && endpoint.method !== "HEAD" && endpoint.method !== "DELETE" && !endpoint.multipart && endpoint.input && Object.keys(plan.remainingArgs).length > 0;
720
971
  if (hasBody)
721
972
  headers["Content-Type"] = "application/json";
@@ -734,6 +985,9 @@ function createFetchExecutor(endpoint, prefix, config, contractConfig) {
734
985
  }
735
986
  if (endpoint.rawResponse)
736
987
  return res;
988
+ if ("stream" in endpoint && endpoint.stream) {
989
+ return parseContractStream(res, endpoint.stream, () => streamAbort?.abort());
990
+ }
737
991
  if (!endpoint.output) {
738
992
  const text = await res.text();
739
993
  if (text.length > 0) {
@@ -864,19 +1118,6 @@ class RealtimeRequestRejectedError extends Error {
864
1118
  }
865
1119
  }
866
1120
 
867
- // src/internal/errors.ts
868
- import { z } from "zod";
869
- function issuePath(path) {
870
- return path.length > 0 ? path.map(String).join(".") : "(root)";
871
- }
872
- function zodIssues(error) {
873
- return error.issues.map((issue) => ({
874
- path: issuePath(issue.path),
875
- code: issue.code,
876
- message: issue.message
877
- }));
878
- }
879
-
880
1121
  // src/realtime/rejected-frame.ts
881
1122
  var REALTIME_REJECTION_KEY = "@stitchkit/realtime-rejected";
882
1123
  var MAX_REJECTION_ISSUES = 20;
@@ -1500,84 +1741,6 @@ function createSocketIOClient(config) {
1500
1741
  }
1501
1742
  };
1502
1743
  }
1503
- // src/server/stream.ts
1504
- async function* parseSSE(response, options) {
1505
- const reader = response.body?.getReader();
1506
- if (!reader)
1507
- return;
1508
- const decoder = new TextDecoder;
1509
- let buffer = "";
1510
- try {
1511
- while (true) {
1512
- const { done, value } = await reader.read();
1513
- if (done)
1514
- break;
1515
- buffer += decoder.decode(value, { stream: true });
1516
- const lines = buffer.split(`
1517
- `);
1518
- buffer = lines.pop() ?? "";
1519
- for (const rawLine of lines) {
1520
- const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
1521
- if (!line.startsWith("data:"))
1522
- continue;
1523
- const data = line.slice(5).replace(/^ /, "");
1524
- if (data === "[DONE]")
1525
- return;
1526
- try {
1527
- yield JSON.parse(data);
1528
- } catch (err) {
1529
- options?.onParseError?.(data, err instanceof Error ? err : new Error(String(err)));
1530
- }
1531
- }
1532
- }
1533
- } finally {
1534
- reader.releaseLock();
1535
- }
1536
- }
1537
-
1538
- // src/browser/stream.ts
1539
- async function* parseNDJSON(response, options) {
1540
- const reader = response.body?.getReader();
1541
- if (!reader)
1542
- return;
1543
- const decoder = new TextDecoder;
1544
- let buffer = "";
1545
- try {
1546
- for (;; ) {
1547
- const { done, value } = await reader.read();
1548
- if (done)
1549
- break;
1550
- buffer += decoder.decode(value, { stream: true });
1551
- const lines = buffer.split(`
1552
- `);
1553
- buffer = lines.pop() ?? "";
1554
- for (const rawLine of lines) {
1555
- const line = (rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine).trim();
1556
- if (line === "")
1557
- continue;
1558
- try {
1559
- yield JSON.parse(line);
1560
- } catch (err) {
1561
- options?.onParseError?.(line, err instanceof Error ? err : new Error(String(err)));
1562
- }
1563
- }
1564
- }
1565
- buffer += decoder.decode();
1566
- const tail = buffer.trim();
1567
- if (tail !== "") {
1568
- try {
1569
- yield JSON.parse(tail);
1570
- } catch (err) {
1571
- options?.onParseError?.(tail, err instanceof Error ? err : new Error(String(err)));
1572
- }
1573
- }
1574
- } finally {
1575
- await reader.cancel().catch(() => {
1576
- return;
1577
- });
1578
- reader.releaseLock();
1579
- }
1580
- }
1581
1744
  // src/realtime/contract.ts
1582
1745
  function defineRealtimeContract(contract) {
1583
1746
  return contract;
@@ -1586,6 +1749,8 @@ export {
1586
1749
  ALL_TRANSPORTS,
1587
1750
  ApiError,
1588
1751
  AppError,
1752
+ ContractStreamFrameSchema,
1753
+ DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
1589
1754
  ManagedFilePathSchema,
1590
1755
  ManagedFileRefSchema,
1591
1756
  REALTIME_REJECTION_KEY,
@@ -0,0 +1,4 @@
1
+ export declare const DEFAULT_STREAM_LINE_BYTES: number;
2
+ /** Bounded, fatal-UTF-8 line reader shared by NDJSON and SSE parsers. */
3
+ export declare function readBoundedUtf8Lines(response: Response, maxLineBytes?: number): AsyncGenerator<string>;
4
+ //# sourceMappingURL=bounded-lines.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bounded-lines.d.ts","sourceRoot":"","sources":["../../src/internal/bounded-lines.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,QAAc,CAAC;AAkBrD,yEAAyE;AACzE,wBAAuB,oBAAoB,CACzC,QAAQ,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,MAAM,GACpB,cAAc,CAAC,MAAM,CAAC,CAgCxB"}
package/dist/node.d.ts CHANGED
@@ -14,4 +14,5 @@ export { bindRealtimeServer, type RealtimeServer, type RealtimeServerConnection,
14
14
  export { type ManagedServerHandle, type ShutdownOptions, ShutdownOptionsSchema, type ShutdownResult, ShutdownResultSchema, type ShutdownState, ShutdownStateSchema, type ShutdownStatus, ShutdownStatusSchema, } from './server/shutdown';
15
15
  export { createNodeSocketIOServer as createSocketIOServer, type NodeSocketIOServerHandle as SocketIOServerHandle, type SocketIOHandshakeConfig, type SocketIOPeerLoaders, type SocketIORequestPolicy, type SocketIOServerConfig, } from './server/socket-io-node';
16
16
  export type { EffectiveScope, FetchComposition, FetchHandler, HandlerConfig, LoggingConfig, LogOutcome, RawRoute, RawRouteContext, ScopeContexts, ScopedHandlers, ServiceDef, } from './server/types';
17
+ export { createUnixClientTransport, type UnixClientDeliveryState, type UnixClientTransport, type UnixClientTransportConfig, UnixClientTransportError, type UnixClientTransportErrorCode, } from './server/unix-client';
17
18
  //# sourceMappingURL=node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,6BAA6B,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,SAAS,EACT,iBAAiB,EACjB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,4BAA4B,EACjC,KAAK,sBAAsB,EAC3B,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,cAAc,EACnB,oBAAoB,EACpB,KAAK,aAAa,EAClB,mBAAmB,EACnB,KAAK,cAAc,EACnB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,wBAAwB,IAAI,oBAAoB,EAChD,KAAK,wBAAwB,IAAI,oBAAoB,EACrD,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,UAAU,EACV,QAAQ,EACR,eAAe,EACf,aAAa,EACb,cAAc,EACd,UAAU,GACX,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,6BAA6B,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,SAAS,EACT,iBAAiB,EACjB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,4BAA4B,EACjC,KAAK,sBAAsB,EAC3B,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,cAAc,EACnB,oBAAoB,EACpB,KAAK,aAAa,EAClB,mBAAmB,EACnB,KAAK,cAAc,EACnB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,wBAAwB,IAAI,oBAAoB,EAChD,KAAK,wBAAwB,IAAI,oBAAoB,EACrD,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,UAAU,EACV,QAAQ,EACR,eAAe,EACf,aAAa,EACb,cAAc,EACd,UAAU,GACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,yBAAyB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,wBAAwB,EACxB,KAAK,4BAA4B,GAClC,MAAM,sBAAsB,CAAC"}
package/dist/node.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import {
2
+ UnixClientTransportError,
2
3
  bindProcessSignals,
3
4
  bindRealtimeServer,
4
5
  createHandler,
5
- createSocketIOServer
6
- } from "./index-s1tywej8.js";
6
+ createSocketIOServer,
7
+ createUnixClientTransport
8
+ } from "./index-nymn7wbg.js";
7
9
  import {
8
10
  createImplement,
9
11
  createImplementRegistry,
@@ -12,7 +14,7 @@ import {
12
14
  createScopedImplementRegistry,
13
15
  implement,
14
16
  implementRegistry
15
- } from "./index-y91zd0ch.js";
17
+ } from "./index-pr0qsmjy.js";
16
18
  import"./index-557by2db.js";
17
19
  import {
18
20
  ShutdownOptionsSchema,
@@ -21,10 +23,8 @@ import {
21
23
  ShutdownStatusSchema,
22
24
  createServerLifecycle
23
25
  } from "./index-dk6e56g0.js";
24
- import"./index-tvwcrx2d.js";
25
- import"./index-wd8g8z6e.js";
26
- import"./index-6k1937bx.js";
27
- import"./index-pzyt11ch.js";
26
+ import"./index-69m2278y.js";
27
+ import"./index-9ky9hhg3.js";
28
28
  import"./index-smpbdg6k.js";
29
29
  import {
30
30
  AppError,
@@ -35,7 +35,8 @@ import {
35
35
  notFound,
36
36
  rateLimited,
37
37
  unauthorized
38
- } from "./index-xxye8j3k.js";
38
+ } from "./index-0w9abg87.js";
39
+ import"./index-6k1937bx.js";
39
40
  // src/server/node.ts
40
41
  import { serve } from "srvx/node";
41
42
 
@@ -251,6 +252,7 @@ export {
251
252
  ShutdownResultSchema,
252
253
  ShutdownStateSchema,
253
254
  ShutdownStatusSchema,
255
+ UnixClientTransportError,
254
256
  appError,
255
257
  badRequest,
256
258
  bindProcessSignals,
@@ -263,6 +265,7 @@ export {
263
265
  createScopedImplement,
264
266
  createScopedImplementRegistry,
265
267
  createNodeSocketIOServer as createSocketIOServer,
268
+ createUnixClientTransport,
266
269
  forbidden,
267
270
  implement,
268
271
  implementRegistry,
@@ -10,33 +10,32 @@ import {
10
10
  redact,
11
11
  sanitizePayload,
12
12
  truncatePreview
13
- } from "../index-6taryy00.js";
13
+ } from "../index-dafax5md.js";
14
14
  import {
15
15
  getRequestContext,
16
16
  getTraceId,
17
17
  getUserId,
18
- recordedErrorMessage,
19
18
  runWithRequestContext,
20
19
  setRequestDimensions,
21
20
  setRequestEndpoint,
22
21
  setRequestError,
23
22
  setRequestUser,
24
23
  wrapInRequestContext
25
- } from "../index-tvwcrx2d.js";
26
- import"../index-wd8g8z6e.js";
27
- import"../index-6k1937bx.js";
24
+ } from "../index-69m2278y.js";
28
25
  import {
29
26
  childSpan,
30
27
  createTraceContext,
31
28
  formatTraceparent,
32
29
  parseTraceparent,
30
+ recordedErrorMessage,
33
31
  resolvePropagationContext,
34
32
  resolveTraceContext
35
- } from "../index-pzyt11ch.js";
33
+ } from "../index-9ky9hhg3.js";
36
34
  import {
37
35
  isRecord
38
36
  } from "../index-smpbdg6k.js";
39
- import"../index-xxye8j3k.js";
37
+ import"../index-0w9abg87.js";
38
+ import"../index-6k1937bx.js";
40
39
 
41
40
  // src/observability/audit.ts
42
41
  function toolErrorMessage(result) {
package/dist/remote.js CHANGED
@@ -1,19 +1,18 @@
1
1
  import {
2
2
  ApiError,
3
3
  createClient
4
- } from "./index-svqhcrrj.js";
5
- import"./index-48ffdxgk.js";
4
+ } from "./index-zd4v31v2.js";
5
+ import"./index-v5bayx1z.js";
6
6
  import {
7
7
  mergeMeta
8
- } from "./index-wd8g8z6e.js";
9
- import"./index-6k1937bx.js";
10
- import"./index-pzyt11ch.js";
8
+ } from "./index-9ky9hhg3.js";
11
9
  import {
12
10
  isRecord
13
11
  } from "./index-smpbdg6k.js";
14
12
  import {
15
13
  AppError
16
- } from "./index-xxye8j3k.js";
14
+ } from "./index-0w9abg87.js";
15
+ import"./index-6k1937bx.js";
17
16
 
18
17
  // src/tools/remote.ts
19
18
  var HTTP_ONLY = Object.freeze(["HTTP"]);
@@ -0,0 +1,5 @@
1
+ import { type EndpointStreamDescriptor } from '../contract';
2
+ import type { RawRouteContext } from './types';
3
+ /** Build the HTTP response for one contract-declared stream. */
4
+ export declare function contractStreamResponse(request: Request, context: RawRouteContext, source: AsyncIterable<unknown>, descriptor: EndpointStreamDescriptor, operationAbort: AbortController): Promise<Response>;
5
+ //# sourceMappingURL=contract-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-stream.d.ts","sourceRoot":"","sources":["../../src/server/contract-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAiB/C,gEAAgE;AAChE,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAC9B,UAAU,EAAE,wBAAwB,EACpC,cAAc,EAAE,eAAe,GAC9B,OAAO,CAAC,QAAQ,CAAC,CAmFnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.ts"],"names":[],"mappings":"AAqDA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAA2B,MAAM,SAAS,CAAC;AA2BpF,wBAAgB,aAAa,CAAC,OAAO,GAAG,OAAO,EAC7C,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,GAC7B,YAAY,CAAC,OAAO,CAAC,CA8gBvB"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.ts"],"names":[],"mappings":"AAsDA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAA2B,MAAM,SAAS,CAAC;AAkCpF,wBAAgB,aAAa,CAAC,OAAO,GAAG,OAAO,EAC7C,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,GAC7B,YAAY,CAAC,OAAO,CAAC,CAijBvB"}