@balchemyai/agent-sdk 0.3.10 → 0.4.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 (142) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/LICENSE +21 -0
  3. package/README.md +160 -6
  4. package/dist/agent-loop/agent-loop.d.ts +19 -8
  5. package/dist/agent-loop/agent-loop.d.ts.map +1 -1
  6. package/dist/agent-loop/agent-loop.js +620 -120
  7. package/dist/agent-loop/agent-loop.js.map +1 -1
  8. package/dist/agent-loop/decision-handler.d.ts.map +1 -1
  9. package/dist/agent-loop/decision-handler.js +64 -3
  10. package/dist/agent-loop/decision-handler.js.map +1 -1
  11. package/dist/agent-loop/llm-adapters/anthropic.d.ts +4 -3
  12. package/dist/agent-loop/llm-adapters/anthropic.d.ts.map +1 -1
  13. package/dist/agent-loop/llm-adapters/anthropic.js +79 -40
  14. package/dist/agent-loop/llm-adapters/anthropic.js.map +1 -1
  15. package/dist/agent-loop/llm-adapters/openai.d.ts +4 -3
  16. package/dist/agent-loop/llm-adapters/openai.d.ts.map +1 -1
  17. package/dist/agent-loop/llm-adapters/openai.js +91 -36
  18. package/dist/agent-loop/llm-adapters/openai.js.map +1 -1
  19. package/dist/agent-loop/llm-adapters/transport.d.ts +5 -0
  20. package/dist/agent-loop/llm-adapters/transport.d.ts.map +1 -0
  21. package/dist/agent-loop/llm-adapters/transport.js +63 -0
  22. package/dist/agent-loop/llm-adapters/transport.js.map +1 -0
  23. package/dist/agent-loop/llm-cost-tracker.d.ts +4 -0
  24. package/dist/agent-loop/llm-cost-tracker.d.ts.map +1 -1
  25. package/dist/agent-loop/llm-cost-tracker.js +37 -5
  26. package/dist/agent-loop/llm-cost-tracker.js.map +1 -1
  27. package/dist/agent-loop/rule-checker.d.ts +1 -20
  28. package/dist/agent-loop/rule-checker.d.ts.map +1 -1
  29. package/dist/agent-loop/rule-checker.js +0 -2
  30. package/dist/agent-loop/rule-checker.js.map +1 -1
  31. package/dist/agent-loop/telemetry-reporter.d.ts +8 -14
  32. package/dist/agent-loop/telemetry-reporter.d.ts.map +1 -1
  33. package/dist/agent-loop/telemetry-reporter.js +74 -8
  34. package/dist/agent-loop/telemetry-reporter.js.map +1 -1
  35. package/dist/agent-loop/types.d.ts +25 -9
  36. package/dist/agent-loop/types.d.ts.map +1 -1
  37. package/dist/agent-loop/types.js +0 -7
  38. package/dist/agent-loop/types.js.map +1 -1
  39. package/dist/agent-loop/webhook-receiver.d.ts +21 -2
  40. package/dist/agent-loop/webhook-receiver.d.ts.map +1 -1
  41. package/dist/agent-loop/webhook-receiver.js +196 -33
  42. package/dist/agent-loop/webhook-receiver.js.map +1 -1
  43. package/dist/auth/onboarding.d.ts.map +1 -1
  44. package/dist/auth/onboarding.js +15 -0
  45. package/dist/auth/onboarding.js.map +1 -1
  46. package/dist/client/http-client.d.ts +4 -2
  47. package/dist/client/http-client.d.ts.map +1 -1
  48. package/dist/client/http-client.js +88 -16
  49. package/dist/client/http-client.js.map +1 -1
  50. package/dist/errors/agent-sdk-error.d.ts +6 -0
  51. package/dist/errors/agent-sdk-error.d.ts.map +1 -1
  52. package/dist/errors/agent-sdk-error.js +16 -0
  53. package/dist/errors/agent-sdk-error.js.map +1 -1
  54. package/dist/errors/failure-metadata.d.ts +19 -0
  55. package/dist/errors/failure-metadata.d.ts.map +1 -0
  56. package/dist/errors/failure-metadata.js +177 -0
  57. package/dist/errors/failure-metadata.js.map +1 -0
  58. package/dist/index.d.ts +35 -10
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +130 -15
  61. package/dist/index.js.map +1 -1
  62. package/dist/local-runner/assessment-client.d.ts +111 -0
  63. package/dist/local-runner/assessment-client.d.ts.map +1 -0
  64. package/dist/local-runner/assessment-client.js +417 -0
  65. package/dist/local-runner/assessment-client.js.map +1 -0
  66. package/dist/local-runner/control-client.d.ts +126 -0
  67. package/dist/local-runner/control-client.d.ts.map +1 -0
  68. package/dist/local-runner/control-client.js +370 -0
  69. package/dist/local-runner/control-client.js.map +1 -0
  70. package/dist/local-runner/execution-build-client.d.ts +184 -0
  71. package/dist/local-runner/execution-build-client.d.ts.map +1 -0
  72. package/dist/local-runner/execution-build-client.js +389 -0
  73. package/dist/local-runner/execution-build-client.js.map +1 -0
  74. package/dist/local-runner/execution-submit-client.d.ts +126 -0
  75. package/dist/local-runner/execution-submit-client.d.ts.map +1 -0
  76. package/dist/local-runner/execution-submit-client.js +287 -0
  77. package/dist/local-runner/execution-submit-client.js.map +1 -0
  78. package/dist/local-runner/llm-client.d.ts +20 -0
  79. package/dist/local-runner/llm-client.d.ts.map +1 -0
  80. package/dist/local-runner/llm-client.js +23 -0
  81. package/dist/local-runner/llm-client.js.map +1 -0
  82. package/dist/local-runner/owner-positions.d.ts +32 -0
  83. package/dist/local-runner/owner-positions.d.ts.map +1 -0
  84. package/dist/local-runner/owner-positions.js +89 -0
  85. package/dist/local-runner/owner-positions.js.map +1 -0
  86. package/dist/local-runner/pairing-client.d.ts +95 -0
  87. package/dist/local-runner/pairing-client.d.ts.map +1 -0
  88. package/dist/local-runner/pairing-client.js +186 -0
  89. package/dist/local-runner/pairing-client.js.map +1 -0
  90. package/dist/local-runner/research-client.d.ts +98 -0
  91. package/dist/local-runner/research-client.d.ts.map +1 -0
  92. package/dist/local-runner/research-client.js +344 -0
  93. package/dist/local-runner/research-client.js.map +1 -0
  94. package/dist/local-runner/runner-proof-transport.d.ts +55 -0
  95. package/dist/local-runner/runner-proof-transport.d.ts.map +1 -0
  96. package/dist/local-runner/runner-proof-transport.js +258 -0
  97. package/dist/local-runner/runner-proof-transport.js.map +1 -0
  98. package/dist/local-runner/runtime-client.d.ts +122 -0
  99. package/dist/local-runner/runtime-client.d.ts.map +1 -0
  100. package/dist/local-runner/runtime-client.js +265 -0
  101. package/dist/local-runner/runtime-client.js.map +1 -0
  102. package/dist/local-runner/sell-assessment-client.d.ts +113 -0
  103. package/dist/local-runner/sell-assessment-client.d.ts.map +1 -0
  104. package/dist/local-runner/sell-assessment-client.js +225 -0
  105. package/dist/local-runner/sell-assessment-client.js.map +1 -0
  106. package/dist/local-runner/signals-client.d.ts +91 -0
  107. package/dist/local-runner/signals-client.d.ts.map +1 -0
  108. package/dist/local-runner/signals-client.js +357 -0
  109. package/dist/local-runner/signals-client.js.map +1 -0
  110. package/dist/local-runner/solana-platform-account.d.ts +5 -0
  111. package/dist/local-runner/solana-platform-account.d.ts.map +1 -0
  112. package/dist/local-runner/solana-platform-account.js +66 -0
  113. package/dist/local-runner/solana-platform-account.js.map +1 -0
  114. package/dist/local-runner/trading-wallet-client.d.ts +67 -0
  115. package/dist/local-runner/trading-wallet-client.d.ts.map +1 -0
  116. package/dist/local-runner/trading-wallet-client.js +144 -0
  117. package/dist/local-runner/trading-wallet-client.js.map +1 -0
  118. package/dist/mcp/mcp-client.d.ts +31 -4
  119. package/dist/mcp/mcp-client.d.ts.map +1 -1
  120. package/dist/mcp/mcp-client.js +491 -83
  121. package/dist/mcp/mcp-client.js.map +1 -1
  122. package/dist/streaming/sse-event-stream.d.ts +14 -0
  123. package/dist/streaming/sse-event-stream.d.ts.map +1 -1
  124. package/dist/streaming/sse-event-stream.js +153 -13
  125. package/dist/streaming/sse-event-stream.js.map +1 -1
  126. package/dist/types.d.ts +11 -2
  127. package/dist/types.d.ts.map +1 -1
  128. package/dist/utils/package-version.d.ts +2 -0
  129. package/dist/utils/package-version.d.ts.map +1 -0
  130. package/dist/utils/package-version.js +54 -0
  131. package/dist/utils/package-version.js.map +1 -0
  132. package/dist/utils/redaction.d.ts +4 -0
  133. package/dist/utils/redaction.d.ts.map +1 -1
  134. package/dist/utils/redaction.js +54 -0
  135. package/dist/utils/redaction.js.map +1 -1
  136. package/dist/utils/retry.d.ts +22 -13
  137. package/dist/utils/retry.d.ts.map +1 -1
  138. package/dist/utils/retry.js +76 -50
  139. package/dist/utils/retry.js.map +1 -1
  140. package/docs/DEPLOYMENT.md +1 -1
  141. package/docs/error-retry-strategy.md +16 -6
  142. package/package.json +9 -9
package/CHANGELOG.md CHANGED
@@ -7,6 +7,55 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
7
7
 
8
8
  ---
9
9
 
10
+ ## [0.4.0] — 2026-11-09
11
+
12
+ ### Added
13
+
14
+ - Local-runner protocol clients for a user-owned background runner: control,
15
+ signals, research, trading-wallet binding, execution build and execution
16
+ submit clients, exported alongside the existing MCP and onboarding clients.
17
+ - Runner-signed swap relay, submission journal and reconciliation client
18
+ support, and build-time decision provenance re-checks.
19
+ - Live-arming (`live_unarmed` / `live_armed`) and spend-limit support in the
20
+ runner protocol, plus the exits protocol (sell assessment, exit guard, owner
21
+ positions) for the runner.
22
+ - Dependency on the shared deterministic rules package
23
+ `@balchemyai/agent-rules` through the paired CLI.
24
+
25
+ ### Changed
26
+
27
+ - The telemetry reporter now reports the SDK version read from this package's
28
+ own `package.json` instead of a hard-coded constant.
29
+ - Added a `LICENSE` file (MIT) to the published package.
30
+
31
+ ### Notes
32
+
33
+ - The local-runner clients target the runner pairing and shadow-decision
34
+ protocol. Live trading is not available in this release; execution stays
35
+ non-executing until every deterministic contract gate is delivered and
36
+ verified.
37
+ - Publish order: `@balchemyai/agent-rules@1.1.0`, then
38
+ `@balchemyai/agent-sdk@0.4.0`, then `balchemy@0.4.0`.
39
+
40
+ ## [0.3.11] — 2026-07-01
41
+
42
+ ### Fixed
43
+
44
+ - Recover the `0.3.10` npm release by restoring the complete SDK root export
45
+ surface for `BalchemyClient`, `agentReadinessReport`, `agentContextSnapshot`,
46
+ `agentMarketBrief`, `agentCandidateReport`, and `agentRiskReport`.
47
+ - Keep the paired `balchemy` CLI dependency aligned with
48
+ `@balchemyai/agent-sdk@0.3.11`.
49
+
50
+ ### Notes
51
+
52
+ - `0.3.10` was published with an incomplete SDK root export surface; consumers
53
+ should use `0.3.11` instead.
54
+ - No live-trade proof, Base live coverage, or source-owner payout rails are
55
+ claimed by this package release.
56
+ - Publish `@balchemyai/agent-sdk@0.3.11` before `balchemy@0.3.11` so the CLI
57
+ dependency resolves from npm semver.
58
+
10
59
  ## [0.3.10] — 2026-06-30
11
60
 
12
61
  ### Changed
@@ -23,6 +72,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
23
72
 
24
73
  - This is a release-prep source entry only. npm publish, public mirror sync, and
25
74
  live package install proof remain separate release steps.
75
+ - The published `0.3.10` package pair has an incomplete SDK root export surface;
76
+ use `0.3.11` instead.
26
77
  - No live-trade proof, Base live coverage, or source-owner payout rails are
27
78
  claimed by this package release.
28
79
  - Publish `@balchemyai/agent-sdk@0.3.10` before `balchemy@0.3.10` so the CLI
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Balchemy Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -10,10 +10,16 @@ keeps the record.
10
10
 
11
11
  ## Release Line
12
12
 
13
- This source tree is prepared for `@balchemyai/agent-sdk@0.3.10`. npm publish,
14
- public mirror sync, and live package installation proof happen in separate
15
- release steps; this README does not claim that `0.3.10` has already been
16
- published.
13
+ Version `0.4.0` adds the local-runner protocol clients (see the changelog).
14
+ It is released together with `balchemy@0.4.0` and
15
+ `@balchemyai/agent-rules@1.1.0`; publish them in that order.
16
+
17
+ The approved ownership target keeps trading keys, model calls and private agent
18
+ context in the user's background runner. The existing onboarding and hosted
19
+ execution interfaces below describe legacy compatibility; local pairing and
20
+ signing are still being implemented and are not ready for live trading.
21
+
22
+ `0.3.11` fixed the incomplete SDK root export surface shipped in `0.3.10`.
17
23
 
18
24
  ## Install
19
25
 
@@ -21,6 +27,127 @@ published.
21
27
  npm install @balchemyai/agent-sdk
22
28
  ```
23
29
 
30
+ ## Unreleased local runner identity client
31
+
32
+ `RunnerPairingClient` is the candidate public client for fixed-purpose pairing
33
+ reads. It uses the configured Hub origin's `/api` proxy, rejects redirects, and
34
+ accepts no owner session token. It does not create wallets, issue execution
35
+ credentials, or enable trading.
36
+
37
+ Pin `frontendOrigin`, `apiBaseUrl` (`frontendOrigin + "/api"`), the runner's
38
+ Ed25519 public key and its locally generated intent. Request a nonce for exactly
39
+ one challenge or receipt read, validate its fixed-purpose bytes with
40
+ `runnerPairingReadMessage`, and sign those bytes with the dedicated local runner
41
+ identity. Do not use a trading-wallet key or expose a general supplied-text
42
+ signer. The CLI implements this private-key boundary; the SDK holds no keys.
43
+
44
+ Receipt reads require the binding digest durably saved at deliberate local
45
+ approval. `validateRunnerPairingBinding` validates a public binding only; it is
46
+ not proof that a request is still pending or that pairing committed.
47
+ `validateRunnerPairingResponse` separately checks the pending request or matching
48
+ committed receipt. A receipt can be recovered after the original request expires,
49
+ but its committed time must fall within that original validity window. Failed
50
+ reads are not automatically replayed; explicit recovery obtains a fresh nonce.
51
+
52
+ This candidate protocol must be released with its matching backend and CLI.
53
+ Source tests do not establish deployed availability or full local-agent readiness.
54
+
55
+ ## Unreleased local runner research client
56
+
57
+ `RunnerResearchClient` connects a durably paired runner to three public reports:
58
+ `market_brief`, `candidate_report` and `risk_report`, for Solana or Base. Requests
59
+ contain closed public fields such as the chain and exact asset address; they do
60
+ not accept chat, prompts, rules, credentials, arbitrary tools or URLs.
61
+
62
+ Pin the adopted origin, agent, binding digest, runner public key and current
63
+ instance. Call `query(request, epoch, signal)` only while the matching runner
64
+ lease remains current. Its signer must validate `runnerResearchNonceMessage`
65
+ against that exact target and request before signing with the dedicated local
66
+ identity. The CLI implements this check; a trading-wallet key is not used.
67
+
68
+ One deadline covers nonce, signing, request and body reading. Redirects and
69
+ automatic retries are disabled. A returned `result.ok` describes tool completion:
70
+ the report may still contain missing, stale or held evidence. Inspect its report
71
+ data and observation times; neither the report nor the lease authorizes a trade.
72
+ This candidate requires matching unreleased backend/CLI code. Published package
73
+ and deployed availability remain separate from the isolated interoperability tests.
74
+
75
+ ## Unreleased local Solana assessment client
76
+
77
+ `RunnerAssessmentClient` requests a read-only assessment for an exact SOL-input
78
+ plan: token, integer lamports, slippage and plan digest. The backend supplies the
79
+ existing global swap fee; the request cannot choose the fee or recipient. The
80
+ response binds fee arithmetic, quote amounts and token-safety observations to
81
+ that same request. It never contains a transaction or authorizes execution.
82
+
83
+ Pin the adopted origin, agent, binding, runner key and active lease instance.
84
+ Before signing, validate `runnerAssessmentNonceMessage` against that target,
85
+ epoch and exact request. Use the dedicated runner identity, never a trading key.
86
+ `query(request, epoch, signal)` has one bounded deadline and no automatic retry.
87
+ Private rules, prompts, model credentials and signing keys are not request fields.
88
+
89
+ `status: "complete"` means the required read sources returned usable observations;
90
+ the safety verdict can still be `block` or `require_approval`. Partial provider
91
+ failure remains `unavailable`, and every result has `executionAvailable: false`.
92
+ The client checks exact fee conservation, quote bounds, request/digest binding
93
+ and expiry. Fetch observation times do not establish an upstream publication time.
94
+ This candidate needs the matching unreleased backend and engine. Connection to
95
+ the private plan consumer, installed-package and deployed acceptance remain open.
96
+
97
+ ## Unreleased local signal receipt client
98
+
99
+ `RunnerSignalsClient` uses the same paired identity and current lease boundary.
100
+ Validate `runnerSignalsNonceMessage` against the exact target and request before
101
+ signing with the dedicated runner identity. `query({ kind: "poll" }, epoch)`
102
+ returns at most 16 unacknowledged public Solana observations from verified
103
+ Telegram/Discord sources. Historical observations remain deliverable; the
104
+ consumer must check freshness before evaluating them.
105
+
106
+ Persist each complete event locally before explicitly calling
107
+ `query({ kind: "ack", eventId, eventDigest }, epoch)`. The client never ACKs or
108
+ retries automatically. An ACK records receipt only; it is not a decision,
109
+ approval or trade. Retain the original event ID and digest across recovery.
110
+ This candidate requires the matching backend. The managed daemon consumer,
111
+ local source setup UI, onchain signals and Base delivery are not yet connected;
112
+ published availability and end-to-end automation are not established.
113
+
114
+ ## Unreleased local model client
115
+
116
+ `createLocalLlmAdapter` makes a text request directly from the caller's process to
117
+ the explicitly selected OpenAI or Anthropic provider. It requires an explicit
118
+ model; it does not select a cheaper model, retry, or fall back to Balchemy. Supply
119
+ the API key from the user's local secret source and never log the configuration.
120
+
121
+ ```ts
122
+ import { createLocalLlmAdapter } from '@balchemyai/agent-sdk';
123
+
124
+ const model = createLocalLlmAdapter({
125
+ provider: 'openai',
126
+ model: selectedModel,
127
+ apiKey: locallyLoadedApiKey,
128
+ timeoutMs: 30_000,
129
+ });
130
+ const result = await model.chat(localMessages, 1_000, { signal: shutdownSignal });
131
+ ```
132
+
133
+ OpenAI-compatible `baseUrl` requires HTTPS; plain HTTP is limited to numeric
134
+ loopback (`127.0.0.1` or `[::1]`). An explicitly supplied `fetchFn` receives private
135
+ messages and provider credentials and must remain in the user's trusted process.
136
+ Redirects are rejected. Timeout and cancellation cover response-body reading; an
137
+ aborted request may still have run or incurred cost at the provider, so this client
138
+ never retries automatically. Errors omit raw provider bodies and transport causes.
139
+
140
+ Only complete text responses are accepted. Truncation, refusal, tool calls and
141
+ unsupported content blocks fail closed. OpenAI `stop` and Anthropic `end_turn`
142
+ follow their respective [Chat Completions](https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create)
143
+ and [Messages](https://platform.claude.com/docs/en/api/messages/create) contracts.
144
+ The existing internal adapters keep their legacy default models; this new factory
145
+ requires the caller's choice. Provider classes and execution internals remain private.
146
+
147
+ This unreleased library boundary does not install a background service, attach a
148
+ private brain, persist memory, provision a wallet or authorize trading. It does not
149
+ establish deployed or real-provider acceptance for the owner-local runner.
150
+
24
151
  ## Create a Client
25
152
 
26
153
  ```ts
@@ -31,6 +158,9 @@ const sdk = new BalchemyAgentSdk({
31
158
  });
32
159
  ```
33
160
 
161
+ `BalchemyClient` is exported as an alias for `BalchemyAgentSdk` for consumers
162
+ that use the shorter root import name.
163
+
34
164
  `apiBaseUrl` includes `/api` and has no trailing slash.
35
165
 
36
166
  ## Auth Path 1: SIWE
@@ -104,6 +234,7 @@ const { tools } = await mcp.listTools();
104
234
 
105
235
  const reply = await mcp.askBot({
106
236
  message: "What is the price of SOL?",
237
+ idempotency_key: crypto.randomUUID(),
107
238
  });
108
239
  ```
109
240
 
@@ -112,9 +243,29 @@ For other tools, call the runtime-advertised name returned by `tools/list`:
112
243
  ```ts
113
244
  const research = await mcp.callTool("ask_bot", {
114
245
  message: "Find low-risk Base setups with deep liquidity.",
246
+ idempotency_key: crypto.randomUUID(),
115
247
  });
116
248
  ```
117
249
 
250
+ Create one idempotency key per deliberate protected operation. Keep that key
251
+ with the operation until its outcome is reconciled. A timeout is not proof that
252
+ the operation failed; do not create a new key and blindly repeat it.
253
+
254
+ For a runtime-advertised manage tool, pass fresh owner step-up proof separately
255
+ from tool arguments:
256
+
257
+ ```ts
258
+ await mcp.callTool("agent_control", {
259
+ action: "pause",
260
+ idempotency_key: crypto.randomUUID(),
261
+ }, { stepUpToken: freshOwnerStepUpProof });
262
+ ```
263
+
264
+ Obtain that proof through authenticated Hub. The SDK sends it only on this
265
+ manage call, using `x-balchemy-step-up`; it does not store it or send it on
266
+ `tools/list`, status, or other read calls. Scope, ownership, idempotency, and
267
+ step-up validation remain backend requirements.
268
+
118
269
  The SDK does not expose typed swap/trade helper methods from the root client.
119
270
  Privileged tools require the backend-advertised tool surface, the right MCP key
120
271
  scope, replay/rate protection, and the approved product flow.
@@ -133,7 +284,10 @@ hidden unless they are returned by `tools/list` for that bot.
133
284
 
134
285
  Use `agent_status` for read-scope runtime state. Safe read wrappers are
135
286
  `agent_context_snapshot`, `agent_market_brief`, `agent_candidate_report`, and
136
- `agent_risk_report`. Runtime mutation uses manage-scope `agent_control`.
287
+ `agent_risk_report`. Runtime mutation uses manage-scope `agent_control`. The SDK
288
+ root also exports `agentReadinessReport`, `agentContextSnapshot`,
289
+ `agentMarketBrief`, `agentCandidateReport`, and `agentRiskReport` helpers that
290
+ delegate to a connected `BalchemyMcpClient`.
137
291
 
138
292
  `AgentLoop` fails closed before `trade_command`: local `shadowMode=false` is not
139
293
  enough. The backend runtime must report `autonomous_runtime.mode=live_armed`,
@@ -168,7 +322,7 @@ function toSdkFailure(err: unknown): SdkFailure | null {
168
322
  }
169
323
  ```
170
324
 
171
- Known codes include `auth_error`, `policy_error`, `rate_limit`,
325
+ Known codes include `auth_error`, `policy_error`, `rate_limit_error`,
172
326
  `provider_auth_error`, `network_error`, `execution_error`, and
173
327
  `invalid_response`.
174
328
 
@@ -14,15 +14,19 @@ export declare class AgentLoop {
14
14
  private status;
15
15
  private startedAt;
16
16
  private eventsReceived;
17
+ private eventsDropped;
17
18
  private decisionsExecuted;
18
19
  private tradesExecuted;
19
20
  private lastEventAt;
20
21
  private lastTradeAt;
21
- private seenTraceIds;
22
+ private readonly seenTraceIds;
23
+ private readonly pendingEvents;
24
+ private drainPromise;
25
+ private processingHalted;
26
+ private lifecycleGeneration;
22
27
  private portfolioCache;
23
28
  private rulesCache;
24
29
  /** Client-side behavior rule limits for pre-check enforcement. */
25
- private readonly ruleLimits;
26
30
  /** Trades executed in the current clock-hour (reset each hour). */
27
31
  private tradesThisHour;
28
32
  /** Timestamp (ms) of the hour boundary when tradesThisHour was last reset. */
@@ -30,6 +34,11 @@ export declare class AgentLoop {
30
34
  /** publicId extracted from the MCP endpoint path (last path segment). */
31
35
  private readonly publicId;
32
36
  private readonly sessionId;
37
+ private readonly userMessageIdempotencyNamespace;
38
+ private userMessageSequence;
39
+ private readonly maxPendingEvents;
40
+ private readonly maxEventAgeMs;
41
+ private readonly maxEvidenceAgeMs;
33
42
  constructor(config: AgentLoopConfig);
34
43
  start(): Promise<void>;
35
44
  stop(): Promise<void>;
@@ -49,12 +58,8 @@ export declare class AgentLoop {
49
58
  * so the decision loop continues with degraded context.
50
59
  */
51
60
  private fetchPortfolio;
52
- /**
53
- * Fetch compressed behavior rules from the MCP resource
54
- * `balchemy://behavior-rules/{publicId}`.
55
- * Result is cached for 5 minutes. On failure, returns empty string
56
- * so decisions still proceed without rule context.
57
- */
61
+ /** Fetch an exact immutable behavior-rule revision binding. Failures are cached
62
+ * briefly and return null so neither decisions nor submissions proceed unbound. */
58
63
  private fetchBehaviorRules;
59
64
  /**
60
65
  * Reset the hourly trade counter when the clock rolls to a new hour.
@@ -62,5 +67,11 @@ export declare class AgentLoop {
62
67
  */
63
68
  private resetHourlyCounterIfNeeded;
64
69
  private createLlmAdapter;
70
+ private startDrain;
71
+ private drainEvents;
72
+ private isGenerationCurrent;
73
+ private awaitCurrentDrain;
74
+ private notifyError;
75
+ private notifyStatus;
65
76
  }
66
77
  //# sourceMappingURL=agent-loop.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../../src/agent-loop/agent-loop.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EAMZ,MAAM,SAAS,CAAC;AAmVjB,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAiB;IAC7C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAa;IACjC,OAAO,CAAC,QAA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