stitchkit 0.124.0 → 0.124.2
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/CHANGELOG.md +63 -0
- package/dist/browser/client-executors.d.ts.map +1 -1
- package/dist/browser/contract-stream.d.ts +7 -2
- package/dist/browser/contract-stream.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/coding-tools.js +1 -1
- package/dist/entrypoints/agent-runtime/realtime.js +3 -3
- package/dist/entrypoints/agent-runtime/sandbox.js +2 -2
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +3 -3
- package/dist/entrypoints/agent-runtime/sqlite/node.js +3 -3
- package/dist/entrypoints/agent-runtime/testing.js +3 -3
- package/dist/entrypoints/agent-runtime.js +3 -3
- package/dist/entrypoints/application/diagnostic-journal.js +3 -5
- package/dist/entrypoints/application/directory-inbox.js +9 -11
- package/dist/entrypoints/application.js +3 -3
- package/dist/entrypoints/cli/publish.js +6 -6
- package/dist/entrypoints/cli.js +6 -3
- package/dist/entrypoints/files.js +5 -5
- package/dist/entrypoints/http.js +2 -2
- package/dist/entrypoints/index.js +6 -6
- package/dist/entrypoints/node.js +1 -1
- package/dist/entrypoints/process.js +1 -1
- package/dist/entrypoints/remote.js +1 -1
- package/dist/entrypoints/server.js +8 -8
- package/dist/entrypoints/telegram.js +2 -2
- package/dist/entrypoints/testing.js +1 -1
- package/dist/entrypoints/tools/connections.d.ts +2 -2
- package/dist/entrypoints/tools/connections.d.ts.map +1 -1
- package/dist/entrypoints/tools/connections.js +122 -30
- package/dist/entrypoints/tools/mcp.d.ts +1 -1
- package/dist/entrypoints/tools/mcp.d.ts.map +1 -1
- package/dist/entrypoints/tools/mcp.js +8 -6
- package/dist/entrypoints/tools/toolkit.js +2 -2
- package/dist/entrypoints/tools.js +3 -3
- package/dist/{index-8yky60kq.js → index-1szhrfsf.js} +5 -7
- package/dist/{index-mqttte96.js → index-3ymcmpa9.js} +3 -5
- package/dist/{index-v8xm2s9v.js → index-7177dxjn.js} +1 -1
- package/dist/{index-2x2ch0bt.js → index-782qtc24.js} +1 -1
- package/dist/{index-j8rda9n6.js → index-8pwwd6rp.js} +3 -3
- package/dist/{index-m616f0yz.js → index-8x0q6yfb.js} +134 -7
- package/dist/{index-jswst0h3.js → index-b2sey031.js} +50 -5
- package/dist/{index-tt3ej8r3.js → index-btjwc7xr.js} +217 -24
- package/dist/{index-ezwvsqx9.js → index-fvd6pvw3.js} +1 -1
- package/dist/{index-6qrspvxp.js → index-gbj964dt.js} +1 -1
- package/dist/{index-q89kd1xc.js → index-hzk4ydpy.js} +1 -1
- package/dist/{index-w0wy05gr.js → index-jkjh7zw4.js} +50 -40
- package/dist/{index-ac6vvm30.js → index-jp2qd9jb.js} +1 -1
- package/dist/{index-45dyex0j.js → index-m9hb9wnk.js} +1 -1
- package/dist/index-mm89hd8v.js +39 -0
- package/dist/{index-zbzagr9k.js → index-ne4j9998.js} +16 -15
- package/dist/{index-jc5xgkpk.js → index-qsm899qp.js} +1 -1
- package/dist/{index-cjbn98zt.js → index-ss67fxhj.js} +21 -3
- package/dist/index-wqzw3qg9.js +91 -0
- package/dist/{index-364k2zwa.js → index-wt6rw7rf.js} +5 -7
- package/dist/{index-5efrpfmj.js → index-wxadzdb7.js} +1 -1
- package/dist/internal/deadline.d.ts +30 -0
- package/dist/internal/deadline.d.ts.map +1 -1
- package/dist/internal/pinned-http.d.ts +1 -1
- package/dist/internal/pinned-http.d.ts.map +1 -1
- package/dist/internal/secure-fetch.d.ts +8 -0
- package/dist/internal/secure-fetch.d.ts.map +1 -1
- package/dist/internal/stream-chunks.d.ts +10 -0
- package/dist/internal/stream-chunks.d.ts.map +1 -1
- package/dist/tools/cli/resumable-download.d.ts +18 -0
- package/dist/tools/cli/resumable-download.d.ts.map +1 -0
- package/dist/tools/cli/update.d.ts +18 -0
- package/dist/tools/cli/update.d.ts.map +1 -1
- package/dist/tools/connections/catalog-cache.d.ts +9 -0
- package/dist/tools/connections/catalog-cache.d.ts.map +1 -0
- package/dist/tools/connections/errors.d.ts +10 -1
- package/dist/tools/connections/errors.d.ts.map +1 -1
- package/dist/tools/connections/limits.d.ts +16 -4
- package/dist/tools/connections/limits.d.ts.map +1 -1
- package/dist/tools/connections/mcp-client.d.ts +10 -2
- package/dist/tools/connections/mcp-client.d.ts.map +1 -1
- package/dist/tools/connections/mcp.d.ts.map +1 -1
- package/dist/tools/connections/operation-limits.d.ts +12 -1
- package/dist/tools/connections/operation-limits.d.ts.map +1 -1
- package/dist/tools/connections/sse-session.d.ts +2 -2
- package/dist/tools/connections/sse-session.d.ts.map +1 -1
- package/dist/tools/connections/types.d.ts +38 -2
- package/dist/tools/connections/types.d.ts.map +1 -1
- package/dist/tools/mcp/catalog-stamp.d.ts +47 -0
- package/dist/tools/mcp/catalog-stamp.d.ts.map +1 -0
- package/dist/tools/mcp/catalog.d.ts +1 -30
- package/dist/tools/mcp/catalog.d.ts.map +1 -1
- package/dist/tools/mcp/handler.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +6 -1
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts +1 -1
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
- package/llms/cli.2.txt +60 -6
- package/llms/stitchkit.2.txt +6 -0
- package/llms/stitchkit.3.txt +1 -1
- package/llms/tools-connections.txt +5 -3
- package/llms/tools-mcp.txt +5 -2
- package/llms/tools.txt +10 -3
- package/llms-full.txt +87 -15
- package/llms.txt +5 -5
- package/package.json +6 -6
- package/dist/index-9tqbxv5p.js +0 -44
- package/dist/index-b56nnscm.js +0 -132
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
raceAbort
|
|
3
3
|
} from "./index-b0kddvzw.js";
|
|
4
|
+
import {
|
|
5
|
+
startIdleTimer
|
|
6
|
+
} from "./index-wqzw3qg9.js";
|
|
4
7
|
import {
|
|
5
8
|
readBoundedChunks
|
|
6
|
-
} from "./index-
|
|
9
|
+
} from "./index-wxadzdb7.js";
|
|
7
10
|
|
|
8
11
|
// src/internal/secure-fetch.ts
|
|
9
12
|
import { lookup } from "node:dns/promises";
|
|
@@ -25,7 +28,7 @@ async function requestPinned(url, resolved, signal, headers = {}) {
|
|
|
25
28
|
method: "GET",
|
|
26
29
|
signal,
|
|
27
30
|
...url.protocol === "https:" ? { servername: url.hostname } : {},
|
|
28
|
-
headers: {
|
|
31
|
+
headers: { accept: "*/*", ...headers, host: url.host }
|
|
29
32
|
}, (response) => {
|
|
30
33
|
answered = true;
|
|
31
34
|
resolve(response);
|
|
@@ -200,6 +203,7 @@ async function fetchGuarded(start, allowPrivate, options = {}) {
|
|
|
200
203
|
controller.abort(new Error(`fetch did not produce response headers within ${timeoutMs}ms`));
|
|
201
204
|
}, timeoutMs);
|
|
202
205
|
headerTimer.unref?.();
|
|
206
|
+
const idle = options.idleTimeoutMs === undefined ? undefined : startIdleTimer(options.idleTimeoutMs, () => controller.abort(new Error(`fetch received nothing for ${options.idleTimeoutMs}ms`)), { unref: true });
|
|
203
207
|
const transport = options.transport ?? requestPinned;
|
|
204
208
|
let settled = false;
|
|
205
209
|
try {
|
|
@@ -209,7 +213,9 @@ async function fetchGuarded(start, allowPrivate, options = {}) {
|
|
|
209
213
|
throw new Error("refusing to fetch a URL that carries credentials");
|
|
210
214
|
}
|
|
211
215
|
const resolved = await resolveAddress(url, allowPrivate, signal, options.dns);
|
|
212
|
-
const
|
|
216
|
+
const headers = url.origin === start.origin ? options.headers : undefined;
|
|
217
|
+
const res = await transport(url, resolved, signal, headers);
|
|
218
|
+
idle?.touch();
|
|
213
219
|
const location = res.status >= 300 && res.status < 400 ? res.headers.get("location") : null;
|
|
214
220
|
if (location === null) {
|
|
215
221
|
settled = true;
|
|
@@ -218,16 +224,55 @@ async function fetchGuarded(start, allowPrivate, options = {}) {
|
|
|
218
224
|
controller.abort(new Error(`fetch body was not consumed within ${bodyTimeoutMs}ms`));
|
|
219
225
|
}, bodyTimeoutMs);
|
|
220
226
|
bodyTimer.unref?.();
|
|
221
|
-
return res;
|
|
227
|
+
return observeBody(res, signal, idle, bodyTimer);
|
|
222
228
|
}
|
|
223
229
|
await res.body?.cancel();
|
|
224
230
|
url = new URL(location, url);
|
|
225
231
|
}
|
|
226
232
|
throw new Error("too many redirects");
|
|
227
233
|
} finally {
|
|
228
|
-
if (!settled)
|
|
234
|
+
if (!settled) {
|
|
229
235
|
clearTimeout(headerTimer);
|
|
236
|
+
idle?.stop();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function observeBody(res, signal, idle, bodyTimer) {
|
|
241
|
+
const end = () => {
|
|
242
|
+
idle?.stop();
|
|
243
|
+
clearTimeout(bodyTimer);
|
|
244
|
+
};
|
|
245
|
+
if (!res.body) {
|
|
246
|
+
end();
|
|
247
|
+
return res;
|
|
230
248
|
}
|
|
249
|
+
const reader = res.body.getReader();
|
|
250
|
+
const body = new ReadableStream({
|
|
251
|
+
async pull(controller) {
|
|
252
|
+
try {
|
|
253
|
+
const { done, value } = await reader.read();
|
|
254
|
+
if (done) {
|
|
255
|
+
end();
|
|
256
|
+
controller.close();
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
idle?.touch();
|
|
260
|
+
controller.enqueue(value);
|
|
261
|
+
} catch (error) {
|
|
262
|
+
end();
|
|
263
|
+
controller.error(signal.aborted ? signal.reason : error);
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
cancel(reason) {
|
|
267
|
+
end();
|
|
268
|
+
return reader.cancel(reason);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
return new Response(body, {
|
|
272
|
+
status: res.status,
|
|
273
|
+
statusText: res.statusText,
|
|
274
|
+
headers: res.headers
|
|
275
|
+
});
|
|
231
276
|
}
|
|
232
277
|
async function resolveAddress(url, allowPrivate, signal, dns) {
|
|
233
278
|
if (!allowPrivate)
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
ExclusiveLockError2,
|
|
3
|
+
withExclusiveLock2
|
|
4
|
+
} from "./index-fvd6pvw3.js";
|
|
4
5
|
import {
|
|
5
6
|
writeFileAtomicSync2
|
|
6
|
-
} from "./index-
|
|
7
|
+
} from "./index-jp2qd9jb.js";
|
|
7
8
|
import {
|
|
8
9
|
fetchGuarded,
|
|
9
10
|
PrivateAddressRefusal,
|
|
10
11
|
readCapped
|
|
11
|
-
} from "./index-
|
|
12
|
+
} from "./index-b2sey031.js";
|
|
12
13
|
import {
|
|
13
14
|
raceAbort
|
|
14
15
|
} from "./index-b0kddvzw.js";
|
|
16
|
+
import {
|
|
17
|
+
withSignalDeadline
|
|
18
|
+
} from "./index-wqzw3qg9.js";
|
|
15
19
|
import {
|
|
16
20
|
assertPositiveSafeInteger
|
|
17
21
|
} from "./index-0s4xebbg.js";
|
|
@@ -139,8 +143,8 @@ function assertCliPublishable2(previous, next) {
|
|
|
139
143
|
|
|
140
144
|
// src/tools/cli/update.ts
|
|
141
145
|
import { createHash as createHash2, randomBytes } from "node:crypto";
|
|
142
|
-
import { existsSync, readFileSync, statSync, unlinkSync } from "node:fs";
|
|
143
|
-
import { basename, dirname, extname, join } from "node:path";
|
|
146
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, statSync as statSync2, unlinkSync } from "node:fs";
|
|
147
|
+
import { basename, dirname as dirname2, extname, join } from "node:path";
|
|
144
148
|
|
|
145
149
|
// src/tools/cli/publication-assets.ts
|
|
146
150
|
import { createHash } from "node:crypto";
|
|
@@ -251,10 +255,198 @@ async function decodeCliAsset(transferred, asset, maxBytes, signal) {
|
|
|
251
255
|
return { bytes, sha256 };
|
|
252
256
|
}
|
|
253
257
|
|
|
258
|
+
// src/tools/cli/resumable-download.ts
|
|
259
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, statSync } from "node:fs";
|
|
260
|
+
import { open } from "node:fs/promises";
|
|
261
|
+
import { dirname } from "node:path";
|
|
262
|
+
import { z as z3 } from "zod";
|
|
263
|
+
var PartialRecordSchema = z3.object({
|
|
264
|
+
url: z3.string(),
|
|
265
|
+
sha256: z3.string(),
|
|
266
|
+
validator: z3.string().optional()
|
|
267
|
+
});
|
|
268
|
+
async function downloadCliAsset(config, decode) {
|
|
269
|
+
const { partialPath } = config;
|
|
270
|
+
if (partialPath === undefined)
|
|
271
|
+
return decode(await downloadInMemory(config));
|
|
272
|
+
mkdirSync(dirname(partialPath), { recursive: true, mode: 448 });
|
|
273
|
+
try {
|
|
274
|
+
return await withExclusiveLock2(`${partialPath}.lock`, async () => {
|
|
275
|
+
const first = await downloadToPart(config, partialPath, true);
|
|
276
|
+
try {
|
|
277
|
+
return await decodeAndForget(first, partialPath, decode);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
if (!first.continued)
|
|
280
|
+
throw error;
|
|
281
|
+
return decodeAndForget(await downloadToPart(config, partialPath, false), partialPath, decode);
|
|
282
|
+
}
|
|
283
|
+
}, { timeoutMs: 0, label: "CLI update download" });
|
|
284
|
+
} catch (error) {
|
|
285
|
+
if (error instanceof ExclusiveLockError2 && error.code === "LOCK_TIMEOUT") {
|
|
286
|
+
throw new Error(`[stitchkit] update: another update is already downloading into ${partialPath}`, { cause: error });
|
|
287
|
+
}
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
async function decodeAndForget(transfer, partialPath, decode) {
|
|
292
|
+
try {
|
|
293
|
+
return await decode(transfer.bytes);
|
|
294
|
+
} finally {
|
|
295
|
+
forgetPart(partialPath);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async function downloadInMemory(config) {
|
|
299
|
+
const response = await fetchGuarded(config.url, config.allowPrivateHosts, fetchOptions(config));
|
|
300
|
+
if (!response.ok) {
|
|
301
|
+
throw new Error(`[stitchkit] update download responded ${response.status}`);
|
|
302
|
+
}
|
|
303
|
+
const transferred = await readCapped(response, config.maxBytes);
|
|
304
|
+
if (!transferred)
|
|
305
|
+
throw new Error("[stitchkit] update download exceeded the size ceiling");
|
|
306
|
+
return transferred;
|
|
307
|
+
}
|
|
308
|
+
function fetchOptions(config, headers) {
|
|
309
|
+
return {
|
|
310
|
+
timeoutMs: config.timeoutMs,
|
|
311
|
+
bodyTimeoutMs: config.timeoutMs,
|
|
312
|
+
...config.idleTimeoutMs !== undefined && { idleTimeoutMs: config.idleTimeoutMs },
|
|
313
|
+
...headers && { headers }
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function recordPath(partialPath) {
|
|
317
|
+
return `${partialPath}.json`;
|
|
318
|
+
}
|
|
319
|
+
function forgetPart(partialPath) {
|
|
320
|
+
rmSync(partialPath, { force: true });
|
|
321
|
+
rmSync(recordPath(partialPath), { force: true });
|
|
322
|
+
}
|
|
323
|
+
function keptLength(config, partialPath) {
|
|
324
|
+
if (!existsSync(partialPath) || !existsSync(recordPath(partialPath))) {
|
|
325
|
+
forgetPart(partialPath);
|
|
326
|
+
return { offset: 0 };
|
|
327
|
+
}
|
|
328
|
+
let record;
|
|
329
|
+
try {
|
|
330
|
+
const parsed = PartialRecordSchema.safeParse(JSON.parse(readFileSync(recordPath(partialPath), "utf8")));
|
|
331
|
+
if (parsed.success)
|
|
332
|
+
record = parsed.data;
|
|
333
|
+
} catch {
|
|
334
|
+
record = undefined;
|
|
335
|
+
}
|
|
336
|
+
if (!record || record.url !== config.url.href || record.sha256 !== config.sha256) {
|
|
337
|
+
forgetPart(partialPath);
|
|
338
|
+
return { offset: 0 };
|
|
339
|
+
}
|
|
340
|
+
const offset = statSync(partialPath).size;
|
|
341
|
+
if (offset > config.maxBytes) {
|
|
342
|
+
forgetPart(partialPath);
|
|
343
|
+
return { offset: 0 };
|
|
344
|
+
}
|
|
345
|
+
return { offset, record };
|
|
346
|
+
}
|
|
347
|
+
function readContentRange(value) {
|
|
348
|
+
if (value === null)
|
|
349
|
+
return null;
|
|
350
|
+
const match = /^bytes\s+(?:(\d+)-\d+|\*)\/(\d+|\*)$/i.exec(value.trim());
|
|
351
|
+
if (!match)
|
|
352
|
+
return null;
|
|
353
|
+
return {
|
|
354
|
+
...match[1] !== undefined && { start: Number(match[1]) },
|
|
355
|
+
...match[2] !== "*" && match[2] !== undefined && { total: Number(match[2]) }
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function validatorOf(response) {
|
|
359
|
+
const etag = response.headers.get("etag");
|
|
360
|
+
if (etag && !etag.startsWith("W/"))
|
|
361
|
+
return etag;
|
|
362
|
+
return response.headers.get("last-modified") ?? undefined;
|
|
363
|
+
}
|
|
364
|
+
async function downloadToPart(config, partialPath, resume) {
|
|
365
|
+
if (!resume)
|
|
366
|
+
forgetPart(partialPath);
|
|
367
|
+
const kept = resume ? keptLength(config, partialPath) : { offset: 0 };
|
|
368
|
+
const headers = {};
|
|
369
|
+
if (kept.offset > 0) {
|
|
370
|
+
headers.range = `bytes=${kept.offset}-`;
|
|
371
|
+
if (kept.record?.validator)
|
|
372
|
+
headers["if-range"] = kept.record.validator;
|
|
373
|
+
}
|
|
374
|
+
const response = await fetchGuarded(config.url, config.allowPrivateHosts, fetchOptions(config, headers));
|
|
375
|
+
if (kept.offset > 0 && response.status === 416) {
|
|
376
|
+
await response.body?.cancel().catch(() => {
|
|
377
|
+
return;
|
|
378
|
+
});
|
|
379
|
+
if (readContentRange(response.headers.get("content-range"))?.total === kept.offset) {
|
|
380
|
+
return { bytes: readFileSync(partialPath), continued: true };
|
|
381
|
+
}
|
|
382
|
+
return downloadToPart(config, partialPath, false);
|
|
383
|
+
}
|
|
384
|
+
if (!response.ok) {
|
|
385
|
+
await response.body?.cancel().catch(() => {
|
|
386
|
+
return;
|
|
387
|
+
});
|
|
388
|
+
throw new Error(`[stitchkit] update download responded ${response.status}`);
|
|
389
|
+
}
|
|
390
|
+
let offset = 0;
|
|
391
|
+
if (kept.offset > 0 && response.status === 206) {
|
|
392
|
+
if (readContentRange(response.headers.get("content-range"))?.start !== kept.offset) {
|
|
393
|
+
await response.body?.cancel().catch(() => {
|
|
394
|
+
return;
|
|
395
|
+
});
|
|
396
|
+
return downloadToPart(config, partialPath, false);
|
|
397
|
+
}
|
|
398
|
+
offset = kept.offset;
|
|
399
|
+
} else if (response.status === 206) {
|
|
400
|
+
await response.body?.cancel().catch(() => {
|
|
401
|
+
return;
|
|
402
|
+
});
|
|
403
|
+
throw new Error("[stitchkit] update download answered a range nobody asked for");
|
|
404
|
+
}
|
|
405
|
+
const validator = offset > 0 ? kept.record?.validator : validatorOf(response);
|
|
406
|
+
if (offset === 0)
|
|
407
|
+
rmSync(partialPath, { force: true });
|
|
408
|
+
writeFileAtomicSync2(recordPath(partialPath), JSON.stringify({
|
|
409
|
+
url: config.url.href,
|
|
410
|
+
sha256: config.sha256,
|
|
411
|
+
...validator !== undefined && { validator }
|
|
412
|
+
}), { mode: 384 });
|
|
413
|
+
await appendBody(response, partialPath, offset, config.maxBytes);
|
|
414
|
+
return { bytes: readFileSync(partialPath), continued: offset > 0 };
|
|
415
|
+
}
|
|
416
|
+
async function appendBody(response, partialPath, offset, maxBytes) {
|
|
417
|
+
const out = await open(partialPath, offset > 0 ? "a" : "w", 384);
|
|
418
|
+
let total = offset;
|
|
419
|
+
try {
|
|
420
|
+
if (response.body) {
|
|
421
|
+
for await (const chunk of response.body) {
|
|
422
|
+
if (total + chunk.byteLength > maxBytes)
|
|
423
|
+
throw new SizeCeilingError;
|
|
424
|
+
await out.write(chunk);
|
|
425
|
+
total += chunk.byteLength;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
} catch (error) {
|
|
429
|
+
await out.close().catch(() => {
|
|
430
|
+
return;
|
|
431
|
+
});
|
|
432
|
+
if (error instanceof SizeCeilingError) {
|
|
433
|
+
forgetPart(partialPath);
|
|
434
|
+
throw new Error("[stitchkit] update download exceeded the size ceiling");
|
|
435
|
+
}
|
|
436
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
437
|
+
throw new Error(`[stitchkit] update download stopped after ${total} bytes (${reason}); ` + `they are kept in ${partialPath} and the next update continues from there`, { cause: error });
|
|
438
|
+
}
|
|
439
|
+
await out.close();
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
class SizeCeilingError extends Error {
|
|
443
|
+
}
|
|
444
|
+
|
|
254
445
|
// src/tools/cli/update.ts
|
|
255
446
|
var DEFAULT_CHECK_TIMEOUT_MS = 2000;
|
|
256
447
|
var DEFAULT_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
257
|
-
var DEFAULT_DOWNLOAD_TIMEOUT_MS =
|
|
448
|
+
var DEFAULT_DOWNLOAD_TIMEOUT_MS = 30 * 60 * 1000;
|
|
449
|
+
var DEFAULT_DOWNLOAD_IDLE_TIMEOUT_MS = 30000;
|
|
258
450
|
var DEFAULT_VERIFY_TIMEOUT_MS = 30000;
|
|
259
451
|
var MANIFEST_MAX_BYTES = 256 * 1024;
|
|
260
452
|
var DEFAULT_MAX_ASSET_BYTES = 256 * 1024 * 1024;
|
|
@@ -379,17 +571,18 @@ async function applyCliUpdate2(config) {
|
|
|
379
571
|
throw new Error("[stitchkit] update: the asset is not one the signed manifest names");
|
|
380
572
|
}
|
|
381
573
|
}
|
|
382
|
-
const
|
|
574
|
+
const maxBytes = config.maxBytes ?? DEFAULT_MAX_ASSET_BYTES;
|
|
575
|
+
const { bytes, sha256 } = await downloadCliAsset({
|
|
576
|
+
url: new URL(config.asset.url),
|
|
577
|
+
sha256: config.asset.sha256,
|
|
578
|
+
allowPrivateHosts: config.allowPrivateHosts ?? false,
|
|
579
|
+
maxBytes,
|
|
383
580
|
timeoutMs: config.timeoutMs ?? DEFAULT_DOWNLOAD_TIMEOUT_MS,
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
const transferred = await readCapped(response, config.maxBytes ?? DEFAULT_MAX_ASSET_BYTES);
|
|
390
|
-
if (!transferred)
|
|
391
|
-
throw new Error("[stitchkit] update download exceeded the size ceiling");
|
|
392
|
-
const { bytes, sha256 } = await decodeCliAsset(transferred, config.asset, config.maxBytes ?? DEFAULT_MAX_ASSET_BYTES);
|
|
581
|
+
...(config.idleTimeoutMs !== undefined || config.timeoutMs === undefined) && {
|
|
582
|
+
idleTimeoutMs: config.idleTimeoutMs ?? DEFAULT_DOWNLOAD_IDLE_TIMEOUT_MS
|
|
583
|
+
},
|
|
584
|
+
...config.partialPath !== undefined && { partialPath: config.partialPath }
|
|
585
|
+
}, (transferred) => decodeCliAsset(transferred, config.asset, maxBytes));
|
|
393
586
|
if (config.verify)
|
|
394
587
|
await verifyCandidate(target, bytes, config.verify, config.verifyTimeoutMs);
|
|
395
588
|
const backup = config.backupPath ? keepReplacedBinary(target, config.backupPath) : undefined;
|
|
@@ -405,7 +598,7 @@ async function verifyCandidate(target, bytes, verify, timeoutMs = DEFAULT_VERIFY
|
|
|
405
598
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
406
599
|
throw new RangeError("[stitchkit] update: verifyTimeoutMs must be a positive number");
|
|
407
600
|
}
|
|
408
|
-
const candidate = join(
|
|
601
|
+
const candidate = join(dirname2(target), `.${basename(target)}.candidate-${randomBytes(8).toString("hex")}${extname(target)}`);
|
|
409
602
|
writeFileAtomicSync2(candidate, bytes, { mode: 493 });
|
|
410
603
|
const controller = new AbortController;
|
|
411
604
|
let timer;
|
|
@@ -434,23 +627,23 @@ async function verifyCandidate(target, bytes, verify, timeoutMs = DEFAULT_VERIFY
|
|
|
434
627
|
}
|
|
435
628
|
}
|
|
436
629
|
function keepReplacedBinary(target, backupPath) {
|
|
437
|
-
if (!
|
|
630
|
+
if (!existsSync2(target))
|
|
438
631
|
return;
|
|
439
|
-
const previous =
|
|
440
|
-
writeFileAtomicSync2(backupPath, previous, { mode:
|
|
632
|
+
const previous = readFileSync2(target);
|
|
633
|
+
writeFileAtomicSync2(backupPath, previous, { mode: statSync2(target).mode & 511 });
|
|
441
634
|
return { path: backupPath, sha256: createHash2("sha256").update(previous).digest("hex") };
|
|
442
635
|
}
|
|
443
636
|
function rollbackCliUpdate2(config) {
|
|
444
637
|
const target = config.targetPath ?? process.execPath;
|
|
445
|
-
if (!
|
|
638
|
+
if (!existsSync2(config.backupPath)) {
|
|
446
639
|
throw new Error(`[stitchkit] rollback: no backup at ${config.backupPath}`);
|
|
447
640
|
}
|
|
448
|
-
const bytes =
|
|
641
|
+
const bytes = readFileSync2(config.backupPath);
|
|
449
642
|
const sha256 = createHash2("sha256").update(bytes).digest("hex");
|
|
450
643
|
if (sha256 !== config.expectedSha256) {
|
|
451
644
|
throw new Error(`[stitchkit] rollback: backup digest ${sha256} does not match the expected ${config.expectedSha256} — refusing to restore it`);
|
|
452
645
|
}
|
|
453
|
-
writeFileAtomicSync2(target, bytes, { mode:
|
|
646
|
+
writeFileAtomicSync2(target, bytes, { mode: statSync2(config.backupPath).mode & 511 });
|
|
454
647
|
return { path: target, bytes: bytes.length, sha256 };
|
|
455
648
|
}
|
|
456
649
|
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
toJsonSchema
|
|
3
3
|
} from "./index-ct75c3at.js";
|
|
4
|
-
import {
|
|
5
|
-
publishedToolAnnotations
|
|
6
|
-
} from "./index-332d0m9g.js";
|
|
7
4
|
import {
|
|
8
5
|
toolSurfaceOutputSchema,
|
|
9
6
|
staticInputRounds,
|
|
@@ -22,9 +19,17 @@ import {
|
|
|
22
19
|
createToolRunner,
|
|
23
20
|
formatToolError
|
|
24
21
|
} from "./index-qc7tq0za.js";
|
|
22
|
+
import {
|
|
23
|
+
publishedToolAnnotations
|
|
24
|
+
} from "./index-332d0m9g.js";
|
|
25
25
|
import {
|
|
26
26
|
redact2
|
|
27
27
|
} from "./index-fpwbskp2.js";
|
|
28
|
+
import {
|
|
29
|
+
MCP_CATALOG_HEADER,
|
|
30
|
+
mcpCatalogMeta2,
|
|
31
|
+
mcpCatalogHeaderValue
|
|
32
|
+
} from "./index-mm89hd8v.js";
|
|
28
33
|
import {
|
|
29
34
|
argumentsDigest
|
|
30
35
|
} from "./index-mfntvj58.js";
|
|
@@ -78,9 +83,23 @@ function inlineMcpAppBundle2(html) {
|
|
|
78
83
|
return html.replace(EXT_APPS_BUNDLE_PLACEHOLDER2, () => bundle);
|
|
79
84
|
}
|
|
80
85
|
|
|
86
|
+
// src/tools/mcp/handler.ts
|
|
87
|
+
import {
|
|
88
|
+
createMcpHandler as createSdkMcpHandler,
|
|
89
|
+
hostHeaderValidationResponse,
|
|
90
|
+
localhostAllowedHostnames,
|
|
91
|
+
localhostAllowedOrigins,
|
|
92
|
+
originValidationResponse
|
|
93
|
+
} from "@modelcontextprotocol/server";
|
|
94
|
+
|
|
95
|
+
// src/tools/mcp/mount.ts
|
|
96
|
+
import {
|
|
97
|
+
createRequestStateCodec,
|
|
98
|
+
McpServer
|
|
99
|
+
} from "@modelcontextprotocol/server";
|
|
100
|
+
|
|
81
101
|
// src/tools/mcp/catalog.ts
|
|
82
102
|
import { createHash } from "node:crypto";
|
|
83
|
-
var MCP_CATALOG_META_KEY2 = "stitchkit/catalog";
|
|
84
103
|
var stampCache = new WeakMap;
|
|
85
104
|
function toolFingerprint(descriptor) {
|
|
86
105
|
const { mountable } = descriptor;
|
|
@@ -89,7 +108,8 @@ function toolFingerprint(descriptor) {
|
|
|
89
108
|
description: mountable.method.desc,
|
|
90
109
|
input: descriptor.inputSchema,
|
|
91
110
|
output: descriptor.outputSchema ? toJsonSchema(descriptor.outputSchema, "output", "any") : null,
|
|
92
|
-
annotations: publishedToolAnnotations(mountable.method) ?? null
|
|
111
|
+
annotations: publishedToolAnnotations(mountable.method) ?? null,
|
|
112
|
+
ui: mountable.method.ui ?? null
|
|
93
113
|
};
|
|
94
114
|
}
|
|
95
115
|
function mcpCatalogStamp(surface) {
|
|
@@ -108,22 +128,6 @@ function mcpCatalogStamp(surface) {
|
|
|
108
128
|
stampCache.set(surface, stamp);
|
|
109
129
|
return stamp;
|
|
110
130
|
}
|
|
111
|
-
function mcpCatalogMeta2(stamp) {
|
|
112
|
-
return { [MCP_CATALOG_META_KEY2]: { ...stamp } };
|
|
113
|
-
}
|
|
114
|
-
function readMcpCatalogStamp2(meta) {
|
|
115
|
-
if (!isRecord(meta))
|
|
116
|
-
return null;
|
|
117
|
-
const value = meta[MCP_CATALOG_META_KEY2];
|
|
118
|
-
if (!isRecord(value))
|
|
119
|
-
return null;
|
|
120
|
-
const { digest, tools } = value;
|
|
121
|
-
if (typeof digest !== "string" || digest.length === 0)
|
|
122
|
-
return null;
|
|
123
|
-
if (typeof tools !== "number" || !Number.isInteger(tools) || tools < 0)
|
|
124
|
-
return null;
|
|
125
|
-
return { digest, tools };
|
|
126
|
-
}
|
|
127
131
|
function stampToolRegistration(config, stamp) {
|
|
128
132
|
if (!stamp)
|
|
129
133
|
return config;
|
|
@@ -135,21 +139,6 @@ function stampToolResult(result, stamp) {
|
|
|
135
139
|
return { ...result, _meta: { ...result._meta, ...mcpCatalogMeta2(stamp) } };
|
|
136
140
|
}
|
|
137
141
|
|
|
138
|
-
// src/tools/mcp/handler.ts
|
|
139
|
-
import {
|
|
140
|
-
createMcpHandler as createSdkMcpHandler,
|
|
141
|
-
hostHeaderValidationResponse,
|
|
142
|
-
localhostAllowedHostnames,
|
|
143
|
-
localhostAllowedOrigins,
|
|
144
|
-
originValidationResponse
|
|
145
|
-
} from "@modelcontextprotocol/server";
|
|
146
|
-
|
|
147
|
-
// src/tools/mcp/mount.ts
|
|
148
|
-
import {
|
|
149
|
-
createRequestStateCodec,
|
|
150
|
-
McpServer
|
|
151
|
-
} from "@modelcontextprotocol/server";
|
|
152
|
-
|
|
153
142
|
// src/tools/mcp/prepare.ts
|
|
154
143
|
function textBlock(text) {
|
|
155
144
|
return [{ type: "text", text }];
|
|
@@ -764,6 +753,10 @@ function buildMcpServer2(config, auth) {
|
|
|
764
753
|
function isMcpServerBuildConfig(value) {
|
|
765
754
|
return isRecord(value) && isRecord(value.serverInfo);
|
|
766
755
|
}
|
|
756
|
+
var servedCatalogs = new WeakMap;
|
|
757
|
+
function servedMcpCatalog(server) {
|
|
758
|
+
return servedCatalogs.get(server);
|
|
759
|
+
}
|
|
767
760
|
function buildMcpServerFromPrepared(config, auth, prepared) {
|
|
768
761
|
let roundCodec;
|
|
769
762
|
if (config.multiRound) {
|
|
@@ -790,6 +783,8 @@ function buildMcpServerFromPrepared(config, auth, prepared) {
|
|
|
790
783
|
const server = new McpServer(config.serverInfo, serverOptions);
|
|
791
784
|
const context = config.context?.(auth);
|
|
792
785
|
const catalog = mcpCatalogStamp(prepared);
|
|
786
|
+
if (!config.rawTools)
|
|
787
|
+
servedCatalogs.set(server, catalog);
|
|
793
788
|
mountPreparedMcp(server, prepared.contractTools, {
|
|
794
789
|
catalog,
|
|
795
790
|
context,
|
|
@@ -910,7 +905,9 @@ function createMcpHandler2(config) {
|
|
|
910
905
|
throw new Error("[stitchkit] MCP request reached the SDK without resolved auth");
|
|
911
906
|
}
|
|
912
907
|
const auth = resolved.value;
|
|
913
|
-
|
|
908
|
+
const server = buildPrepared ? buildPrepared(auth) : buildMcpServer2(config, auth);
|
|
909
|
+
resolved.served = servedMcpCatalog(server);
|
|
910
|
+
return server;
|
|
914
911
|
}, {
|
|
915
912
|
legacy: config.legacy === "reject" ? "reject" : "stateless",
|
|
916
913
|
maxSubscriptions: 0
|
|
@@ -955,9 +952,11 @@ function createMcpHandler2(config) {
|
|
|
955
952
|
clientId: config.multiRound?.state.principal(auth) ?? "stitchkit",
|
|
956
953
|
scopes: []
|
|
957
954
|
};
|
|
958
|
-
|
|
955
|
+
const resolved = { value: auth };
|
|
956
|
+
authByCarrier.set(authCarrier, resolved);
|
|
959
957
|
try {
|
|
960
|
-
|
|
958
|
+
const response = await sdkHandler.fetch(request, { authInfo: authCarrier });
|
|
959
|
+
return observeRejection(request, withCatalogHeader(response, resolved.served));
|
|
961
960
|
} finally {
|
|
962
961
|
authByCarrier.delete(authCarrier);
|
|
963
962
|
}
|
|
@@ -971,6 +970,17 @@ function createMcpHandler2(config) {
|
|
|
971
970
|
}
|
|
972
971
|
};
|
|
973
972
|
}
|
|
973
|
+
function withCatalogHeader(response, served) {
|
|
974
|
+
if (!served)
|
|
975
|
+
return response;
|
|
976
|
+
const headers = new Headers(response.headers);
|
|
977
|
+
headers.set(MCP_CATALOG_HEADER, mcpCatalogHeaderValue(served));
|
|
978
|
+
return new Response(response.body, {
|
|
979
|
+
status: response.status,
|
|
980
|
+
statusText: response.statusText,
|
|
981
|
+
headers
|
|
982
|
+
});
|
|
983
|
+
}
|
|
974
984
|
function createMcpHttpRoute2(config) {
|
|
975
985
|
return {
|
|
976
986
|
method: "ALL",
|
|
@@ -989,4 +999,4 @@ async function createStdioMcpServer2(config) {
|
|
|
989
999
|
});
|
|
990
1000
|
}
|
|
991
1001
|
|
|
992
|
-
export { RESOURCE_MIME_TYPE2, EXT_APPS_BUNDLE_PLACEHOLDER2, inlineMcpAppBundle2,
|
|
1002
|
+
export { RESOURCE_MIME_TYPE2, EXT_APPS_BUNDLE_PLACEHOLDER2, inlineMcpAppBundle2, validateMcpSchemas2, mountMcp2, buildMcpServer2, mountMcpResource2, createMcpHandler2, createMcpHttpRoute2, createStdioMcpServer2 };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isRecord
|
|
3
|
+
} from "./index-hkxgennw.js";
|
|
4
|
+
|
|
5
|
+
// src/tools/mcp/catalog-stamp.ts
|
|
6
|
+
var MCP_CATALOG_META_KEY2 = "stitchkit/catalog";
|
|
7
|
+
var MCP_CATALOG_HEADER = "stitchkit-catalog";
|
|
8
|
+
function mcpCatalogMeta2(stamp) {
|
|
9
|
+
return { [MCP_CATALOG_META_KEY2]: { ...stamp } };
|
|
10
|
+
}
|
|
11
|
+
function mcpCatalogHeaderValue(stamp) {
|
|
12
|
+
return JSON.stringify({ digest: stamp.digest, tools: stamp.tools });
|
|
13
|
+
}
|
|
14
|
+
function readMcpCatalogStamp2(meta) {
|
|
15
|
+
if (!isRecord(meta))
|
|
16
|
+
return null;
|
|
17
|
+
return parseCatalogStamp(meta[MCP_CATALOG_META_KEY2]);
|
|
18
|
+
}
|
|
19
|
+
function readMcpCatalogHeader(value) {
|
|
20
|
+
if (value === null)
|
|
21
|
+
return null;
|
|
22
|
+
try {
|
|
23
|
+
return parseCatalogStamp(JSON.parse(value));
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function parseCatalogStamp(value) {
|
|
29
|
+
if (!isRecord(value))
|
|
30
|
+
return null;
|
|
31
|
+
const { digest, tools } = value;
|
|
32
|
+
if (typeof digest !== "string" || digest.length === 0)
|
|
33
|
+
return null;
|
|
34
|
+
if (typeof tools !== "number" || !Number.isInteger(tools) || tools < 0)
|
|
35
|
+
return null;
|
|
36
|
+
return { digest, tools };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { MCP_CATALOG_META_KEY2, MCP_CATALOG_HEADER, mcpCatalogMeta2, mcpCatalogHeaderValue, readMcpCatalogStamp2, readMcpCatalogHeader };
|