stitchkit 0.124.0 → 0.124.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/CHANGELOG.md +48 -0
- 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 +1 -1
- 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/index.js +3 -3
- package/dist/entrypoints/server.js +6 -6
- package/dist/entrypoints/telegram.js +2 -2
- 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 +121 -29
- 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 +2 -2
- package/dist/{index-jswst0h3.js → index-03qrr49d.js} +49 -4
- 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-q89kd1xc.js → index-e1x6vze4.js} +1 -1
- package/dist/{index-ezwvsqx9.js → index-fvd6pvw3.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-mm89hd8v.js +39 -0
- package/dist/{index-jc5xgkpk.js → index-qsm899qp.js} +1 -1
- package/dist/index-wqzw3qg9.js +91 -0
- package/dist/{index-364k2zwa.js → index-wt6rw7rf.js} +5 -7
- package/dist/{index-tt3ej8r3.js → index-x0769xt9.js} +217 -24
- 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/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/tools-connections.txt +5 -3
- package/llms/tools-mcp.txt +5 -2
- package/llms/tools.txt +10 -3
- package/llms-full.txt +80 -14
- package/llms.txt +4 -4
- package/package.json +1 -1
- package/dist/index-9tqbxv5p.js +0 -44
- package/dist/index-b56nnscm.js +0 -132
|
@@ -1,10 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
} from "
|
|
1
|
+
// src/internal/atomic-publication.ts
|
|
2
|
+
import { closeSync, fsyncSync, linkSync, openSync, renameSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { link, open, rename, unlink } from "node:fs/promises";
|
|
4
|
+
import { dirname } from "node:path";
|
|
5
|
+
|
|
6
|
+
// src/internal/close-after.ts
|
|
7
|
+
async function closeAfter(handle, run) {
|
|
8
|
+
let result;
|
|
9
|
+
try {
|
|
10
|
+
result = await run();
|
|
11
|
+
} catch (error) {
|
|
12
|
+
await handle.close().catch(() => {
|
|
13
|
+
return;
|
|
14
|
+
});
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
await handle.close();
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
function closeAfterSync(close, run) {
|
|
21
|
+
let result;
|
|
22
|
+
try {
|
|
23
|
+
result = run();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
try {
|
|
26
|
+
close();
|
|
27
|
+
} catch {}
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
close();
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/internal/atomic-publication.ts
|
|
35
|
+
class AtomicFilePublicationError2 extends Error {
|
|
36
|
+
phase;
|
|
37
|
+
published = true;
|
|
38
|
+
constructor(phase, cause) {
|
|
39
|
+
super(`File published but ${phase} failed`, { cause });
|
|
40
|
+
this.phase = phase;
|
|
41
|
+
this.name = "AtomicFilePublicationError";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
var native = { rename, link, unlink, open };
|
|
45
|
+
var nativeSync = {
|
|
46
|
+
rename: renameSync,
|
|
47
|
+
link: linkSync,
|
|
48
|
+
unlink: unlinkSync,
|
|
49
|
+
open(path, flags) {
|
|
50
|
+
const descriptor = openSync(path, flags);
|
|
51
|
+
return { sync: () => fsyncSync(descriptor), close: () => closeSync(descriptor) };
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function assertDirectoryDurability() {
|
|
55
|
+
if (process.platform === "win32")
|
|
56
|
+
throw new Error("Directory durability is unsupported on Windows");
|
|
57
|
+
}
|
|
58
|
+
async function syncDirectory(path, io = native) {
|
|
59
|
+
assertDirectoryDurability();
|
|
60
|
+
const directory = await io.open(path, "r");
|
|
61
|
+
await closeAfter(directory, () => directory.sync());
|
|
62
|
+
}
|
|
63
|
+
async function publishAtomicFile(staged, target, { replace, durability }, io = native) {
|
|
64
|
+
const directorySync = durability === "directory";
|
|
65
|
+
if (directorySync)
|
|
66
|
+
assertDirectoryDurability();
|
|
67
|
+
const directory = directorySync ? await io.open(dirname(target), "r") : undefined;
|
|
68
|
+
const publish = async () => {
|
|
69
|
+
if (replace)
|
|
70
|
+
await io.rename(staged, target);
|
|
71
|
+
else {
|
|
72
|
+
await io.link(staged, target);
|
|
73
|
+
try {
|
|
74
|
+
await io.unlink(staged);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
throw new AtomicFilePublicationError2("cleanup", error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
await directory?.sync();
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw new AtomicFilePublicationError2("directory-sync", error);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
if (directory === undefined)
|
|
86
|
+
return publish();
|
|
87
|
+
await closeAfter({
|
|
88
|
+
close: async () => {
|
|
89
|
+
try {
|
|
90
|
+
await directory.close();
|
|
91
|
+
} catch (error) {
|
|
92
|
+
throw new AtomicFilePublicationError2("directory-close", error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, publish);
|
|
96
|
+
}
|
|
97
|
+
function publishAtomicFileSync(staged, target, { replace, durability }, io = nativeSync) {
|
|
98
|
+
const directorySync = durability === "directory";
|
|
99
|
+
if (directorySync)
|
|
100
|
+
assertDirectoryDurability();
|
|
101
|
+
const directory = directorySync ? io.open(dirname(target), "r") : undefined;
|
|
102
|
+
const publish = () => {
|
|
103
|
+
if (replace)
|
|
104
|
+
io.rename(staged, target);
|
|
105
|
+
else {
|
|
106
|
+
io.link(staged, target);
|
|
107
|
+
try {
|
|
108
|
+
io.unlink(staged);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
throw new AtomicFilePublicationError2("cleanup", error);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
directory?.sync();
|
|
115
|
+
} catch (error) {
|
|
116
|
+
throw new AtomicFilePublicationError2("directory-sync", error);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
if (directory === undefined) {
|
|
120
|
+
publish();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
closeAfterSync(() => {
|
|
124
|
+
try {
|
|
125
|
+
directory.close();
|
|
126
|
+
} catch (error) {
|
|
127
|
+
throw new AtomicFilePublicationError2("directory-close", error);
|
|
128
|
+
}
|
|
129
|
+
}, publish);
|
|
130
|
+
}
|
|
4
131
|
|
|
5
132
|
// src/internal/bounded-file-read.ts
|
|
6
133
|
import { constants } from "node:fs";
|
|
7
|
-
import { open } from "node:fs/promises";
|
|
134
|
+
import { open as open2 } from "node:fs/promises";
|
|
8
135
|
class BoundedFileReadError extends Error {
|
|
9
136
|
code;
|
|
10
137
|
observation;
|
|
@@ -53,10 +180,10 @@ async function openChecked(target, options, openDescriptor) {
|
|
|
53
180
|
}
|
|
54
181
|
}
|
|
55
182
|
function openRegularFile(target, options = {}) {
|
|
56
|
-
return openChecked(target, options,
|
|
183
|
+
return openChecked(target, options, open2);
|
|
57
184
|
}
|
|
58
185
|
var tooLarge = (maxBytes, observation) => new BoundedFileReadError("FILE_TOO_LARGE", `file exceeds the ${maxBytes}-byte cap`, observation);
|
|
59
|
-
async function readBoundedFile(target, maxBytes, options = {}, openDescriptor =
|
|
186
|
+
async function readBoundedFile(target, maxBytes, options = {}, openDescriptor = open2) {
|
|
60
187
|
options.signal?.throwIfAborted();
|
|
61
188
|
const { handle, before } = await openChecked(target, options, openDescriptor);
|
|
62
189
|
return closeAfter(handle, async () => {
|
|
@@ -117,4 +244,4 @@ async function readHandle(handle, maxBytes, signal) {
|
|
|
117
244
|
return bytes;
|
|
118
245
|
}
|
|
119
246
|
|
|
120
|
-
export { BoundedFileReadError, openRegularFile, readBoundedFile };
|
|
247
|
+
export { closeAfter, closeAfterSync, AtomicFilePublicationError2, assertDirectoryDurability, syncDirectory, publishAtomicFile, publishAtomicFileSync, BoundedFileReadError, openRegularFile, readBoundedFile };
|
|
@@ -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 };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_TIMER_MS
|
|
3
|
+
} from "./index-eemvahkc.js";
|
|
4
|
+
import {
|
|
5
|
+
assertPositiveSafeInteger
|
|
6
|
+
} from "./index-0s4xebbg.js";
|
|
7
|
+
|
|
8
|
+
// src/internal/deadline.ts
|
|
9
|
+
async function withDeadline(value, timeoutMs) {
|
|
10
|
+
if (!(value instanceof Promise))
|
|
11
|
+
return { settled: true, value };
|
|
12
|
+
let timer;
|
|
13
|
+
const expiry = new Promise((resolve) => {
|
|
14
|
+
timer = setTimeout(() => resolve({ settled: false }), timeoutMs);
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
return await Promise.race([
|
|
18
|
+
value.then((settledValue) => ({
|
|
19
|
+
settled: true,
|
|
20
|
+
value: settledValue
|
|
21
|
+
})),
|
|
22
|
+
expiry
|
|
23
|
+
]);
|
|
24
|
+
} finally {
|
|
25
|
+
if (timer !== undefined)
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function withSignalDeadline(timeoutMs, caller, makeReason, body) {
|
|
30
|
+
assertPositiveSafeInteger("Deadline timeoutMs", timeoutMs, RangeError);
|
|
31
|
+
if (timeoutMs > MAX_TIMER_MS)
|
|
32
|
+
throw new RangeError("Deadline timeoutMs exceeds the timer range");
|
|
33
|
+
caller?.throwIfAborted();
|
|
34
|
+
const deadline = new AbortController;
|
|
35
|
+
const timer = setTimeout(() => deadline.abort(makeReason()), timeoutMs);
|
|
36
|
+
const signal = caller ? AbortSignal.any([caller, deadline.signal]) : deadline.signal;
|
|
37
|
+
try {
|
|
38
|
+
return await body(signal);
|
|
39
|
+
} finally {
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function withIdleDeadline(idleMs, parent, makeReason, body) {
|
|
44
|
+
if (idleMs === undefined)
|
|
45
|
+
return body({ signal: parent, touch: () => {
|
|
46
|
+
return;
|
|
47
|
+
} });
|
|
48
|
+
parent.throwIfAborted();
|
|
49
|
+
const quiet = new AbortController;
|
|
50
|
+
const timer = startIdleTimer(idleMs, () => quiet.abort(makeReason()));
|
|
51
|
+
const signal = AbortSignal.any([parent, quiet.signal]);
|
|
52
|
+
const touch = () => {
|
|
53
|
+
if (!signal.aborted)
|
|
54
|
+
timer.touch();
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
return await body({ signal, touch });
|
|
58
|
+
} finally {
|
|
59
|
+
timer.stop();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function startIdleTimer(idleMs, onIdle, options = {}) {
|
|
63
|
+
assertPositiveSafeInteger("Idle timer idleMs", idleMs, RangeError);
|
|
64
|
+
if (idleMs > MAX_TIMER_MS)
|
|
65
|
+
throw new RangeError("Idle timer idleMs exceeds the timer range");
|
|
66
|
+
let done = false;
|
|
67
|
+
const arm = () => {
|
|
68
|
+
const handle = setTimeout(() => {
|
|
69
|
+
done = true;
|
|
70
|
+
onIdle();
|
|
71
|
+
}, idleMs);
|
|
72
|
+
if (options.unref)
|
|
73
|
+
handle.unref?.();
|
|
74
|
+
return handle;
|
|
75
|
+
};
|
|
76
|
+
let handle = arm();
|
|
77
|
+
return {
|
|
78
|
+
touch() {
|
|
79
|
+
if (done)
|
|
80
|
+
return;
|
|
81
|
+
clearTimeout(handle);
|
|
82
|
+
handle = arm();
|
|
83
|
+
},
|
|
84
|
+
stop() {
|
|
85
|
+
done = true;
|
|
86
|
+
clearTimeout(handle);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { withDeadline, withSignalDeadline, withIdleDeadline, startIdleTimer };
|
|
@@ -5,17 +5,15 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
isWithinDir2
|
|
7
7
|
} from "./index-5cc6r990.js";
|
|
8
|
-
import {
|
|
9
|
-
BoundedFileReadError,
|
|
10
|
-
readBoundedFile
|
|
11
|
-
} from "./index-m616f0yz.js";
|
|
12
8
|
import {
|
|
13
9
|
writeAllBytes,
|
|
14
10
|
writeAtomicFileStaged
|
|
15
|
-
} from "./index-
|
|
11
|
+
} from "./index-jp2qd9jb.js";
|
|
16
12
|
import {
|
|
17
|
-
AtomicFilePublicationError2
|
|
18
|
-
|
|
13
|
+
AtomicFilePublicationError2,
|
|
14
|
+
BoundedFileReadError,
|
|
15
|
+
readBoundedFile
|
|
16
|
+
} from "./index-8x0q6yfb.js";
|
|
19
17
|
import {
|
|
20
18
|
raceAbort
|
|
21
19
|
} from "./index-b0kddvzw.js";
|