agentfootprint 11.2.0 → 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/CAPABILITIES.md +2 -0
- package/ai-instructions/claude-code/SKILL.md +1 -1
- package/dist/adapters/identity/verify/claims.js +3 -3
- package/dist/adapters/mcp/agentcoreRuntime/invoke.js +3 -2
- package/dist/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -1
- package/dist/adapters/mcp/agentcoreRuntime/sessionBusy.js +6 -5
- package/dist/adapters/mcp/agentcoreRuntime/sessionBusy.js.map +1 -1
- package/dist/adapters/mcp/agentcoreRuntime/transport.js +8 -6
- package/dist/adapters/mcp/agentcoreRuntime/transport.js.map +1 -1
- package/dist/core/agent/buildToolRegistry.js +1 -1
- package/dist/core/agent/buildToolRegistry.js.map +1 -1
- package/dist/core/agent/evidence/evidenceIndex.js +30 -2
- package/dist/core/agent/evidence/evidenceIndex.js.map +1 -1
- package/dist/core/agent/evidence/extract.js +34 -5
- package/dist/core/agent/evidence/extract.js.map +1 -1
- package/dist/core/agent/evidence/figures.js +31 -3
- package/dist/core/agent/evidence/figures.js.map +1 -1
- package/dist/core/agent/evidence/numberPrecision.js +58 -2
- package/dist/core/agent/evidence/numberPrecision.js.map +1 -1
- package/dist/core/agent/stages/route.js +2 -1
- package/dist/core/agent/stages/route.js.map +1 -1
- package/dist/core/agent/stages/toolCalls.js +14 -1
- package/dist/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/core/slots/buildToolsSlot.js +1 -1
- package/dist/core/slots/buildToolsSlot.js.map +1 -1
- package/dist/esm/adapters/identity/jwks.d.ts +2 -2
- package/dist/esm/adapters/identity/verify/claims.d.ts +3 -3
- package/dist/esm/adapters/identity/verify/claims.js +3 -3
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.d.ts +3 -2
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js +3 -2
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -1
- package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts +6 -5
- package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.js +6 -5
- package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.js.map +1 -1
- package/dist/esm/adapters/mcp/agentcoreRuntime/transport.d.ts +3 -1
- package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js +9 -7
- package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js.map +1 -1
- package/dist/esm/core/agent/buildToolRegistry.js +1 -1
- package/dist/esm/core/agent/buildToolRegistry.js.map +1 -1
- package/dist/esm/core/agent/evidence/evidenceIndex.d.ts +12 -2
- package/dist/esm/core/agent/evidence/evidenceIndex.js +30 -2
- package/dist/esm/core/agent/evidence/evidenceIndex.js.map +1 -1
- package/dist/esm/core/agent/evidence/extract.js +35 -6
- package/dist/esm/core/agent/evidence/extract.js.map +1 -1
- package/dist/esm/core/agent/evidence/figures.d.ts +6 -0
- package/dist/esm/core/agent/evidence/figures.js +32 -4
- package/dist/esm/core/agent/evidence/figures.js.map +1 -1
- package/dist/esm/core/agent/evidence/numberPrecision.d.ts +28 -1
- package/dist/esm/core/agent/evidence/numberPrecision.js +56 -1
- package/dist/esm/core/agent/evidence/numberPrecision.js.map +1 -1
- package/dist/esm/core/agent/stages/route.js +2 -1
- package/dist/esm/core/agent/stages/route.js.map +1 -1
- package/dist/esm/core/agent/stages/toolCalls.js +14 -1
- package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/esm/core/slots/buildToolsSlot.js +1 -1
- package/dist/esm/core/slots/buildToolsSlot.js.map +1 -1
- package/dist/esm/events/payloads.d.ts +185 -0
- package/dist/esm/events/registry.d.ts +3 -1
- package/dist/esm/events/registry.js +2 -0
- package/dist/esm/events/registry.js.map +1 -1
- package/dist/esm/hosting/doorGuard.d.ts +3 -3
- package/dist/esm/hosting/doorGuard.js +2 -2
- package/dist/esm/hosting/nodeHost.d.ts +1 -1
- package/dist/esm/mcp/callLifetime.d.ts +49 -0
- package/dist/esm/mcp/callLifetime.js +99 -0
- package/dist/esm/mcp/callLifetime.js.map +1 -0
- package/dist/esm/mcp/mcpClient.d.ts +4 -1
- package/dist/esm/mcp/mcpClient.js +70 -28
- package/dist/esm/mcp/mcpClient.js.map +1 -1
- package/dist/esm/mcp/requestLedger.d.ts +97 -0
- package/dist/esm/mcp/requestLedger.js +192 -0
- package/dist/esm/mcp/requestLedger.js.map +1 -0
- package/dist/esm/mcp/seriesEvidence.d.ts +102 -0
- package/dist/esm/mcp/seriesEvidence.js +246 -0
- package/dist/esm/mcp/seriesEvidence.js.map +1 -0
- package/dist/esm/mcp/throttleRetry.d.ts +70 -35
- package/dist/esm/mcp/throttleRetry.js +181 -54
- package/dist/esm/mcp/throttleRetry.js.map +1 -1
- package/dist/esm/mcp/types.d.ts +12 -7
- package/dist/esm/redaction/knownStrings.js +29 -0
- package/dist/esm/redaction/knownStrings.js.map +1 -1
- package/dist/esm/security/PermissionPolicy.d.ts +1 -1
- package/dist/esm/security/PermissionPolicy.js +1 -1
- package/dist/esm/strategies/defaults/chatBubbleLiveStatus.d.ts +1 -1
- package/dist/esm/strategies/defaults/chatBubbleLiveStatus.js +1 -1
- package/dist/esm/tool-lint/analyze.d.ts +1 -1
- package/dist/esm/tool-lint/analyze.js +1 -1
- package/dist/esm/tool-lint/rules.d.ts +3 -3
- package/dist/esm/tool-lint/rules.js +3 -3
- package/dist/esm/tools/requestEvidence.d.ts +78 -0
- package/dist/esm/tools/requestEvidence.js +331 -0
- package/dist/esm/tools/requestEvidence.js.map +1 -0
- package/dist/events/registry.js +2 -0
- package/dist/events/registry.js.map +1 -1
- package/dist/hosting/doorGuard.js +2 -2
- package/dist/mcp/callLifetime.js +103 -0
- package/dist/mcp/callLifetime.js.map +1 -0
- package/dist/mcp/mcpClient.js +69 -27
- package/dist/mcp/mcpClient.js.map +1 -1
- package/dist/mcp/requestLedger.js +196 -0
- package/dist/mcp/requestLedger.js.map +1 -0
- package/dist/mcp/seriesEvidence.js +251 -0
- package/dist/mcp/seriesEvidence.js.map +1 -0
- package/dist/mcp/throttleRetry.js +184 -55
- package/dist/mcp/throttleRetry.js.map +1 -1
- package/dist/redaction/knownStrings.js +29 -0
- package/dist/redaction/knownStrings.js.map +1 -1
- package/dist/security/PermissionPolicy.js +1 -1
- package/dist/strategies/defaults/chatBubbleLiveStatus.js +1 -1
- package/dist/tool-lint/analyze.js +1 -1
- package/dist/tool-lint/rules.js +3 -3
- package/dist/tools/requestEvidence.js +337 -0
- package/dist/tools/requestEvidence.js.map +1 -0
- package/dist/types/adapters/identity/jwks.d.ts +2 -2
- package/dist/types/adapters/identity/verify/claims.d.ts +3 -3
- package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts +3 -2
- package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts.map +1 -1
- package/dist/types/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts +6 -5
- package/dist/types/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts.map +1 -1
- package/dist/types/adapters/mcp/agentcoreRuntime/transport.d.ts +3 -1
- package/dist/types/adapters/mcp/agentcoreRuntime/transport.d.ts.map +1 -1
- package/dist/types/core/agent/evidence/evidenceIndex.d.ts +12 -2
- package/dist/types/core/agent/evidence/evidenceIndex.d.ts.map +1 -1
- package/dist/types/core/agent/evidence/extract.d.ts.map +1 -1
- package/dist/types/core/agent/evidence/figures.d.ts +6 -0
- package/dist/types/core/agent/evidence/figures.d.ts.map +1 -1
- package/dist/types/core/agent/evidence/numberPrecision.d.ts +28 -1
- package/dist/types/core/agent/evidence/numberPrecision.d.ts.map +1 -1
- package/dist/types/core/agent/stages/route.d.ts.map +1 -1
- package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
- package/dist/types/events/payloads.d.ts +185 -0
- package/dist/types/events/payloads.d.ts.map +1 -1
- package/dist/types/events/registry.d.ts +3 -1
- package/dist/types/events/registry.d.ts.map +1 -1
- package/dist/types/hosting/doorGuard.d.ts +3 -3
- package/dist/types/hosting/nodeHost.d.ts +1 -1
- package/dist/types/mcp/callLifetime.d.ts +50 -0
- package/dist/types/mcp/callLifetime.d.ts.map +1 -0
- package/dist/types/mcp/mcpClient.d.ts +4 -1
- package/dist/types/mcp/mcpClient.d.ts.map +1 -1
- package/dist/types/mcp/requestLedger.d.ts +98 -0
- package/dist/types/mcp/requestLedger.d.ts.map +1 -0
- package/dist/types/mcp/seriesEvidence.d.ts +103 -0
- package/dist/types/mcp/seriesEvidence.d.ts.map +1 -0
- package/dist/types/mcp/throttleRetry.d.ts +70 -35
- package/dist/types/mcp/throttleRetry.d.ts.map +1 -1
- package/dist/types/mcp/types.d.ts +12 -7
- package/dist/types/mcp/types.d.ts.map +1 -1
- package/dist/types/redaction/knownStrings.d.ts.map +1 -1
- package/dist/types/security/PermissionPolicy.d.ts +1 -1
- package/dist/types/strategies/defaults/chatBubbleLiveStatus.d.ts +1 -1
- package/dist/types/tool-lint/analyze.d.ts +1 -1
- package/dist/types/tool-lint/rules.d.ts +3 -3
- package/dist/types/tools/requestEvidence.d.ts +79 -0
- package/dist/types/tools/requestEvidence.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -33,7 +33,10 @@
|
|
|
33
33
|
* `agentfootprint.stream.tool_start` / `tool_end` events
|
|
34
34
|
* when the agent calls them. Add `name: '<mcp-server>'` to
|
|
35
35
|
* `McpClientOptions` so observability surfaces can group
|
|
36
|
-
* tool calls by server.
|
|
36
|
+
* tool calls by server. On a transport this module builds,
|
|
37
|
+
* a call the agent dispatched also gets its request's retry
|
|
38
|
+
* series as `agentfootprint.tools.request_attempts`, filed by
|
|
39
|
+
* the series through the call's own port (`requestLedger.ts`).
|
|
37
40
|
*
|
|
38
41
|
* Lazy-require pattern: the `@modelcontextprotocol/sdk` peer-dep
|
|
39
42
|
* loads only when a consumer actually constructs a client. Tests
|
|
@@ -33,7 +33,10 @@
|
|
|
33
33
|
* `agentfootprint.stream.tool_start` / `tool_end` events
|
|
34
34
|
* when the agent calls them. Add `name: '<mcp-server>'` to
|
|
35
35
|
* `McpClientOptions` so observability surfaces can group
|
|
36
|
-
* tool calls by server.
|
|
36
|
+
* tool calls by server. On a transport this module builds,
|
|
37
|
+
* a call the agent dispatched also gets its request's retry
|
|
38
|
+
* series as `agentfootprint.tools.request_attempts`, filed by
|
|
39
|
+
* the series through the call's own port (`requestLedger.ts`).
|
|
37
40
|
*
|
|
38
41
|
* Lazy-require pattern: the `@modelcontextprotocol/sdk` peer-dep
|
|
39
42
|
* loads only when a consumer actually constructs a client. Tests
|
|
@@ -42,7 +45,9 @@
|
|
|
42
45
|
import { callMetaOf, readToolExtras } from './toolExtras.js';
|
|
43
46
|
import { readToolResult, resultModeOf } from './toolResult.js';
|
|
44
47
|
import { createVendingFetch } from './gatewayTransport.js';
|
|
45
|
-
import { retryingFetch } from './throttleRetry.js';
|
|
48
|
+
import { ledgeredFetch, retryingFetch } from './throttleRetry.js';
|
|
49
|
+
import { RequestLedger } from './requestLedger.js';
|
|
50
|
+
import { openCall } from './callLifetime.js';
|
|
46
51
|
import { refuseConflictingOptions } from './connectionRefusals.js';
|
|
47
52
|
import { sdkLoadFailure } from './sdkLoadFailure.js';
|
|
48
53
|
import { transportUrl } from './transportUrl.js';
|
|
@@ -82,7 +87,7 @@ export async function mcpClient(opts) {
|
|
|
82
87
|
// Before anything connects: an option that names a behaviour which cannot
|
|
83
88
|
// happen on the chosen arm is a defect, not a preference.
|
|
84
89
|
refuseConflictingOptions(opts, name);
|
|
85
|
-
const connection = await openConnection(opts);
|
|
90
|
+
const { connection, ledger } = await openConnection(opts);
|
|
86
91
|
// Tool cache so consumers calling `.tools()` more than once don't
|
|
87
92
|
// hammer the server. `.refresh()` invalidates it.
|
|
88
93
|
let cache = null;
|
|
@@ -98,7 +103,7 @@ export async function mcpClient(opts) {
|
|
|
98
103
|
const listed = opts.signal
|
|
99
104
|
? await connection.listTools(undefined, { signal: opts.signal })
|
|
100
105
|
: await connection.listTools();
|
|
101
|
-
return listed.tools.map((t) => wrapMcpTool(name, connection, t, opts.signal, resultMode));
|
|
106
|
+
return listed.tools.map((t) => wrapMcpTool(name, connection, t, opts.signal, resultMode, ledger));
|
|
102
107
|
};
|
|
103
108
|
return {
|
|
104
109
|
name,
|
|
@@ -122,19 +127,20 @@ export async function mcpClient(opts) {
|
|
|
122
127
|
},
|
|
123
128
|
};
|
|
124
129
|
}
|
|
125
|
-
// ─── Getting a connection ──────────────────────────────────────────
|
|
126
130
|
/**
|
|
127
131
|
* The one funnel every arm passes through, in precedence order: a connection
|
|
128
132
|
* you handed over, the internal test seam, then the library building one.
|
|
133
|
+
* Only the last has a ledger: a connection built elsewhere has no retry series
|
|
134
|
+
* of ours to file a call's attempts.
|
|
129
135
|
*
|
|
130
136
|
* A call with neither `connection` nor `sdk` reaches `resolveClient` with two
|
|
131
137
|
* `undefined` arguments and takes the identical path it always took.
|
|
132
138
|
*/
|
|
133
139
|
async function openConnection(opts) {
|
|
134
140
|
if (opts.connection !== undefined)
|
|
135
|
-
return opts.connection;
|
|
141
|
+
return { connection: opts.connection };
|
|
136
142
|
if (opts._client !== undefined)
|
|
137
|
-
return opts._client;
|
|
143
|
+
return { connection: opts._client };
|
|
138
144
|
// `refuseConflictingOptions` has already refused the case where this is
|
|
139
145
|
// absent, so the assertion documents that guarantee rather than assuming it.
|
|
140
146
|
const transport = opts.transport;
|
|
@@ -148,13 +154,13 @@ async function resolveClient(transport, clientInfo, signal, retryOnThrottle, sdk
|
|
|
148
154
|
const client = new mod.Client(clientInfo ?? DEFAULT_CLIENT_INFO, {
|
|
149
155
|
capabilities: {},
|
|
150
156
|
});
|
|
151
|
-
const
|
|
157
|
+
const built = await buildTransport(transport, retryOnThrottle, sdk);
|
|
152
158
|
// Same rule as callTool: options ride beside the transport, never inside it.
|
|
153
159
|
if (signal)
|
|
154
|
-
await client.connect(
|
|
160
|
+
await client.connect(built.transport, { signal });
|
|
155
161
|
else
|
|
156
|
-
await client.connect(
|
|
157
|
-
return client;
|
|
162
|
+
await client.connect(built.transport);
|
|
163
|
+
return { connection: client, ...(built.ledger !== undefined && { ledger: built.ledger }) };
|
|
158
164
|
}
|
|
159
165
|
/**
|
|
160
166
|
* An injected `sdk` is checked before anything is built, so a wrong import (a
|
|
@@ -218,12 +224,15 @@ async function buildTransport(t, retryOnThrottle, sdk) {
|
|
|
218
224
|
"reach the server over `transport: { transport: 'http', url }` instead.",
|
|
219
225
|
}));
|
|
220
226
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
// No fetch, so no retry series: a stdio call has no attempts to file.
|
|
228
|
+
return {
|
|
229
|
+
transport: new stdioMod.StdioClientTransport({
|
|
230
|
+
command: t.command,
|
|
231
|
+
args: t.args ? [...t.args] : [],
|
|
232
|
+
...(t.env && { env: { ...t.env } }),
|
|
233
|
+
...(t.cwd !== undefined && { cwd: t.cwd }),
|
|
234
|
+
}),
|
|
235
|
+
};
|
|
227
236
|
}
|
|
228
237
|
// http + gateway transports both ride Streamable HTTP. They differ only in
|
|
229
238
|
// WHEN the auth headers are decided: `http` fixes them at construction,
|
|
@@ -237,6 +246,12 @@ async function buildTransport(t, retryOnThrottle, sdk) {
|
|
|
237
246
|
// did before 8.11.0. A transport fetch that already runs a retry series of
|
|
238
247
|
// its own (AgentCore Runtime's) is never wrapped: `retryingFetch` joins the
|
|
239
248
|
// 429 rule to that series, so one call is one series.
|
|
249
|
+
//
|
|
250
|
+
// The ledger joins the same series, so each request a dispatched tool call
|
|
251
|
+
// sends files its attempts into that call's run; the transport's `send` is
|
|
252
|
+
// watched to bind each request to its call (`requestLedger.ts`). A fetch that
|
|
253
|
+
// runs no series (retry off) gets no ledger: there is nothing to file.
|
|
254
|
+
const ledger = new RequestLedger();
|
|
240
255
|
if (t.transport === 'gateway') {
|
|
241
256
|
// The consumer's own `fetch` (9.32.0) goes UNDERNEATH the vending, not
|
|
242
257
|
// beside it: `createVendingFetch` resolves the credential, applies it to
|
|
@@ -245,19 +260,34 @@ async function buildTransport(t, retryOnThrottle, sdk) {
|
|
|
245
260
|
// credential is still vended per request. Passing `undefined` is the
|
|
246
261
|
// default global `fetch`, which is byte-identical to every release before
|
|
247
262
|
// the seam existed.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
263
|
+
const gatewayFetch = retryingFetch(createVendingFetch(t, t.fetch), retryOnThrottle);
|
|
264
|
+
const ledgered = gatewayFetch && ledgeredFetch(gatewayFetch, ledger);
|
|
265
|
+
return watched(new httpMod.StreamableHTTPClientTransport(transportUrl(t.url, 'mcpClient'), {
|
|
266
|
+
fetch: ledgered ?? gatewayFetch,
|
|
267
|
+
}), ledgered && ledger);
|
|
251
268
|
}
|
|
252
269
|
// Both options ride the SAME SDK transport, and both are forwarded when both
|
|
253
270
|
// are given. The SDK folds `requestInit.headers` into the `init.headers` it
|
|
254
271
|
// hands the custom fetch, so a signer sees the static headers and has the
|
|
255
272
|
// final word over the bytes — see `McpHttpTransport.fetch`.
|
|
256
273
|
const httpFetch = retryingFetch(t.fetch, retryOnThrottle);
|
|
257
|
-
|
|
274
|
+
const ledgered = httpFetch && ledgeredFetch(httpFetch, ledger);
|
|
275
|
+
const fetch = ledgered ?? httpFetch;
|
|
276
|
+
return watched(new httpMod.StreamableHTTPClientTransport(transportUrl(t.url, 'mcpClient'), {
|
|
258
277
|
...(t.headers && { requestInit: { headers: { ...t.headers } } }),
|
|
259
|
-
...(
|
|
260
|
-
});
|
|
278
|
+
...(fetch && { fetch }),
|
|
279
|
+
}), ledgered && ledger);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* `transport` with its sends watched by `ledger` — the SAME object, its own
|
|
283
|
+
* `send` installed in place. As it is, with no ledger, when there is none or it
|
|
284
|
+
* cannot be watched: then no call expects its attempts filed.
|
|
285
|
+
*/
|
|
286
|
+
function watched(transport, ledger) {
|
|
287
|
+
if (ledger === undefined || transport === null || typeof transport !== 'object') {
|
|
288
|
+
return { transport };
|
|
289
|
+
}
|
|
290
|
+
return ledger.watch(transport) === undefined ? { transport } : { transport, ledger };
|
|
261
291
|
}
|
|
262
292
|
/** The Node loader path for Streamable HTTP — reached only with no `sdk`. */
|
|
263
293
|
function loadHttpModule(transport) {
|
|
@@ -277,7 +307,7 @@ function loadHttpModule(transport) {
|
|
|
277
307
|
}
|
|
278
308
|
}
|
|
279
309
|
// ─── Tool wrapping ─────────────────────────────────────────────────
|
|
280
|
-
function wrapMcpTool(serverName, connection, mcp, signal, resultMode) {
|
|
310
|
+
function wrapMcpTool(serverName, connection, mcp, signal, resultMode, ledger) {
|
|
281
311
|
const tool = {
|
|
282
312
|
schema: {
|
|
283
313
|
name: mcp.name,
|
|
@@ -318,10 +348,22 @@ function wrapMcpTool(serverName, connection, mcp, signal, resultMode) {
|
|
|
318
348
|
arguments: argsObj,
|
|
319
349
|
...(ctx?.time !== undefined && { _meta: callMetaOf(ctx.time) }),
|
|
320
350
|
};
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
351
|
+
// The call's lifetime (`callLifetime.ts`): its context's signal and the
|
|
352
|
+
// client's cancel the SDK request while it runs; a call the agent
|
|
353
|
+
// dispatched issues a ticket keyed by THIS params object — the one the
|
|
354
|
+
// SDK hands the transport — so the retry series that sends it files its
|
|
355
|
+
// attempts into the call's run; and however the call settles, a series
|
|
356
|
+
// still sending is cut, inside the call. Nothing is added to the request.
|
|
357
|
+
const call = openCall(params, ctx, signal, ledger, serverName);
|
|
358
|
+
try {
|
|
359
|
+
const result = call.signal
|
|
360
|
+
? await connection.callTool(params, undefined, { signal: call.signal })
|
|
361
|
+
: await connection.callTool(params);
|
|
362
|
+
return readToolResult(result, mcp.name, serverName, resultMode);
|
|
363
|
+
}
|
|
364
|
+
finally {
|
|
365
|
+
call.close();
|
|
366
|
+
}
|
|
325
367
|
},
|
|
326
368
|
};
|
|
327
369
|
return tool;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcpClient.js","sourceRoot":"","sources":["../../../src/mcp/mcpClient.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mcpClient.js","sourceRoot":"","sources":["../../../src/mcp/mcpClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAaH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAwB,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,qEAAqE;AACrE,uEAAuE;AACvE,mEAAmE;AACnE,MAAM,mBAAmB,GAAG;IAC1B,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,OAAO;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAA6C;IAC3E,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC;IAChC,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACvD,0EAA0E;IAC1E,0DAA0D;IAC1D,wBAAwB,CAAC,IAAI,EAA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AI,EAAE,GAAG,CAAC,IAAI;gBACd,SAAS,EAAE,OAAO;gBAClB,GAAG,CAAC,GAAG,EAAE,IAAI,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;aAChE,CAAC;YACF,wEAAwE;YACxE,kEAAkE;YAClE,uEAAuE;YACvE,wEAAwE;YACxE,uEAAuE;YACvE,0EAA0E;YAC1E,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;YAC/D,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM;oBACxB,CAAC,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;oBACvE,CAAC,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;gBACtC,OAAO,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;YAClE,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,CAAC;QACH,CAAC;KACF,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* requestLedger — which dispatched tool call an MCP request belongs to, so the
|
|
3
|
+
* retry series that sends it files its attempts into THAT call's run; and when
|
|
4
|
+
* the MCP SDK cancels a request, so the series sending it stops.
|
|
5
|
+
*
|
|
6
|
+
* Pattern: a per-connection ledger + the SDK transport's `send`, watched in place.
|
|
7
|
+
* Role: The middle of the evidence seam (`tools/requestEvidence.ts` is its
|
|
8
|
+
* door). The retry series runs inside the transport's `fetch`, which
|
|
9
|
+
* the MCP SDK calls with a serialized body and nothing else — no tool
|
|
10
|
+
* call, no run. Three hops carry the call down to it, each by an
|
|
11
|
+
* identity the hop already holds:
|
|
12
|
+
*
|
|
13
|
+
* 1. call → params `issue`: the MCP tool keys its ticket by the request's
|
|
14
|
+
* params OBJECT. The SDK puts that very object into the
|
|
15
|
+
* JSON-RPC message it hands the transport.
|
|
16
|
+
* 2. params → id the watched `send` finds the ticket by `message.params`
|
|
17
|
+
* and keys it by the JSON-RPC `id` the SDK assigned, until
|
|
18
|
+
* that send settles.
|
|
19
|
+
* 3. id → series `claim`: the series reads the `id` back out of the body
|
|
20
|
+
* it is about to send.
|
|
21
|
+
*
|
|
22
|
+
* CANCELLATION DOES NOT WAIT ON ATTRIBUTION. Every `tools/call` in flight gets
|
|
23
|
+
* an entry, ticket or not, and the SDK says when it gives a request up: it sends
|
|
24
|
+
* `notifications/cancelled` naming the request's id — on its own timeout, or
|
|
25
|
+
* when the call's signal fires — through this same `send`. The ledger aborts
|
|
26
|
+
* that request's series there and then, so a request nobody waits for is never
|
|
27
|
+
* asked again, even when its params could not be matched to a call.
|
|
28
|
+
*
|
|
29
|
+
* Nothing is added to the wire: the request the server receives is
|
|
30
|
+
* byte-identical, and the SDK's own options keep their meanings. Ids are the
|
|
31
|
+
* client's, one ledger per connection, so concurrent calls — and concurrent
|
|
32
|
+
* runs sharing one client — can never claim each other's request. A request
|
|
33
|
+
* that is not a `tools/call` (a `tools/list`, a notification, a response)
|
|
34
|
+
* claims nothing.
|
|
35
|
+
*
|
|
36
|
+
* `send` is installed as an OWN property of the transport instance — the same
|
|
37
|
+
* object, its own `send` bound to it, so a transport class with `#private`
|
|
38
|
+
* fields works as it always did. Assigning `send` again afterwards THROWS: a
|
|
39
|
+
* send that bypassed the ledger would quietly lose every call's attempts.
|
|
40
|
+
*
|
|
41
|
+
* What it does NOT do: retry, wait, or decide anything. The series is the one
|
|
42
|
+
* retry owner; this only tells it whose attempts it is making, and when the SDK
|
|
43
|
+
* has stopped waiting for them.
|
|
44
|
+
*/
|
|
45
|
+
import type { RequestEvidenceSink } from '../tools/requestEvidence.js';
|
|
46
|
+
/** One call's claim on the request it sends. */
|
|
47
|
+
export interface RequestTicket {
|
|
48
|
+
/** Where the request's attempts are filed. */
|
|
49
|
+
readonly sink: RequestEvidenceSink;
|
|
50
|
+
/** What cancels the call's series — the call's own signal, the client's, the call settling. */
|
|
51
|
+
readonly signal?: AbortSignal;
|
|
52
|
+
}
|
|
53
|
+
/** What a series claims for the `tools/call` request it sends. */
|
|
54
|
+
export interface ClaimedRequest {
|
|
55
|
+
/** The ticket a dispatched call issued for this request — absent when none was matched. */
|
|
56
|
+
readonly ticket?: RequestTicket;
|
|
57
|
+
/** Fires when the MCP SDK cancels this request (`notifications/cancelled`). */
|
|
58
|
+
readonly cancelled: AbortSignal;
|
|
59
|
+
}
|
|
60
|
+
/** Per connection: the tickets issued and not yet sent, and the requests being sent. */
|
|
61
|
+
export declare class RequestLedger {
|
|
62
|
+
/** Issued, not yet sent — keyed by the request's params object. Collected with it. */
|
|
63
|
+
private readonly issued;
|
|
64
|
+
/** Tickets a request was bound to. */
|
|
65
|
+
private readonly bound;
|
|
66
|
+
/** Every `tools/call` sent and not yet settled — keyed by its JSON-RPC id. */
|
|
67
|
+
private readonly sending;
|
|
68
|
+
private calls;
|
|
69
|
+
private unboundNamed;
|
|
70
|
+
/** The call about to send `params` files its attempts through `ticket`. */
|
|
71
|
+
issue(params: object, ticket: RequestTicket): void;
|
|
72
|
+
/** Whether a request the transport sent was bound to `ticket`. */
|
|
73
|
+
wasBound(ticket: RequestTicket): boolean;
|
|
74
|
+
/** How many `tools/call` requests the watched transport has sent — matched to a call or not. */
|
|
75
|
+
get toolCallsSent(): number;
|
|
76
|
+
/** `true` the first time it is asked, then never again: an unmatched request is named once per connection. */
|
|
77
|
+
firstUnbound(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Watch `transport`'s `send`: install a wrapped `send` as its OWN property, the
|
|
80
|
+
* original bound to the instance itself. Returns the SAME object — or
|
|
81
|
+
* `undefined` when it has no `send` to watch or refuses the property, and
|
|
82
|
+
* then nothing is watched and no call should expect its attempts filed.
|
|
83
|
+
*/
|
|
84
|
+
watch<T extends object>(transport: T): T | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* The `tools/call` request `body` carries, while its send runs — its ticket
|
|
87
|
+
* when a call issued one, and the signal its cancellation fires. `undefined`
|
|
88
|
+
* for any other body. Parses only while some request is being sent.
|
|
89
|
+
*/
|
|
90
|
+
claim(body: unknown): ClaimedRequest | undefined;
|
|
91
|
+
/** One message through the watched transport. */
|
|
92
|
+
private send;
|
|
93
|
+
/** Register a `tools/call` in flight, with the ticket its params were issued — if any. */
|
|
94
|
+
private bind;
|
|
95
|
+
/** The SDK gave a request up: stop the series still sending it. */
|
|
96
|
+
private cancelIfAsked;
|
|
97
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* requestLedger — which dispatched tool call an MCP request belongs to, so the
|
|
3
|
+
* retry series that sends it files its attempts into THAT call's run; and when
|
|
4
|
+
* the MCP SDK cancels a request, so the series sending it stops.
|
|
5
|
+
*
|
|
6
|
+
* Pattern: a per-connection ledger + the SDK transport's `send`, watched in place.
|
|
7
|
+
* Role: The middle of the evidence seam (`tools/requestEvidence.ts` is its
|
|
8
|
+
* door). The retry series runs inside the transport's `fetch`, which
|
|
9
|
+
* the MCP SDK calls with a serialized body and nothing else — no tool
|
|
10
|
+
* call, no run. Three hops carry the call down to it, each by an
|
|
11
|
+
* identity the hop already holds:
|
|
12
|
+
*
|
|
13
|
+
* 1. call → params `issue`: the MCP tool keys its ticket by the request's
|
|
14
|
+
* params OBJECT. The SDK puts that very object into the
|
|
15
|
+
* JSON-RPC message it hands the transport.
|
|
16
|
+
* 2. params → id the watched `send` finds the ticket by `message.params`
|
|
17
|
+
* and keys it by the JSON-RPC `id` the SDK assigned, until
|
|
18
|
+
* that send settles.
|
|
19
|
+
* 3. id → series `claim`: the series reads the `id` back out of the body
|
|
20
|
+
* it is about to send.
|
|
21
|
+
*
|
|
22
|
+
* CANCELLATION DOES NOT WAIT ON ATTRIBUTION. Every `tools/call` in flight gets
|
|
23
|
+
* an entry, ticket or not, and the SDK says when it gives a request up: it sends
|
|
24
|
+
* `notifications/cancelled` naming the request's id — on its own timeout, or
|
|
25
|
+
* when the call's signal fires — through this same `send`. The ledger aborts
|
|
26
|
+
* that request's series there and then, so a request nobody waits for is never
|
|
27
|
+
* asked again, even when its params could not be matched to a call.
|
|
28
|
+
*
|
|
29
|
+
* Nothing is added to the wire: the request the server receives is
|
|
30
|
+
* byte-identical, and the SDK's own options keep their meanings. Ids are the
|
|
31
|
+
* client's, one ledger per connection, so concurrent calls — and concurrent
|
|
32
|
+
* runs sharing one client — can never claim each other's request. A request
|
|
33
|
+
* that is not a `tools/call` (a `tools/list`, a notification, a response)
|
|
34
|
+
* claims nothing.
|
|
35
|
+
*
|
|
36
|
+
* `send` is installed as an OWN property of the transport instance — the same
|
|
37
|
+
* object, its own `send` bound to it, so a transport class with `#private`
|
|
38
|
+
* fields works as it always did. Assigning `send` again afterwards THROWS: a
|
|
39
|
+
* send that bypassed the ledger would quietly lose every call's attempts.
|
|
40
|
+
*
|
|
41
|
+
* What it does NOT do: retry, wait, or decide anything. The series is the one
|
|
42
|
+
* retry owner; this only tells it whose attempts it is making, and when the SDK
|
|
43
|
+
* has stopped waiting for them.
|
|
44
|
+
*/
|
|
45
|
+
/** The method whose requests a tool call issues tickets for. */
|
|
46
|
+
const TOOLS_CALL = 'tools/call';
|
|
47
|
+
/** The notification the SDK sends when it gives up one of its own requests. */
|
|
48
|
+
const CANCELLED = 'notifications/cancelled';
|
|
49
|
+
/** Per connection: the tickets issued and not yet sent, and the requests being sent. */
|
|
50
|
+
export class RequestLedger {
|
|
51
|
+
/** Issued, not yet sent — keyed by the request's params object. Collected with it. */
|
|
52
|
+
issued = new WeakMap();
|
|
53
|
+
/** Tickets a request was bound to. */
|
|
54
|
+
bound = new WeakSet();
|
|
55
|
+
/** Every `tools/call` sent and not yet settled — keyed by its JSON-RPC id. */
|
|
56
|
+
sending = new Map();
|
|
57
|
+
calls = 0;
|
|
58
|
+
unboundNamed = false;
|
|
59
|
+
/** The call about to send `params` files its attempts through `ticket`. */
|
|
60
|
+
issue(params, ticket) {
|
|
61
|
+
this.issued.set(params, ticket);
|
|
62
|
+
}
|
|
63
|
+
/** Whether a request the transport sent was bound to `ticket`. */
|
|
64
|
+
wasBound(ticket) {
|
|
65
|
+
return this.bound.has(ticket);
|
|
66
|
+
}
|
|
67
|
+
/** How many `tools/call` requests the watched transport has sent — matched to a call or not. */
|
|
68
|
+
get toolCallsSent() {
|
|
69
|
+
return this.calls;
|
|
70
|
+
}
|
|
71
|
+
/** `true` the first time it is asked, then never again: an unmatched request is named once per connection. */
|
|
72
|
+
firstUnbound() {
|
|
73
|
+
if (this.unboundNamed)
|
|
74
|
+
return false;
|
|
75
|
+
this.unboundNamed = true;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Watch `transport`'s `send`: install a wrapped `send` as its OWN property, the
|
|
80
|
+
* original bound to the instance itself. Returns the SAME object — or
|
|
81
|
+
* `undefined` when it has no `send` to watch or refuses the property, and
|
|
82
|
+
* then nothing is watched and no call should expect its attempts filed.
|
|
83
|
+
*/
|
|
84
|
+
watch(transport) {
|
|
85
|
+
const send = Reflect.get(transport, 'send');
|
|
86
|
+
if (typeof send !== 'function')
|
|
87
|
+
return undefined;
|
|
88
|
+
const original = send.bind(transport);
|
|
89
|
+
const watched = (message, options) => this.send(original, message, options);
|
|
90
|
+
try {
|
|
91
|
+
Object.defineProperty(transport, 'send', {
|
|
92
|
+
configurable: false,
|
|
93
|
+
enumerable: false,
|
|
94
|
+
get: () => watched,
|
|
95
|
+
set: () => {
|
|
96
|
+
throw new TypeError("mcpClient: this transport's `send` is watched by its request ledger, which " +
|
|
97
|
+
'matches each tools/call request to the call that sent it. Assigning `send` ' +
|
|
98
|
+
'again would send requests the ledger never sees, so it is refused.');
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return transport;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The `tools/call` request `body` carries, while its send runs — its ticket
|
|
109
|
+
* when a call issued one, and the signal its cancellation fires. `undefined`
|
|
110
|
+
* for any other body. Parses only while some request is being sent.
|
|
111
|
+
*/
|
|
112
|
+
claim(body) {
|
|
113
|
+
if (this.sending.size === 0 || typeof body !== 'string')
|
|
114
|
+
return undefined;
|
|
115
|
+
let message;
|
|
116
|
+
try {
|
|
117
|
+
message = JSON.parse(body);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
const id = requestIdOf(message);
|
|
123
|
+
const entry = id === undefined ? undefined : this.sending.get(id);
|
|
124
|
+
if (entry === undefined)
|
|
125
|
+
return undefined;
|
|
126
|
+
return {
|
|
127
|
+
...(entry.ticket !== undefined && { ticket: entry.ticket }),
|
|
128
|
+
cancelled: entry.cut.signal,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** One message through the watched transport. */
|
|
132
|
+
send(original, message, options) {
|
|
133
|
+
this.cancelIfAsked(message);
|
|
134
|
+
const id = this.bind(message);
|
|
135
|
+
if (id === undefined)
|
|
136
|
+
return original(message, options);
|
|
137
|
+
const entry = this.sending.get(id);
|
|
138
|
+
const release = () => {
|
|
139
|
+
if (this.sending.get(id) === entry)
|
|
140
|
+
this.sending.delete(id);
|
|
141
|
+
};
|
|
142
|
+
try {
|
|
143
|
+
return Promise.resolve(original(message, options)).finally(release);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
release();
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** Register a `tools/call` in flight, with the ticket its params were issued — if any. */
|
|
151
|
+
bind(message) {
|
|
152
|
+
const id = requestIdOf(message);
|
|
153
|
+
if (id === undefined)
|
|
154
|
+
return undefined;
|
|
155
|
+
this.calls += 1;
|
|
156
|
+
const params = message.params;
|
|
157
|
+
const ticket = params !== null && typeof params === 'object' ? this.issued.get(params) : undefined;
|
|
158
|
+
if (ticket !== undefined) {
|
|
159
|
+
// One request per ticket: a second message reusing these params is not this call's.
|
|
160
|
+
this.issued.delete(params);
|
|
161
|
+
this.bound.add(ticket);
|
|
162
|
+
}
|
|
163
|
+
this.sending.set(id, { ...(ticket !== undefined && { ticket }), cut: new AbortController() });
|
|
164
|
+
return id;
|
|
165
|
+
}
|
|
166
|
+
/** The SDK gave a request up: stop the series still sending it. */
|
|
167
|
+
cancelIfAsked(message) {
|
|
168
|
+
if (message === null || typeof message !== 'object' || Array.isArray(message))
|
|
169
|
+
return;
|
|
170
|
+
const { method, params } = message;
|
|
171
|
+
if (method !== CANCELLED || params === null || typeof params !== 'object')
|
|
172
|
+
return;
|
|
173
|
+
const requestId = params.requestId;
|
|
174
|
+
if (typeof requestId !== 'string' && typeof requestId !== 'number')
|
|
175
|
+
return;
|
|
176
|
+
this.sending.get(requestId)?.cut.abort(sdkCancelled());
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** The reason a series stops when the SDK cancelled its request — a fixed sentence. */
|
|
180
|
+
function sdkCancelled() {
|
|
181
|
+
return Object.assign(new Error('The MCP SDK cancelled this request.'), { name: 'AbortError' });
|
|
182
|
+
}
|
|
183
|
+
/** The id of a `tools/call` REQUEST — a response or a notification has none to claim. */
|
|
184
|
+
function requestIdOf(message) {
|
|
185
|
+
if (message === null || typeof message !== 'object' || Array.isArray(message))
|
|
186
|
+
return undefined;
|
|
187
|
+
const { method, id } = message;
|
|
188
|
+
if (method !== TOOLS_CALL)
|
|
189
|
+
return undefined;
|
|
190
|
+
return typeof id === 'string' || typeof id === 'number' ? id : undefined;
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=requestLedger.js.map
|
|
@@ -0,0 +1 @@
|
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AAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAChG,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,OAA+D,CAAC;IACvF,IAAI,MAAM,KAAK,UAAU;QAAE,OAAO,SAAS,CAAC;IAC5C,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* seriesEvidence — one MCP request's retry series, written down for its run.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: a collector over footprintjs's attempt records, filed once.
|
|
5
|
+
* Role: The series (`throttleRetry.ts` · `Series`) is the one retry owner and
|
|
6
|
+
* the attempt runner makes one record per try; this turns each record
|
|
7
|
+
* into an allow-listed row and files the request's whole story — its
|
|
8
|
+
* rows, how many were not listed, and how it ended — to the call's sink
|
|
9
|
+
* (`tools/requestEvidence.ts`) exactly ONCE.
|
|
10
|
+
*
|
|
11
|
+
* WHAT A ROW MAY SAY. Numbers and the library's own words; never the server's
|
|
12
|
+
* answer, the call's arguments or an error's text. A failure is a fixed sentence
|
|
13
|
+
* and its category — a network or SDK error message can carry a URL with a token
|
|
14
|
+
* in it, a host's internal name or a server's reply.
|
|
15
|
+
*
|
|
16
|
+
* A RESPONSE IS NOT A SUCCESS. The runner records an attempt that returned a
|
|
17
|
+
* response as `ok` with the reason `succeeded`; here it is `answered`, with the
|
|
18
|
+
* status the server sent — a 503 delivered is `answered` + `503`, never success.
|
|
19
|
+
*
|
|
20
|
+
* EVERY REQUEST SENT IS COUNTED. Each attempt the series started is a row — or,
|
|
21
|
+
* past the cap, one more in `omitted` — so `rows + omitted` is the number of
|
|
22
|
+
* requests the series sent. An attempt a cancellation cuts in flight is a row
|
|
23
|
+
* too (`cut`), exactly as an attempt the deadline cuts is (`timed-out`). A
|
|
24
|
+
* request the series never sent — the next one after a cancelled wait — has no
|
|
25
|
+
* row.
|
|
26
|
+
*
|
|
27
|
+
* A CUT IS NOT A "NOT RUN". An attempt that ended without an answer — cut,
|
|
28
|
+
* timed out, or failed — was sent, and the server may have received it and run
|
|
29
|
+
* it. Its row says so (`remote: 'unknown'`); nothing here records it as not run.
|
|
30
|
+
*
|
|
31
|
+
* WHEN IT FILES. When the series ends — and, for a cancellation, at the moment the
|
|
32
|
+
* signal fires: a cancelled run stops waiting for its stage at once, so a record
|
|
33
|
+
* filed when the series later unwinds would land after the run was saved. The
|
|
34
|
+
* runner makes no record for an attempt it abandons at that moment or for a wait
|
|
35
|
+
* it was cut out of, so those are written here: the cut attempt's row and
|
|
36
|
+
* `during: 'request'`, or `during: 'wait'`. Anything the series reports after it
|
|
37
|
+
* has filed is not part of the request's story any more and is ignored.
|
|
38
|
+
*/
|
|
39
|
+
import type { AttemptRecord } from 'footprintjs';
|
|
40
|
+
import type { ToolRequestAttempt, ToolRequestReason } from '../events/payloads.js';
|
|
41
|
+
import { type RequestEvidence, type RequestEvidenceSink } from '../tools/requestEvidence.js';
|
|
42
|
+
/** Where the request went, as a row may say it: the app's label for it, or its origin. */
|
|
43
|
+
export type RequestWhere = Pick<RequestEvidence, 'endpoint' | 'origin'>;
|
|
44
|
+
/** What the series saw of one attempt that its record does not hold. */
|
|
45
|
+
export interface AttemptSeen {
|
|
46
|
+
/** The response's status, when a response arrived. */
|
|
47
|
+
readonly status?: number;
|
|
48
|
+
/** The refusal a rule recognised in that response, when one did. */
|
|
49
|
+
readonly refusal?: {
|
|
50
|
+
readonly kind: 'throttle' | 'session-busy';
|
|
51
|
+
readonly retryAfterMs?: number;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Why the series' `retryOn` said no — the reasons the runner calls `declined`. */
|
|
55
|
+
export type DeclineReason = Extract<ToolRequestReason, 'exhausted' | 'wait-limit' | 'no-time-left' | 'not-replayable' | 'not-retryable'>;
|
|
56
|
+
/** One request's evidence, collected as its series runs and filed once. */
|
|
57
|
+
export declare class SeriesEvidence {
|
|
58
|
+
private readonly sink;
|
|
59
|
+
private readonly where;
|
|
60
|
+
private readonly rows;
|
|
61
|
+
private omitted;
|
|
62
|
+
private last;
|
|
63
|
+
private filed;
|
|
64
|
+
constructor(sink: RequestEvidenceSink, where: RequestWhere);
|
|
65
|
+
/** One attempt as the runner recorded it. */
|
|
66
|
+
attempt(record: AttemptRecord, seen: AttemptSeen | undefined, declined?: DeclineReason): void;
|
|
67
|
+
/**
|
|
68
|
+
* The caller's cancellation cut attempt `n` in flight. It was sent — the
|
|
69
|
+
* server may have it, and may have run it — so it is a row, `cut`, with the
|
|
70
|
+
* remote outcome `unknown`; then the request's end says the same.
|
|
71
|
+
*/
|
|
72
|
+
cutInFlight(n: number): void;
|
|
73
|
+
/**
|
|
74
|
+
* The caller's cancellation landed with NO request in flight: between two —
|
|
75
|
+
* `during: 'wait'`, the next request never sent — or before the first, when
|
|
76
|
+
* nothing was sent and there is no `during`. No row is added: there is no
|
|
77
|
+
* request to account for. A request that had already ended keeps its end.
|
|
78
|
+
*/
|
|
79
|
+
cancelled(): void;
|
|
80
|
+
/**
|
|
81
|
+
* The series delivered a response. It is the last attempt's — an answer, or a
|
|
82
|
+
* refusal it will not ask again after. A refusal it MEANT to ask again after
|
|
83
|
+
* is delivered when the deadline lands inside the wait: the runner's wait
|
|
84
|
+
* ends early, the series stops, and the end says so (`no-time-left`, during
|
|
85
|
+
* the `wait`).
|
|
86
|
+
*/
|
|
87
|
+
delivered(): void;
|
|
88
|
+
/**
|
|
89
|
+
* The series threw. The end is the last attempt's when that attempt ended it
|
|
90
|
+
* (a failure, a timed-out request). The rest is defensive — footprintjs 10.6's
|
|
91
|
+
* runner never throws without a record but for a cancellation, which is filed
|
|
92
|
+
* as one: a deadline that had passed before the first request (`timed-out`,
|
|
93
|
+
* no `during`, nothing sent) or one a future runner reports from inside a wait
|
|
94
|
+
* (`during: 'wait'`); anything else is filed as a failure the record cannot
|
|
95
|
+
* account for, so a request is never left unfiled.
|
|
96
|
+
*/
|
|
97
|
+
threw(outOfTime: boolean): void;
|
|
98
|
+
private add;
|
|
99
|
+
private file;
|
|
100
|
+
}
|
|
101
|
+
/** One record as a row — see the module note for what a row may say. */
|
|
102
|
+
export declare function rowOf(record: AttemptRecord, seen: AttemptSeen | undefined, declined?: DeclineReason): ToolRequestAttempt;
|