stitchkit 0.118.1 → 0.119.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 (144) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/browser/http.d.ts.map +1 -1
  3. package/dist/contract/client-types.d.ts +6 -3
  4. package/dist/contract/client-types.d.ts.map +1 -1
  5. package/dist/contract/define-validation.d.ts.map +1 -1
  6. package/dist/contract/define.d.ts +18 -12
  7. package/dist/contract/define.d.ts.map +1 -1
  8. package/dist/contract/endpoint-capabilities.d.ts +28 -0
  9. package/dist/contract/endpoint-capabilities.d.ts.map +1 -0
  10. package/dist/contract/factory.d.ts +49 -19
  11. package/dist/contract/factory.d.ts.map +1 -1
  12. package/dist/contract/tool-view.d.ts +1 -1
  13. package/dist/contract/tool-view.d.ts.map +1 -1
  14. package/dist/contract/transports.d.ts +5 -0
  15. package/dist/contract/transports.d.ts.map +1 -0
  16. package/dist/entrypoints/agent-runtime/coding-tools.js +6 -5
  17. package/dist/entrypoints/agent-runtime/harness.js +6 -5
  18. package/dist/entrypoints/agent-runtime/sandbox.js +6 -5
  19. package/dist/entrypoints/agent-runtime/sqlite/bun.js +9 -8
  20. package/dist/entrypoints/agent-runtime/sqlite/node.js +9 -8
  21. package/dist/entrypoints/agent-runtime/testing.js +9 -8
  22. package/dist/entrypoints/agent-runtime.js +14 -13
  23. package/dist/entrypoints/application/diagnostic-journal.js +3 -3
  24. package/dist/entrypoints/application/directory-inbox.js +4 -4
  25. package/dist/entrypoints/application/opentelemetry.js +1 -1
  26. package/dist/entrypoints/application.js +5 -5
  27. package/dist/entrypoints/cli/publish.js +4 -4
  28. package/dist/entrypoints/cli.js +8 -7
  29. package/dist/entrypoints/contract.d.ts +1 -1
  30. package/dist/entrypoints/contract.d.ts.map +1 -1
  31. package/dist/entrypoints/contract.js +6 -4
  32. package/dist/entrypoints/files.js +3 -3
  33. package/dist/entrypoints/geo/contract.d.ts +7 -0
  34. package/dist/entrypoints/geo/contract.d.ts.map +1 -0
  35. package/dist/entrypoints/geo/contract.js +6 -0
  36. package/dist/entrypoints/geo.js +60 -23
  37. package/dist/entrypoints/http.js +2 -2
  38. package/dist/entrypoints/index.js +8 -6
  39. package/dist/entrypoints/live.js +1 -1
  40. package/dist/entrypoints/node.js +7 -6
  41. package/dist/entrypoints/primitives.js +1 -1
  42. package/dist/entrypoints/process/owner-loss.js +1 -1
  43. package/dist/entrypoints/process.js +3 -3
  44. package/dist/entrypoints/react.js +1 -1
  45. package/dist/entrypoints/remote.js +4 -3
  46. package/dist/entrypoints/server.js +11 -10
  47. package/dist/entrypoints/telegram.js +2 -2
  48. package/dist/entrypoints/testing.js +7 -6
  49. package/dist/entrypoints/tools/connections.js +3 -2
  50. package/dist/entrypoints/tools/contract.js +1 -1
  51. package/dist/entrypoints/tools/invoker.js +5 -4
  52. package/dist/entrypoints/tools/mcp.js +7 -6
  53. package/dist/entrypoints/tools.js +17 -15
  54. package/dist/entrypoints/tracking/contract.js +5 -3
  55. package/dist/entrypoints/tracking/performance.js +3 -3
  56. package/dist/entrypoints/tracking.d.ts +1 -1
  57. package/dist/entrypoints/tracking.d.ts.map +1 -1
  58. package/dist/entrypoints/tracking.js +63 -83
  59. package/dist/entrypoints/xlsx.js +1 -1
  60. package/dist/geo/index.d.ts +2 -1
  61. package/dist/geo/index.d.ts.map +1 -1
  62. package/dist/geo/record.d.ts +8 -0
  63. package/dist/geo/record.d.ts.map +1 -0
  64. package/dist/geo/resolver.d.ts +1 -3
  65. package/dist/geo/resolver.d.ts.map +1 -1
  66. package/dist/geo/schema.d.ts +44 -0
  67. package/dist/geo/schema.d.ts.map +1 -0
  68. package/dist/geo/types.d.ts +2 -13
  69. package/dist/geo/types.d.ts.map +1 -1
  70. package/dist/{index-n5sv4z0w.js → index-1k18qzqa.js} +13 -15
  71. package/dist/{index-tsngj2b5.js → index-2dfvv1jg.js} +206 -206
  72. package/dist/{index-d9hq291n.js → index-4jpykzvw.js} +70 -81
  73. package/dist/{index-ghtpfz4z.js → index-57gqaq8b.js} +2 -2
  74. package/dist/index-69t14s4a.js +39 -0
  75. package/dist/{index-6p3frkv5.js → index-6a69xzrx.js} +4 -4
  76. package/dist/{index-dky0dcmf.js → index-72r9k0av.js} +6 -2
  77. package/dist/{index-vv1sch8a.js → index-8vzh5wpv.js} +13 -8
  78. package/dist/{index-xx1j310k.js → index-8yxgcyt6.js} +171 -169
  79. package/dist/{index-p6apg0jg.js → index-9frf01t9.js} +16 -9
  80. package/dist/{index-q0th8q0z.js → index-9mjrnqxs.js} +1 -3
  81. package/dist/{index-ega3yz4c.js → index-aqwg2dm5.js} +1 -1
  82. package/dist/{index-073nw9qr.js → index-ba7are04.js} +524 -522
  83. package/dist/{index-095ya5hm.js → index-bbvc59gw.js} +13 -11
  84. package/dist/{index-txg1npmg.js → index-cyxp8rbf.js} +1 -1
  85. package/dist/index-d3xdyjt6.js +38 -0
  86. package/dist/{index-n8z3rvzw.js → index-f4njz9j0.js} +3 -5
  87. package/dist/{index-90p34rts.js → index-fcqj44mb.js} +3 -1
  88. package/dist/{index-86nbfysb.js → index-ff39f9dr.js} +3 -3
  89. package/dist/{index-75ns2ybj.js → index-fqd4yqwd.js} +1 -1
  90. package/dist/{index-nqxrm176.js → index-g444vfz2.js} +1 -1
  91. package/dist/{index-vwhrnp67.js → index-kz9734jc.js} +3 -3
  92. package/dist/{index-dr3t5n1v.js → index-nn9qvkww.js} +46 -46
  93. package/dist/{index-qezhmp51.js → index-nz06qw5a.js} +3 -1
  94. package/dist/{index-1bx1xv1k.js → index-pfvde2fz.js} +5 -2
  95. package/dist/{index-s80awwsw.js → index-qch1vcaa.js} +3 -1
  96. package/dist/{index-cycp3r3e.js → index-rxcgp4b9.js} +2 -2
  97. package/dist/{index-w7jq3fz9.js → index-s0qjs6ee.js} +1198 -1196
  98. package/dist/{index-p0rf7sq9.js → index-s20s2mad.js} +209 -209
  99. package/dist/{index-v6vb5qx8.js → index-s3yxw6kt.js} +1 -1
  100. package/dist/{index-cqmqyjax.js → index-sa99p98w.js} +1 -1
  101. package/dist/{index-0gxvns6s.js → index-sba3e6m4.js} +1 -0
  102. package/dist/{index-f24bdt13.js → index-v1swr26p.js} +3 -1
  103. package/dist/{index-rhzkndr5.js → index-x4p3kw1p.js} +533 -530
  104. package/dist/{index-hdjmdwsj.js → index-x8d9fdeg.js} +513 -507
  105. package/dist/{index-htxh46ej.js → index-ycqhyars.js} +2 -2
  106. package/dist/{index-9bwcthxw.js → index-yj6saztf.js} +31 -13
  107. package/dist/{index-tdpmfks8.js → index-ynrf908v.js} +1 -1
  108. package/dist/{index-f6m4c545.js → index-zrdcmg6j.js} +4 -6
  109. package/dist/process/bun-child.d.ts +3 -2
  110. package/dist/process/bun-child.d.ts.map +1 -1
  111. package/dist/server/contract-method.d.ts.map +1 -1
  112. package/dist/tools/internal/surface-projector.d.ts.map +1 -1
  113. package/dist/tools/operations/async-operation-canonical-types.d.ts +1 -1
  114. package/dist/tracking/attribution.d.ts +21 -25
  115. package/dist/tracking/attribution.d.ts.map +1 -1
  116. package/dist/tracking/client-visit.d.ts +5 -7
  117. package/dist/tracking/client-visit.d.ts.map +1 -1
  118. package/dist/tracking/client.d.ts +2 -2
  119. package/dist/tracking/client.d.ts.map +1 -1
  120. package/dist/tracking/contract.d.ts +1 -1
  121. package/dist/tracking/host.d.ts +0 -1
  122. package/dist/tracking/host.d.ts.map +1 -1
  123. package/dist/tracking/privacy.d.ts +6 -0
  124. package/dist/tracking/privacy.d.ts.map +1 -1
  125. package/dist/tracking/schemas.d.ts +2 -2
  126. package/dist/tracking/schemas.d.ts.map +1 -1
  127. package/llms/contract.txt +46 -24
  128. package/llms/geo-contract.txt +23 -0
  129. package/llms/geo.txt +40 -4
  130. package/llms/stitchkit.txt +4 -3
  131. package/llms/tools.2.txt +2 -2
  132. package/llms/tools.3.txt +1 -1
  133. package/llms/tracking-contract.txt +1 -1
  134. package/llms/tracking.txt +27 -5
  135. package/llms/{upgrading-0.105.0-0.118.0.txt → upgrading-0.106.0-0.119.0.txt} +121 -410
  136. package/llms/upgrading-0.37.0-0.53.0.txt +969 -0
  137. package/llms/{upgrading-0.44.0-0.62.0.txt → upgrading-0.55.0-0.68.0.txt} +509 -528
  138. package/llms/{upgrading-0.63.0-0.83.0.txt → upgrading-0.69.0-0.95.0.txt} +506 -509
  139. package/llms/{upgrading-0.84.0-0.104.0.txt → upgrading-0.96.0-0.105.0.txt} +410 -506
  140. package/llms/upgrading.txt +5 -5
  141. package/llms-full.txt +247 -38
  142. package/llms.txt +10 -9
  143. package/package.json +23 -19
  144. package/llms/upgrading-0.37.0-0.44.0.txt +0 -444
@@ -16,7 +16,7 @@ import {
16
16
  ownHttpStream,
17
17
  settleStreamCleanup,
18
18
  ShutdownOptionsSchema2
19
- } from "./index-q0th8q0z.js";
19
+ } from "./index-9mjrnqxs.js";
20
20
  import {
21
21
  RELEASE_HEADER2
22
22
  } from "./index-n15jny5b.js";
@@ -26,7 +26,7 @@ import {
26
26
  import {
27
27
  bindContract,
28
28
  mediaTypeEssence
29
- } from "./index-cqmqyjax.js";
29
+ } from "./index-sa99p98w.js";
30
30
  import {
31
31
  assertCorsConfig,
32
32
  isOriginAllowed,
@@ -80,6 +80,101 @@ import {
80
80
  transportResult
81
81
  } from "./index-9jfdm5tg.js";
82
82
 
83
+ // src/server/context-contribution.ts
84
+ var RUNTIME_CONTEXT_RESERVED_KEYS = new Set([
85
+ "params",
86
+ "input",
87
+ "files",
88
+ "rawBody",
89
+ "source",
90
+ "req",
91
+ "url",
92
+ "headers",
93
+ "traceId",
94
+ "spanId",
95
+ "ipAddress",
96
+ "userAgent",
97
+ "signal",
98
+ "mcp",
99
+ "reportProgress"
100
+ ]);
101
+ function contributionError(scope, reason) {
102
+ return new TypeError(`[stitchkit] auth: invalid context contribution for scope ${JSON.stringify(scope)}: ${reason}`);
103
+ }
104
+ function descriptorsEqual(left, right) {
105
+ if (!left || !right)
106
+ return left === right;
107
+ if (left.enumerable !== right.enumerable || left.configurable !== right.configurable || left.writable !== right.writable) {
108
+ return false;
109
+ }
110
+ if ("value" in left || "value" in right) {
111
+ return "value" in left && "value" in right && Object.is(left.value, right.value);
112
+ }
113
+ return left.get === right.get && left.set === right.set;
114
+ }
115
+ function contextContributionDelta(original, shadow, scope) {
116
+ if (Object.getPrototypeOf(shadow) !== Object.getPrototypeOf(original)) {
117
+ throw contributionError(scope, "context prototype changes are not supported");
118
+ }
119
+ const originalKeys = Reflect.ownKeys(original);
120
+ const shadowKeys = Reflect.ownKeys(shadow);
121
+ const shadowKeySet = new Set(shadowKeys);
122
+ for (const key of originalKeys) {
123
+ if (!shadowKeySet.has(key)) {
124
+ const printable = typeof key === "string" ? JSON.stringify(key) : "a symbol key";
125
+ throw contributionError(scope, `context key ${printable} may not be deleted`);
126
+ }
127
+ }
128
+ const contribution = Object.create(null);
129
+ for (const key of shadowKeys) {
130
+ const originalDescriptor = Object.getOwnPropertyDescriptor(original, key);
131
+ const shadowDescriptor = Object.getOwnPropertyDescriptor(shadow, key);
132
+ if (!shadowDescriptor || descriptorsEqual(originalDescriptor, shadowDescriptor))
133
+ continue;
134
+ Object.defineProperty(contribution, key, shadowDescriptor);
135
+ }
136
+ return contribution;
137
+ }
138
+ function prepareContextContribution(value, scope) {
139
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
140
+ throw contributionError(scope, "expected a plain record");
141
+ }
142
+ let prototype;
143
+ let descriptors;
144
+ let keys;
145
+ try {
146
+ prototype = Object.getPrototypeOf(value);
147
+ descriptors = Object.getOwnPropertyDescriptors(value);
148
+ keys = Reflect.ownKeys(value);
149
+ } catch {
150
+ throw contributionError(scope, "record inspection failed");
151
+ }
152
+ if (prototype !== Object.prototype && prototype !== null) {
153
+ throw contributionError(scope, "expected Object.prototype or null prototype");
154
+ }
155
+ const prepared = Object.create(null);
156
+ for (const key of keys) {
157
+ if (typeof key !== "string") {
158
+ throw contributionError(scope, "symbol keys are not supported");
159
+ }
160
+ if (isUnsafeKey(key)) {
161
+ throw contributionError(scope, `unsafe key ${JSON.stringify(key)}`);
162
+ }
163
+ if (RUNTIME_CONTEXT_RESERVED_KEYS.has(key)) {
164
+ throw contributionError(scope, `reserved key ${JSON.stringify(key)}`);
165
+ }
166
+ const descriptor = descriptors[key];
167
+ if (!descriptor?.enumerable || !("value" in descriptor)) {
168
+ throw contributionError(scope, `key ${JSON.stringify(key)} must be enumerable data`);
169
+ }
170
+ prepared[key] = descriptor.value;
171
+ }
172
+ return prepared;
173
+ }
174
+ function mergeContextContribution(ctx, value, scope) {
175
+ Object.assign(ctx, prepareContextContribution(value, scope));
176
+ }
177
+
83
178
  // src/server/multipart-reader.ts
84
179
  var DEFAULT_MAX_HEADER_BYTES = 64 * 1024;
85
180
  var CRLF = new Uint8Array([13, 10]);
@@ -552,6 +647,110 @@ async function parseMultipart2(req, descriptor, fieldsSchema, receivers) {
552
647
  }
553
648
  }
554
649
 
650
+ // src/server/request-body.ts
651
+ async function readRequestText(req, maxBytes) {
652
+ if (req.signal.aborted)
653
+ throw abortReason(req.signal);
654
+ if (maxBytes === undefined)
655
+ return req.text();
656
+ assertPositiveSafeInteger("maxJsonBodyBytes", maxBytes, Error);
657
+ const result = await readBoundedChunks(req.body, { maxBytes, signal: req.signal });
658
+ if (result.kind === "over-limit")
659
+ badRequest2(`JSON body exceeds the ${maxBytes}-byte limit`);
660
+ return new TextDecoder().decode(concatChunks(result.chunks, result.total));
661
+ }
662
+
663
+ // src/server/context.ts
664
+ function parseJsonBody(req, text, method, cors) {
665
+ if (text.trim() === "")
666
+ return {};
667
+ const essence = mediaTypeEssence(req.headers.get("content-type"));
668
+ if (essence !== "application/json") {
669
+ if (!method.safelistedBody || essence !== "text/plain") {
670
+ badRequest2("Request body must be application/json");
671
+ }
672
+ const origin = req.headers.get("origin");
673
+ if (!cors || cors.origin === undefined || cors.origin === "*") {
674
+ forbidden2("A text/plain body requires an explicit cors.origin allow-list on the server");
675
+ }
676
+ if (!origin)
677
+ forbidden2("A text/plain body requires an Origin header");
678
+ if (!isOriginAllowed(cors, origin)) {
679
+ forbidden2("A text/plain body is accepted only from an allowed origin");
680
+ }
681
+ }
682
+ try {
683
+ return safeJsonParse(text);
684
+ } catch {
685
+ badRequest2("Invalid JSON body");
686
+ }
687
+ }
688
+ function buildBaseContext(req, url, pathParams, traceId, clientIp) {
689
+ const safePathParams = {};
690
+ for (const [k, v] of Object.entries(pathParams)) {
691
+ if (!RUNTIME_CONTEXT_RESERVED_KEYS.has(k) && !isUnsafeKey(k))
692
+ safePathParams[k] = v;
693
+ }
694
+ return {
695
+ params: pathParams,
696
+ input: undefined,
697
+ source: "http",
698
+ req,
699
+ url,
700
+ headers: req.headers,
701
+ signal: req.signal,
702
+ ...safePathParams,
703
+ traceId,
704
+ ...getClientInfo2(req, clientIp)
705
+ };
706
+ }
707
+ function parsePathParamsInto(ctx, method) {
708
+ if (method.paramsSchema) {
709
+ ctx.params = method.paramsSchema.parse(ctx.params);
710
+ }
711
+ }
712
+ async function parseRequestPayloadInto(ctx, req, url, method, maxJsonBodyBytes, cors) {
713
+ if (method.multipart) {
714
+ const multipart = await parseMultipart2(req, method.multipart, method.inputSchema, method.multipartReceivers);
715
+ ctx.input = multipart.fields;
716
+ ctx.files = multipart.files;
717
+ return multipart;
718
+ }
719
+ if (method.inputSchema) {
720
+ if (req.method === "GET") {
721
+ ctx.input = method.inputSchema.parse(parseQueryParams(url));
722
+ } else if (req.method === "DELETE") {
723
+ if (mediaTypeEssence(req.headers.get("content-type")) === "application/json") {
724
+ const text = await readRequestText(req, method.maxJsonBodyBytes ?? maxJsonBodyBytes);
725
+ if (method.rawBody)
726
+ ctx.rawBody = text;
727
+ ctx.input = method.inputSchema.parse(parseJsonBody(req, text, method, cors));
728
+ } else {
729
+ ctx.input = method.inputSchema.parse(parseQueryParams(url));
730
+ }
731
+ } else {
732
+ const text = await readRequestText(req, method.maxJsonBodyBytes ?? maxJsonBodyBytes);
733
+ if (method.rawBody)
734
+ ctx.rawBody = text;
735
+ ctx.input = method.inputSchema.parse(parseJsonBody(req, text, method, cors));
736
+ }
737
+ }
738
+ return;
739
+ }
740
+ function buildErrorContext(req, url, traceId, clientIp) {
741
+ return {
742
+ params: undefined,
743
+ input: undefined,
744
+ source: "http",
745
+ req,
746
+ url,
747
+ headers: req.headers,
748
+ signal: req.signal,
749
+ traceId,
750
+ ...getClientInfo2(req, clientIp)
751
+ };
752
+ }
753
+
555
754
  // src/server/streaming-pump.ts
556
755
  async function pumpFrames(p) {
557
756
  let sinceYield = 0;
@@ -792,205 +991,6 @@ function sseRoute2(options) {
792
991
  return streamingRoute2({ ...options, format: "sse" });
793
992
  }
794
993
 
795
- // src/server/context-contribution.ts
796
- var RUNTIME_CONTEXT_RESERVED_KEYS = new Set([
797
- "params",
798
- "input",
799
- "files",
800
- "rawBody",
801
- "source",
802
- "req",
803
- "url",
804
- "headers",
805
- "traceId",
806
- "spanId",
807
- "ipAddress",
808
- "userAgent",
809
- "signal",
810
- "mcp",
811
- "reportProgress"
812
- ]);
813
- function contributionError(scope, reason) {
814
- return new TypeError(`[stitchkit] auth: invalid context contribution for scope ${JSON.stringify(scope)}: ${reason}`);
815
- }
816
- function descriptorsEqual(left, right) {
817
- if (!left || !right)
818
- return left === right;
819
- if (left.enumerable !== right.enumerable || left.configurable !== right.configurable || left.writable !== right.writable) {
820
- return false;
821
- }
822
- if ("value" in left || "value" in right) {
823
- return "value" in left && "value" in right && Object.is(left.value, right.value);
824
- }
825
- return left.get === right.get && left.set === right.set;
826
- }
827
- function contextContributionDelta(original, shadow, scope) {
828
- if (Object.getPrototypeOf(shadow) !== Object.getPrototypeOf(original)) {
829
- throw contributionError(scope, "context prototype changes are not supported");
830
- }
831
- const originalKeys = Reflect.ownKeys(original);
832
- const shadowKeys = Reflect.ownKeys(shadow);
833
- const shadowKeySet = new Set(shadowKeys);
834
- for (const key of originalKeys) {
835
- if (!shadowKeySet.has(key)) {
836
- const printable = typeof key === "string" ? JSON.stringify(key) : "a symbol key";
837
- throw contributionError(scope, `context key ${printable} may not be deleted`);
838
- }
839
- }
840
- const contribution = Object.create(null);
841
- for (const key of shadowKeys) {
842
- const originalDescriptor = Object.getOwnPropertyDescriptor(original, key);
843
- const shadowDescriptor = Object.getOwnPropertyDescriptor(shadow, key);
844
- if (!shadowDescriptor || descriptorsEqual(originalDescriptor, shadowDescriptor))
845
- continue;
846
- Object.defineProperty(contribution, key, shadowDescriptor);
847
- }
848
- return contribution;
849
- }
850
- function prepareContextContribution(value, scope) {
851
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
852
- throw contributionError(scope, "expected a plain record");
853
- }
854
- let prototype;
855
- let descriptors;
856
- let keys;
857
- try {
858
- prototype = Object.getPrototypeOf(value);
859
- descriptors = Object.getOwnPropertyDescriptors(value);
860
- keys = Reflect.ownKeys(value);
861
- } catch {
862
- throw contributionError(scope, "record inspection failed");
863
- }
864
- if (prototype !== Object.prototype && prototype !== null) {
865
- throw contributionError(scope, "expected Object.prototype or null prototype");
866
- }
867
- const prepared = Object.create(null);
868
- for (const key of keys) {
869
- if (typeof key !== "string") {
870
- throw contributionError(scope, "symbol keys are not supported");
871
- }
872
- if (isUnsafeKey(key)) {
873
- throw contributionError(scope, `unsafe key ${JSON.stringify(key)}`);
874
- }
875
- if (RUNTIME_CONTEXT_RESERVED_KEYS.has(key)) {
876
- throw contributionError(scope, `reserved key ${JSON.stringify(key)}`);
877
- }
878
- const descriptor = descriptors[key];
879
- if (!descriptor?.enumerable || !("value" in descriptor)) {
880
- throw contributionError(scope, `key ${JSON.stringify(key)} must be enumerable data`);
881
- }
882
- prepared[key] = descriptor.value;
883
- }
884
- return prepared;
885
- }
886
- function mergeContextContribution(ctx, value, scope) {
887
- Object.assign(ctx, prepareContextContribution(value, scope));
888
- }
889
-
890
- // src/server/request-body.ts
891
- async function readRequestText(req, maxBytes) {
892
- if (req.signal.aborted)
893
- throw abortReason(req.signal);
894
- if (maxBytes === undefined)
895
- return req.text();
896
- assertPositiveSafeInteger("maxJsonBodyBytes", maxBytes, Error);
897
- const result = await readBoundedChunks(req.body, { maxBytes, signal: req.signal });
898
- if (result.kind === "over-limit")
899
- badRequest2(`JSON body exceeds the ${maxBytes}-byte limit`);
900
- return new TextDecoder().decode(concatChunks(result.chunks, result.total));
901
- }
902
-
903
- // src/server/context.ts
904
- function parseJsonBody(req, text, method, cors) {
905
- if (text.trim() === "")
906
- return {};
907
- const essence = mediaTypeEssence(req.headers.get("content-type"));
908
- if (essence !== "application/json") {
909
- if (!method.safelistedBody || essence !== "text/plain") {
910
- badRequest2("Request body must be application/json");
911
- }
912
- const origin = req.headers.get("origin");
913
- if (!cors || cors.origin === undefined || cors.origin === "*") {
914
- forbidden2("A text/plain body requires an explicit cors.origin allow-list on the server");
915
- }
916
- if (!origin)
917
- forbidden2("A text/plain body requires an Origin header");
918
- if (!isOriginAllowed(cors, origin)) {
919
- forbidden2("A text/plain body is accepted only from an allowed origin");
920
- }
921
- }
922
- try {
923
- return safeJsonParse(text);
924
- } catch {
925
- badRequest2("Invalid JSON body");
926
- }
927
- }
928
- function buildBaseContext(req, url, pathParams, traceId, clientIp) {
929
- const safePathParams = {};
930
- for (const [k, v] of Object.entries(pathParams)) {
931
- if (!RUNTIME_CONTEXT_RESERVED_KEYS.has(k) && !isUnsafeKey(k))
932
- safePathParams[k] = v;
933
- }
934
- return {
935
- params: pathParams,
936
- input: undefined,
937
- source: "http",
938
- req,
939
- url,
940
- headers: req.headers,
941
- signal: req.signal,
942
- ...safePathParams,
943
- traceId,
944
- ...getClientInfo2(req, clientIp)
945
- };
946
- }
947
- function parsePathParamsInto(ctx, method) {
948
- if (method.paramsSchema) {
949
- ctx.params = method.paramsSchema.parse(ctx.params);
950
- }
951
- }
952
- async function parseRequestPayloadInto(ctx, req, url, method, maxJsonBodyBytes, cors) {
953
- if (method.multipart) {
954
- const multipart = await parseMultipart2(req, method.multipart, method.inputSchema, method.multipartReceivers);
955
- ctx.input = multipart.fields;
956
- ctx.files = multipart.files;
957
- return multipart;
958
- }
959
- if (method.inputSchema) {
960
- if (req.method === "GET") {
961
- ctx.input = method.inputSchema.parse(parseQueryParams(url));
962
- } else if (req.method === "DELETE") {
963
- if (mediaTypeEssence(req.headers.get("content-type")) === "application/json") {
964
- const text = await readRequestText(req, method.maxJsonBodyBytes ?? maxJsonBodyBytes);
965
- if (method.rawBody)
966
- ctx.rawBody = text;
967
- ctx.input = method.inputSchema.parse(parseJsonBody(req, text, method, cors));
968
- } else {
969
- ctx.input = method.inputSchema.parse(parseQueryParams(url));
970
- }
971
- } else {
972
- const text = await readRequestText(req, method.maxJsonBodyBytes ?? maxJsonBodyBytes);
973
- if (method.rawBody)
974
- ctx.rawBody = text;
975
- ctx.input = method.inputSchema.parse(parseJsonBody(req, text, method, cors));
976
- }
977
- }
978
- return;
979
- }
980
- function buildErrorContext(req, url, traceId, clientIp) {
981
- return {
982
- params: undefined,
983
- input: undefined,
984
- source: "http",
985
- req,
986
- url,
987
- headers: req.headers,
988
- signal: req.signal,
989
- traceId,
990
- ...getClientInfo2(req, clientIp)
991
- };
992
- }
993
-
994
994
  // src/server/contract-stream.ts
995
995
  function encodedBytes(value, format) {
996
996
  const json = JSON.stringify(value);
@@ -2342,7 +2342,7 @@ function webSocketLane2(lane) {
2342
2342
  handlers: {
2343
2343
  message(ws, message) {
2344
2344
  if (match(ws))
2345
- handlers.message(ws, message);
2345
+ handlers.message?.(ws, message);
2346
2346
  },
2347
2347
  open(ws) {
2348
2348
  if (match(ws))
@@ -2372,7 +2372,7 @@ function composeWebSocketHandlers2(lanes, config) {
2372
2372
  return {
2373
2373
  ...config,
2374
2374
  message(ws, message) {
2375
- pick(ws)?.handlers.message(ws, message);
2375
+ pick(ws)?.handlers.message?.(ws, message);
2376
2376
  },
2377
2377
  open(ws) {
2378
2378
  pick(ws)?.handlers.open?.(ws);
@@ -2577,6 +2577,12 @@ function socketIoLane2(websocket) {
2577
2577
  });
2578
2578
  }
2579
2579
 
2580
+ // src/server/unix-client.ts
2581
+ import {
2582
+ Agent,
2583
+ request as httpRequest
2584
+ } from "node:http";
2585
+
2580
2586
  // src/server/unix-client-error.ts
2581
2587
  class UnixClientTransportError2 extends Error {
2582
2588
  code;
@@ -2589,12 +2595,6 @@ class UnixClientTransportError2 extends Error {
2589
2595
  }
2590
2596
  }
2591
2597
 
2592
- // src/server/unix-client.ts
2593
- import {
2594
- Agent,
2595
- request as httpRequest
2596
- } from "node:http";
2597
-
2598
2598
  // src/server/unix-client-body.ts
2599
2599
  async function readBoundedRequestBody(request, maxBytes) {
2600
2600
  if (!request.body)
@@ -12,7 +12,7 @@ import {
12
12
  applyToolViewDefaults,
13
13
  projectToolView,
14
14
  objectShapeKeys
15
- } from "./index-rhzkndr5.js";
15
+ } from "./index-x4p3kw1p.js";
16
16
  import {
17
17
  runWithRequestContext2,
18
18
  getRequestContext2
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  contractMethodFields
3
- } from "./index-1bx1xv1k.js";
3
+ } from "./index-pfvde2fz.js";
4
4
  import {
5
5
  AppError2
6
6
  } from "./index-qcn84byh.js";
@@ -15,6 +15,7 @@ function createAsyncOperationSnapshotSchema2(config) {
15
15
  z.object({ phase: z.literal("cancelled"), ...progress })
16
16
  ]);
17
17
  }
18
+
18
19
  // src/tools/transfer/view-file-contract.ts
19
20
  import { z as z2 } from "zod";
20
21
  var MAX_VIEW_FILES = 20;
@@ -9,6 +9,9 @@ import {
9
9
  ApplicationIdSchema2
10
10
  } from "./index-w5s3xftz.js";
11
11
 
12
+ // src/application/activity.ts
13
+ import { z as z2 } from "zod";
14
+
12
15
  // src/application/latest-sink.ts
13
16
  import { z } from "zod";
14
17
  var SnapshotRevisionSchema = z.number().int().nonnegative();
@@ -131,7 +134,6 @@ function createApplicationSnapshotSink2(config) {
131
134
  }
132
135
 
133
136
  // src/application/activity.ts
134
- import { z as z2 } from "zod";
135
137
  var BoundedOperationalIdSchema = z2.string().min(1).max(64).regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]*$/);
136
138
  var NonNegativeIntegerSchema = z2.number().int().nonnegative();
137
139
  var ActivityIdSchema2 = BoundedOperationalIdSchema;