@langwatch/mcp-server 0.10.0 → 1.0.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 (122) hide show
  1. package/.release-please-shim +1 -1
  2. package/CHANGELOG.md +62 -0
  3. package/README.md +9 -17
  4. package/dist/{archive-project-HZBRPR2S.js → archive-project-MK3673A7.js} +4 -3
  5. package/dist/{archive-scenario-P5RRITRM.js → archive-scenario-KATSXRIN.js} +4 -3
  6. package/dist/{archive-suite-NUUFD2EM.js → archive-suite-C3KX6IIZ.js} +4 -3
  7. package/dist/{assign-prompt-tag-FKCCZPML.js → assign-prompt-tag-E3C5W6PI.js} +3 -2
  8. package/dist/chunk-37SMPMQS.js +12 -0
  9. package/dist/{chunk-42ZHHHIJ.js → chunk-5UWY24RP.js} +79 -4
  10. package/dist/chunk-BJ7B4R26.js +42 -0
  11. package/dist/chunk-CE6QMZOP.js +432 -0
  12. package/dist/{chunk-X2SEURT2.js → chunk-DAIQKS27.js} +2 -2
  13. package/dist/{chunk-R7C7OUVG.js → chunk-EU22L52K.js} +2 -2
  14. package/dist/{chunk-TROIWSEQ.js → chunk-J45SVWPR.js} +2 -2
  15. package/dist/{chunk-CCM4ZFGF.js → chunk-O3LWVN67.js} +2 -2
  16. package/dist/{chunk-BB7EOKHR.js → chunk-RYRB2YVJ.js} +2 -2
  17. package/dist/{chunk-HKY3GW45.js → chunk-T7WJVS2N.js} +2 -2
  18. package/dist/{chunk-JHOSVOHT.js → chunk-UXXA4D6K.js} +2 -2
  19. package/dist/{chunk-FVDAZ4XG.js → chunk-VYPSKRPN.js} +219 -137
  20. package/dist/{chunk-CHKCEZBP.js → chunk-WDH5P5RF.js} +2 -2
  21. package/dist/{chunk-BBJ5WAJB.js → chunk-WWMDHZZV.js} +2 -2
  22. package/dist/{chunk-ADSJ2FDA.js → chunk-XY4STOBE.js} +2 -2
  23. package/dist/{chunk-BYWYM2RP.js → chunk-Y3HDZ6OW.js} +2 -2
  24. package/dist/config.js +1 -0
  25. package/dist/{create-agent-K5Q7BFGZ.js → create-agent-7W57J7MT.js} +4 -3
  26. package/dist/{create-annotation-KN3GE3DK.js → create-annotation-W2XELBCQ.js} +4 -3
  27. package/dist/{create-api-key-OQI5PUNQ.js → create-api-key-MKRXKFJM.js} +4 -3
  28. package/dist/{create-dashboard-G4QA5AXP.js → create-dashboard-QGL7IODC.js} +4 -3
  29. package/dist/{create-dataset-WQSC37N7.js → create-dataset-3PH7A4HG.js} +4 -3
  30. package/dist/{create-dataset-records-B4RL3FLC.js → create-dataset-records-4DZS3VRL.js} +4 -3
  31. package/dist/{create-evaluator-YFFQIR7E.js → create-evaluator-YWH6NC4M.js} +4 -3
  32. package/dist/create-mcp-server.js +3 -2
  33. package/dist/{create-project-CUVQ67VN.js → create-project-BOBQ32C5.js} +4 -3
  34. package/dist/{create-prompt-NGXKSP4X.js → create-prompt-FLCFGITE.js} +3 -2
  35. package/dist/{create-prompt-tag-IUKYPVHH.js → create-prompt-tag-EMPNIKEA.js} +3 -2
  36. package/dist/{create-scenario-FNBXALH3.js → create-scenario-BSBIHUL6.js} +4 -3
  37. package/dist/{create-suite-DJEPD4ZB.js → create-suite-TWF6BBR4.js} +4 -3
  38. package/dist/{delete-agent-TJI5XBBM.js → delete-agent-7MSYNY5E.js} +4 -3
  39. package/dist/{delete-annotation-KRP53TUU.js → delete-annotation-ZT5IGN24.js} +4 -3
  40. package/dist/{delete-dashboard-N5SZJIR3.js → delete-dashboard-BTIY5S3L.js} +4 -3
  41. package/dist/{delete-dataset-KDUOHL2P.js → delete-dataset-U45HQHPR.js} +4 -3
  42. package/dist/{delete-dataset-records-DM4W3PAW.js → delete-dataset-records-R43IMAWB.js} +4 -3
  43. package/dist/{delete-evaluator-7ZATLJOA.js → delete-evaluator-U6JMQ6C7.js} +4 -3
  44. package/dist/{delete-prompt-tag-I6HNMSVJ.js → delete-prompt-tag-4EV4TDHB.js} +3 -2
  45. package/dist/{delete-workflow-QEO74JQR.js → delete-workflow-5QYALXEL.js} +4 -3
  46. package/dist/discover-evaluator-schema-MRGHVNTT.js +2175 -0
  47. package/dist/{discover-scenario-schema-MEEEVND7.js → discover-scenario-schema-UPBTCWPG.js} +3 -1
  48. package/dist/{discover-schema-3T52ORPB.js → discover-schema-ICGXPHUW.js} +3 -1
  49. package/dist/{get-agent-3KDWCP5N.js → get-agent-7QJVPH72.js} +4 -3
  50. package/dist/{get-analytics-GPVJX7SF.js → get-analytics-PVERWOA5.js} +3 -2
  51. package/dist/{get-dashboard-YPTIE5YY.js → get-dashboard-ZZPC3WMD.js} +4 -3
  52. package/dist/{get-dataset-6DQFYITM.js → get-dataset-25TB2LQH.js} +4 -3
  53. package/dist/{get-evaluator-PCM6XQAU.js → get-evaluator-3FTRQKEC.js} +4 -3
  54. package/dist/{get-project-JCMWXVLU.js → get-project-5OAXYC57.js} +4 -3
  55. package/dist/{get-prompt-5XAGWWBG.js → get-prompt-I753LZKZ.js} +3 -2
  56. package/dist/{get-scenario-7XBCDZWX.js → get-scenario-DSSTR6FI.js} +4 -3
  57. package/dist/{get-simulation-run-AV24FJWI.js → get-simulation-run-RQPMS2MC.js} +4 -3
  58. package/dist/{get-suite-4DBVHFEM.js → get-suite-GTOCY5PL.js} +4 -3
  59. package/dist/{get-trace-MRBDS3HJ.js → get-trace-O5VT3NAC.js} +7 -9
  60. package/dist/{get-workflow-UR4Y6UFX.js → get-workflow-3EZDOEIF.js} +4 -3
  61. package/dist/http-server-2ACJ3CXW.js +24366 -0
  62. package/dist/index.js +23374 -3140
  63. package/dist/{langwatch-api-annotations-ZJDRB4JH.js → langwatch-api-annotations-E65MI3WZ.js} +4 -3
  64. package/dist/{langwatch-api-dashboards-WARLI6NF.js → langwatch-api-dashboards-QCDECRCY.js} +4 -3
  65. package/dist/{langwatch-api-monitors-4XKXHYCG.js → langwatch-api-monitors-UIO2KTDV.js} +3 -2
  66. package/dist/{langwatch-api-secrets-6SHK5G7Q.js → langwatch-api-secrets-4T2EKSJ7.js} +3 -2
  67. package/dist/{langwatch-api-triggers-5SX6R2WU.js → langwatch-api-triggers-MPOEKPUY.js} +3 -2
  68. package/dist/{langwatch-api-workflows-NLJENNXE.js → langwatch-api-workflows-5HRZ7HR4.js} +4 -3
  69. package/dist/{list-agents-NECO7MPI.js → list-agents-TIJTP566.js} +4 -3
  70. package/dist/{list-annotations-3OJEO774.js → list-annotations-CGX5BT7E.js} +4 -3
  71. package/dist/{list-api-keys-AWW7ROLB.js → list-api-keys-JLWJPFRX.js} +4 -3
  72. package/dist/{list-dashboards-DVPVVVKW.js → list-dashboards-RNIWX3TX.js} +4 -3
  73. package/dist/{list-dataset-records-I4BYORF5.js → list-dataset-records-B5MHZR66.js} +4 -3
  74. package/dist/{list-datasets-WUAE5HGX.js → list-datasets-BVCAMQCP.js} +4 -3
  75. package/dist/{list-evaluators-B6OSVAM2.js → list-evaluators-65FBTL2U.js} +4 -3
  76. package/dist/{list-model-providers-NL6IP4UZ.js → list-model-providers-GRK3I3VV.js} +4 -3
  77. package/dist/{list-projects-5FHMJ4PQ.js → list-projects-JLMBFMW3.js} +4 -3
  78. package/dist/{list-prompt-tags-Z2DD6FLQ.js → list-prompt-tags-UHNWDGQI.js} +3 -2
  79. package/dist/{list-prompts-VNXKHK7T.js → list-prompts-7254B3U7.js} +3 -2
  80. package/dist/{list-scenarios-CFZHXL76.js → list-scenarios-46YNICKM.js} +4 -3
  81. package/dist/{list-simulation-runs-AM2BXLBW.js → list-simulation-runs-LGNEFNPN.js} +4 -3
  82. package/dist/{list-suites-ZDOHAAXF.js → list-suites-5VK4HXEK.js} +4 -3
  83. package/dist/{list-workflows-WBRBKLIT.js → list-workflows-MLQDM6CP.js} +4 -3
  84. package/dist/{rename-prompt-tag-A4RJUK7Z.js → rename-prompt-tag-RHQMNEQL.js} +3 -2
  85. package/dist/report-issue-DXJ6TPTC.js +412 -0
  86. package/dist/{revoke-api-key-ZSPSPF5G.js → revoke-api-key-3Y35EMBT.js} +4 -3
  87. package/dist/{run-agent-JFNDY7MR.js → run-agent-RBSIFKRT.js} +4 -3
  88. package/dist/{run-suite-TH7LO5TJ.js → run-suite-K3DNQ3SE.js} +4 -3
  89. package/dist/{run-workflow-CK3JP5U2.js → run-workflow-5LVBZYLS.js} +4 -3
  90. package/dist/{search-traces-3BBVYPC3.js → search-traces-U4HLOCZ2.js} +9 -2
  91. package/dist/{set-model-provider-WOC5FNMV.js → set-model-provider-V3M5CDIY.js} +4 -3
  92. package/dist/{update-agent-YMEV5MTL.js → update-agent-47RZIHS7.js} +4 -3
  93. package/dist/{update-dataset-EYT5POFM.js → update-dataset-G6QJJGS5.js} +4 -3
  94. package/dist/{update-dataset-record-VFF5JTX4.js → update-dataset-record-RMWLSWCS.js} +4 -3
  95. package/dist/{update-evaluator-6IJHFG2E.js → update-evaluator-SFRRI5Q3.js} +4 -3
  96. package/dist/{update-project-OIT4WPFI.js → update-project-PI5DWBVK.js} +4 -3
  97. package/dist/{update-prompt-ZU2DD6KM.js → update-prompt-RQFTEO7Y.js} +3 -2
  98. package/dist/{update-scenario-3VUTPDRU.js → update-scenario-G3IU2UIB.js} +4 -3
  99. package/dist/{update-suite-C6JFDQHL.js → update-suite-TRGGLNR7.js} +4 -3
  100. package/package.json +20 -18
  101. package/pnpm-workspace.yaml +27 -2
  102. package/pyproject.toml +9 -1
  103. package/src/__tests__/all-tools.integration.test.ts +56 -120
  104. package/src/__tests__/documentation-fetch-security.integration.test.ts +176 -0
  105. package/src/__tests__/langwatch-api.unit.test.ts +206 -0
  106. package/src/__tests__/public-http-request-security.integration.test.ts +118 -0
  107. package/src/__tests__/report-issue.integration.test.ts +147 -0
  108. package/src/__tests__/tools.unit.test.ts +24 -0
  109. package/src/create-mcp-server.ts +43 -29
  110. package/src/documentation-fetch.ts +111 -0
  111. package/src/langwatch-api-agents.ts +2 -2
  112. package/src/langwatch-api.ts +138 -8
  113. package/src/public-http-request.ts +242 -0
  114. package/src/tools/get-trace.ts +2 -12
  115. package/src/tools/report-issue.ts +150 -0
  116. package/src/tools/search-traces.ts +4 -0
  117. package/src/utils/format-evaluations.ts +20 -0
  118. package/tsconfig.json +8 -1
  119. package/uv.lock +259 -205
  120. package/dist/chunk-XC62KJIT.js +0 -71
  121. package/dist/discover-evaluator-schema-H23XCLNE.js +0 -1402
  122. package/dist/http-server-XUQLIFE7.js +0 -226
@@ -0,0 +1,432 @@
1
+ import {
2
+ makeRequest
3
+ } from "./chunk-5UWY24RP.js";
4
+
5
+ // src/public-http-request.ts
6
+ import { lookup as dnsLookup } from "dns/promises";
7
+ import { request as httpRequest } from "http";
8
+ import { request as httpsRequest } from "https";
9
+ import { isIP } from "net";
10
+
11
+ // ../langwatch/packages/ssrf/src/index.ts
12
+ function ipv4ToBytes(input) {
13
+ const parts = input.split(".");
14
+ if (parts.length !== 4) return null;
15
+ const bytes = new Uint8Array(4);
16
+ for (let i = 0; i < 4; i++) {
17
+ if (!/^\d{1,3}$/.test(parts[i])) return null;
18
+ const n = Number(parts[i]);
19
+ if (n > 255) return null;
20
+ bytes[i] = n;
21
+ }
22
+ return bytes;
23
+ }
24
+ function ipv6ToBytes(input) {
25
+ let s = input;
26
+ const zone = s.indexOf("%");
27
+ if (zone !== -1) s = s.slice(0, zone);
28
+ if (s.includes(".")) {
29
+ const lastColon = s.lastIndexOf(":");
30
+ if (lastColon === -1) return null;
31
+ const v4 = ipv4ToBytes(s.slice(lastColon + 1));
32
+ if (!v4) return null;
33
+ const hi = (v4[0] << 8 | v4[1]).toString(16);
34
+ const lo = (v4[2] << 8 | v4[3]).toString(16);
35
+ s = `${s.slice(0, lastColon + 1)}${hi}:${lo}`;
36
+ }
37
+ const halves = s.split("::");
38
+ if (halves.length > 2) return null;
39
+ const parseGroups = (part) => {
40
+ if (part === "") return [];
41
+ const out = [];
42
+ for (const g of part.split(":")) {
43
+ if (!/^[0-9a-fA-F]{1,4}$/.test(g)) return null;
44
+ out.push(parseInt(g, 16));
45
+ }
46
+ return out;
47
+ };
48
+ const head = parseGroups(halves[0]);
49
+ if (head === null) return null;
50
+ let groups;
51
+ if (halves.length === 2) {
52
+ const tail = parseGroups(halves[1]);
53
+ if (tail === null) return null;
54
+ const missing = 8 - head.length - tail.length;
55
+ if (missing < 0) return null;
56
+ groups = [...head, ...new Array(missing).fill(0), ...tail];
57
+ } else {
58
+ groups = head;
59
+ }
60
+ if (groups.length !== 8) return null;
61
+ const bytes = new Uint8Array(16);
62
+ for (let i = 0; i < 8; i++) {
63
+ bytes[i * 2] = groups[i] >> 8 & 255;
64
+ bytes[i * 2 + 1] = groups[i] & 255;
65
+ }
66
+ return bytes;
67
+ }
68
+ function ipToBytes(ip) {
69
+ return ip.includes(":") ? ipv6ToBytes(ip) : ipv4ToBytes(ip);
70
+ }
71
+ function unmap(bytes) {
72
+ if (bytes.length !== 16) return bytes;
73
+ for (let i = 0; i < 10; i++) {
74
+ if (bytes[i] !== 0) return bytes;
75
+ }
76
+ if (bytes[10] === 255 && bytes[11] === 255) return bytes.slice(12, 16);
77
+ return bytes;
78
+ }
79
+ function parsePrefix({ cidr, rfc }) {
80
+ const slash = cidr.lastIndexOf("/");
81
+ const bytes = ipToBytes(cidr.slice(0, slash));
82
+ if (!bytes) throw new Error(`@langwatch/ssrf: bad prefix ${cidr}`);
83
+ return { bytes, bits: Number(cidr.slice(slash + 1)), rfc };
84
+ }
85
+ function prefixContains({
86
+ prefix,
87
+ addr
88
+ }) {
89
+ if (prefix.bytes.length !== addr.length) return false;
90
+ let bits = prefix.bits;
91
+ let i = 0;
92
+ while (bits >= 8) {
93
+ if (prefix.bytes[i] !== addr[i]) return false;
94
+ i++;
95
+ bits -= 8;
96
+ }
97
+ if (bits > 0) {
98
+ const mask = 255 << 8 - bits & 255;
99
+ if ((prefix.bytes[i] & mask) !== (addr[i] & mask)) return false;
100
+ }
101
+ return true;
102
+ }
103
+ var METADATA_ADDRESSES = [
104
+ "169.254.169.254",
105
+ // AWS/GCP/Azure/Oracle IMDS
106
+ "169.254.170.2",
107
+ // AWS ECS/Fargate task metadata
108
+ "168.63.129.16",
109
+ // Azure WireServer / host DNS
110
+ "fd00:ec2::254"
111
+ // AWS EC2 IMDS over IPv6
112
+ ].map((ip) => {
113
+ const bytes = unmap(ipToBytes(ip));
114
+ return bytes;
115
+ });
116
+ var SPECIAL_PREFIXES = [
117
+ // IPv4
118
+ parsePrefix({ cidr: "0.0.0.0/8", rfc: "RFC1122 this network / unspecified" }),
119
+ parsePrefix({ cidr: "10.0.0.0/8", rfc: "RFC1918 private" }),
120
+ parsePrefix({
121
+ cidr: "100.64.0.0/10",
122
+ rfc: "RFC6598 CGNAT / shared address space"
123
+ }),
124
+ parsePrefix({ cidr: "127.0.0.0/8", rfc: "RFC1122 loopback" }),
125
+ parsePrefix({ cidr: "169.254.0.0/16", rfc: "RFC3927 link-local" }),
126
+ parsePrefix({ cidr: "172.16.0.0/12", rfc: "RFC1918 private" }),
127
+ parsePrefix({
128
+ cidr: "192.0.0.0/24",
129
+ rfc: "RFC6890 IETF protocol assignments"
130
+ }),
131
+ parsePrefix({
132
+ cidr: "192.0.2.0/24",
133
+ rfc: "RFC5737 TEST-NET-1 documentation"
134
+ }),
135
+ parsePrefix({
136
+ cidr: "192.88.99.0/24",
137
+ rfc: "RFC7526 6to4 relay anycast, deprecated"
138
+ }),
139
+ parsePrefix({ cidr: "192.168.0.0/16", rfc: "RFC1918 private" }),
140
+ parsePrefix({ cidr: "198.18.0.0/15", rfc: "RFC2544 benchmarking" }),
141
+ parsePrefix({
142
+ cidr: "198.51.100.0/24",
143
+ rfc: "RFC5737 TEST-NET-2 documentation"
144
+ }),
145
+ parsePrefix({
146
+ cidr: "203.0.113.0/24",
147
+ rfc: "RFC5737 TEST-NET-3 documentation"
148
+ }),
149
+ parsePrefix({ cidr: "224.0.0.0/4", rfc: "RFC5771 multicast" }),
150
+ parsePrefix({
151
+ cidr: "240.0.0.0/4",
152
+ rfc: "RFC1112 reserved incl. 255.255.255.255 broadcast"
153
+ }),
154
+ // IPv6
155
+ parsePrefix({ cidr: "::/128", rfc: "RFC4291 unspecified" }),
156
+ parsePrefix({ cidr: "::1/128", rfc: "RFC4291 loopback" }),
157
+ parsePrefix({ cidr: "64:ff9b::/96", rfc: "RFC6052 well-known NAT64" }),
158
+ parsePrefix({ cidr: "64:ff9b:1::/48", rfc: "RFC8215 local-use NAT64" }),
159
+ parsePrefix({ cidr: "100::/64", rfc: "RFC6666 discard-only" }),
160
+ parsePrefix({ cidr: "2001::/32", rfc: "RFC4380 Teredo" }),
161
+ parsePrefix({ cidr: "2001:db8::/32", rfc: "RFC3849 documentation" }),
162
+ parsePrefix({ cidr: "2002::/16", rfc: "RFC3056 6to4" }),
163
+ parsePrefix({ cidr: "3fff::/20", rfc: "RFC9637 documentation" }),
164
+ parsePrefix({ cidr: "fc00::/7", rfc: "RFC4193 unique-local" }),
165
+ parsePrefix({ cidr: "fe80::/10", rfc: "RFC4291 link-local unicast" }),
166
+ parsePrefix({ cidr: "ff00::/8", rfc: "RFC4291 multicast" })
167
+ ];
168
+ function bytesEqual({ a, b }) {
169
+ if (a.length !== b.length) return false;
170
+ for (let i = 0; i < a.length; i++) {
171
+ if (a[i] !== b[i]) return false;
172
+ }
173
+ return true;
174
+ }
175
+ function classify(ip) {
176
+ const raw = ipToBytes(ip);
177
+ if (!raw) return "special";
178
+ const addr = unmap(raw);
179
+ if (METADATA_ADDRESSES.some((m) => bytesEqual({ a: m, b: addr })))
180
+ return "metadata";
181
+ for (const prefix of SPECIAL_PREFIXES) {
182
+ if (prefixContains({ prefix, addr })) return "special";
183
+ }
184
+ return "global";
185
+ }
186
+
187
+ // src/public-http-request.ts
188
+ var MAX_REDIRECTS = 5;
189
+ var MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
190
+ var REQUEST_TIMEOUT_MS = 3e4;
191
+ var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
192
+ var SENSITIVE_REDIRECT_HEADERS = /* @__PURE__ */ new Set([
193
+ "authorization",
194
+ "cookie",
195
+ "cookie2",
196
+ "proxy-authorization",
197
+ "x-api-key",
198
+ "api-key",
199
+ "x-auth-token",
200
+ "x-access-token"
201
+ ]);
202
+ function unsafeDestinationError() {
203
+ return new Error("HTTP agent destinations must resolve only to globally routable public addresses");
204
+ }
205
+ function hostnameWithoutBrackets(hostname) {
206
+ return hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname;
207
+ }
208
+ function assertPublicAddress(address) {
209
+ if (classify(address) !== "global") {
210
+ throw unsafeDestinationError();
211
+ }
212
+ }
213
+ async function withTimeout(promise, timeoutMs) {
214
+ let timeout;
215
+ try {
216
+ return await Promise.race([
217
+ promise,
218
+ new Promise((_resolve, reject) => {
219
+ timeout = setTimeout(() => reject(new Error("request timed out")), timeoutMs);
220
+ timeout.unref();
221
+ })
222
+ ]);
223
+ } finally {
224
+ if (timeout) {
225
+ clearTimeout(timeout);
226
+ }
227
+ }
228
+ }
229
+ function headersForRedirect(headers, crossOrigin) {
230
+ if (!headers || !crossOrigin) {
231
+ return headers;
232
+ }
233
+ const safeHeaders = Object.fromEntries(
234
+ Object.entries(headers).filter(([name]) => !SENSITIVE_REDIRECT_HEADERS.has(name.toLowerCase()))
235
+ );
236
+ return Object.keys(safeHeaders).length > 0 ? safeHeaders : void 0;
237
+ }
238
+ async function resolvePublicDestination(input, resolver = dnsLookup) {
239
+ let url;
240
+ try {
241
+ url = new URL(input);
242
+ } catch {
243
+ throw new Error("HTTP agent URL is invalid");
244
+ }
245
+ if (url.protocol !== "http:" && url.protocol !== "https:" || url.username !== "" || url.password !== "") {
246
+ throw unsafeDestinationError();
247
+ }
248
+ const hostname = hostnameWithoutBrackets(url.hostname);
249
+ const literalFamily = isIP(hostname);
250
+ if (literalFamily !== 0) {
251
+ assertPublicAddress(hostname);
252
+ return { address: hostname, family: literalFamily, url };
253
+ }
254
+ let addresses;
255
+ try {
256
+ addresses = await withTimeout(
257
+ resolver(hostname, { all: true, verbatim: true }),
258
+ REQUEST_TIMEOUT_MS
259
+ );
260
+ } catch {
261
+ throw new Error("HTTP agent destination could not be resolved");
262
+ }
263
+ if (addresses.length === 0) {
264
+ throw new Error("HTTP agent destination could not be resolved");
265
+ }
266
+ for (const { address } of addresses) {
267
+ assertPublicAddress(address);
268
+ }
269
+ const selected = addresses.find(({ family }) => family === 4) ?? addresses[0];
270
+ return {
271
+ address: selected.address,
272
+ family: selected.family,
273
+ url
274
+ };
275
+ }
276
+ function requestBody(destination, options) {
277
+ return new Promise((resolve, reject) => {
278
+ const hostname = hostnameWithoutBrackets(destination.url.hostname);
279
+ const requestOptions = {
280
+ protocol: destination.url.protocol,
281
+ hostname,
282
+ port: destination.url.port || void 0,
283
+ path: `${destination.url.pathname}${destination.url.search}`,
284
+ method: options.method ?? "GET",
285
+ headers: options.headers,
286
+ family: destination.family,
287
+ signal: options.signal,
288
+ lookup: (_hostname, _options, callback) => {
289
+ callback(null, destination.address, destination.family);
290
+ }
291
+ };
292
+ const transport = destination.url.protocol === "https:" ? httpsRequest : httpRequest;
293
+ const request = transport(requestOptions, (response) => {
294
+ const chunks = [];
295
+ let receivedBytes = 0;
296
+ response.once("aborted", () => {
297
+ reject(new Error("HTTP agent response was interrupted"));
298
+ });
299
+ response.once("error", reject);
300
+ const contentLength = Number(response.headers["content-length"]);
301
+ if (Number.isFinite(contentLength) && contentLength > MAX_RESPONSE_BYTES) {
302
+ response.destroy(new Error("HTTP agent response is too large"));
303
+ return;
304
+ }
305
+ response.on("data", (chunk) => {
306
+ receivedBytes += chunk.length;
307
+ if (receivedBytes > MAX_RESPONSE_BYTES) {
308
+ response.destroy(new Error("HTTP agent response is too large"));
309
+ return;
310
+ }
311
+ chunks.push(chunk);
312
+ });
313
+ response.once("end", () => {
314
+ resolve({
315
+ body: Buffer.concat(chunks).toString("utf8"),
316
+ location: response.headers.location,
317
+ statusCode: response.statusCode ?? 0
318
+ });
319
+ });
320
+ });
321
+ request.once("error", reject);
322
+ request.setTimeout(REQUEST_TIMEOUT_MS, () => {
323
+ request.destroy(new Error("HTTP agent request timed out"));
324
+ });
325
+ if (options.body !== void 0) {
326
+ request.write(options.body);
327
+ }
328
+ request.end();
329
+ });
330
+ }
331
+ async function requestPublicJson(input, options = {}, redirectCount = 0) {
332
+ const destination = await resolvePublicDestination(input);
333
+ const response = await requestBody(destination, options);
334
+ if (REDIRECT_STATUSES.has(response.statusCode) && response.location) {
335
+ if (redirectCount >= MAX_REDIRECTS) {
336
+ throw new Error(`HTTP agent returned too many redirects`);
337
+ }
338
+ const redirectUrl = new URL(response.location, destination.url);
339
+ const redirectHeaders = headersForRedirect(
340
+ options.headers,
341
+ redirectUrl.origin !== destination.url.origin
342
+ );
343
+ const preserveBody = response.statusCode === 307 || response.statusCode === 308;
344
+ return requestPublicJson(
345
+ redirectUrl.toString(),
346
+ preserveBody ? { ...options, headers: redirectHeaders } : {
347
+ ...options,
348
+ body: void 0,
349
+ headers: redirectHeaders,
350
+ method: "GET"
351
+ },
352
+ redirectCount + 1
353
+ );
354
+ }
355
+ if (response.statusCode < 200 || response.statusCode >= 300) {
356
+ throw new Error(`HTTP agent returned an unsuccessful status: ${response.statusCode}`);
357
+ }
358
+ let parsed;
359
+ try {
360
+ parsed = JSON.parse(response.body);
361
+ } catch {
362
+ throw new Error("HTTP agent returned invalid JSON");
363
+ }
364
+ return parsed;
365
+ }
366
+
367
+ // src/langwatch-api-agents.ts
368
+ async function listAgents(params) {
369
+ const query = new URLSearchParams();
370
+ if (params?.page) query.set("page", String(params.page));
371
+ if (params?.limit) query.set("limit", String(params.limit));
372
+ const qs = query.toString() ? `?${query}` : "";
373
+ return makeRequest("GET", `/api/agents${qs}`);
374
+ }
375
+ async function getAgent(id) {
376
+ return makeRequest(
377
+ "GET",
378
+ `/api/agents/${encodeURIComponent(id)}`
379
+ );
380
+ }
381
+ async function createAgent(data) {
382
+ return makeRequest("POST", "/api/agents", data);
383
+ }
384
+ async function updateAgent(params) {
385
+ const { id, ...data } = params;
386
+ return makeRequest(
387
+ "PATCH",
388
+ `/api/agents/${encodeURIComponent(id)}`,
389
+ data
390
+ );
391
+ }
392
+ async function runAgent(id, input) {
393
+ const agent = await getAgent(id);
394
+ const config = agent.config ?? {};
395
+ if (agent.type === "http") {
396
+ const url = config.url;
397
+ if (!url) {
398
+ throw new Error("HTTP agent has no URL configured");
399
+ }
400
+ const result2 = await requestPublicJson(url, {
401
+ method: "POST",
402
+ headers: { "Content-Type": "application/json" },
403
+ body: JSON.stringify(input ?? {})
404
+ });
405
+ return { agentType: "http", result: result2 };
406
+ }
407
+ const workflowId = config.workflowId;
408
+ if (!workflowId) {
409
+ throw new Error(
410
+ `Agent "${agent.name}" (type: ${agent.type}) cannot be executed directly. Only HTTP agents and workflow-linked agents can be run.`
411
+ );
412
+ }
413
+ const { runWorkflow } = await import("./langwatch-api-workflows-5HRZ7HR4.js");
414
+ const result = await runWorkflow(workflowId, input);
415
+ return { agentType: agent.type, result };
416
+ }
417
+ async function deleteAgent(id) {
418
+ return makeRequest(
419
+ "DELETE",
420
+ `/api/agents/${encodeURIComponent(id)}`
421
+ );
422
+ }
423
+
424
+ export {
425
+ listAgents,
426
+ getAgent,
427
+ createAgent,
428
+ updateAgent,
429
+ runAgent,
430
+ deleteAgent
431
+ };
432
+ //# sourceMappingURL=chunk-CE6QMZOP.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  makeRequest
3
- } from "./chunk-42ZHHHIJ.js";
3
+ } from "./chunk-5UWY24RP.js";
4
4
 
5
5
  // src/langwatch-api-model-providers.ts
6
6
  async function listModelProviders() {
@@ -19,4 +19,4 @@ export {
19
19
  listModelProviders,
20
20
  setModelProvider
21
21
  };
22
- //# sourceMappingURL=chunk-X2SEURT2.js.map
22
+ //# sourceMappingURL=chunk-DAIQKS27.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  makeRequest
3
- } from "./chunk-42ZHHHIJ.js";
3
+ } from "./chunk-5UWY24RP.js";
4
4
 
5
5
  // src/langwatch-api-evaluators.ts
6
6
  function getEvaluatorType(evaluator) {
@@ -41,4 +41,4 @@ export {
41
41
  updateEvaluator,
42
42
  deleteEvaluator
43
43
  };
44
- //# sourceMappingURL=chunk-R7C7OUVG.js.map
44
+ //# sourceMappingURL=chunk-EU22L52K.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  makeRequest
3
- } from "./chunk-42ZHHHIJ.js";
3
+ } from "./chunk-5UWY24RP.js";
4
4
 
5
5
  // src/langwatch-api-datasets.ts
6
6
  async function listDatasets(params) {
@@ -83,4 +83,4 @@ export {
83
83
  deleteDatasetRecords,
84
84
  listDatasetRecords
85
85
  };
86
- //# sourceMappingURL=chunk-TROIWSEQ.js.map
86
+ //# sourceMappingURL=chunk-J45SVWPR.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  makeRequest
3
- } from "./chunk-42ZHHHIJ.js";
3
+ } from "./chunk-5UWY24RP.js";
4
4
 
5
5
  // src/langwatch-api-scenarios.ts
6
6
  async function listScenarios() {
@@ -37,4 +37,4 @@ export {
37
37
  updateScenario,
38
38
  archiveScenario
39
39
  };
40
- //# sourceMappingURL=chunk-CCM4ZFGF.js.map
40
+ //# sourceMappingURL=chunk-O3LWVN67.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  makeRequest
3
- } from "./chunk-42ZHHHIJ.js";
3
+ } from "./chunk-5UWY24RP.js";
4
4
 
5
5
  // src/langwatch-api-annotations.ts
6
6
  async function listAnnotations() {
@@ -39,4 +39,4 @@ export {
39
39
  createAnnotation,
40
40
  deleteAnnotation
41
41
  };
42
- //# sourceMappingURL=chunk-BB7EOKHR.js.map
42
+ //# sourceMappingURL=chunk-RYRB2YVJ.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  makeRequest
3
- } from "./chunk-42ZHHHIJ.js";
3
+ } from "./chunk-5UWY24RP.js";
4
4
 
5
5
  // src/langwatch-api-workflows.ts
6
6
  async function listWorkflows() {
@@ -32,4 +32,4 @@ export {
32
32
  runWorkflow,
33
33
  deleteWorkflow
34
34
  };
35
- //# sourceMappingURL=chunk-HKY3GW45.js.map
35
+ //# sourceMappingURL=chunk-T7WJVS2N.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  makeRequest
3
- } from "./chunk-42ZHHHIJ.js";
3
+ } from "./chunk-5UWY24RP.js";
4
4
 
5
5
  // src/langwatch-api-dashboards.ts
6
6
  async function listDashboards() {
@@ -36,4 +36,4 @@ export {
36
36
  renameDashboard,
37
37
  deleteDashboard
38
38
  };
39
- //# sourceMappingURL=chunk-JHOSVOHT.js.map
39
+ //# sourceMappingURL=chunk-UXXA4D6K.js.map