stitchkit 0.8.0 → 0.8.1
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.
- package/dist/cli.js +3 -7
- package/dist/contract/index.js +0 -1
- package/dist/{index-za2p453b.js → index-031q8xmx.js} +1 -1
- package/dist/{index-5qe31283.js → index-9zrq8x5z.js} +9 -6
- package/dist/{index-tr7r1530.js → index-f39j6twc.js} +4 -8
- package/dist/index-jgpsd7dy.js +105 -0
- package/dist/{index-mwmpw6j1.js → index-p9m9c0jw.js} +2 -4
- package/dist/{index-5789sbt8.js → index-svvpy5bz.js} +8 -16
- package/dist/index-tm7dqzxc.js +20 -0
- package/dist/index.js +429 -13
- package/dist/node.js +4 -8
- package/dist/observability/index.js +4 -7
- package/dist/react.js +0 -2
- package/dist/server/index.js +89 -34
- package/dist/tools/mcp-app.d.ts.map +1 -1
- package/dist/tools.js +253 -21
- package/package.json +5 -3
- package/dist/index-37x76zdn.js +0 -4
- package/dist/index-48ffdxgk.js +0 -6
- package/dist/index-809wc1tt.js +0 -18
- package/dist/index-a1702zj4.js +0 -72
- package/dist/index-kdkvp26v.js +0 -380
- package/dist/index-kzfs85xp.js +0 -9
- package/dist/index-wjwj5bz2.js +0 -37
- package/dist/index-x3fcszf8.js +0 -8
package/dist/index.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ApiError,
|
|
3
|
-
createClient,
|
|
4
|
-
createClients,
|
|
5
|
-
createHttpClient
|
|
6
|
-
} from "./index-kdkvp26v.js";
|
|
7
|
-
import {
|
|
8
|
-
parseSSE
|
|
9
|
-
} from "./index-a1702zj4.js";
|
|
10
|
-
import"./index-48ffdxgk.js";
|
|
11
|
-
import"./index-wjwj5bz2.js";
|
|
12
1
|
import {
|
|
13
2
|
ALL_TRANSPORTS,
|
|
14
3
|
AppError,
|
|
@@ -26,8 +15,398 @@ import {
|
|
|
26
15
|
rateLimited,
|
|
27
16
|
unauthorized
|
|
28
17
|
} from "./index-eq29zkrx.js";
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
|
|
19
|
+
// src/internal/http-input.ts
|
|
20
|
+
function inputIsQuery(method) {
|
|
21
|
+
return method === "GET" || method === "DELETE";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/internal/typed.ts
|
|
25
|
+
function typedEntries(value) {
|
|
26
|
+
return Object.entries(value);
|
|
27
|
+
}
|
|
28
|
+
function isRecord(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
function mapObject(source, mapper) {
|
|
32
|
+
const result = {};
|
|
33
|
+
for (const [key, value] of typedEntries(source)) {
|
|
34
|
+
const mapped = mapper(key, value);
|
|
35
|
+
if (mapped !== undefined)
|
|
36
|
+
result[key] = mapped;
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/browser/http.ts
|
|
42
|
+
import ky, { isHTTPError } from "ky";
|
|
43
|
+
class ApiError extends Error {
|
|
44
|
+
code;
|
|
45
|
+
status;
|
|
46
|
+
details;
|
|
47
|
+
hint;
|
|
48
|
+
constructor(code, status = 0, details, message, hint) {
|
|
49
|
+
super(message ?? `API Error: ${code}`);
|
|
50
|
+
this.code = code;
|
|
51
|
+
this.status = status;
|
|
52
|
+
this.details = details;
|
|
53
|
+
this.hint = hint;
|
|
54
|
+
this.name = "ApiError";
|
|
55
|
+
}
|
|
56
|
+
static is(error) {
|
|
57
|
+
return error instanceof ApiError;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function parseApiErrorBody(body) {
|
|
61
|
+
if (!isRecord(body) || !isRecord(body.error))
|
|
62
|
+
return null;
|
|
63
|
+
const error = body.error;
|
|
64
|
+
if (typeof error.code !== "string")
|
|
65
|
+
return null;
|
|
66
|
+
return {
|
|
67
|
+
code: error.code,
|
|
68
|
+
message: typeof error.message === "string" ? error.message : undefined,
|
|
69
|
+
details: error.details,
|
|
70
|
+
hint: typeof error.hint === "string" ? error.hint : undefined
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function createHttpClient(config) {
|
|
74
|
+
let ssrCookies = null;
|
|
75
|
+
let isLoggedOut = false;
|
|
76
|
+
const listeners = new Set;
|
|
77
|
+
const authEndpoints = config.authEndpoints ?? ["/auth/"];
|
|
78
|
+
const parseError = config.parseError ?? parseApiErrorBody;
|
|
79
|
+
function emit(event) {
|
|
80
|
+
for (const fn of listeners) {
|
|
81
|
+
try {
|
|
82
|
+
fn(event);
|
|
83
|
+
} catch {}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const client = ky.create({
|
|
87
|
+
prefix: config.baseUrl,
|
|
88
|
+
credentials: config.credentials ?? "include",
|
|
89
|
+
timeout: config.timeout ?? 30000,
|
|
90
|
+
retry: {
|
|
91
|
+
limit: config.retry?.limit ?? 2,
|
|
92
|
+
methods: config.retry?.methods ?? ["get"],
|
|
93
|
+
statusCodes: config.retry?.statusCodes ?? []
|
|
94
|
+
},
|
|
95
|
+
hooks: {
|
|
96
|
+
beforeRequest: [
|
|
97
|
+
({ request: request2 }) => {
|
|
98
|
+
if (ssrCookies) {
|
|
99
|
+
request2.headers.set("Cookie", ssrCookies);
|
|
100
|
+
}
|
|
101
|
+
const extra = typeof config.headers === "function" ? config.headers() : config.headers;
|
|
102
|
+
if (extra) {
|
|
103
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
104
|
+
request2.headers.set(key, value);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
afterResponse: [
|
|
110
|
+
async ({ request: request2, response }) => {
|
|
111
|
+
if (response.status === 401) {
|
|
112
|
+
const url = new URL(request2.url).pathname;
|
|
113
|
+
if (!isLoggedOut && !authEndpoints.some((path) => url.startsWith(path))) {
|
|
114
|
+
isLoggedOut = true;
|
|
115
|
+
emit({ type: "unauthorized" });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!response.ok) {
|
|
119
|
+
const body = await response.clone().json().catch(() => null);
|
|
120
|
+
if (body) {
|
|
121
|
+
const parsed = parseError(body);
|
|
122
|
+
if (parsed) {
|
|
123
|
+
throw new ApiError(parsed.code, response.status, parsed.details, parsed.message, parsed.hint);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
async function request(method, url, data, options = {}) {
|
|
132
|
+
const kyOptions = {
|
|
133
|
+
timeout: options.timeout
|
|
134
|
+
};
|
|
135
|
+
if (options.params) {
|
|
136
|
+
const searchParams = new URLSearchParams;
|
|
137
|
+
for (const [key, value] of Object.entries(options.params)) {
|
|
138
|
+
if (value === undefined)
|
|
139
|
+
continue;
|
|
140
|
+
if (Array.isArray(value)) {
|
|
141
|
+
for (const item of value)
|
|
142
|
+
searchParams.append(key, String(item));
|
|
143
|
+
} else {
|
|
144
|
+
searchParams.set(key, String(value));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (searchParams.size > 0) {
|
|
148
|
+
kyOptions.searchParams = searchParams;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (data instanceof FormData) {
|
|
152
|
+
kyOptions.body = data;
|
|
153
|
+
} else if (data !== undefined) {
|
|
154
|
+
kyOptions.json = data;
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
if (options.responseType === "blob") {
|
|
158
|
+
return client[method](url, kyOptions).blob();
|
|
159
|
+
}
|
|
160
|
+
const response = await client[method](url, kyOptions);
|
|
161
|
+
if (response.status === 204 || response.headers.get("content-length") === "0") {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
return response.json();
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (ApiError.is(error))
|
|
167
|
+
throw error;
|
|
168
|
+
const isAbort = error instanceof Error && error.name === "AbortError";
|
|
169
|
+
if (!isAbort) {
|
|
170
|
+
emit({ type: "network_error" });
|
|
171
|
+
}
|
|
172
|
+
const status = isAbort ? 0 : isHTTPError(error) ? error.response.status : 0;
|
|
173
|
+
const msg = error instanceof Error ? error.message : undefined;
|
|
174
|
+
throw new ApiError("UNKNOWN_ERROR", status, msg ? { message: msg } : undefined);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
get: (url, options) => request("get", url, undefined, options),
|
|
179
|
+
post: (url, data, options) => request("post", url, data, options),
|
|
180
|
+
put: (url, data, options) => request("put", url, data, options),
|
|
181
|
+
patch: (url, data, options) => request("patch", url, data, options),
|
|
182
|
+
delete: (url, options) => request("delete", url, undefined, options),
|
|
183
|
+
setServerContext(cookies) {
|
|
184
|
+
ssrCookies = cookies;
|
|
185
|
+
},
|
|
186
|
+
subscribe(listener) {
|
|
187
|
+
listeners.add(listener);
|
|
188
|
+
return () => listeners.delete(listener);
|
|
189
|
+
},
|
|
190
|
+
logout() {
|
|
191
|
+
isLoggedOut = true;
|
|
192
|
+
emit({ type: "logout" });
|
|
193
|
+
},
|
|
194
|
+
resetLogoutState() {
|
|
195
|
+
isLoggedOut = false;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/browser/client.ts
|
|
201
|
+
function withTimeout(options, timeout) {
|
|
202
|
+
if (timeout === undefined)
|
|
203
|
+
return options;
|
|
204
|
+
return { ...options, timeout };
|
|
205
|
+
}
|
|
206
|
+
function isParamArray(value) {
|
|
207
|
+
return Array.isArray(value) && value.every((v) => typeof v === "string" || typeof v === "number");
|
|
208
|
+
}
|
|
209
|
+
function collectQueryParams(args, skipKeys) {
|
|
210
|
+
const params = {};
|
|
211
|
+
let hasParams = false;
|
|
212
|
+
for (const [key, value] of Object.entries(args)) {
|
|
213
|
+
if (skipKeys.has(key) || value === undefined || value === null)
|
|
214
|
+
continue;
|
|
215
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || isParamArray(value)) {
|
|
216
|
+
params[key] = value;
|
|
217
|
+
hasParams = true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return hasParams ? params : undefined;
|
|
221
|
+
}
|
|
222
|
+
function createClient(contract, configOrClient, contractConfig) {
|
|
223
|
+
const client = {};
|
|
224
|
+
const makeMethod = isHttpAdapter(configOrClient) ? (endpoint) => createHttpMethod(endpoint, contract.meta.prefix, configOrClient, contractConfig) : (endpoint) => createFetchMethod(endpoint, contract.meta.prefix, configOrClient, contractConfig);
|
|
225
|
+
for (const [key, endpoint] of typedEntries(contract.endpoints)) {
|
|
226
|
+
if (endpoint.expose && !endpoint.expose.includes("HTTP"))
|
|
227
|
+
continue;
|
|
228
|
+
setClientMethod(client, key, makeMethod(endpoint));
|
|
229
|
+
}
|
|
230
|
+
return client;
|
|
231
|
+
}
|
|
232
|
+
function createClients(contracts, http) {
|
|
233
|
+
return mapObject(contracts, (_key, contract) => createClient(contract, http));
|
|
234
|
+
}
|
|
235
|
+
function isHttpAdapter(value) {
|
|
236
|
+
return typeof value === "object" && "get" in value && typeof value.get === "function";
|
|
237
|
+
}
|
|
238
|
+
function setClientMethod(target, key, method) {
|
|
239
|
+
target[key] = method;
|
|
240
|
+
}
|
|
241
|
+
function createHttpMethod(endpoint, prefix, client, config) {
|
|
242
|
+
const httpMethod = endpoint.method.toLowerCase();
|
|
243
|
+
const isGet = httpMethod === "get";
|
|
244
|
+
const paramNames = extractParamNames(endpoint.path);
|
|
245
|
+
const prefixKeys = new Set([...config?.stripPrefixKeys ?? [], ...paramNames]);
|
|
246
|
+
return (...args) => {
|
|
247
|
+
const firstArg = args[0] ?? {};
|
|
248
|
+
let pathPrefixStr = "";
|
|
249
|
+
if (config?.pathPrefix) {
|
|
250
|
+
pathPrefixStr = typeof config.pathPrefix === "function" ? config.pathPrefix(firstArg) : config.pathPrefix;
|
|
251
|
+
if (pathPrefixStr && !pathPrefixStr.endsWith("/"))
|
|
252
|
+
pathPrefixStr += "/";
|
|
253
|
+
}
|
|
254
|
+
let url = `${pathPrefixStr}${prefix}${endpoint.path}`;
|
|
255
|
+
for (const name of paramNames) {
|
|
256
|
+
const value = firstArg[name];
|
|
257
|
+
if (value === undefined || value === null) {
|
|
258
|
+
throw new Error(`Missing path param: ${name}`);
|
|
259
|
+
}
|
|
260
|
+
url = url.replace(`:${name}`, encodeURIComponent(String(value)));
|
|
261
|
+
}
|
|
262
|
+
if (url.endsWith("/"))
|
|
263
|
+
url = url.slice(0, -1);
|
|
264
|
+
if (endpoint.multipart) {
|
|
265
|
+
const file = firstArg[endpoint.multipart];
|
|
266
|
+
if (!(file instanceof Blob)) {
|
|
267
|
+
throw new Error(`Missing multipart file field: ${endpoint.multipart}`);
|
|
268
|
+
}
|
|
269
|
+
const formData = new FormData;
|
|
270
|
+
formData.append(endpoint.multipart, file);
|
|
271
|
+
appendFormFields(formData, firstArg, new Set([...prefixKeys, endpoint.multipart]));
|
|
272
|
+
return client.post(url, formData, withTimeout(undefined, endpoint.timeout));
|
|
273
|
+
}
|
|
274
|
+
if (isGet) {
|
|
275
|
+
const params = collectQueryParams(firstArg, prefixKeys);
|
|
276
|
+
return client.get(url, withTimeout(params ? { params } : undefined, endpoint.timeout));
|
|
277
|
+
}
|
|
278
|
+
if (httpMethod === "delete") {
|
|
279
|
+
const params = collectQueryParams(firstArg, prefixKeys);
|
|
280
|
+
return client.delete(url, withTimeout(params ? { params } : undefined, endpoint.timeout));
|
|
281
|
+
}
|
|
282
|
+
const payload = {};
|
|
283
|
+
for (const [key, value] of Object.entries(firstArg)) {
|
|
284
|
+
if (!prefixKeys.has(key) && value !== undefined) {
|
|
285
|
+
payload[key] = value;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return client[httpMethod](url, Object.keys(payload).length > 0 ? payload : undefined, withTimeout(undefined, endpoint.timeout));
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
function createFetchMethod(endpoint, prefix, config, contractConfig) {
|
|
292
|
+
const prefixKeys = new Set(contractConfig?.stripPrefixKeys ?? []);
|
|
293
|
+
return async (args) => {
|
|
294
|
+
let pathPrefixStr = "";
|
|
295
|
+
if (contractConfig?.pathPrefix) {
|
|
296
|
+
pathPrefixStr = typeof contractConfig.pathPrefix === "function" ? contractConfig.pathPrefix(args ?? {}) : contractConfig.pathPrefix;
|
|
297
|
+
if (pathPrefixStr && !pathPrefixStr.endsWith("/"))
|
|
298
|
+
pathPrefixStr += "/";
|
|
299
|
+
}
|
|
300
|
+
let url = buildFetchUrl(config.baseUrl, prefix, endpoint.path, args, pathPrefixStr);
|
|
301
|
+
const headers = {
|
|
302
|
+
Accept: "application/json",
|
|
303
|
+
...typeof config.headers === "function" ? config.headers() : config.headers
|
|
304
|
+
};
|
|
305
|
+
const isQuery = inputIsQuery(endpoint.method);
|
|
306
|
+
const hasBody = !isQuery && !endpoint.multipart && endpoint.input && args;
|
|
307
|
+
if (isQuery && args) {
|
|
308
|
+
const remaining = stripParams(args, endpoint.path, prefixKeys);
|
|
309
|
+
const searchParams = new URLSearchParams;
|
|
310
|
+
for (const [k, v] of Object.entries(remaining)) {
|
|
311
|
+
if (v === undefined || v === null)
|
|
312
|
+
continue;
|
|
313
|
+
if (isParamArray(v)) {
|
|
314
|
+
for (const item of v)
|
|
315
|
+
searchParams.append(k, String(item));
|
|
316
|
+
} else if (typeof v !== "object") {
|
|
317
|
+
searchParams.set(k, String(v));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (searchParams.size > 0)
|
|
321
|
+
url += `?${searchParams}`;
|
|
322
|
+
}
|
|
323
|
+
if (hasBody)
|
|
324
|
+
headers["Content-Type"] = "application/json";
|
|
325
|
+
if (endpoint.multipart && args) {
|
|
326
|
+
const file = args[endpoint.multipart];
|
|
327
|
+
if (!(file instanceof Blob)) {
|
|
328
|
+
throw new Error(`Missing multipart file field: ${endpoint.multipart}`);
|
|
329
|
+
}
|
|
330
|
+
const formData = new FormData;
|
|
331
|
+
formData.append(endpoint.multipart, file);
|
|
332
|
+
appendFormFields(formData, stripParams(args, endpoint.path, prefixKeys), new Set([endpoint.multipart]));
|
|
333
|
+
const res2 = await fetch(url, {
|
|
334
|
+
method: endpoint.method,
|
|
335
|
+
headers,
|
|
336
|
+
credentials: config.credentials,
|
|
337
|
+
body: formData
|
|
338
|
+
});
|
|
339
|
+
if (!res2.ok) {
|
|
340
|
+
await throwForErrorResponse(res2, config, null);
|
|
341
|
+
}
|
|
342
|
+
if (res2.status === 204)
|
|
343
|
+
return;
|
|
344
|
+
const json2 = await res2.json();
|
|
345
|
+
return endpoint.output ? endpoint.output.parse(json2) : json2;
|
|
346
|
+
}
|
|
347
|
+
const res = await fetch(url, {
|
|
348
|
+
method: endpoint.method,
|
|
349
|
+
headers,
|
|
350
|
+
credentials: config.credentials,
|
|
351
|
+
...hasBody && {
|
|
352
|
+
body: JSON.stringify(stripParams(hasBody, endpoint.path, prefixKeys))
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
if (!res.ok) {
|
|
356
|
+
await throwForErrorResponse(res, config, { error: res.statusText });
|
|
357
|
+
}
|
|
358
|
+
if (res.status === 204)
|
|
359
|
+
return;
|
|
360
|
+
const json = await res.json();
|
|
361
|
+
return endpoint.output ? endpoint.output.parse(json) : json;
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
function appendFormFields(formData, values, skipKeys) {
|
|
365
|
+
for (const [key, value] of Object.entries(values)) {
|
|
366
|
+
if (skipKeys.has(key) || value === undefined || value === null)
|
|
367
|
+
continue;
|
|
368
|
+
formData.append(key, typeof value === "string" ? value : JSON.stringify(value));
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
async function throwForErrorResponse(res, config, fallbackBody) {
|
|
372
|
+
const body = await res.json().catch(() => fallbackBody);
|
|
373
|
+
config.onError?.(res.status, body);
|
|
374
|
+
const parsed = parseApiErrorBody(body);
|
|
375
|
+
if (parsed) {
|
|
376
|
+
throw new ApiError(parsed.code, res.status, parsed.details, parsed.message, parsed.hint);
|
|
377
|
+
}
|
|
378
|
+
throw new ApiError("HTTP_ERROR", res.status, { body });
|
|
379
|
+
}
|
|
380
|
+
function extractParamNames(path) {
|
|
381
|
+
const matches = path.match(/:(\w+)/g);
|
|
382
|
+
return matches ? matches.map((m) => m.slice(1)) : [];
|
|
383
|
+
}
|
|
384
|
+
function buildFetchUrl(baseUrl, prefix, path, args, pathPrefix = "") {
|
|
385
|
+
let fullPath = `/${pathPrefix}${prefix}${path === "/" ? "" : path}`;
|
|
386
|
+
if (args) {
|
|
387
|
+
fullPath = fullPath.replace(/:(\w+)/g, (_, key) => {
|
|
388
|
+
const val = args[key];
|
|
389
|
+
if (val === undefined || val === null) {
|
|
390
|
+
throw new Error(`Missing path param: ${key}`);
|
|
391
|
+
}
|
|
392
|
+
return encodeURIComponent(String(val));
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
return `${baseUrl}${fullPath}`;
|
|
396
|
+
}
|
|
397
|
+
function stripParams(args, path, extra) {
|
|
398
|
+
const skip = new Set(extra);
|
|
399
|
+
for (const match of path.matchAll(/:(\w+)/g)) {
|
|
400
|
+
if (match[1])
|
|
401
|
+
skip.add(match[1]);
|
|
402
|
+
}
|
|
403
|
+
const result = {};
|
|
404
|
+
for (const [k, v] of Object.entries(args)) {
|
|
405
|
+
if (!skip.has(k))
|
|
406
|
+
result[k] = v;
|
|
407
|
+
}
|
|
408
|
+
return result;
|
|
409
|
+
}
|
|
31
410
|
// src/browser/socket-io.ts
|
|
32
411
|
import { io } from "socket.io-client";
|
|
33
412
|
function toIoAuth(auth) {
|
|
@@ -107,6 +486,43 @@ function createSocketIOClient(config) {
|
|
|
107
486
|
}
|
|
108
487
|
};
|
|
109
488
|
}
|
|
489
|
+
// src/internal/errors.ts
|
|
490
|
+
import { z } from "zod";
|
|
491
|
+
|
|
492
|
+
// src/server/stream.ts
|
|
493
|
+
async function* parseSSE(response, options) {
|
|
494
|
+
const reader = response.body?.getReader();
|
|
495
|
+
if (!reader)
|
|
496
|
+
return;
|
|
497
|
+
const decoder = new TextDecoder;
|
|
498
|
+
let buffer = "";
|
|
499
|
+
try {
|
|
500
|
+
while (true) {
|
|
501
|
+
const { done, value } = await reader.read();
|
|
502
|
+
if (done)
|
|
503
|
+
break;
|
|
504
|
+
buffer += decoder.decode(value, { stream: true });
|
|
505
|
+
const lines = buffer.split(`
|
|
506
|
+
`);
|
|
507
|
+
buffer = lines.pop() ?? "";
|
|
508
|
+
for (const rawLine of lines) {
|
|
509
|
+
const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
|
|
510
|
+
if (!line.startsWith("data:"))
|
|
511
|
+
continue;
|
|
512
|
+
const data = line.slice(5).replace(/^ /, "");
|
|
513
|
+
if (data === "[DONE]")
|
|
514
|
+
return;
|
|
515
|
+
try {
|
|
516
|
+
yield JSON.parse(data);
|
|
517
|
+
} catch (err) {
|
|
518
|
+
options?.onParseError?.(data, err instanceof Error ? err : new Error(String(err)));
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
} finally {
|
|
523
|
+
reader.releaseLock();
|
|
524
|
+
}
|
|
525
|
+
}
|
|
110
526
|
export {
|
|
111
527
|
unauthorized,
|
|
112
528
|
rateLimited,
|
package/dist/node.js
CHANGED
|
@@ -3,9 +3,7 @@ import {
|
|
|
3
3
|
createImplement,
|
|
4
4
|
createSocketIOServer,
|
|
5
5
|
implement
|
|
6
|
-
} from "./index-
|
|
7
|
-
import"./index-x3fcszf8.js";
|
|
8
|
-
import"./index-wjwj5bz2.js";
|
|
6
|
+
} from "./index-svvpy5bz.js";
|
|
9
7
|
import {
|
|
10
8
|
AppError,
|
|
11
9
|
appError,
|
|
@@ -15,11 +13,9 @@ import {
|
|
|
15
13
|
notFound,
|
|
16
14
|
rateLimited,
|
|
17
15
|
unauthorized
|
|
18
|
-
} from "./index-
|
|
19
|
-
import"./index-
|
|
20
|
-
import"./index-
|
|
21
|
-
import"./index-809wc1tt.js";
|
|
22
|
-
import"./index-37x76zdn.js";
|
|
16
|
+
} from "./index-jgpsd7dy.js";
|
|
17
|
+
import"./index-p9m9c0jw.js";
|
|
18
|
+
import"./index-tm7dqzxc.js";
|
|
23
19
|
// src/server/node.ts
|
|
24
20
|
import { serve } from "srvx";
|
|
25
21
|
async function serveNode(config) {
|
|
@@ -11,15 +11,12 @@ import {
|
|
|
11
11
|
setRequestError,
|
|
12
12
|
setRequestUser,
|
|
13
13
|
wrapInRequestContext
|
|
14
|
-
} from "../index-
|
|
15
|
-
import"../index-
|
|
14
|
+
} from "../index-031q8xmx.js";
|
|
15
|
+
import"../index-p9m9c0jw.js";
|
|
16
16
|
import {
|
|
17
|
+
isRecord,
|
|
17
18
|
isUnsafeKey
|
|
18
|
-
} from "../index-
|
|
19
|
-
import {
|
|
20
|
-
isRecord
|
|
21
|
-
} from "../index-809wc1tt.js";
|
|
22
|
-
import"../index-37x76zdn.js";
|
|
19
|
+
} from "../index-tm7dqzxc.js";
|
|
23
20
|
|
|
24
21
|
// src/observability/sanitize.ts
|
|
25
22
|
var DEFAULT_SENSITIVE_KEYS = /(password|passwd|pwd|secret|token|apikey|api[-_ ]?key|auth|authorization|bearer|session|cookie|init[-_ ]?data|credential|private[-_ ]?key)/i;
|
package/dist/react.js
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -1,48 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
composeWebSocketHandlers,
|
|
3
|
+
corsHeaders,
|
|
4
|
+
corsPreflightResponse,
|
|
5
|
+
createHandler,
|
|
6
|
+
createImplement,
|
|
7
|
+
createServer,
|
|
8
|
+
createSocketIOServer,
|
|
9
|
+
implement,
|
|
10
|
+
mimeForPath,
|
|
11
|
+
parseMultipart,
|
|
12
|
+
socketIoLane,
|
|
13
|
+
staticRoute,
|
|
14
|
+
webSocketLane
|
|
15
|
+
} from "../index-svvpy5bz.js";
|
|
5
16
|
import {
|
|
6
17
|
createAuthHook,
|
|
7
18
|
createBearerResolver,
|
|
8
19
|
defineCookie,
|
|
9
20
|
deriveCodeChallenge,
|
|
10
21
|
extractToken,
|
|
22
|
+
inputIsQuery,
|
|
11
23
|
parseCookies,
|
|
12
24
|
serializeCookie,
|
|
13
25
|
signJwt,
|
|
14
26
|
verifyJwt,
|
|
15
27
|
verifyPkce
|
|
16
|
-
} from "../index-
|
|
17
|
-
import {
|
|
18
|
-
inputIsQuery
|
|
19
|
-
} from "../index-48ffdxgk.js";
|
|
28
|
+
} from "../index-9zrq8x5z.js";
|
|
20
29
|
import {
|
|
21
30
|
jsonSchemaFields,
|
|
22
31
|
toJsonSchema
|
|
23
32
|
} from "../index-0ed3bx43.js";
|
|
24
|
-
import {
|
|
25
|
-
getTraceId
|
|
26
|
-
} from "../index-za2p453b.js";
|
|
27
|
-
import {
|
|
28
|
-
composeWebSocketHandlers,
|
|
29
|
-
corsHeaders,
|
|
30
|
-
corsPreflightResponse,
|
|
31
|
-
createHandler,
|
|
32
|
-
createImplement,
|
|
33
|
-
createServer,
|
|
34
|
-
createSocketIOServer,
|
|
35
|
-
implement,
|
|
36
|
-
mimeForPath,
|
|
37
|
-
parseMultipart,
|
|
38
|
-
socketIoLane,
|
|
39
|
-
staticRoute,
|
|
40
|
-
webSocketLane
|
|
41
|
-
} from "../index-5789sbt8.js";
|
|
42
|
-
import"../index-x3fcszf8.js";
|
|
43
|
-
import {
|
|
44
|
-
normalizeError
|
|
45
|
-
} from "../index-wjwj5bz2.js";
|
|
46
33
|
import {
|
|
47
34
|
AppError,
|
|
48
35
|
STITCH_ERROR_STATUS,
|
|
@@ -51,22 +38,24 @@ import {
|
|
|
51
38
|
conflict,
|
|
52
39
|
forbidden,
|
|
53
40
|
isStitchErrorCode,
|
|
41
|
+
normalizeError,
|
|
54
42
|
notFound,
|
|
55
43
|
rateLimited,
|
|
56
44
|
unauthorized
|
|
57
|
-
} from "../index-
|
|
45
|
+
} from "../index-jgpsd7dy.js";
|
|
46
|
+
import {
|
|
47
|
+
getTraceId
|
|
48
|
+
} from "../index-031q8xmx.js";
|
|
58
49
|
import {
|
|
59
50
|
extractIp,
|
|
60
51
|
generateTraceId,
|
|
61
52
|
getClientInfo,
|
|
62
53
|
resolveSocketIp,
|
|
63
54
|
resolveTraceId
|
|
64
|
-
} from "../index-
|
|
65
|
-
import"../index-kzfs85xp.js";
|
|
55
|
+
} from "../index-p9m9c0jw.js";
|
|
66
56
|
import {
|
|
67
57
|
isRecord
|
|
68
|
-
} from "../index-
|
|
69
|
-
import"../index-37x76zdn.js";
|
|
58
|
+
} from "../index-tm7dqzxc.js";
|
|
70
59
|
// src/server/swept-map.ts
|
|
71
60
|
function createSweptMap(options) {
|
|
72
61
|
const store = new Map;
|
|
@@ -539,6 +528,72 @@ async function parseBody(req, schema) {
|
|
|
539
528
|
const parsed = schema.safeParse(raw);
|
|
540
529
|
return parsed.success ? parsed.data : null;
|
|
541
530
|
}
|
|
531
|
+
// src/server/stream.ts
|
|
532
|
+
function streamSSE(generator) {
|
|
533
|
+
const encoder = new TextEncoder;
|
|
534
|
+
const stream = new ReadableStream({
|
|
535
|
+
async start(controller) {
|
|
536
|
+
try {
|
|
537
|
+
for await (const chunk of generator) {
|
|
538
|
+
const data = JSON.stringify(chunk);
|
|
539
|
+
controller.enqueue(encoder.encode(`data: ${data}
|
|
540
|
+
|
|
541
|
+
`));
|
|
542
|
+
}
|
|
543
|
+
controller.enqueue(encoder.encode(`data: [DONE]
|
|
544
|
+
|
|
545
|
+
`));
|
|
546
|
+
controller.close();
|
|
547
|
+
} catch (err) {
|
|
548
|
+
const envelope = normalizeError(err).toJSON();
|
|
549
|
+
controller.enqueue(encoder.encode(`data: ${JSON.stringify(envelope)}
|
|
550
|
+
|
|
551
|
+
`));
|
|
552
|
+
controller.close();
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
return new Response(stream, {
|
|
557
|
+
headers: {
|
|
558
|
+
"Content-Type": "text/event-stream",
|
|
559
|
+
"Cache-Control": "no-cache",
|
|
560
|
+
Connection: "keep-alive"
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
async function* parseSSE(response, options) {
|
|
565
|
+
const reader = response.body?.getReader();
|
|
566
|
+
if (!reader)
|
|
567
|
+
return;
|
|
568
|
+
const decoder = new TextDecoder;
|
|
569
|
+
let buffer = "";
|
|
570
|
+
try {
|
|
571
|
+
while (true) {
|
|
572
|
+
const { done, value } = await reader.read();
|
|
573
|
+
if (done)
|
|
574
|
+
break;
|
|
575
|
+
buffer += decoder.decode(value, { stream: true });
|
|
576
|
+
const lines = buffer.split(`
|
|
577
|
+
`);
|
|
578
|
+
buffer = lines.pop() ?? "";
|
|
579
|
+
for (const rawLine of lines) {
|
|
580
|
+
const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
|
|
581
|
+
if (!line.startsWith("data:"))
|
|
582
|
+
continue;
|
|
583
|
+
const data = line.slice(5).replace(/^ /, "");
|
|
584
|
+
if (data === "[DONE]")
|
|
585
|
+
return;
|
|
586
|
+
try {
|
|
587
|
+
yield JSON.parse(data);
|
|
588
|
+
} catch (err) {
|
|
589
|
+
options?.onParseError?.(data, err instanceof Error ? err : new Error(String(err)));
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
} finally {
|
|
594
|
+
reader.releaseLock();
|
|
595
|
+
}
|
|
596
|
+
}
|
|
542
597
|
export {
|
|
543
598
|
webSocketLane,
|
|
544
599
|
weakETag,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-app.d.ts","sourceRoot":"","sources":["../../src/tools/mcp-app.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,eAAO,MAAM,kBAAkB,8BAA8B,CAAC;AAE9D,oFAAoF;AACpF,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAErE;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,iFAAiF;IACjF,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gFAAgF;IAChF,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,0BAA0B;IAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,kDAAkD;IAClD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACxB,uEAAuE;IACvE,IAAI,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACtC;
|
|
1
|
+
{"version":3,"file":"mcp-app.d.ts","sourceRoot":"","sources":["../../src/tools/mcp-app.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,eAAO,MAAM,kBAAkB,8BAA8B,CAAC;AAE9D,oFAAoF;AACpF,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAErE;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,iFAAiF;IACjF,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gFAAgF;IAChF,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,0BAA0B;IAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,kDAAkD;IAClD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACxB,uEAAuE;IACvE,IAAI,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACtC;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkCvD"}
|