@j0hanz/superfetch 2.2.0 → 2.2.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/README.md +363 -614
- package/dist/cache.d.ts +2 -2
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +49 -227
- package/dist/cache.js.map +1 -1
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +20 -27
- package/dist/config.js.map +1 -1
- package/dist/dom-noise-removal.d.ts +6 -0
- package/dist/dom-noise-removal.d.ts.map +1 -0
- package/dist/dom-noise-removal.js +482 -0
- package/dist/dom-noise-removal.js.map +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +8 -5
- package/dist/errors.js.map +1 -1
- package/dist/fetch.d.ts.map +1 -1
- package/dist/fetch.js +26 -32
- package/dist/fetch.js.map +1 -1
- package/dist/http-native.d.ts +6 -0
- package/dist/http-native.d.ts.map +1 -0
- package/dist/http-native.js +645 -0
- package/dist/http-native.js.map +1 -0
- package/dist/http-utils.d.ts +61 -0
- package/dist/http-utils.d.ts.map +1 -0
- package/dist/http-utils.js +252 -0
- package/dist/http-utils.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/instructions.md +41 -39
- package/dist/json.d.ts +2 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +30 -0
- package/dist/json.js.map +1 -0
- package/dist/language-detection.d.ts +13 -0
- package/dist/language-detection.d.ts.map +1 -0
- package/dist/language-detection.js +283 -0
- package/dist/language-detection.js.map +1 -0
- package/dist/markdown-cleanup.d.ts +19 -0
- package/dist/markdown-cleanup.d.ts.map +1 -0
- package/dist/markdown-cleanup.js +283 -0
- package/dist/markdown-cleanup.js.map +1 -0
- package/dist/observability.d.ts +1 -0
- package/dist/observability.d.ts.map +1 -1
- package/dist/observability.js +10 -0
- package/dist/observability.js.map +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +23 -8
- package/dist/tools.js.map +1 -1
- package/dist/transform-types.d.ts +81 -0
- package/dist/transform-types.d.ts.map +1 -0
- package/dist/transform-types.js +6 -0
- package/dist/transform-types.js.map +1 -0
- package/dist/transform.d.ts +8 -52
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +419 -825
- package/dist/transform.js.map +1 -1
- package/dist/type-guards.d.ts +1 -1
- package/dist/type-guards.d.ts.map +1 -1
- package/dist/type-guards.js +1 -1
- package/dist/type-guards.js.map +1 -1
- package/dist/workers/transform-worker.js +23 -24
- package/dist/workers/transform-worker.js.map +1 -1
- package/package.json +85 -86
- package/dist/http.d.ts +0 -90
- package/dist/http.d.ts.map +0 -1
- package/dist/http.js +0 -1576
- package/dist/http.js.map +0 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
2
|
+
export type JsonRpcId = string | number | null;
|
|
3
|
+
export interface McpRequestParams {
|
|
4
|
+
_meta?: Record<string, unknown>;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface McpRequestBody {
|
|
8
|
+
jsonrpc: '2.0';
|
|
9
|
+
method: string;
|
|
10
|
+
id?: JsonRpcId;
|
|
11
|
+
params?: McpRequestParams;
|
|
12
|
+
}
|
|
13
|
+
export interface SessionEntry {
|
|
14
|
+
readonly transport: StreamableHTTPServerTransport;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
lastSeen: number;
|
|
17
|
+
protocolInitialized: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface SessionStore {
|
|
20
|
+
get: (sessionId: string) => SessionEntry | undefined;
|
|
21
|
+
touch: (sessionId: string) => void;
|
|
22
|
+
set: (sessionId: string, entry: SessionEntry) => void;
|
|
23
|
+
remove: (sessionId: string) => SessionEntry | undefined;
|
|
24
|
+
size: () => number;
|
|
25
|
+
inFlight: () => number;
|
|
26
|
+
incrementInFlight: () => void;
|
|
27
|
+
decrementInFlight: () => void;
|
|
28
|
+
clear: () => SessionEntry[];
|
|
29
|
+
evictExpired: () => SessionEntry[];
|
|
30
|
+
evictOldest: () => SessionEntry | undefined;
|
|
31
|
+
}
|
|
32
|
+
export interface SlotTracker {
|
|
33
|
+
readonly releaseSlot: () => void;
|
|
34
|
+
readonly markInitialized: () => void;
|
|
35
|
+
readonly isInitialized: () => boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare function normalizeHost(value: string): string | null;
|
|
38
|
+
export type CloseHandler = (() => void) | undefined;
|
|
39
|
+
export declare function composeCloseHandlers(first: CloseHandler, second: CloseHandler): CloseHandler;
|
|
40
|
+
export declare function startSessionCleanupLoop(store: SessionStore, sessionTtlMs: number): AbortController;
|
|
41
|
+
export declare function createSessionStore(sessionTtlMs: number): SessionStore;
|
|
42
|
+
export declare function isJsonRpcBatchRequest(body: unknown): boolean;
|
|
43
|
+
export declare function isMcpRequestBody(body: unknown): body is McpRequestBody;
|
|
44
|
+
export declare function acceptsEventStream(header: string | null | undefined): boolean;
|
|
45
|
+
export declare function createSlotTracker(store: SessionStore): SlotTracker;
|
|
46
|
+
export declare function reserveSessionSlot(store: SessionStore, maxSessions: number): boolean;
|
|
47
|
+
export declare function ensureSessionCapacity({ store, maxSessions, evictOldest, }: {
|
|
48
|
+
store: SessionStore;
|
|
49
|
+
maxSessions: number;
|
|
50
|
+
evictOldest: (store: SessionStore) => boolean;
|
|
51
|
+
}): boolean;
|
|
52
|
+
export interface HttpServerTuningTarget {
|
|
53
|
+
headersTimeout?: number;
|
|
54
|
+
requestTimeout?: number;
|
|
55
|
+
keepAliveTimeout?: number;
|
|
56
|
+
closeIdleConnections?: () => void;
|
|
57
|
+
closeAllConnections?: () => void;
|
|
58
|
+
}
|
|
59
|
+
export declare function applyHttpServerTuning(server: HttpServerTuningTarget): void;
|
|
60
|
+
export declare function drainConnectionsOnShutdown(server: HttpServerTuningTarget): void;
|
|
61
|
+
//# sourceMappingURL=http-utils.d.ts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O,CAAC;CAC/C,GAAG,OAAO,CAgBV;AAID,MAAM,WAAW,sBAAsB;IACrC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAC;IAClC,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;CAClC;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI,CAa1E;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,sBAAsB,GAC7B,IAAI,CAkBN"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { isIP } from 'node:net';
|
|
2
|
+
import { setInterval as setIntervalPromise } from 'node:timers/promises';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { config } from './config.js';
|
|
5
|
+
import { logDebug, logInfo, logWarn } from './observability.js';
|
|
6
|
+
// --- Host Normalization ---
|
|
7
|
+
export function normalizeHost(value) {
|
|
8
|
+
const trimmed = value.trim().toLowerCase();
|
|
9
|
+
if (!trimmed)
|
|
10
|
+
return null;
|
|
11
|
+
const first = takeFirstHostValue(trimmed);
|
|
12
|
+
if (!first)
|
|
13
|
+
return null;
|
|
14
|
+
const ipv6 = stripIpv6Brackets(first);
|
|
15
|
+
if (ipv6)
|
|
16
|
+
return stripTrailingDots(ipv6);
|
|
17
|
+
if (isIpV6Literal(first)) {
|
|
18
|
+
return stripTrailingDots(first);
|
|
19
|
+
}
|
|
20
|
+
return stripTrailingDots(stripPortIfPresent(first));
|
|
21
|
+
}
|
|
22
|
+
function takeFirstHostValue(value) {
|
|
23
|
+
const first = value.split(',')[0];
|
|
24
|
+
if (!first)
|
|
25
|
+
return null;
|
|
26
|
+
const trimmed = first.trim();
|
|
27
|
+
return trimmed ? trimmed : null;
|
|
28
|
+
}
|
|
29
|
+
function stripIpv6Brackets(value) {
|
|
30
|
+
if (!value.startsWith('['))
|
|
31
|
+
return null;
|
|
32
|
+
const end = value.indexOf(']');
|
|
33
|
+
if (end === -1)
|
|
34
|
+
return null;
|
|
35
|
+
return value.slice(1, end);
|
|
36
|
+
}
|
|
37
|
+
function stripPortIfPresent(value) {
|
|
38
|
+
const colonIndex = value.indexOf(':');
|
|
39
|
+
if (colonIndex === -1)
|
|
40
|
+
return value;
|
|
41
|
+
return value.slice(0, colonIndex);
|
|
42
|
+
}
|
|
43
|
+
function isIpV6Literal(value) {
|
|
44
|
+
return isIP(value) === 6;
|
|
45
|
+
}
|
|
46
|
+
function stripTrailingDots(value) {
|
|
47
|
+
let result = value;
|
|
48
|
+
while (result.endsWith('.')) {
|
|
49
|
+
result = result.slice(0, -1);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
export function composeCloseHandlers(first, second) {
|
|
54
|
+
if (!first)
|
|
55
|
+
return second;
|
|
56
|
+
if (!second)
|
|
57
|
+
return first;
|
|
58
|
+
return () => {
|
|
59
|
+
try {
|
|
60
|
+
first();
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
second();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// --- Session Store ---
|
|
68
|
+
function getCleanupIntervalMs(sessionTtlMs) {
|
|
69
|
+
return Math.min(Math.max(Math.floor(sessionTtlMs / 2), 10000), 60000);
|
|
70
|
+
}
|
|
71
|
+
function isAbortError(error) {
|
|
72
|
+
return error instanceof Error && error.name === 'AbortError';
|
|
73
|
+
}
|
|
74
|
+
function handleSessionCleanupError(error) {
|
|
75
|
+
if (isAbortError(error)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
logWarn('Session cleanup loop failed', {
|
|
79
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async function runSessionCleanupLoop(store, sessionTtlMs, signal) {
|
|
83
|
+
const intervalMs = getCleanupIntervalMs(sessionTtlMs);
|
|
84
|
+
for await (const getNow of setIntervalPromise(intervalMs, Date.now, {
|
|
85
|
+
signal,
|
|
86
|
+
ref: false,
|
|
87
|
+
})) {
|
|
88
|
+
const evicted = store.evictExpired();
|
|
89
|
+
for (const session of evicted) {
|
|
90
|
+
void session.transport.close().catch((err) => {
|
|
91
|
+
logWarn('Failed to close expired session', {
|
|
92
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (evicted.length > 0) {
|
|
97
|
+
logInfo('Expired sessions evicted', {
|
|
98
|
+
evicted: evicted.length,
|
|
99
|
+
timestamp: new Date(getNow()).toISOString(),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function startSessionCleanupLoop(store, sessionTtlMs) {
|
|
105
|
+
const controller = new AbortController();
|
|
106
|
+
void runSessionCleanupLoop(store, sessionTtlMs, controller.signal).catch(handleSessionCleanupError);
|
|
107
|
+
return controller;
|
|
108
|
+
}
|
|
109
|
+
export function createSessionStore(sessionTtlMs) {
|
|
110
|
+
const sessions = new Map();
|
|
111
|
+
let inflight = 0;
|
|
112
|
+
return {
|
|
113
|
+
get: (sessionId) => sessions.get(sessionId),
|
|
114
|
+
touch: (sessionId) => {
|
|
115
|
+
const session = sessions.get(sessionId);
|
|
116
|
+
if (session) {
|
|
117
|
+
session.lastSeen = Date.now();
|
|
118
|
+
sessions.delete(sessionId); // Move to end (LRU behavior if needed, but Map insertion order)
|
|
119
|
+
sessions.set(sessionId, session);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
set: (sessionId, entry) => {
|
|
123
|
+
sessions.set(sessionId, entry);
|
|
124
|
+
},
|
|
125
|
+
remove: (sessionId) => {
|
|
126
|
+
const session = sessions.get(sessionId);
|
|
127
|
+
sessions.delete(sessionId);
|
|
128
|
+
return session;
|
|
129
|
+
},
|
|
130
|
+
size: () => sessions.size,
|
|
131
|
+
inFlight: () => inflight,
|
|
132
|
+
incrementInFlight: () => {
|
|
133
|
+
inflight += 1;
|
|
134
|
+
},
|
|
135
|
+
decrementInFlight: () => {
|
|
136
|
+
if (inflight > 0)
|
|
137
|
+
inflight -= 1;
|
|
138
|
+
},
|
|
139
|
+
clear: () => {
|
|
140
|
+
const entries = [...sessions.values()];
|
|
141
|
+
sessions.clear();
|
|
142
|
+
return entries;
|
|
143
|
+
},
|
|
144
|
+
evictExpired: () => {
|
|
145
|
+
const now = Date.now();
|
|
146
|
+
const evicted = [];
|
|
147
|
+
for (const [id, session] of sessions.entries()) {
|
|
148
|
+
if (now - session.lastSeen > sessionTtlMs) {
|
|
149
|
+
sessions.delete(id);
|
|
150
|
+
evicted.push(session);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return evicted;
|
|
154
|
+
},
|
|
155
|
+
evictOldest: () => {
|
|
156
|
+
const oldestEntry = sessions.keys().next();
|
|
157
|
+
if (oldestEntry.done)
|
|
158
|
+
return undefined;
|
|
159
|
+
const oldestId = oldestEntry.value;
|
|
160
|
+
const session = sessions.get(oldestId);
|
|
161
|
+
sessions.delete(oldestId);
|
|
162
|
+
return session;
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
// --- Validation ---
|
|
167
|
+
const paramsSchema = z.looseObject({});
|
|
168
|
+
const mcpRequestSchema = z.looseObject({
|
|
169
|
+
jsonrpc: z.literal('2.0'),
|
|
170
|
+
method: z.string().min(1),
|
|
171
|
+
id: z.union([z.string(), z.number(), z.null()]).optional(),
|
|
172
|
+
params: paramsSchema.optional(),
|
|
173
|
+
});
|
|
174
|
+
export function isJsonRpcBatchRequest(body) {
|
|
175
|
+
return Array.isArray(body);
|
|
176
|
+
}
|
|
177
|
+
export function isMcpRequestBody(body) {
|
|
178
|
+
return mcpRequestSchema.safeParse(body).success;
|
|
179
|
+
}
|
|
180
|
+
export function acceptsEventStream(header) {
|
|
181
|
+
if (!header)
|
|
182
|
+
return false;
|
|
183
|
+
return header
|
|
184
|
+
.split(',')
|
|
185
|
+
.some((value) => value.trim().toLowerCase().startsWith('text/event-stream'));
|
|
186
|
+
}
|
|
187
|
+
// --- Slot Tracker ---
|
|
188
|
+
export function createSlotTracker(store) {
|
|
189
|
+
let slotReleased = false;
|
|
190
|
+
let initialized = false;
|
|
191
|
+
return {
|
|
192
|
+
releaseSlot: () => {
|
|
193
|
+
if (slotReleased)
|
|
194
|
+
return;
|
|
195
|
+
slotReleased = true;
|
|
196
|
+
store.decrementInFlight();
|
|
197
|
+
},
|
|
198
|
+
markInitialized: () => {
|
|
199
|
+
initialized = true;
|
|
200
|
+
},
|
|
201
|
+
isInitialized: () => initialized,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
export function reserveSessionSlot(store, maxSessions) {
|
|
205
|
+
if (store.size() + store.inFlight() >= maxSessions) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
store.incrementInFlight();
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
export function ensureSessionCapacity({ store, maxSessions, evictOldest, }) {
|
|
212
|
+
const currentSize = store.size();
|
|
213
|
+
const isAtCapacity = currentSize + store.inFlight() >= maxSessions;
|
|
214
|
+
if (!isAtCapacity)
|
|
215
|
+
return true;
|
|
216
|
+
// Try to free a slot
|
|
217
|
+
const canFreeSlot = currentSize >= maxSessions &&
|
|
218
|
+
currentSize - 1 + store.inFlight() < maxSessions;
|
|
219
|
+
if (canFreeSlot && evictOldest(store)) {
|
|
220
|
+
return store.size() + store.inFlight() < maxSessions;
|
|
221
|
+
}
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
export function applyHttpServerTuning(server) {
|
|
225
|
+
const { headersTimeoutMs, requestTimeoutMs, keepAliveTimeoutMs } = config.server.http;
|
|
226
|
+
if (headersTimeoutMs !== undefined) {
|
|
227
|
+
server.headersTimeout = headersTimeoutMs;
|
|
228
|
+
}
|
|
229
|
+
if (requestTimeoutMs !== undefined) {
|
|
230
|
+
server.requestTimeout = requestTimeoutMs;
|
|
231
|
+
}
|
|
232
|
+
if (keepAliveTimeoutMs !== undefined) {
|
|
233
|
+
server.keepAliveTimeout = keepAliveTimeoutMs;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
export function drainConnectionsOnShutdown(server) {
|
|
237
|
+
const { shutdownCloseAllConnections, shutdownCloseIdleConnections } = config.server.http;
|
|
238
|
+
if (shutdownCloseAllConnections) {
|
|
239
|
+
if (typeof server.closeAllConnections === 'function') {
|
|
240
|
+
server.closeAllConnections();
|
|
241
|
+
logDebug('Closed all HTTP connections during shutdown');
|
|
242
|
+
}
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (shutdownCloseIdleConnections) {
|
|
246
|
+
if (typeof server.closeIdleConnections === 'function') {
|
|
247
|
+
server.closeIdleConnections();
|
|
248
|
+
logDebug('Closed idle HTTP connections during shutdown');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=http-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-utils.js","sourceRoot":"","sources":["../src/http-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,WAAW,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AA6ChE,6BAA6B;AAE7B,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC3C,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAA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E,2BAA2B,EAAE,4BAA4B,EAAE,GACjE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAErB,IAAI,2BAA2B,EAAE,CAAC;QAChC,IAAI,OAAO,MAAM,CAAC,mBAAmB,KAAK,UAAU,EAAE,CAAC;YACrD,MAAM,CAAC,mBAAmB,EAAE,CAAC;YAC7B,QAAQ,CAAC,6CAA6C,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO;IACT,CAAC;IAED,IAAI,4BAA4B,EAAE,CAAC;QACjC,IAAI,OAAO,MAAM,CAAC,oBAAoB,KAAK,UAAU,EAAE,CAAC;YACtD,MAAM,CAAC,oBAAoB,EAAE,CAAC;YAC9B,QAAQ,CAAC,8CAA8C,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
|
-
import { startHttpServer } from './http.js';
|
|
3
|
+
import { startHttpServer } from './http-native.js';
|
|
4
4
|
import { startStdioServer } from './mcp.js';
|
|
5
5
|
import { logError } from './observability.js';
|
|
6
6
|
const { values } = parseArgs({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,EAA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C,MAAM,KAAK,GAAG,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3E,gBAAgB,CAAC,qBAAqB,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC;AACxE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC;IACH,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,gBAAgB,EAAE,CAAC;IAC3B,CAAC;SAAM,CAAC;QACN,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,eAAe,EAAE,CAAC;QAC7C,kBAAkB,CAAC,OAAO,GAAG,QAAQ,CAAC;IACxC,CAAC;AACH,CAAC;AAAC,OAAO,KAAc,EAAE,CAAC;IACxB,QAAQ,CACN,wBAAwB,EACxB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAC3C,CAAC;IACF,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,OAAO,IAAI,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
package/dist/instructions.md
CHANGED
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
# superFetch Instructions
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
## 1. Core Capability
|
|
6
|
-
|
|
7
|
-
- **Domain:** Fetch public http(s) URLs, extract readable content, and return clean Markdown.
|
|
8
|
-
- **Primary Resources:** `fetch-url` output (`markdown`, `title`, `url`) and cache resources (`superfetch://cache/markdown/{urlHash}`).
|
|
9
|
-
|
|
10
|
-
## 2. The "Golden Path" Workflows (Critical)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- **
|
|
32
|
-
- **
|
|
33
|
-
- **
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
-
|
|
1
|
+
# superFetch Instructions
|
|
2
|
+
|
|
3
|
+
> Guidance for the Agent: These instructions are available as a resource (`internal://instructions`) or prompt (`get-help`). Load them when you are unsure about tool usage.
|
|
4
|
+
|
|
5
|
+
## 1. Core Capability
|
|
6
|
+
|
|
7
|
+
- **Domain:** Fetch public http(s) URLs, extract readable content, and return clean Markdown.
|
|
8
|
+
- **Primary Resources:** `fetch-url` output (`markdown`, `title`, `url`) and cache resources (`superfetch://cache/markdown/{urlHash}`).
|
|
9
|
+
|
|
10
|
+
## 2. The "Golden Path" Workflows (Critical)
|
|
11
|
+
|
|
12
|
+
_Describe the standard order of operations using ONLY tools that exist._
|
|
13
|
+
|
|
14
|
+
### Workflow A: Fetch and Read
|
|
15
|
+
|
|
16
|
+
1. Call `fetch-url` with `url`.
|
|
17
|
+
2. Read `structuredContent.markdown` and `structuredContent.title` from the result.
|
|
18
|
+
3. If content is truncated (look for `...[truncated]`), follow the returned `resource_link` URI.
|
|
19
|
+
> Constraint: Never guess resource URIs. Use the returned `resource_link` or list resources first.
|
|
20
|
+
|
|
21
|
+
### Workflow B: Retrieve Cached Content
|
|
22
|
+
|
|
23
|
+
1. List resources to find available cached pages (`superfetch://cache/...`).
|
|
24
|
+
2. Read the specific `superfetch://cache/markdown/{urlHash}` URI.
|
|
25
|
+
|
|
26
|
+
## 3. Tool Nuances & Gotchas
|
|
27
|
+
|
|
28
|
+
_Do NOT repeat JSON schema. Focus on behavior and pitfalls._
|
|
29
|
+
|
|
30
|
+
- **`fetch-url`**
|
|
31
|
+
- **Purpose:** Fetches a webpage and converts it to clean Markdown format.
|
|
32
|
+
- **Inputs:** `url` (Must be public http/https. Private patterns like localhost/127.0.0.1 are blocked).
|
|
33
|
+
- **Side effects:** Open world network request; writes to internal LRU cache.
|
|
34
|
+
- **Latency/limits:** Network-bound. Large content exceeds inline limits and returns a `resource_link`.
|
|
35
|
+
- **Common failure modes:** `VALIDATION_ERROR` (private/blocked URL), `FETCH_ERROR` (network timeout/404).
|
|
36
|
+
|
|
37
|
+
## 4. Error Handling Strategy
|
|
38
|
+
|
|
39
|
+
- **`VALIDATION_ERROR`**: Ensure the URL is valid and publicly accessible.
|
|
40
|
+
- **`FETCH_ERROR`**: Retry once. If persistent, the site may be blocking automated requests.
|
|
41
|
+
- **Truncation**: If `isError` is false but content ends in `...[truncated]`, you MUST read the provided `resource_link` URI to get the full markdown.
|
package/dist/json.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAqCA,wBAAgB,eAAe,CAC7B,GAAG,EAAE,OAAO,EACZ,KAAK,SAAI,EACT,IAAI,kBAAgB,GACnB,MAAM,CAGR"}
|
package/dist/json.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const MAX_DEPTH = 20;
|
|
2
|
+
function processValue(obj, depth, seen) {
|
|
3
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
4
|
+
return obj;
|
|
5
|
+
}
|
|
6
|
+
// Depth guard
|
|
7
|
+
if (depth > MAX_DEPTH) {
|
|
8
|
+
throw new Error(`stableStringify: Max depth (${MAX_DEPTH}) exceeded`);
|
|
9
|
+
}
|
|
10
|
+
// Cycle detection
|
|
11
|
+
if (seen.has(obj)) {
|
|
12
|
+
throw new Error('stableStringify: Circular reference detected');
|
|
13
|
+
}
|
|
14
|
+
seen.add(obj);
|
|
15
|
+
if (Array.isArray(obj)) {
|
|
16
|
+
return obj.map((item) => processValue(item, depth + 1, seen));
|
|
17
|
+
}
|
|
18
|
+
const keys = Object.keys(obj).sort((a, b) => a.localeCompare(b));
|
|
19
|
+
const record = obj;
|
|
20
|
+
const sortedObj = {};
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
sortedObj[key] = processValue(record[key], depth + 1, seen);
|
|
23
|
+
}
|
|
24
|
+
return sortedObj;
|
|
25
|
+
}
|
|
26
|
+
export function stableStringify(obj, depth = 0, seen = new WeakSet()) {
|
|
27
|
+
const processed = processValue(obj, depth, seen);
|
|
28
|
+
return JSON.stringify(processed);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=json.js.map
|
package/dist/json.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,SAAS,YAAY,CACnB,GAAY,EACZ,KAAa,EACb,IAAqB;IAErB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,GAAG,CAAC;IACb,CAAC;IAED,cAAc;IACd,IAAI,KAAK,GAAG,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,+BAA+B,SAAS,YAAY,CAAC,CAAC;IACxE,CAAC;IAED,kBAAkB;IAClB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEd,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,MAAM,MAAM,GAAG,GAA8B,CAAC;IAC9C,MAAM,SAAS,GAA4B,EAAE,CAAC;IAE9C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,SAAS,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,GAAY,EACZ,KAAK,GAAG,CAAC,EACT,IAAI,GAAG,IAAI,OAAO,EAAE;IAEpB,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language detection for code blocks.
|
|
3
|
+
* Detects programming languages from code content and HTML attributes.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Detect programming language from code content using heuristics.
|
|
7
|
+
*/
|
|
8
|
+
export declare function detectLanguageFromCode(code: string): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Resolve language from HTML attributes (class name and data-language).
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveLanguageFromAttributes(className: string, dataLang: string): string | undefined;
|
|
13
|
+
//# sourceMappingURL=language-detection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-detection.d.ts","sourceRoot":"","sources":["../src/language-detection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmSH;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMvE;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAGpB"}
|