agentfootprint 11.3.0 → 11.5.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.
Files changed (227) hide show
  1. package/CAPABILITIES.md +4 -1
  2. package/dist/adapters/mcp/agentcoreRuntime/invoke.js +7 -6
  3. package/dist/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -1
  4. package/dist/adapters/mcp/agentcoreRuntime/sessionBusy.js +36 -2
  5. package/dist/adapters/mcp/agentcoreRuntime/sessionBusy.js.map +1 -1
  6. package/dist/adapters/mcp/agentcoreRuntime/transport.js +3 -1
  7. package/dist/adapters/mcp/agentcoreRuntime/transport.js.map +1 -1
  8. package/dist/answer-account/account.js +15 -3
  9. package/dist/answer-account/account.js.map +1 -1
  10. package/dist/answer-account/facts/howSure.js +10 -22
  11. package/dist/answer-account/facts/howSure.js.map +1 -1
  12. package/dist/core/Agent.js +26 -3
  13. package/dist/core/Agent.js.map +1 -1
  14. package/dist/core/agent/AgentBuilder.js +69 -12
  15. package/dist/core/agent/AgentBuilder.js.map +1 -1
  16. package/dist/core/agent/assessment/assess.js +15 -4
  17. package/dist/core/agent/assessment/assess.js.map +1 -1
  18. package/dist/core/agent/assessment/compose.js +153 -15
  19. package/dist/core/agent/assessment/compose.js.map +1 -1
  20. package/dist/core/agent/assessment/reasons.js +35 -1
  21. package/dist/core/agent/assessment/reasons.js.map +1 -1
  22. package/dist/core/agent/assessment/sources.js +205 -0
  23. package/dist/core/agent/assessment/sources.js.map +1 -0
  24. package/dist/core/agent/assessment/stage.js +15 -4
  25. package/dist/core/agent/assessment/stage.js.map +1 -1
  26. package/dist/core/agent/buildAgentChart.js.map +1 -1
  27. package/dist/core/agent/buildToolRegistry.js +3 -0
  28. package/dist/core/agent/buildToolRegistry.js.map +1 -1
  29. package/dist/core/agent/evidence/numberPrecision.js.map +1 -1
  30. package/dist/core/agent/honesty/mounts.js.map +1 -1
  31. package/dist/core/agent/stages/prepareFinal.js +33 -17
  32. package/dist/core/agent/stages/prepareFinal.js.map +1 -1
  33. package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.d.ts +7 -6
  34. package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js +7 -6
  35. package/dist/esm/adapters/mcp/agentcoreRuntime/invoke.js.map +1 -1
  36. package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts +32 -1
  37. package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.js +35 -1
  38. package/dist/esm/adapters/mcp/agentcoreRuntime/sessionBusy.js.map +1 -1
  39. package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js +4 -2
  40. package/dist/esm/adapters/mcp/agentcoreRuntime/transport.js.map +1 -1
  41. package/dist/esm/answer-account/account.js +16 -4
  42. package/dist/esm/answer-account/account.js.map +1 -1
  43. package/dist/esm/answer-account/facts/howSure.js +10 -22
  44. package/dist/esm/answer-account/facts/howSure.js.map +1 -1
  45. package/dist/esm/core/Agent.d.ts +2 -1
  46. package/dist/esm/core/Agent.js +26 -3
  47. package/dist/esm/core/Agent.js.map +1 -1
  48. package/dist/esm/core/agent/AgentBuilder.d.ts +22 -1
  49. package/dist/esm/core/agent/AgentBuilder.js +69 -12
  50. package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
  51. package/dist/esm/core/agent/assessment/assess.js +15 -4
  52. package/dist/esm/core/agent/assessment/assess.js.map +1 -1
  53. package/dist/esm/core/agent/assessment/compose.d.ts +82 -5
  54. package/dist/esm/core/agent/assessment/compose.js +148 -14
  55. package/dist/esm/core/agent/assessment/compose.js.map +1 -1
  56. package/dist/esm/core/agent/assessment/reasons.d.ts +17 -1
  57. package/dist/esm/core/agent/assessment/reasons.js +35 -1
  58. package/dist/esm/core/agent/assessment/reasons.js.map +1 -1
  59. package/dist/esm/core/agent/assessment/sources.d.ts +66 -0
  60. package/dist/esm/core/agent/assessment/sources.js +201 -0
  61. package/dist/esm/core/agent/assessment/sources.js.map +1 -0
  62. package/dist/esm/core/agent/assessment/stage.d.ts +17 -4
  63. package/dist/esm/core/agent/assessment/stage.js +16 -5
  64. package/dist/esm/core/agent/assessment/stage.js.map +1 -1
  65. package/dist/esm/core/agent/assessment/types.d.ts +37 -0
  66. package/dist/esm/core/agent/buildAgentChart.d.ts +8 -0
  67. package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
  68. package/dist/esm/core/agent/buildToolRegistry.js +4 -1
  69. package/dist/esm/core/agent/buildToolRegistry.js.map +1 -1
  70. package/dist/esm/core/agent/evidence/numberPrecision.d.ts +3 -2
  71. package/dist/esm/core/agent/evidence/numberPrecision.js.map +1 -1
  72. package/dist/esm/core/agent/honesty/mounts.d.ts +11 -2
  73. package/dist/esm/core/agent/honesty/mounts.js.map +1 -1
  74. package/dist/esm/core/agent/stages/prepareFinal.d.ts +19 -3
  75. package/dist/esm/core/agent/stages/prepareFinal.js +33 -17
  76. package/dist/esm/core/agent/stages/prepareFinal.js.map +1 -1
  77. package/dist/esm/core/agent/types.d.ts +16 -2
  78. package/dist/esm/events/payloads.d.ts +137 -27
  79. package/dist/esm/lib/displayName.d.ts +81 -0
  80. package/dist/esm/lib/displayName.js +119 -0
  81. package/dist/esm/lib/displayName.js.map +1 -0
  82. package/dist/esm/mcp/callLifetime.d.ts +57 -14
  83. package/dist/esm/mcp/callLifetime.js +67 -19
  84. package/dist/esm/mcp/callLifetime.js.map +1 -1
  85. package/dist/esm/mcp/callMarker.d.ts +43 -0
  86. package/dist/esm/mcp/callMarker.js +69 -0
  87. package/dist/esm/mcp/callMarker.js.map +1 -0
  88. package/dist/esm/mcp/connectionRefusals.js +7 -0
  89. package/dist/esm/mcp/connectionRefusals.js.map +1 -1
  90. package/dist/esm/mcp/index.d.ts +2 -0
  91. package/dist/esm/mcp/index.js +3 -0
  92. package/dist/esm/mcp/index.js.map +1 -1
  93. package/dist/esm/mcp/mcpClient.js +93 -26
  94. package/dist/esm/mcp/mcpClient.js.map +1 -1
  95. package/dist/esm/mcp/replay.d.ts +283 -0
  96. package/dist/esm/mcp/replay.js +401 -0
  97. package/dist/esm/mcp/replay.js.map +1 -0
  98. package/dist/esm/mcp/replayUnavailable.d.ts +55 -0
  99. package/dist/esm/mcp/replayUnavailable.js +74 -0
  100. package/dist/esm/mcp/replayUnavailable.js.map +1 -0
  101. package/dist/esm/mcp/requestLedger.d.ts +115 -32
  102. package/dist/esm/mcp/requestLedger.js +193 -52
  103. package/dist/esm/mcp/requestLedger.js.map +1 -1
  104. package/dist/esm/mcp/seriesEvidence.d.ts +73 -15
  105. package/dist/esm/mcp/seriesEvidence.js +114 -21
  106. package/dist/esm/mcp/seriesEvidence.js.map +1 -1
  107. package/dist/esm/mcp/throttleRetry.d.ts +86 -42
  108. package/dist/esm/mcp/throttleRetry.js +158 -50
  109. package/dist/esm/mcp/throttleRetry.js.map +1 -1
  110. package/dist/esm/mcp/toolResult.d.ts +6 -0
  111. package/dist/esm/mcp/toolResult.js +15 -0
  112. package/dist/esm/mcp/toolResult.js.map +1 -1
  113. package/dist/esm/mcp/types.d.ts +70 -8
  114. package/dist/esm/redaction/knownStrings.js +14 -0
  115. package/dist/esm/redaction/knownStrings.js.map +1 -1
  116. package/dist/esm/semantics/coverage/answer.d.ts +9 -1
  117. package/dist/esm/semantics/coverage/answer.js +50 -10
  118. package/dist/esm/semantics/coverage/answer.js.map +1 -1
  119. package/dist/esm/tool-providers/index.d.ts +2 -2
  120. package/dist/esm/tool-providers/index.js +4 -0
  121. package/dist/esm/tool-providers/index.js.map +1 -1
  122. package/dist/esm/tools/requestEvidence.js +60 -0
  123. package/dist/esm/tools/requestEvidence.js.map +1 -1
  124. package/dist/esm/tools/tools.d.ts +30 -0
  125. package/dist/esm/tools/tools.js +16 -0
  126. package/dist/esm/tools/tools.js.map +1 -1
  127. package/dist/lib/displayName.js +125 -0
  128. package/dist/lib/displayName.js.map +1 -0
  129. package/dist/mcp/callLifetime.js +66 -18
  130. package/dist/mcp/callLifetime.js.map +1 -1
  131. package/dist/mcp/callMarker.js +74 -0
  132. package/dist/mcp/callMarker.js.map +1 -0
  133. package/dist/mcp/connectionRefusals.js +7 -0
  134. package/dist/mcp/connectionRefusals.js.map +1 -1
  135. package/dist/mcp/index.js +5 -1
  136. package/dist/mcp/index.js.map +1 -1
  137. package/dist/mcp/mcpClient.js +91 -24
  138. package/dist/mcp/mcpClient.js.map +1 -1
  139. package/dist/mcp/replay.js +411 -0
  140. package/dist/mcp/replay.js.map +1 -0
  141. package/dist/mcp/replayUnavailable.js +79 -0
  142. package/dist/mcp/replayUnavailable.js.map +1 -0
  143. package/dist/mcp/requestLedger.js +193 -52
  144. package/dist/mcp/requestLedger.js.map +1 -1
  145. package/dist/mcp/seriesEvidence.js +116 -22
  146. package/dist/mcp/seriesEvidence.js.map +1 -1
  147. package/dist/mcp/throttleRetry.js +160 -51
  148. package/dist/mcp/throttleRetry.js.map +1 -1
  149. package/dist/mcp/toolResult.js +17 -1
  150. package/dist/mcp/toolResult.js.map +1 -1
  151. package/dist/redaction/knownStrings.js +14 -0
  152. package/dist/redaction/knownStrings.js.map +1 -1
  153. package/dist/semantics/coverage/answer.js +49 -9
  154. package/dist/semantics/coverage/answer.js.map +1 -1
  155. package/dist/tool-providers/index.js +5 -1
  156. package/dist/tool-providers/index.js.map +1 -1
  157. package/dist/tools/requestEvidence.js +60 -0
  158. package/dist/tools/requestEvidence.js.map +1 -1
  159. package/dist/tools/tools.js +18 -1
  160. package/dist/tools/tools.js.map +1 -1
  161. package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts +7 -6
  162. package/dist/types/adapters/mcp/agentcoreRuntime/invoke.d.ts.map +1 -1
  163. package/dist/types/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts +32 -1
  164. package/dist/types/adapters/mcp/agentcoreRuntime/sessionBusy.d.ts.map +1 -1
  165. package/dist/types/adapters/mcp/agentcoreRuntime/transport.d.ts.map +1 -1
  166. package/dist/types/answer-account/account.d.ts.map +1 -1
  167. package/dist/types/answer-account/facts/howSure.d.ts.map +1 -1
  168. package/dist/types/core/Agent.d.ts +2 -1
  169. package/dist/types/core/Agent.d.ts.map +1 -1
  170. package/dist/types/core/agent/AgentBuilder.d.ts +22 -1
  171. package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
  172. package/dist/types/core/agent/assessment/assess.d.ts.map +1 -1
  173. package/dist/types/core/agent/assessment/compose.d.ts +82 -5
  174. package/dist/types/core/agent/assessment/compose.d.ts.map +1 -1
  175. package/dist/types/core/agent/assessment/reasons.d.ts +17 -1
  176. package/dist/types/core/agent/assessment/reasons.d.ts.map +1 -1
  177. package/dist/types/core/agent/assessment/sources.d.ts +67 -0
  178. package/dist/types/core/agent/assessment/sources.d.ts.map +1 -0
  179. package/dist/types/core/agent/assessment/stage.d.ts +17 -4
  180. package/dist/types/core/agent/assessment/stage.d.ts.map +1 -1
  181. package/dist/types/core/agent/assessment/types.d.ts +37 -0
  182. package/dist/types/core/agent/assessment/types.d.ts.map +1 -1
  183. package/dist/types/core/agent/buildAgentChart.d.ts +8 -0
  184. package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
  185. package/dist/types/core/agent/buildToolRegistry.d.ts.map +1 -1
  186. package/dist/types/core/agent/evidence/numberPrecision.d.ts +3 -2
  187. package/dist/types/core/agent/evidence/numberPrecision.d.ts.map +1 -1
  188. package/dist/types/core/agent/honesty/mounts.d.ts +11 -2
  189. package/dist/types/core/agent/honesty/mounts.d.ts.map +1 -1
  190. package/dist/types/core/agent/stages/prepareFinal.d.ts +19 -3
  191. package/dist/types/core/agent/stages/prepareFinal.d.ts.map +1 -1
  192. package/dist/types/core/agent/types.d.ts +16 -2
  193. package/dist/types/core/agent/types.d.ts.map +1 -1
  194. package/dist/types/events/payloads.d.ts +137 -27
  195. package/dist/types/events/payloads.d.ts.map +1 -1
  196. package/dist/types/lib/displayName.d.ts +82 -0
  197. package/dist/types/lib/displayName.d.ts.map +1 -0
  198. package/dist/types/mcp/callLifetime.d.ts +57 -14
  199. package/dist/types/mcp/callLifetime.d.ts.map +1 -1
  200. package/dist/types/mcp/callMarker.d.ts +44 -0
  201. package/dist/types/mcp/callMarker.d.ts.map +1 -0
  202. package/dist/types/mcp/index.d.ts +2 -0
  203. package/dist/types/mcp/index.d.ts.map +1 -1
  204. package/dist/types/mcp/mcpClient.d.ts.map +1 -1
  205. package/dist/types/mcp/replay.d.ts +284 -0
  206. package/dist/types/mcp/replay.d.ts.map +1 -0
  207. package/dist/types/mcp/replayUnavailable.d.ts +56 -0
  208. package/dist/types/mcp/replayUnavailable.d.ts.map +1 -0
  209. package/dist/types/mcp/requestLedger.d.ts +115 -32
  210. package/dist/types/mcp/requestLedger.d.ts.map +1 -1
  211. package/dist/types/mcp/seriesEvidence.d.ts +73 -15
  212. package/dist/types/mcp/seriesEvidence.d.ts.map +1 -1
  213. package/dist/types/mcp/throttleRetry.d.ts +86 -42
  214. package/dist/types/mcp/throttleRetry.d.ts.map +1 -1
  215. package/dist/types/mcp/toolResult.d.ts +6 -0
  216. package/dist/types/mcp/toolResult.d.ts.map +1 -1
  217. package/dist/types/mcp/types.d.ts +70 -8
  218. package/dist/types/mcp/types.d.ts.map +1 -1
  219. package/dist/types/redaction/knownStrings.d.ts.map +1 -1
  220. package/dist/types/semantics/coverage/answer.d.ts +9 -1
  221. package/dist/types/semantics/coverage/answer.d.ts.map +1 -1
  222. package/dist/types/tool-providers/index.d.ts +2 -2
  223. package/dist/types/tool-providers/index.d.ts.map +1 -1
  224. package/dist/types/tools/requestEvidence.d.ts.map +1 -1
  225. package/dist/types/tools/tools.d.ts +30 -0
  226. package/dist/types/tools/tools.d.ts.map +1 -1
  227. package/package.json +1 -1
@@ -28,44 +28,76 @@
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
- * 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.
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 { MAX_REQUEST_ATTEMPT_ROWS, } from '../tools/requestEvidence.js';
53
+ import { SeriesKnowledge } from './replay.js';
40
54
  const FAILED = 'The request failed before an answer arrived. Its error is not kept.';
41
55
  const OUT_OF_TIME = 'The call ran out of time before an answer arrived.';
42
56
  /** One request's evidence, collected as its series runs and filed once. */
43
57
  export class SeriesEvidence {
44
58
  sink;
45
59
  where;
60
+ settlement;
46
61
  rows = [];
47
62
  omitted = 0;
48
63
  last;
49
64
  filed = false;
50
- constructor(sink, where) {
65
+ waiting = false;
66
+ /** What is known of the series' effect, attempt by attempt — the answer's excepted. */
67
+ knowledge = new SeriesKnowledge();
68
+ /** The answered attempt, while its effect waits for the call's verdict. */
69
+ answer;
70
+ constructor(sink, where, settlement) {
51
71
  this.sink = sink;
52
72
  this.where = where;
73
+ this.settlement = settlement;
53
74
  }
54
- /** One attempt as the runner recorded it. */
55
- attempt(record, seen, declined) {
75
+ /** One attempt as the runner recorded it, with what the series knows of it. */
76
+ attempt(record, seen, declined, facts) {
56
77
  if (this.filed)
57
78
  return;
58
- this.add(rowOf(record, seen, declined));
79
+ const row = withFacts(rowOf(record, seen, declined), facts);
80
+ if (facts !== undefined && row.effect === undefined && row.outcome === 'answered') {
81
+ this.answer = row;
82
+ }
83
+ this.add(row);
59
84
  }
60
85
  /**
61
86
  * The caller's cancellation cut attempt `n` in flight. It was sent — the
62
87
  * server may have it, and may have run it — so it is a row, `cut`, with the
63
88
  * remote outcome `unknown`; then the request's end says the same.
64
89
  */
65
- cutInFlight(n) {
90
+ cutInFlight(n, durationMs) {
66
91
  if (this.filed)
67
92
  return;
68
- this.add({ attempt: n, outcome: 'cut', reason: 'cancelled', remote: 'unknown' });
93
+ this.add({
94
+ attempt: n,
95
+ outcome: 'cut',
96
+ reason: 'cancelled',
97
+ remote: 'unknown',
98
+ effect: 'unknown',
99
+ ...(durationMs !== undefined && { durationMs }),
100
+ });
69
101
  this.file({ outcome: 'cut', reason: 'cancelled', during: 'request', remote: 'unknown' });
70
102
  }
71
103
  /**
@@ -91,15 +123,15 @@ export class SeriesEvidence {
91
123
  * refusal it will not ask again after. A refusal it MEANT to ask again after
92
124
  * is delivered when the deadline lands inside the wait: the runner's wait
93
125
  * ends early, the series stops, and the end says so (`no-time-left`, during
94
- * the `wait`).
126
+ * the `wait`). Filed when the call has read it.
95
127
  */
96
128
  delivered() {
97
129
  const last = this.last;
98
130
  if (last === undefined) {
99
- this.file(UNACCOUNTED);
131
+ this.fileWhenSettled(UNACCOUNTED);
100
132
  return;
101
133
  }
102
- this.file(last.reason === 'retryable'
134
+ this.fileWhenSettled(last.reason === 'retryable'
103
135
  ? { ...endOf(last), reason: 'no-time-left', during: 'wait' }
104
136
  : endOf(last));
105
137
  }
@@ -110,19 +142,19 @@ export class SeriesEvidence {
110
142
  * as one: a deadline that had passed before the first request (`timed-out`,
111
143
  * no `during`, nothing sent) or one a future runner reports from inside a wait
112
144
  * (`during: 'wait'`); anything else is filed as a failure the record cannot
113
- * account for, so a request is never left unfiled.
145
+ * account for, so a request is never left unfiled. Filed when the call settles.
114
146
  */
115
147
  threw(outOfTime) {
116
148
  const last = this.last;
117
149
  if (last !== undefined && last.reason !== 'retryable') {
118
- this.file(endOf(last));
150
+ this.fileWhenSettled(endOf(last));
119
151
  return;
120
152
  }
121
153
  if (!outOfTime) {
122
- this.file(UNACCOUNTED);
154
+ this.fileWhenSettled(UNACCOUNTED);
123
155
  return;
124
156
  }
125
- this.file({
157
+ this.fileWhenSettled({
126
158
  outcome: 'timed-out',
127
159
  reason: 'no-time-left',
128
160
  failure: 'timeout',
@@ -132,22 +164,67 @@ export class SeriesEvidence {
132
164
  }
133
165
  add(row) {
134
166
  this.last = row;
167
+ if (row.effect !== undefined)
168
+ this.knowledge.note(row.effect);
135
169
  if (this.rows.length < MAX_REQUEST_ATTEMPT_ROWS)
136
170
  this.rows.push(row);
137
171
  else
138
172
  this.omitted += 1;
139
173
  }
174
+ /**
175
+ * File `end` once the call has settled — its verdict is what says whether an
176
+ * answered attempt completed — or at once, when the call is already settled
177
+ * or cancelled, or there is no call to wait for.
178
+ */
179
+ fileWhenSettled(end) {
180
+ const signal = this.settlement?.signal;
181
+ if (signal === undefined || signal.aborted) {
182
+ this.file(end);
183
+ return;
184
+ }
185
+ if (this.waiting)
186
+ return;
187
+ this.waiting = true;
188
+ signal.addEventListener('abort', () => this.file(end), { once: true });
189
+ }
140
190
  file(end) {
141
191
  if (this.filed)
142
192
  return;
143
193
  this.filed = true;
194
+ const replay = this.settlement?.replay;
195
+ const rows = this.settleAnswer(replay);
144
196
  try {
145
- this.sink.file({ ...this.where, attempts: [...this.rows], omitted: this.omitted, end });
197
+ this.sink.file({
198
+ ...this.where,
199
+ attempts: rows,
200
+ omitted: this.omitted,
201
+ end: {
202
+ ...end,
203
+ attempts: this.rows.length + this.omitted,
204
+ effect: this.knowledge.effect,
205
+ ...(replay?.mayHaveRun === true && { mayHaveRun: true }),
206
+ },
207
+ });
146
208
  }
147
209
  catch {
148
210
  // The library's sink never throws; one that does must not fail the call.
149
211
  }
150
212
  }
213
+ /**
214
+ * The rows, the answered one given its effect: `applied` when the call
215
+ * completed — the server answered it, and not with an error — else `unknown`
216
+ * (a 5xx, a JSON-RPC error, a tool error, a call cancelled before it read the
217
+ * answer). The answer's effect joins the series' knowledge here.
218
+ */
219
+ settleAnswer(replay) {
220
+ const answer = this.answer;
221
+ if (answer === undefined)
222
+ return [...this.rows];
223
+ const effect = replay?.verdict === 'completed' ? 'applied' : 'unknown';
224
+ this.knowledge.note(effect);
225
+ const settled = { ...answer, effect };
226
+ return this.rows.map((row) => (row === answer ? settled : row));
227
+ }
151
228
  }
152
229
  /**
153
230
  * An end no attempt accounts for — never seen; kept so a request is never left
@@ -183,6 +260,22 @@ export function rowOf(record, seen, declined) {
183
260
  ...(noAnswer(outcome) && { remote: 'unknown' }),
184
261
  };
185
262
  }
263
+ /**
264
+ * `row` with what the series knows of its attempt beyond the record — its
265
+ * effect, what permitted the next attempt, how long it took. Without `facts`,
266
+ * the row as the record alone says it.
267
+ */
268
+ export function withFacts(row, facts) {
269
+ if (facts === undefined)
270
+ return row;
271
+ return {
272
+ ...row,
273
+ ...(facts.effect !== undefined && { effect: facts.effect }),
274
+ ...(row.reason === 'retryable' &&
275
+ facts.permission !== undefined && { permission: facts.permission }),
276
+ durationMs: facts.durationMs,
277
+ };
278
+ }
186
279
  /** An attempt that ended without an answer — the server may have run it, or not. */
187
280
  function noAnswer(outcome) {
188
281
  return outcome === 'failed' || outcome === 'timed-out' || outcome === 'cut';
@@ -1 +1 @@
1
- {"version":3,"file":"seriesEvidence.js","sourceRoot":"","sources":["../../../src/mcp/seriesEvidence.ts"],"names":[],"mappings":"AA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,CAAC;AACJ,CAAC"}
@@ -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
- * ── What retrying a 429 assumes, and why the policy is 429-ONLY ─────────────
14
- * **Automatic 429 retries assume the server rejected the request before
15
- * executing it.** A rate limiter that refuses at the edge has not run the tool —
16
- * but HTTP 429 says only that the request was rate-limited (RFC 6585 §4), so the
17
- * saved response records the assumption's basis (the server's 429), not proof
18
- * that nothing ran. There is no side-effect guard here: a tool with side
19
- * effects is retried on 429 like any other today, and `retryOnThrottle: false`
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
- * That assumption is the whole license for this module, so the policy must
25
- * never widen. Only HTTP 429 retries here. Not 5xx, not network errors, not timeouts
26
- * — those belong to a caller who knows whether the specific tool is idempotent,
27
- * and this seam does not. A property test pins the boundary.
21
+ * - `'compatibility'` (the 11.x default) keeps today's behaviour by name: a
22
+ * 429 is repeated for every tool, ASSUMING the server refused it before
23
+ * running it — and every such repeat records that assumption.
24
+ * - `'app-authorized'` (opt-in, the next major's default) repeats a 429 only
25
+ * for a tool the 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; what
33
- * `mcpClient` and `retryingFetch` retry is still a 429 and nothing else.
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 nothing
62
- * else — so a 5xx, a dropped connection or a timeout ends the series on the
63
- * attempt it happened in, as it always did. When the
64
- * series ends on a refusal (attempts spent, a ceiling reached, no time left),
65
- * the refusal's response is delivered as the server sent it: the caller sees
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
- /** Which refusal this retry answers. */
111
- readonly kind: RetryKind;
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 may answer "again" ONLY for a response the library treats as a
244
- * refusal made before anything ran — the assumption a 429 retry rests on (see
245
- * the module note: the 429 is its basis, not proof). A response that could be
246
- * the record of half-done work is never one.
247
- * The library holds exactly two such decisions: {@link throttled} below, and
248
- * AgentCore Runtime's documented "session operation in progress" refusal,
249
- * which lives with that vendor's adapter (`adapters/mcp/agentcoreRuntime/`).
250
- * Each stays ONE small function, so a retry has exactly one place it is
251
- * decided — and each attempt is written down as one footprintjs attempt
252
- * record.
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 What one call's series is built from: the rules it asks, in order,
350
- * and the connection's ledger — which tool call each request belongs to, so the
351
- * series can file its attempts into that call's run (`requestLedger.ts`).
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
- /** @internal What a joinable fetch's series can be rebuilt with: one more rule, or a ledger. */
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` — or `undefined` when `fetch` runs no series (retry off), so there
376
- * is nothing to file and the caller keeps `fetch` as it is.
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;