agentfootprint 11.4.0 → 12.0.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/CAPABILITIES.md +3 -1
- package/dist/adapters/code/agentcore.js +295 -214
- package/dist/adapters/code/agentcore.js.map +1 -1
- package/dist/adapters/code/agentcoreClient.js +178 -0
- package/dist/adapters/code/agentcoreClient.js.map +1 -0
- package/dist/adapters/code/agentcoreWire.js +348 -0
- package/dist/adapters/code/agentcoreWire.js.map +1 -0
- package/dist/adapters/code/fileName.js +100 -0
- package/dist/adapters/code/fileName.js.map +1 -0
- package/dist/adapters/code/local.js +529 -183
- package/dist/adapters/code/local.js.map +1 -1
- package/dist/adapters/code/output.js +140 -0
- package/dist/adapters/code/output.js.map +1 -0
- package/dist/adapters/mcp/agentcoreRuntime/invoke.js +7 -6
- package/dist/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -1
- package/dist/adapters/mcp/agentcoreRuntime/sessionBusy.js +36 -2
- package/dist/adapters/mcp/agentcoreRuntime/sessionBusy.js.map +1 -1
- package/dist/adapters/mcp/agentcoreRuntime/transport.js +3 -1
- package/dist/adapters/mcp/agentcoreRuntime/transport.js.map +1 -1
- package/dist/core/codeRunnerTool.js +52 -7
- package/dist/core/codeRunnerTool.js.map +1 -1
- package/dist/doors/providers.js.map +1 -1
- package/dist/esm/adapters/code/agentcore.d.ts +65 -68
- package/dist/esm/adapters/code/agentcore.js +293 -212
- package/dist/esm/adapters/code/agentcore.js.map +1 -1
- package/dist/esm/adapters/code/agentcoreClient.d.ts +193 -0
- package/dist/esm/adapters/code/agentcoreClient.js +173 -0
- package/dist/esm/adapters/code/agentcoreClient.js.map +1 -0
- package/dist/esm/adapters/code/agentcoreWire.d.ts +119 -0
- package/dist/esm/adapters/code/agentcoreWire.js +334 -0
- package/dist/esm/adapters/code/agentcoreWire.js.map +1 -0
- package/dist/esm/adapters/code/fileName.d.ts +43 -0
- package/dist/esm/adapters/code/fileName.js +96 -0
- package/dist/esm/adapters/code/fileName.js.map +1 -0
- package/dist/esm/adapters/code/local.d.ts +91 -12
- package/dist/esm/adapters/code/local.js +528 -182
- package/dist/esm/adapters/code/local.js.map +1 -1
- package/dist/esm/adapters/code/output.d.ts +70 -0
- package/dist/esm/adapters/code/output.js +129 -0
- package/dist/esm/adapters/code/output.js.map +1 -0
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.d.ts +7 -6
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js +7 -6
- package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -1
- package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts +32 -1
- package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.js +35 -1
- package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.js.map +1 -1
- package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js +4 -2
- package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js.map +1 -1
- package/dist/esm/core/codeRunnerTool.d.ts +15 -3
- package/dist/esm/core/codeRunnerTool.js +52 -7
- package/dist/esm/core/codeRunnerTool.js.map +1 -1
- package/dist/esm/doors/providers.d.ts +1 -1
- package/dist/esm/doors/providers.js.map +1 -1
- package/dist/esm/events/payloads.d.ts +144 -29
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mcp/callLifetime.d.ts +57 -14
- package/dist/esm/mcp/callLifetime.js +67 -19
- package/dist/esm/mcp/callLifetime.js.map +1 -1
- package/dist/esm/mcp/callMarker.d.ts +43 -0
- package/dist/esm/mcp/callMarker.js +69 -0
- package/dist/esm/mcp/callMarker.js.map +1 -0
- package/dist/esm/mcp/connectionRefusals.js +7 -0
- package/dist/esm/mcp/connectionRefusals.js.map +1 -1
- package/dist/esm/mcp/index.d.ts +2 -0
- package/dist/esm/mcp/index.js +3 -0
- package/dist/esm/mcp/index.js.map +1 -1
- package/dist/esm/mcp/mcpClient.js +93 -26
- package/dist/esm/mcp/mcpClient.js.map +1 -1
- package/dist/esm/mcp/replay.d.ts +291 -0
- package/dist/esm/mcp/replay.js +405 -0
- package/dist/esm/mcp/replay.js.map +1 -0
- package/dist/esm/mcp/replayUnavailable.d.ts +68 -0
- package/dist/esm/mcp/replayUnavailable.js +87 -0
- package/dist/esm/mcp/replayUnavailable.js.map +1 -0
- package/dist/esm/mcp/requestLedger.d.ts +115 -32
- package/dist/esm/mcp/requestLedger.js +193 -52
- package/dist/esm/mcp/requestLedger.js.map +1 -1
- package/dist/esm/mcp/seriesEvidence.d.ts +73 -15
- package/dist/esm/mcp/seriesEvidence.js +114 -21
- package/dist/esm/mcp/seriesEvidence.js.map +1 -1
- package/dist/esm/mcp/throttleRetry.d.ts +86 -42
- package/dist/esm/mcp/throttleRetry.js +158 -50
- package/dist/esm/mcp/throttleRetry.js.map +1 -1
- package/dist/esm/mcp/toolResult.d.ts +6 -0
- package/dist/esm/mcp/toolResult.js +15 -0
- package/dist/esm/mcp/toolResult.js.map +1 -1
- package/dist/esm/mcp/types.d.ts +73 -8
- package/dist/esm/provider-contract/codeSandbox.d.ts +89 -0
- package/dist/esm/provider-contract/codeSandbox.js +119 -0
- package/dist/esm/provider-contract/codeSandbox.js.map +1 -0
- package/dist/esm/provider-contract/sessionExpired.d.ts +31 -0
- package/dist/esm/provider-contract/sessionExpired.js +40 -0
- package/dist/esm/provider-contract/sessionExpired.js.map +1 -0
- package/dist/esm/provider-contract/types.d.ts +166 -17
- package/dist/esm/provider-contract/types.js +9 -0
- package/dist/esm/provider-contract/types.js.map +1 -1
- package/dist/esm/redaction/knownStrings.js +16 -0
- package/dist/esm/redaction/knownStrings.js.map +1 -1
- package/dist/esm/tool-providers/index.d.ts +2 -2
- package/dist/esm/tool-providers/index.js +4 -0
- package/dist/esm/tool-providers/index.js.map +1 -1
- package/dist/esm/tools/requestEvidence.js +60 -0
- package/dist/esm/tools/requestEvidence.js.map +1 -1
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/mcp/callLifetime.js +66 -18
- package/dist/mcp/callLifetime.js.map +1 -1
- package/dist/mcp/callMarker.js +74 -0
- package/dist/mcp/callMarker.js.map +1 -0
- package/dist/mcp/connectionRefusals.js +7 -0
- package/dist/mcp/connectionRefusals.js.map +1 -1
- package/dist/mcp/index.js +5 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/mcpClient.js +91 -24
- package/dist/mcp/mcpClient.js.map +1 -1
- package/dist/mcp/replay.js +415 -0
- package/dist/mcp/replay.js.map +1 -0
- package/dist/mcp/replayUnavailable.js +92 -0
- package/dist/mcp/replayUnavailable.js.map +1 -0
- package/dist/mcp/requestLedger.js +193 -52
- package/dist/mcp/requestLedger.js.map +1 -1
- package/dist/mcp/seriesEvidence.js +116 -22
- package/dist/mcp/seriesEvidence.js.map +1 -1
- package/dist/mcp/throttleRetry.js +160 -51
- package/dist/mcp/throttleRetry.js.map +1 -1
- package/dist/mcp/toolResult.js +17 -1
- package/dist/mcp/toolResult.js.map +1 -1
- package/dist/provider-contract/codeSandbox.js +125 -0
- package/dist/provider-contract/codeSandbox.js.map +1 -0
- package/dist/provider-contract/sessionExpired.js +44 -0
- package/dist/provider-contract/sessionExpired.js.map +1 -0
- package/dist/provider-contract/types.js +12 -1
- package/dist/provider-contract/types.js.map +1 -1
- package/dist/redaction/knownStrings.js +16 -0
- package/dist/redaction/knownStrings.js.map +1 -1
- package/dist/tool-providers/index.js +5 -1
- package/dist/tool-providers/index.js.map +1 -1
- package/dist/tools/requestEvidence.js +60 -0
- package/dist/tools/requestEvidence.js.map +1 -1
- package/dist/types/adapters/code/agentcore.d.ts +65 -68
- package/dist/types/adapters/code/agentcore.d.ts.map +1 -1
- package/dist/types/adapters/code/agentcoreClient.d.ts +194 -0
- package/dist/types/adapters/code/agentcoreClient.d.ts.map +1 -0
- package/dist/types/adapters/code/agentcoreWire.d.ts +120 -0
- package/dist/types/adapters/code/agentcoreWire.d.ts.map +1 -0
- package/dist/types/adapters/code/fileName.d.ts +44 -0
- package/dist/types/adapters/code/fileName.d.ts.map +1 -0
- package/dist/types/adapters/code/local.d.ts +91 -12
- package/dist/types/adapters/code/local.d.ts.map +1 -1
- package/dist/types/adapters/code/output.d.ts +71 -0
- package/dist/types/adapters/code/output.d.ts.map +1 -0
- package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts +7 -6
- package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts.map +1 -1
- package/dist/types/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts +32 -1
- package/dist/types/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts.map +1 -1
- package/dist/types/adapters/mcp/agentcoreRuntime/transport.d.ts.map +1 -1
- package/dist/types/core/codeRunnerTool.d.ts +15 -3
- package/dist/types/core/codeRunnerTool.d.ts.map +1 -1
- package/dist/types/doors/providers.d.ts +1 -1
- package/dist/types/doors/providers.d.ts.map +1 -1
- package/dist/types/events/payloads.d.ts +144 -29
- package/dist/types/events/payloads.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/mcp/callLifetime.d.ts +57 -14
- package/dist/types/mcp/callLifetime.d.ts.map +1 -1
- package/dist/types/mcp/callMarker.d.ts +44 -0
- package/dist/types/mcp/callMarker.d.ts.map +1 -0
- package/dist/types/mcp/index.d.ts +2 -0
- package/dist/types/mcp/index.d.ts.map +1 -1
- package/dist/types/mcp/mcpClient.d.ts.map +1 -1
- package/dist/types/mcp/replay.d.ts +292 -0
- package/dist/types/mcp/replay.d.ts.map +1 -0
- package/dist/types/mcp/replayUnavailable.d.ts +69 -0
- package/dist/types/mcp/replayUnavailable.d.ts.map +1 -0
- package/dist/types/mcp/requestLedger.d.ts +115 -32
- package/dist/types/mcp/requestLedger.d.ts.map +1 -1
- package/dist/types/mcp/seriesEvidence.d.ts +73 -15
- package/dist/types/mcp/seriesEvidence.d.ts.map +1 -1
- package/dist/types/mcp/throttleRetry.d.ts +86 -42
- package/dist/types/mcp/throttleRetry.d.ts.map +1 -1
- package/dist/types/mcp/toolResult.d.ts +6 -0
- package/dist/types/mcp/toolResult.d.ts.map +1 -1
- package/dist/types/mcp/types.d.ts +73 -8
- package/dist/types/mcp/types.d.ts.map +1 -1
- package/dist/types/provider-contract/codeSandbox.d.ts +90 -0
- package/dist/types/provider-contract/codeSandbox.d.ts.map +1 -0
- package/dist/types/provider-contract/sessionExpired.d.ts +32 -0
- package/dist/types/provider-contract/sessionExpired.d.ts.map +1 -0
- package/dist/types/provider-contract/types.d.ts +166 -17
- package/dist/types/provider-contract/types.d.ts.map +1 -1
- package/dist/types/redaction/knownStrings.d.ts.map +1 -1
- package/dist/types/tool-providers/index.d.ts +2 -2
- package/dist/types/tool-providers/index.d.ts.map +1 -1
- package/dist/types/tools/requestEvidence.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,48 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
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;
|
|
4
|
-
*
|
|
3
|
+
* retry series that sends it files its attempts into THAT call's run; when the
|
|
4
|
+
* MCP SDK cancels a request, so the series sending it stops; and whether the
|
|
5
|
+
* request's JSON-RPC answer arrived.
|
|
5
6
|
*
|
|
6
7
|
* Pattern: a per-connection ledger + the SDK transport's `send`, watched in place.
|
|
7
8
|
* Role: The middle of the evidence seam (`tools/requestEvidence.ts` is its
|
|
8
9
|
* door). The retry series runs inside the transport's `fetch`, which
|
|
9
10
|
* 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
|
|
11
|
-
* identity the hop already holds:
|
|
11
|
+
* call, no run. Three hops carry the call down to it:
|
|
12
12
|
*
|
|
13
|
-
* 1. call →
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* 2.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
13
|
+
* 1. call → marker `issue`: the MCP tool gets a library-private marker and
|
|
14
|
+
* puts it in its request's `_meta` (`callMarker.ts`). It
|
|
15
|
+
* survives an SDK that copies the params.
|
|
16
|
+
* 2. marker → id the watched `send` takes the marker out of the message
|
|
17
|
+
* — the server receives the bytes it always did — and
|
|
18
|
+
* keys the call by the JSON-RPC `id` the SDK assigned.
|
|
19
19
|
* 3. id → series `claim`: the series reads the `id` back out of the body
|
|
20
20
|
* it is about to send.
|
|
21
21
|
*
|
|
22
22
|
* CANCELLATION DOES NOT WAIT ON ATTRIBUTION. Every `tools/call` in flight gets
|
|
23
|
-
* an entry,
|
|
24
|
-
* `notifications/cancelled` naming the request's id — on its own
|
|
25
|
-
* when the call's signal fires — through this same `send`. The
|
|
26
|
-
* that request's series there and then, so a request nobody waits
|
|
27
|
-
* asked again, even when
|
|
23
|
+
* an entry, matched or not, and the SDK says when it gives a request up: it
|
|
24
|
+
* sends `notifications/cancelled` naming the request's id — on its own
|
|
25
|
+
* timeout, or when the call's signal fires — through this same `send`. The
|
|
26
|
+
* ledger aborts that request's series there and then, so a request nobody waits
|
|
27
|
+
* for is never asked again, even when it could not be matched to a call.
|
|
28
28
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
29
|
+
* Under `'app-authorized'` (`strict`), two more things hold:
|
|
30
|
+
* - A `tools/call` that reaches `send` without a marker this ledger issued
|
|
31
|
+
* and has not used is REFUSED there (`replayUnavailable.ts`,
|
|
32
|
+
* `'request-unmatched'`): its answer could not be tied to any call, so it
|
|
33
|
+
* is never sent rather than guessed at.
|
|
34
|
+
* - Each matched request's answer is AWAITED, by its id: the connection's
|
|
35
|
+
* incoming messages are observed for the JSON-RPC response to it. A 202, or
|
|
36
|
+
* a stream, is not that answer. The watch ends when the answer arrives,
|
|
37
|
+
* when the SDK cancels the request, when the call settles (found by its
|
|
38
|
+
* marker, never by its params object) or when the connection closes —
|
|
39
|
+
* never when only the HTTP send finished, since a 202 or a stream can still
|
|
40
|
+
* carry the answer later.
|
|
41
|
+
*
|
|
42
|
+
* Whether the answers are observed at all is established once, at
|
|
43
|
+
* initialization: the `initialize` answer must pass the observer
|
|
44
|
+
* (`answersObserved`). An SDK whose `connect` replaces the transport's
|
|
45
|
+
* `onmessage` instead of keeping it leaves the observer out, and a call under
|
|
46
|
+
* `'app-authorized'` is then refused before it is sent (`replayUnavailable.ts`).
|
|
47
|
+
*
|
|
48
|
+
* Ids are the client's, one ledger per connection, so concurrent calls — and
|
|
49
|
+
* concurrent runs sharing one client — can never claim each other's request. A
|
|
50
|
+
* request that is not a `tools/call` (a `tools/list`, a notification, a
|
|
51
|
+
* response) claims nothing.
|
|
35
52
|
*
|
|
36
53
|
* `send` is installed as an OWN property of the transport instance — the same
|
|
37
54
|
* object, its own `send` bound to it, so a transport class with `#private`
|
|
38
55
|
* fields works as it always did. Assigning `send` again afterwards THROWS: a
|
|
39
56
|
* send that bypassed the ledger would quietly lose every call's attempts.
|
|
40
57
|
*
|
|
58
|
+
* Each matched `tools/call` also gets ONE `RequestReplay` (`replay.ts`), the
|
|
59
|
+
* facts its series, this ledger and its call share: the series' claim hands it
|
|
60
|
+
* over by the request's id, the call reads it from the entry it was issued
|
|
61
|
+
* (`IssuedCall`), which outlives the connection's close. The
|
|
62
|
+
* series writes what HTTP showed; this ledger writes whether the JSON-RPC
|
|
63
|
+
* answer arrived; the call writes how it settled.
|
|
64
|
+
*
|
|
41
65
|
* What it does NOT do: retry, wait, or decide anything. The series is the one
|
|
42
66
|
* retry owner; this only tells it whose attempts it is making, and when the SDK
|
|
43
67
|
* has stopped waiting for them.
|
|
44
68
|
*/
|
|
45
69
|
import type { RequestEvidenceSink } from '../tools/requestEvidence.js';
|
|
70
|
+
import { RequestReplay } from './replay.js';
|
|
46
71
|
/** One call's claim on the request it sends. */
|
|
47
72
|
export interface RequestTicket {
|
|
48
73
|
/** Where the request's attempts are filed. */
|
|
@@ -56,23 +81,71 @@ export interface ClaimedRequest {
|
|
|
56
81
|
readonly ticket?: RequestTicket;
|
|
57
82
|
/** Fires when the MCP SDK cancels this request (`notifications/cancelled`). */
|
|
58
83
|
readonly cancelled: AbortSignal;
|
|
84
|
+
/** What this request's series and its call share (`replay.ts` · `RequestReplay`). */
|
|
85
|
+
readonly replay: RequestReplay;
|
|
86
|
+
}
|
|
87
|
+
/** How a connection's ledger is set up. */
|
|
88
|
+
export interface RequestLedgerOptions {
|
|
89
|
+
/** The client's name, which a refusal names. */
|
|
90
|
+
readonly server: string;
|
|
91
|
+
/** The `'app-authorized'` policy is in force: see the module note. */
|
|
92
|
+
readonly strict: boolean;
|
|
59
93
|
}
|
|
60
|
-
|
|
94
|
+
type JsonRpcId = string | number;
|
|
95
|
+
/** The request a call's marker was matched to. */
|
|
96
|
+
export interface MatchedRequest {
|
|
97
|
+
readonly id: JsonRpcId;
|
|
98
|
+
readonly replay: RequestReplay;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* One call, from `issue` until it settles: the marker it sends, and the
|
|
102
|
+
* request matched to it once one was. The call holds this entry itself, so
|
|
103
|
+
* what it reads does not depend on the ledger still holding it.
|
|
104
|
+
*/
|
|
105
|
+
export interface IssuedCall {
|
|
106
|
+
readonly marker: string;
|
|
107
|
+
readonly ticket?: RequestTicket;
|
|
108
|
+
/** Set once, by the watched `send`: a marker matches ONE request. */
|
|
109
|
+
readonly request?: MatchedRequest;
|
|
110
|
+
}
|
|
111
|
+
/** Per connection: the calls issued and not yet settled, the requests being sent, the answers awaited. */
|
|
61
112
|
export declare class RequestLedger {
|
|
62
|
-
|
|
113
|
+
private readonly options;
|
|
114
|
+
/** Every call issued and not yet settled — keyed by its marker. */
|
|
63
115
|
private readonly issued;
|
|
64
|
-
/** Tickets a request was bound to. */
|
|
65
|
-
private readonly bound;
|
|
66
116
|
/** Every `tools/call` sent and not yet settled — keyed by its JSON-RPC id. */
|
|
67
117
|
private readonly sending;
|
|
118
|
+
/** Matched requests whose JSON-RPC answer is awaited (`strict` only) — by id. */
|
|
119
|
+
private readonly awaiting;
|
|
120
|
+
private initializeId;
|
|
121
|
+
private initializeAnswered;
|
|
122
|
+
private markers;
|
|
68
123
|
private calls;
|
|
69
124
|
private unboundNamed;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
125
|
+
constructor(options?: RequestLedgerOptions);
|
|
126
|
+
/**
|
|
127
|
+
* A call is about to send its request: its entry, whose `marker` the call
|
|
128
|
+
* puts in the request's `_meta` (`callMarker.ts` · `markParams`). `ticket`
|
|
129
|
+
* is where its attempts are filed, when the call carries the run's evidence
|
|
130
|
+
* port.
|
|
131
|
+
*/
|
|
132
|
+
issue(ticket?: RequestTicket): IssuedCall;
|
|
133
|
+
/** `call` settled: forget it, and stop awaiting its request's answer. */
|
|
134
|
+
settle(call: IssuedCall): void;
|
|
135
|
+
/** The connection closed: nothing it sent is awaited, and no call is pending, any more. */
|
|
136
|
+
close(): void;
|
|
137
|
+
/**
|
|
138
|
+
* Whether this connection's answers pass the observer: the `initialize`
|
|
139
|
+
* answer did. Read once the connection is initialized.
|
|
140
|
+
*/
|
|
141
|
+
get answersObserved(): boolean;
|
|
74
142
|
/** How many `tools/call` requests the watched transport has sent — matched to a call or not. */
|
|
75
143
|
get toolCallsSent(): number;
|
|
144
|
+
/**
|
|
145
|
+
* @internal How many entries the ledger holds: calls issued and not settled,
|
|
146
|
+
* requests being sent, answers awaited. Zero once every call settled.
|
|
147
|
+
*/
|
|
148
|
+
get retained(): number;
|
|
76
149
|
/** `true` the first time it is asked, then never again: an unmatched request is named once per connection. */
|
|
77
150
|
firstUnbound(): boolean;
|
|
78
151
|
/**
|
|
@@ -80,8 +153,17 @@ export declare class RequestLedger {
|
|
|
80
153
|
* original bound to the instance itself. Returns the SAME object — or
|
|
81
154
|
* `undefined` when it has no `send` to watch or refuses the property, and
|
|
82
155
|
* then nothing is watched and no call should expect its attempts filed.
|
|
156
|
+
*
|
|
157
|
+
* Its incoming messages are watched too: an `onmessage` set before the
|
|
158
|
+
* client connects, which the current MCP SDK's `Protocol.connect` keeps and
|
|
159
|
+
* calls before its own dispatch. Whether it was kept is known once the
|
|
160
|
+
* `initialize` answer has, or has not, passed it (`answersObserved`).
|
|
83
161
|
*/
|
|
84
162
|
watch<T extends object>(transport: T): T | undefined;
|
|
163
|
+
/** Observe incoming messages before whatever handled them already — never instead of it. */
|
|
164
|
+
private watchMessages;
|
|
165
|
+
/** One incoming message: the `initialize` answer, or the answer to an awaited request. */
|
|
166
|
+
private observe;
|
|
85
167
|
/**
|
|
86
168
|
* The `tools/call` request `body` carries, while its send runs — its ticket
|
|
87
169
|
* when a call issued one, and the signal its cancellation fires. `undefined`
|
|
@@ -90,9 +172,10 @@ export declare class RequestLedger {
|
|
|
90
172
|
claim(body: unknown): ClaimedRequest | undefined;
|
|
91
173
|
/** One message through the watched transport. */
|
|
92
174
|
private send;
|
|
93
|
-
/**
|
|
94
|
-
private
|
|
95
|
-
/** The SDK gave a request up: stop the series still sending it. */
|
|
175
|
+
/** The `initialize` request: its answer is the one that proves the observer is in place. */
|
|
176
|
+
private noteInitialize;
|
|
177
|
+
/** The SDK gave a request up: stop the series still sending it, and stop awaiting its answer. */
|
|
96
178
|
private cancelIfAsked;
|
|
97
179
|
}
|
|
180
|
+
export {};
|
|
98
181
|
//# sourceMappingURL=requestLedger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestLedger.d.ts","sourceRoot":"","sources":["../../../src/mcp/requestLedger.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"requestLedger.d.ts","sourceRoot":"","sources":["../../../src/mcp/requestLedger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,C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,CAAC,QAAQ,CAAuC;IAChE,OAAO,CAAC,YAAY,CAAwB;IAC5C,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,YAAY,CAAS;gBAEA,OAAO,GAAE,oBAA8B;IAEpE;;;;;OAKG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,UAAU;IAUzC,yEAAyE;IACzE,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAQ9B,2FAA2F;IAC3F,KAAK,IAAI,IAAI;IAMb;;;OAGG;IACH,IAAI,eAAe,IAAI,OAAO,CAE7B;IAED,gGAAgG;IAChG,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,8GAA8G;IAC9G,YAAY,IAAI,OAAO;IAMvB;;;;;;;;;;OAUG;IACH,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAyBpD,4FAA4F;IAC5F,OAAO,CAAC,aAAa;IAcrB,0FAA0F;IAC1F,OAAO,CAAC,OAAO;IAUf;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS;IAkBhD,iDAAiD;IACjD,OAAO,CAAC,IAAI;IA0CZ,4FAA4F;IAC5F,OAAO,CAAC,cAAc;IAQtB,iGAAiG;IACjG,OAAO,CAAC,aAAa;CAStB"}
|
|
@@ -28,17 +28,31 @@
|
|
|
28
28
|
* timed out, or failed — was sent, and the server may have received it and run
|
|
29
29
|
* it. Its row says so (`remote: 'unknown'`); nothing here records it as not run.
|
|
30
30
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
31
|
+
* THREE FACTS PER ATTEMPT, NONE READ FROM ANOTHER (`replay.ts`): the failure
|
|
32
|
+
* (footprintjs's category), what is known of its effect (`unknown` for every
|
|
33
|
+
* attempt sent that did not complete — a refusal included; `applied` when the
|
|
34
|
+
* call completed, never proof of a write; `none` only for what was never
|
|
35
|
+
* sent), and — on an attempt the series asked again after — what permitted it.
|
|
36
|
+
* Each row also says how long it took. The end says how many requests were
|
|
37
|
+
* sent and what is known of the whole series' effect; uncertainty survives
|
|
38
|
+
* (`SeriesKnowledge`).
|
|
39
|
+
*
|
|
40
|
+
* WHEN IT FILES. When the call settles — the series has ended by then, and the
|
|
41
|
+
* call's verdict is what says whether an answered attempt completed (a 200 can
|
|
42
|
+
* carry a tool error) — and, for a cancellation, at the moment the signal
|
|
43
|
+
* fires: a cancelled run stops waiting for its stage at once, so a record filed
|
|
44
|
+
* when the series later unwinds would land after the run was saved. The runner
|
|
45
|
+
* makes no record for an attempt it abandons at that moment or for a wait it
|
|
46
|
+
* was cut out of, so those are written here: the cut attempt's row and
|
|
47
|
+
* `during: 'request'`, or `during: 'wait'`. A series ended and waiting for its
|
|
48
|
+
* call files at once if the call is cancelled first, with what it knows.
|
|
49
|
+
* Anything the series reports after it has filed is not part of the request's
|
|
50
|
+
* story any more and is ignored.
|
|
38
51
|
*/
|
|
39
52
|
import type { AttemptRecord } from 'footprintjs';
|
|
40
|
-
import type { ToolRequestAttempt, ToolRequestReason } from '../events/payloads.js';
|
|
53
|
+
import type { ToolRequestAttempt, ToolRequestEffect, ToolRequestPermission, ToolRequestReason } from '../events/payloads.js';
|
|
41
54
|
import { type RequestEvidence, type RequestEvidenceSink } from '../tools/requestEvidence.js';
|
|
55
|
+
import { type RequestReplay } from './replay.js';
|
|
42
56
|
/** Where the request went, as a row may say it: the app's label for it, or its origin. */
|
|
43
57
|
export type RequestWhere = Pick<RequestEvidence, 'endpoint' | 'origin'>;
|
|
44
58
|
/** What the series saw of one attempt that its record does not hold. */
|
|
@@ -52,24 +66,49 @@ export interface AttemptSeen {
|
|
|
52
66
|
};
|
|
53
67
|
}
|
|
54
68
|
/** 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'>;
|
|
69
|
+
export type DeclineReason = Extract<ToolRequestReason, 'exhausted' | 'wait-limit' | 'no-time-left' | 'not-replayable' | 'not-retryable' | 'not-permitted' | 'changes-without-key'>;
|
|
70
|
+
/**
|
|
71
|
+
* What the series knows of one attempt beyond the runner's record (`replay.ts`):
|
|
72
|
+
* its effect — absent for an answered attempt, which the call's verdict decides
|
|
73
|
+
* when the record is filed — what permitted the next attempt, and how long it
|
|
74
|
+
* took.
|
|
75
|
+
*/
|
|
76
|
+
export interface AttemptFacts {
|
|
77
|
+
readonly effect?: ToolRequestEffect;
|
|
78
|
+
readonly permission?: ToolRequestPermission;
|
|
79
|
+
readonly durationMs: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Where the record waits for its call: the call's signal (it fires when the
|
|
83
|
+
* call settles or is cancelled), and the facts the call leaves there.
|
|
84
|
+
*/
|
|
85
|
+
export interface Settlement {
|
|
86
|
+
readonly signal: AbortSignal;
|
|
87
|
+
readonly replay: RequestReplay;
|
|
88
|
+
}
|
|
56
89
|
/** One request's evidence, collected as its series runs and filed once. */
|
|
57
90
|
export declare class SeriesEvidence {
|
|
58
91
|
private readonly sink;
|
|
59
92
|
private readonly where;
|
|
93
|
+
private readonly settlement?;
|
|
60
94
|
private readonly rows;
|
|
61
95
|
private omitted;
|
|
62
96
|
private last;
|
|
63
97
|
private filed;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
|
|
98
|
+
private waiting;
|
|
99
|
+
/** What is known of the series' effect, attempt by attempt — the answer's excepted. */
|
|
100
|
+
private readonly knowledge;
|
|
101
|
+
/** The answered attempt, while its effect waits for the call's verdict. */
|
|
102
|
+
private answer;
|
|
103
|
+
constructor(sink: RequestEvidenceSink, where: RequestWhere, settlement?: Settlement | undefined);
|
|
104
|
+
/** One attempt as the runner recorded it, with what the series knows of it. */
|
|
105
|
+
attempt(record: AttemptRecord, seen: AttemptSeen | undefined, declined?: DeclineReason, facts?: AttemptFacts): void;
|
|
67
106
|
/**
|
|
68
107
|
* The caller's cancellation cut attempt `n` in flight. It was sent — the
|
|
69
108
|
* server may have it, and may have run it — so it is a row, `cut`, with the
|
|
70
109
|
* remote outcome `unknown`; then the request's end says the same.
|
|
71
110
|
*/
|
|
72
|
-
cutInFlight(n: number): void;
|
|
111
|
+
cutInFlight(n: number, durationMs?: number): void;
|
|
73
112
|
/**
|
|
74
113
|
* The caller's cancellation landed with NO request in flight: between two —
|
|
75
114
|
* `during: 'wait'`, the next request never sent — or before the first, when
|
|
@@ -82,7 +121,7 @@ export declare class SeriesEvidence {
|
|
|
82
121
|
* refusal it will not ask again after. A refusal it MEANT to ask again after
|
|
83
122
|
* is delivered when the deadline lands inside the wait: the runner's wait
|
|
84
123
|
* ends early, the series stops, and the end says so (`no-time-left`, during
|
|
85
|
-
* the `wait`).
|
|
124
|
+
* the `wait`). Filed when the call has read it.
|
|
86
125
|
*/
|
|
87
126
|
delivered(): void;
|
|
88
127
|
/**
|
|
@@ -92,12 +131,31 @@ export declare class SeriesEvidence {
|
|
|
92
131
|
* as one: a deadline that had passed before the first request (`timed-out`,
|
|
93
132
|
* no `during`, nothing sent) or one a future runner reports from inside a wait
|
|
94
133
|
* (`during: 'wait'`); anything else is filed as a failure the record cannot
|
|
95
|
-
* account for, so a request is never left unfiled.
|
|
134
|
+
* account for, so a request is never left unfiled. Filed when the call settles.
|
|
96
135
|
*/
|
|
97
136
|
threw(outOfTime: boolean): void;
|
|
98
137
|
private add;
|
|
138
|
+
/**
|
|
139
|
+
* File `end` once the call has settled — its verdict is what says whether an
|
|
140
|
+
* answered attempt completed — or at once, when the call is already settled
|
|
141
|
+
* or cancelled, or there is no call to wait for.
|
|
142
|
+
*/
|
|
143
|
+
private fileWhenSettled;
|
|
99
144
|
private file;
|
|
145
|
+
/**
|
|
146
|
+
* The rows, the answered one given its effect: `applied` when the call
|
|
147
|
+
* completed — the server answered it, and not with an error — else `unknown`
|
|
148
|
+
* (a 5xx, a JSON-RPC error, a tool error, a call cancelled before it read the
|
|
149
|
+
* answer). The answer's effect joins the series' knowledge here.
|
|
150
|
+
*/
|
|
151
|
+
private settleAnswer;
|
|
100
152
|
}
|
|
101
153
|
/** One record as a row — see the module note for what a row may say. */
|
|
102
154
|
export declare function rowOf(record: AttemptRecord, seen: AttemptSeen | undefined, declined?: DeclineReason): ToolRequestAttempt;
|
|
155
|
+
/**
|
|
156
|
+
* `row` with what the series knows of its attempt beyond the record — its
|
|
157
|
+
* effect, what permitted the next attempt, how long it took. Without `facts`,
|
|
158
|
+
* the row as the record alone says it.
|
|
159
|
+
*/
|
|
160
|
+
export declare function withFacts(row: ToolRequestAttempt, facts: AttemptFacts | undefined): ToolRequestAttempt;
|
|
103
161
|
//# sourceMappingURL=seriesEvidence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seriesEvidence.d.ts","sourceRoot":"","sources":["../../../src/mcp/seriesEvidence.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"seriesEvidence.d.ts","sourceRoot":"","sources":["../../../src/mcp/seriesEvidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAGjB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAElE,0FAA0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;IACnD,2EAA2E;IAC3E,OAAO,CAAC,MAAM,CAAiC;gBAG5B,IAAI,EAAE,mBAAmB,EACzB,KAAK,EAAE,YAAY,EACnB,UAAU,CAAC,wBAAY;IAG1C,+EAA+E;IAC/E,OAAO,CACL,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,QAAQ,CAAC,EAAE,aAAa,EACxB,KAAK,CAAC,EAAE,YAAY,GACnB,IAAI;IASP;;;;OAIG;IACH,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAajD;;;;;OAKG;IACH,SAAS,IAAI,IAAI;IAajB;;;;;;OAMG;IACH,SAAS,IAAI,IAAI;IAajB;;;;;;;;OAQG;IACH,KAAK,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI;IAmB/B,OAAO,CAAC,GAAG;IAOX;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,IAAI;IAsBZ;;;;;OAKG;IACH,OAAO,CAAC,YAAY;CAQrB;AAcD,wEAAwE;AACxE,wBAAgB,KAAK,CACnB,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,QAAQ,CAAC,EAAE,aAAa,GACvB,kBAAkB,CAqBpB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,kBAAkB,EACvB,KAAK,EAAE,YAAY,GAAG,SAAS,GAC9B,kBAAkB,CASpB"}
|
|
@@ -10,27 +10,33 @@
|
|
|
10
10
|
* tool, or invents an answer. A designed, transient, self-clearing condition
|
|
11
11
|
* was being turned into a wrong answer.
|
|
12
12
|
*
|
|
13
|
-
* ──
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* turns that off per server. What is certain is the contrast with a 500 or a
|
|
21
|
-
* timeout, where the call may have half-run and a retry could charge a card
|
|
22
|
-
* twice.
|
|
13
|
+
* ── Who may ask again: the app, by declaration (`replay.ts`) ─────────────────
|
|
14
|
+
* HTTP 429 says only that the request was rate-limited (RFC 6585 §4). It does
|
|
15
|
+
* not prove the server ran nothing, and `Retry-After` says when to ask again,
|
|
16
|
+
* not that asking is safe. So permission to send a tool call again is the
|
|
17
|
+
* APP's, declared per (server, tool) when the client is built (`mcpClient({
|
|
18
|
+
* replay })`), and kept apart from what is known of an attempt's effect. Before
|
|
19
|
+
* every repeat the series asks `permit`; the record keeps its answer.
|
|
23
20
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
21
|
+
* - `'compatibility'` (the default, kept in 12.0) keeps today's behaviour by
|
|
22
|
+
* name: a 429 is repeated for every tool, ASSUMING the server refused it
|
|
23
|
+
* before running it — and every such repeat records that assumption.
|
|
24
|
+
* - `'app-authorized'` (opt-in, by name) repeats a 429 only for a tool the
|
|
25
|
+
* app declared repeatable on it.
|
|
26
|
+
* - A request that failed in transport without an answer (footprintjs's
|
|
27
|
+
* `network`: a lost connection, a timeout below the series) is repeated
|
|
28
|
+
* only when the app declared that for the tool. A 5xx is an answer, never
|
|
29
|
+
* repeated. A cut or a deadline ends the series.
|
|
30
|
+
* - Under both, a tool the app declares as making changes is never repeated
|
|
31
|
+
* automatically unless the server is declared to deduplicate by a key the
|
|
32
|
+
* call carries — footprintjs's side-effect guard, now wired here.
|
|
28
33
|
*
|
|
29
34
|
* The loop takes its question as a {@link RetryDecision}, so the one other
|
|
30
35
|
* refusal a service documents as one to retry — AgentCore Runtime's "session
|
|
31
36
|
* operation in progress" — reuses this loop rather than growing a second one.
|
|
32
|
-
* That decision is applied only by that vendor's own transport
|
|
33
|
-
*
|
|
37
|
+
* That decision is applied only by that vendor's own transport, and its rule
|
|
38
|
+
* carries the adapter's retry assumption (`RetryRule.assumes`) — a policy,
|
|
39
|
+
* never evidence: its attempts record effect `unknown`, as a 429's do.
|
|
34
40
|
*
|
|
35
41
|
* ── Why it lives at the fetch seam and not around `Tool.execute` ─────────────
|
|
36
42
|
* Because `Retry-After` is only reachable here. The MCP SDK reads the response,
|
|
@@ -58,12 +64,17 @@
|
|
|
58
64
|
* operation that succeeded: a 503 is delivered as the answer it was, never
|
|
59
65
|
* retried — and written down as `answered` with its status, never success.
|
|
60
66
|
* A response a rule's decision recognises is thrown as a refusal that names
|
|
61
|
-
* its kind, and the policy's `retryOn` accepts those refusals and
|
|
62
|
-
*
|
|
63
|
-
* attempt it happened in, as it
|
|
64
|
-
* series ends on a refusal (attempts spent, a ceiling
|
|
65
|
-
* the refusal's response is delivered
|
|
66
|
-
* the 429, never an error of ours.
|
|
67
|
+
* its kind, and the policy's `retryOn` accepts those refusals — and a network
|
|
68
|
+
* failure the app declared for the tool — when the replay rule permits them,
|
|
69
|
+
* and nothing else: a 5xx ends the series on the attempt it happened in, as it
|
|
70
|
+
* always did. When the series ends on a refusal (attempts spent, a ceiling
|
|
71
|
+
* reached, no time left, no permission), the refusal's response is delivered
|
|
72
|
+
* as the server sent it: the caller sees the 429, never an error of ours. The
|
|
73
|
+
* call decides what that means for it (`callLifetime.ts`): under
|
|
74
|
+
* 'app-authorized', a call that genuinely lacked an answer somewhere and does
|
|
75
|
+
* not complete fails as "may have run". This series reports the HTTP half of
|
|
76
|
+
* that — an attempt that got no response at all, and the status it delivered;
|
|
77
|
+
* a received refusal is an answer, its effect still unknown.
|
|
67
78
|
*
|
|
68
79
|
* ── A fetch that already retries is JOINED, never wrapped ────────────────────
|
|
69
80
|
* A transport whose own fetch runs a series (AgentCore Runtime's session-busy
|
|
@@ -90,6 +101,7 @@
|
|
|
90
101
|
*
|
|
91
102
|
* Pattern: Decorator over `fetch`. Role: Layer-3 tool transport.
|
|
92
103
|
*/
|
|
104
|
+
import { type ReplayDeclaration } from './replay.js';
|
|
93
105
|
import type { RequestLedger } from './requestLedger.js';
|
|
94
106
|
/**
|
|
95
107
|
* The fetch shape the MCP SDK's `fetch` hook uses — deliberately NARROWER
|
|
@@ -107,8 +119,12 @@ export type ThrottleFetch = (input: string | URL, init?: RequestInit) => Promise
|
|
|
107
119
|
export type RetryKind = 'throttle' | 'session-busy';
|
|
108
120
|
/** Reported to {@link ThrottleRetryOptions.onRetry} before each wait. */
|
|
109
121
|
export interface ThrottleRetryInfo {
|
|
110
|
-
/**
|
|
111
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Which refusal this retry answers — or `'network'`, a tool call the app
|
|
124
|
+
* declared repeatable after a request that failed without an answer
|
|
125
|
+
* (`McpClientOptions.replay`). It is reported to the series' first rule.
|
|
126
|
+
*/
|
|
127
|
+
readonly kind: RetryKind | 'network';
|
|
112
128
|
/** The attempt about to START. `2` is the first retry. */
|
|
113
129
|
readonly attempt: number;
|
|
114
130
|
/** Ceiling in force for this refusal, including the first attempt. */
|
|
@@ -240,16 +256,18 @@ export interface RetryVerdict {
|
|
|
240
256
|
* The one question the loop asks of each response.
|
|
241
257
|
*
|
|
242
258
|
* ── The license every decision must hold ─────────────────────────────────────
|
|
243
|
-
* A decision
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
259
|
+
* A decision RECOGNISES a refusal; whether the request is sent again is the
|
|
260
|
+
* replay rule's (`replay.ts`), never the decision's. It may recognise only a
|
|
261
|
+
* response that is a refusal — never one that could be the record of
|
|
262
|
+
* half-done work. The library holds exactly two: {@link throttled} below, a
|
|
263
|
+
* 429, and AgentCore Runtime's "session operation in progress" refusal, which
|
|
264
|
+
* lives with that vendor's adapter (`adapters/mcp/agentcoreRuntime/`) and whose
|
|
265
|
+
* rule carries the adapter's retry assumption (`RetryRule.assumes`). Either
|
|
266
|
+
* one's effect stays unknown: a 429 says the request was rate-limited, and the
|
|
267
|
+
* busy body is matched by its code and words, which a server behind the
|
|
268
|
+
* runtime can send after it ran the call. Each stays ONE small function, so a
|
|
269
|
+
* refusal has exactly one place it is recognised — and each attempt is written
|
|
270
|
+
* down as one footprintjs attempt record.
|
|
253
271
|
*/
|
|
254
272
|
export type RetryDecision = (response: Response,
|
|
255
273
|
/**
|
|
@@ -297,6 +315,13 @@ export interface RetryRule {
|
|
|
297
315
|
/** The caller's own name for the endpoint, reported as `endpoint`. */
|
|
298
316
|
readonly endpointLabel?: string;
|
|
299
317
|
readonly onRetry?: (info: ThrottleRetryInfo) => void;
|
|
318
|
+
/**
|
|
319
|
+
* Set only by an adapter that retries this refusal as its own policy
|
|
320
|
+
* (`sessionBusy.ts`): what it assumes in doing so. The assumption is recorded
|
|
321
|
+
* beside each repeat (`permission: { by: 'adapter', assumes }`) — never as
|
|
322
|
+
* evidence: the attempt's effect stays `unknown`.
|
|
323
|
+
*/
|
|
324
|
+
readonly assumes?: 'refused-before-execution';
|
|
300
325
|
}
|
|
301
326
|
/**
|
|
302
327
|
* @internal A rule from a caller's options — `undefined` when retry is off
|
|
@@ -307,7 +332,7 @@ export interface RetryRule {
|
|
|
307
332
|
* @throws TypeError, when the rule is BUILT, for a value the schedule cannot
|
|
308
333
|
* mean — named by option, never echoing a value that is not a number.
|
|
309
334
|
*/
|
|
310
|
-
export declare function retryRule(kind: RetryKind, decide: RetryDecision, config: RetryOnThrottle | undefined, defaults: RetryDefaults, where: string): RetryRule | undefined;
|
|
335
|
+
export declare function retryRule(kind: RetryKind, decide: RetryDecision, config: RetryOnThrottle | undefined, defaults: RetryDefaults, where: string, assumes?: 'refused-before-execution'): RetryRule | undefined;
|
|
311
336
|
/**
|
|
312
337
|
* Wrap a `fetch` so HTTP 429 responses are retried, honouring `Retry-After`.
|
|
313
338
|
*
|
|
@@ -346,19 +371,37 @@ export declare function retryRule(kind: RetryKind, decide: RetryDecision, config
|
|
|
346
371
|
*/
|
|
347
372
|
export declare function retryingFetch(inner: ThrottleFetch | undefined, config: RetryOnThrottle | undefined): ThrottleFetch | undefined;
|
|
348
373
|
/**
|
|
349
|
-
* @internal
|
|
350
|
-
*
|
|
351
|
-
*
|
|
374
|
+
* @internal The series for a transport whose 429 rule is off (`retryOnThrottle:
|
|
375
|
+
* false`) while the app's replay declaration still needs one (`replay.ts` ·
|
|
376
|
+
* `needsSeries`): a tool declared repeatable on `'network'`, or the
|
|
377
|
+
* `'app-authorized'` policy, whose record and "may have run" rest on the series.
|
|
378
|
+
* `retryOnThrottle: false` turns off the 429 rule and nothing else, so its one
|
|
379
|
+
* rule is that rule switched off: it recognises no response and holds the
|
|
380
|
+
* call's budget (`retryOnThrottle`'s defaults). A transport fetch that already
|
|
381
|
+
* runs a series is joined, as `retryingFetch` joins it.
|
|
382
|
+
*/
|
|
383
|
+
export declare function seriesWithoutThrottle(inner: ThrottleFetch | undefined): ThrottleFetch;
|
|
384
|
+
/**
|
|
385
|
+
* @internal What one call's series is built from: the rules it asks, in order;
|
|
386
|
+
* the connection's ledger — which tool call each request belongs to, so the
|
|
387
|
+
* series can file its attempts into that call's run (`requestLedger.ts`); and
|
|
388
|
+
* the app's replay declaration — who may send a tool call again (`replay.ts`).
|
|
389
|
+
* No declaration is the compatibility policy, naming no tool.
|
|
352
390
|
*/
|
|
353
391
|
export interface SeriesSpec {
|
|
354
392
|
readonly rules: readonly RetryRule[];
|
|
355
393
|
readonly ledger?: RequestLedger;
|
|
394
|
+
readonly replay?: ReplayDeclaration;
|
|
356
395
|
}
|
|
357
|
-
/**
|
|
396
|
+
/**
|
|
397
|
+
* @internal What a joinable fetch's series can be rebuilt with: one more rule,
|
|
398
|
+
* or a ledger and the replay declaration (they arrive together, from `mcpClient`).
|
|
399
|
+
*/
|
|
358
400
|
export type SeriesJoin = {
|
|
359
401
|
readonly rule: RetryRule;
|
|
360
402
|
} | {
|
|
361
403
|
readonly ledger: RequestLedger;
|
|
404
|
+
readonly replay?: ReplayDeclaration;
|
|
362
405
|
};
|
|
363
406
|
/** @internal `spec` with `join` in it. */
|
|
364
407
|
export declare function joinedSpec(spec: SeriesSpec, join: SeriesJoin): SeriesSpec;
|
|
@@ -372,10 +415,11 @@ export declare function joinedSpec(spec: SeriesSpec, join: SeriesJoin): SeriesSp
|
|
|
372
415
|
export declare function joinableRetry(fetch: ThrottleFetch, rebuild: (join: SeriesJoin) => ThrottleFetch): ThrottleFetch;
|
|
373
416
|
/**
|
|
374
417
|
* @internal `fetch` rebuilt so its series files each request's attempts through
|
|
375
|
-
* `ledger
|
|
376
|
-
* is nothing to file and the
|
|
418
|
+
* `ledger`, and asks `replay` before sending a tool call again — or `undefined`
|
|
419
|
+
* when `fetch` runs no series (retry off), so there is nothing to file and the
|
|
420
|
+
* caller keeps `fetch` as it is.
|
|
377
421
|
*/
|
|
378
|
-
export declare function ledgeredFetch(fetch: ThrottleFetch, ledger: RequestLedger): ThrottleFetch | undefined;
|
|
422
|
+
export declare function ledgeredFetch(fetch: ThrottleFetch, ledger: RequestLedger, replay?: ReplayDeclaration): ThrottleFetch | undefined;
|
|
379
423
|
/**
|
|
380
424
|
* @internal The one series per call over `inner`, asking `spec.rules` in order —
|
|
381
425
|
* `inner` itself when there are none. The first rule holds the call's budget;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttleRetry.d.ts","sourceRoot":"","sources":["../../../src/mcp/throttleRetry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"throttleRetry.d.ts","sourceRoot":"","sources":["../../../src/mcp/throttleRetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsGG;AAaH,OAAO,EAOL,KAAK,iBAAiB,EAEvB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,oBAAoB,CAAC;AAUvE;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG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AAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,iBAAiB,CAAA;CAAE,CAAC;AAE5E,0CAA0C;AAC1C,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAOzE;AASD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,aAAa,GAC3C,aAAa,CAGf;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,aAAa,EACrB,MAAM,CAAC,EAAE,iBAAiB,GACzB,aAAa,GAAG,SAAS,CAE3B;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,GAAG,aAAa,CAStF;AAgfD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAOpF"}
|
|
@@ -3,6 +3,12 @@ import type { McpCallToolResult, McpClientOptions } from './types.js';
|
|
|
3
3
|
type ResultMode = NonNullable<McpClientOptions['resultMode']>;
|
|
4
4
|
/** Validate before opening a transport; a misspelled opt-in must not disappear. */
|
|
5
5
|
export declare function resultModeOf(value: unknown, name: string): ResultMode;
|
|
6
|
+
/**
|
|
7
|
+
* Whether a `tools/call` answer is the tool's own error (`isError: true`, an
|
|
8
|
+
* own data property). Read once, never throwing: anything it cannot read is
|
|
9
|
+
* not a tool error — the decoder refuses it on its own.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isToolError(result: unknown): boolean;
|
|
6
12
|
/** Internal shared decoder for the real connection and curated mock. */
|
|
7
13
|
export declare function readToolResult(result: McpCallToolResult, toolName: string, serverName: string, mode?: ResultMode): unknown;
|
|
8
14
|
export {};
|