@balchemyai/agent-sdk 0.3.11 → 0.6.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 (154) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/LICENSE +21 -0
  3. package/README.md +152 -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 +33 -9
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +147 -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/decision-report-client.d.ts +64 -0
  71. package/dist/local-runner/decision-report-client.d.ts.map +1 -0
  72. package/dist/local-runner/decision-report-client.js +169 -0
  73. package/dist/local-runner/decision-report-client.js.map +1 -0
  74. package/dist/local-runner/execution-build-client.d.ts +207 -0
  75. package/dist/local-runner/execution-build-client.d.ts.map +1 -0
  76. package/dist/local-runner/execution-build-client.js +426 -0
  77. package/dist/local-runner/execution-build-client.js.map +1 -0
  78. package/dist/local-runner/execution-submit-client.d.ts +126 -0
  79. package/dist/local-runner/execution-submit-client.d.ts.map +1 -0
  80. package/dist/local-runner/execution-submit-client.js +287 -0
  81. package/dist/local-runner/execution-submit-client.js.map +1 -0
  82. package/dist/local-runner/llm-client.d.ts +20 -0
  83. package/dist/local-runner/llm-client.d.ts.map +1 -0
  84. package/dist/local-runner/llm-client.js +23 -0
  85. package/dist/local-runner/llm-client.js.map +1 -0
  86. package/dist/local-runner/owner-approval-client.d.ts +124 -0
  87. package/dist/local-runner/owner-approval-client.d.ts.map +1 -0
  88. package/dist/local-runner/owner-approval-client.js +261 -0
  89. package/dist/local-runner/owner-approval-client.js.map +1 -0
  90. package/dist/local-runner/owner-approval-message.d.ts +82 -0
  91. package/dist/local-runner/owner-approval-message.d.ts.map +1 -0
  92. package/dist/local-runner/owner-approval-message.js +174 -0
  93. package/dist/local-runner/owner-approval-message.js.map +1 -0
  94. package/dist/local-runner/owner-positions.d.ts +37 -0
  95. package/dist/local-runner/owner-positions.d.ts.map +1 -0
  96. package/dist/local-runner/owner-positions.js +94 -0
  97. package/dist/local-runner/owner-positions.js.map +1 -0
  98. package/dist/local-runner/pairing-client.d.ts +95 -0
  99. package/dist/local-runner/pairing-client.d.ts.map +1 -0
  100. package/dist/local-runner/pairing-client.js +186 -0
  101. package/dist/local-runner/pairing-client.js.map +1 -0
  102. package/dist/local-runner/research-client.d.ts +98 -0
  103. package/dist/local-runner/research-client.d.ts.map +1 -0
  104. package/dist/local-runner/research-client.js +344 -0
  105. package/dist/local-runner/research-client.js.map +1 -0
  106. package/dist/local-runner/runner-proof-transport.d.ts +55 -0
  107. package/dist/local-runner/runner-proof-transport.d.ts.map +1 -0
  108. package/dist/local-runner/runner-proof-transport.js +258 -0
  109. package/dist/local-runner/runner-proof-transport.js.map +1 -0
  110. package/dist/local-runner/runtime-client.d.ts +142 -0
  111. package/dist/local-runner/runtime-client.d.ts.map +1 -0
  112. package/dist/local-runner/runtime-client.js +306 -0
  113. package/dist/local-runner/runtime-client.js.map +1 -0
  114. package/dist/local-runner/sell-assessment-client.d.ts +113 -0
  115. package/dist/local-runner/sell-assessment-client.d.ts.map +1 -0
  116. package/dist/local-runner/sell-assessment-client.js +225 -0
  117. package/dist/local-runner/sell-assessment-client.js.map +1 -0
  118. package/dist/local-runner/signals-client.d.ts +91 -0
  119. package/dist/local-runner/signals-client.d.ts.map +1 -0
  120. package/dist/local-runner/signals-client.js +357 -0
  121. package/dist/local-runner/signals-client.js.map +1 -0
  122. package/dist/local-runner/solana-platform-account.d.ts +5 -0
  123. package/dist/local-runner/solana-platform-account.d.ts.map +1 -0
  124. package/dist/local-runner/solana-platform-account.js +66 -0
  125. package/dist/local-runner/solana-platform-account.js.map +1 -0
  126. package/dist/local-runner/trading-wallet-client.d.ts +67 -0
  127. package/dist/local-runner/trading-wallet-client.d.ts.map +1 -0
  128. package/dist/local-runner/trading-wallet-client.js +144 -0
  129. package/dist/local-runner/trading-wallet-client.js.map +1 -0
  130. package/dist/mcp/mcp-client.d.ts +31 -4
  131. package/dist/mcp/mcp-client.d.ts.map +1 -1
  132. package/dist/mcp/mcp-client.js +491 -83
  133. package/dist/mcp/mcp-client.js.map +1 -1
  134. package/dist/streaming/sse-event-stream.d.ts +14 -0
  135. package/dist/streaming/sse-event-stream.d.ts.map +1 -1
  136. package/dist/streaming/sse-event-stream.js +153 -13
  137. package/dist/streaming/sse-event-stream.js.map +1 -1
  138. package/dist/types.d.ts +11 -2
  139. package/dist/types.d.ts.map +1 -1
  140. package/dist/utils/package-version.d.ts +2 -0
  141. package/dist/utils/package-version.d.ts.map +1 -0
  142. package/dist/utils/package-version.js +54 -0
  143. package/dist/utils/package-version.js.map +1 -0
  144. package/dist/utils/redaction.d.ts +4 -0
  145. package/dist/utils/redaction.d.ts.map +1 -1
  146. package/dist/utils/redaction.js +54 -0
  147. package/dist/utils/redaction.js.map +1 -1
  148. package/dist/utils/retry.d.ts +22 -13
  149. package/dist/utils/retry.d.ts.map +1 -1
  150. package/dist/utils/retry.js +76 -50
  151. package/dist/utils/retry.js.map +1 -1
  152. package/docs/DEPLOYMENT.md +1 -1
  153. package/docs/error-retry-strategy.md +16 -6
  154. package/package.json +9 -9
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RunnerDecisionReportClient = exports.RUNNER_DECISION_REPORT_LEASE_CONFLICT = exports.RUNNER_DECISION_REPORT_CONFLICT = exports.RUNNER_DECISION_REPORT_RECEIPT_SKEW_MS = exports.RUNNER_DECISION_HOLD_REASONS = exports.RUNNER_DECISION_ACTIONS = void 0;
4
+ exports.validateRunnerDecisionReport = validateRunnerDecisionReport;
5
+ exports.runnerDecisionReportRequestDigest = runnerDecisionReportRequestDigest;
6
+ exports.validateRunnerDecisionReportNonce = validateRunnerDecisionReportNonce;
7
+ exports.runnerDecisionReportNonceMessage = runnerDecisionReportNonceMessage;
8
+ exports.validateRunnerDecisionReportReceipt = validateRunnerDecisionReportReceipt;
9
+ const agent_sdk_error_1 = require("../errors/agent-sdk-error");
10
+ const redaction_1 = require("../utils/redaction");
11
+ const runner_proof_transport_1 = require("./runner-proof-transport");
12
+ exports.RUNNER_DECISION_ACTIONS = ["buy", "sell", "hold", "skip"];
13
+ /** Closed hold reasons, identical to the backend list. `other` stands for a runner reason this list does not name yet. */
14
+ exports.RUNNER_DECISION_HOLD_REASONS = [
15
+ "scope_mismatch", "runtime_changed", "runtime_disallowed", "signal_future", "signal_stale",
16
+ "rules_changed", "rules_missing", "rules_held", "rules_invalid", "evidence_unresolved", "evidence_missing",
17
+ "evidence_held", "evidence_mismatch", "entry_facts_missing", "entry_signals_missing", "entry_rule_failed",
18
+ "strategy_facts_missing", "model_locked", "source_stale", "lease_unavailable", "admission_unavailable",
19
+ "daily_call_limit", "token_cooldown", "legacy_usage_unknown", "clock_rollback", "call_allowance_unavailable", "sizing_policy_changed",
20
+ "provider_unavailable", "research_unavailable", "invalid_result", "other",
21
+ ];
22
+ const PATH = "/nest/local-agents/decision-reports";
23
+ const PURPOSE = "balchemy.local-agent.decision-report.v1";
24
+ const REQUEST_PURPOSE = "balchemy.local-agent.decision-report.request.v1";
25
+ const REPORT_KEYS = ["version", "eventId", "assetId", "action", "holdReason", "decidedAt"];
26
+ const EVENT_ID = /^lsi_[0-9a-f]{64}$/;
27
+ const MAX_PAYLOAD_BYTES = 2048;
28
+ /** A 409 body is read only to find its bounded reason; anything larger is not a reason this client knows. */
29
+ const MAX_CONFLICT_BYTES = 8192;
30
+ /** The backend accepts a decidedAt up to 60 s ahead of its clock (LOCAL_AGENT_DECISION_REPORT_SKEW_MS); the receipt time is
31
+ * informational, so a runner clock that far behind the server must not turn a stored report into a failed send. */
32
+ exports.RUNNER_DECISION_REPORT_RECEIPT_SKEW_MS = 60_000;
33
+ /** `details.reason` of a 409 (the backend's global error filter keeps only generic codes). A report conflict is permanent: a
34
+ * different report is already recorded for this eventId and is never overwritten. A lease conflict is transient. Surfaced as
35
+ * AgentSdkError.machineCode with status 409; a 409 without a known reason keeps the generic machine code. */
36
+ exports.RUNNER_DECISION_REPORT_CONFLICT = "DECISION_REPORT_CONFLICT";
37
+ exports.RUNNER_DECISION_REPORT_LEASE_CONFLICT = "DECISION_REPORT_LEASE_CONFLICT";
38
+ const CONFLICT_REASONS = [exports.RUNNER_DECISION_REPORT_CONFLICT, exports.RUNNER_DECISION_REPORT_LEASE_CONFLICT];
39
+ const invalid = (0, runner_proof_transport_1.invalidFor)("decision report");
40
+ const cancelled = (0, runner_proof_transport_1.cancelledFor)("decision report");
41
+ const exact = (0, runner_proof_transport_1.exactWith)(invalid);
42
+ const timestamp = (0, runner_proof_transport_1.timestampWith)(invalid);
43
+ /** Closed validation of one report; anything outside the six bounded fields is refused before it can be sent. */
44
+ function validateRunnerDecisionReport(value) {
45
+ exact(value, REPORT_KEYS);
46
+ if (value.version !== 1 || !(0, runner_proof_transport_1.matches)(value.eventId, EVENT_ID) || !(0, runner_proof_transport_1.solanaAddress)(value.assetId)
47
+ || !exports.RUNNER_DECISION_ACTIONS.includes(value.action))
48
+ invalid();
49
+ if (value.holdReason !== null && (value.action !== "hold"
50
+ || !exports.RUNNER_DECISION_HOLD_REASONS.includes(value.holdReason)))
51
+ invalid();
52
+ timestamp(value.decidedAt);
53
+ return Object.freeze({ version: 1, eventId: value.eventId, assetId: value.assetId, action: value.action,
54
+ holdReason: value.holdReason, decidedAt: value.decidedAt });
55
+ }
56
+ function runnerDecisionReportRequestDigest(value) {
57
+ const report = validateRunnerDecisionReport(value);
58
+ return (0, runner_proof_transport_1.sha256)([REQUEST_PURPOSE, ...REPORT_KEYS.map((key) => report[key])]);
59
+ }
60
+ function expected(value) {
61
+ exact(value, [...runner_proof_transport_1.TARGET_KEYS, "epoch", "report"]);
62
+ if (!(0, runner_proof_transport_1.positive)(value.epoch))
63
+ invalid();
64
+ return Object.freeze({ ...(0, runner_proof_transport_1.pinTarget)((0, runner_proof_transport_1.targetPart)(value), invalid), epoch: value.epoch, report: validateRunnerDecisionReport(value.report) });
65
+ }
66
+ function validateRunnerDecisionReportNonce(value, expectedTarget, now = Date.now()) {
67
+ const pinned = expected(expectedTarget);
68
+ return (0, runner_proof_transport_1.validateProofNonce)(value, pinned, PURPOSE, "decision-reports/submit", runnerDecisionReportRequestDigest(pinned.report), now, invalid);
69
+ }
70
+ function runnerDecisionReportNonceMessage(value, expectedTarget, now = Date.now()) {
71
+ return (0, runner_proof_transport_1.proofNonceMessage)(validateRunnerDecisionReportNonce(value, expectedTarget, now));
72
+ }
73
+ function validateRunnerDecisionReportReceipt(value, expectedTarget, now = Date.now()) {
74
+ const pinned = expected(expectedTarget);
75
+ exact(value, ["version", "requestDigest", "agentId", "eventId", "receivedAt"]);
76
+ if (!Number.isFinite(now) || value.version !== 1 || !(0, runner_proof_transport_1.matches)(value.requestDigest, runner_proof_transport_1.HEX)
77
+ || value.requestDigest !== runnerDecisionReportRequestDigest(pinned.report) || value.agentId !== pinned.agentId
78
+ || value.eventId !== pinned.report.eventId || timestamp(value.receivedAt) > now + exports.RUNNER_DECISION_REPORT_RECEIPT_SKEW_MS)
79
+ invalid();
80
+ return Object.freeze({ ...value });
81
+ }
82
+ /** The closed conflict reason of a 409 body (canonical `error.details.reason` or legacy `details.reason`), else undefined. */
83
+ function conflictReason(text) {
84
+ let body;
85
+ try {
86
+ body = JSON.parse(text);
87
+ }
88
+ catch {
89
+ return undefined;
90
+ }
91
+ const reason = (value) => value && typeof value === "object" && !Array.isArray(value)
92
+ ? value.details?.reason : undefined;
93
+ if (!body || typeof body !== "object" || Array.isArray(body))
94
+ return undefined;
95
+ const found = reason(body.error) ?? reason(body);
96
+ return typeof found === "string" && CONFLICT_REASONS.includes(found) ? found : undefined;
97
+ }
98
+ /** Public runner route only (POST /api/nest/local-agents/decision-reports/{nonce,submit}); credential-free, redirect-refusing. */
99
+ class RunnerDecisionReportClient {
100
+ pinned;
101
+ signer;
102
+ timeoutMs;
103
+ transport;
104
+ constructor(config) {
105
+ exact(config, [...runner_proof_transport_1.TARGET_KEYS, "apiBaseUrl", "signer"], ["timeoutMs", "fetchFn"]);
106
+ this.pinned = (0, runner_proof_transport_1.pinTarget)((0, runner_proof_transport_1.targetPart)(config), invalid);
107
+ if (config.apiBaseUrl !== `${this.pinned.frontendOrigin}/api` || typeof config.signer !== "function"
108
+ || (config.fetchFn !== undefined && typeof config.fetchFn !== "function")
109
+ || (config.timeoutMs !== undefined && (!(0, runner_proof_transport_1.positive)(config.timeoutMs) || config.timeoutMs > 30_000)))
110
+ invalid();
111
+ this.signer = config.signer;
112
+ this.timeoutMs = config.timeoutMs ?? 20_000;
113
+ this.transport = config.fetchFn ?? fetch;
114
+ }
115
+ /** One signed attempt. An identical resubmission answers the original receipt; a different report for the event is a 409
116
+ * whose machineCode is RUNNER_DECISION_REPORT_CONFLICT (permanent); a lease conflict is RUNNER_DECISION_REPORT_LEASE_CONFLICT. */
117
+ async submit(input, epoch, callerSignal) {
118
+ const operation = expected({ ...this.pinned, epoch, report: input });
119
+ if (callerSignal !== undefined && !(callerSignal instanceof AbortSignal))
120
+ invalid();
121
+ const scope = new AbortController();
122
+ const forward = () => scope.abort();
123
+ callerSignal?.addEventListener("abort", forward, { once: true });
124
+ if (callerSignal?.aborted)
125
+ scope.abort();
126
+ const deadline = setTimeout(forward, this.timeoutMs);
127
+ // Only a 409 body is inspected, for its closed reason; the bytes are handed on unchanged.
128
+ let conflict;
129
+ const transport = async (url, init) => {
130
+ const response = await this.transport(url, init);
131
+ if (response.status !== 409)
132
+ return response;
133
+ const text = await (0, redaction_1.readBoundedResponseText)(response, MAX_CONFLICT_BYTES, init?.signal ?? undefined);
134
+ conflict = conflictReason(text);
135
+ return new Response(text, { status: response.status, statusText: response.statusText, headers: response.headers });
136
+ };
137
+ const http = (0, runner_proof_transport_1.proofHttpClient)(this.pinned.frontendOrigin, this.timeoutMs, transport, scope.signal, MAX_PAYLOAD_BYTES, invalid, cancelled);
138
+ try {
139
+ const data = await (0, runner_proof_transport_1.waitFor)(() => http.post(`${PATH}/nonce`, { agentId: operation.agentId, bindingDigest: operation.bindingDigest,
140
+ instanceId: operation.instanceId, epoch: operation.epoch, requestDigest: runnerDecisionReportRequestDigest(operation.report) }, { kind: "side_effecting", operation: "local-agent:decision-report-nonce" }), scope.signal, cancelled);
141
+ const nonce = validateRunnerDecisionReportNonce(data, operation);
142
+ const signature = await (0, runner_proof_transport_1.signWithin)(() => this.signer(nonce, operation), nonce.expiresAt, scope.signal, invalid, cancelled);
143
+ validateRunnerDecisionReportNonce(nonce, operation);
144
+ if (!(0, runner_proof_transport_1.base64)(signature, 64))
145
+ invalid();
146
+ const response = await (0, runner_proof_transport_1.waitFor)(() => http.post(`${PATH}/submit`, { nonceId: nonce.nonceId, signature, epoch: operation.epoch,
147
+ report: operation.report }, { kind: "side_effecting", operation: "local-agent:decision-report-submit" }), scope.signal, cancelled);
148
+ return validateRunnerDecisionReportReceipt(response, operation);
149
+ }
150
+ catch (error) {
151
+ if (scope.signal.aborted)
152
+ throw cancelled();
153
+ if (error instanceof agent_sdk_error_1.AgentSdkError && error.status === 409 && conflict !== undefined) {
154
+ throw new agent_sdk_error_1.AgentSdkError({ code: error.code, status: 409, message: error.message,
155
+ details: { layer: "http_ingress", code: conflict, retryable: conflict !== exports.RUNNER_DECISION_REPORT_CONFLICT } });
156
+ }
157
+ if (error instanceof agent_sdk_error_1.AgentSdkError)
158
+ throw error;
159
+ return invalid();
160
+ }
161
+ finally {
162
+ clearTimeout(deadline);
163
+ callerSignal?.removeEventListener("abort", forward);
164
+ scope.abort();
165
+ }
166
+ }
167
+ }
168
+ exports.RunnerDecisionReportClient = RunnerDecisionReportClient;
169
+ //# sourceMappingURL=decision-report-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decision-report-client.js","sourceRoot":"","sources":["../../src/local-runner/decision-report-client.ts"],"names":[],"mappings":";;;AAyDA,oEASC;AACD,8EAGC;AAMD,8EAGC;AACD,4EAEC;AACD,kFAOC;AA1FD,+DAA0D;AAC1D,kDAA6D;AAE7D,qEAE0D;AAG7C,QAAA,uBAAuB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAEhF,0HAA0H;AAC7G,QAAA,4BAA4B,GAAG;IAC1C,gBAAgB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,eAAe,EAAE,cAAc;IAC1F,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,eAAe,EAAE,qB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AE,CAAC;YAC5C,IAAI,KAAK,YAAY,+BAAa,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBACrF,MAAM,IAAI,+BAAa,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO;oBAC7E,OAAO,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,KAAK,uCAA+B,EAAE,EAAE,CAAC,CAAC;YACnH,CAAC;YACD,IAAI,KAAK,YAAY,+BAAa;gBAAE,MAAM,KAAK,CAAC;YAChD,OAAO,OAAO,EAAE,CAAC;QACnB,CAAC;gBAAS,CAAC;YAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;YAAC,YAAY,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAAC,CAAC;IAC3G,CAAC;CACF;AAnDD,gEAmDC"}
@@ -0,0 +1,207 @@
1
+ import type { RunnerRuntimeTarget } from "./runtime-client";
2
+ import { type RunnerProofNonce } from "./runner-proof-transport";
3
+ export type RunnerExecutionTarget = RunnerRuntimeTarget;
4
+ export interface RunnerExecutionEvidence {
5
+ kind: "candidate_report" | "risk_report";
6
+ serverEvidenceId: string;
7
+ snapshotDigest: string;
8
+ staleAt: string;
9
+ }
10
+ /** Closed runner ENTRY intent (a buy; key order is the digest order). An exit (sell) is RunnerExitRequest. */
11
+ export interface RunnerExecutionRequest {
12
+ version: 1;
13
+ chain: "solana";
14
+ direction: "buy";
15
+ reservationId: string;
16
+ planDigest: string;
17
+ assessmentDigest: string;
18
+ /** Signal provenance (covered by the request digest): the delivered inbox event and the source revision behind the decision. */
19
+ eventId: string;
20
+ eventDigest: string;
21
+ sourceId: string;
22
+ sourceRevision: number;
23
+ /** 1-2 public evidence bindings, one per kind; `staleAt` is the original server evidence expiry, never a decision time. */
24
+ evidence: RunnerExecutionEvidence[];
25
+ walletAddress: string;
26
+ inputMint: string;
27
+ outputMint: string;
28
+ grossInputAmount: string;
29
+ slippageBps: number;
30
+ minOutBound: string;
31
+ maxPriorityFeeLamports: string;
32
+ feeRateBps: number;
33
+ feePolicyDigest: string;
34
+ dailyCapLamports: string;
35
+ }
36
+ /** The owner's daily cap as a v2 buy carries it: no cap, or 1..10 SOL in canonical u64 lamports. Never a bare null. */
37
+ export type RunnerDailyCap = {
38
+ kind: "none";
39
+ } | {
40
+ kind: "lamports";
41
+ lamports: string;
42
+ };
43
+ /** v2 buy (purpose balchemy.local-agent.execution.request.v2): the v1 fields in the same order, except that
44
+ * `dailyCapLamports` is replaced by `dailyCap`. Whether "none" is accepted is decided by the backend's signed-cap gate. */
45
+ export interface RunnerExecutionRequestV2 extends Omit<RunnerExecutionRequest, "dailyCapLamports"> {
46
+ dailyCap: RunnerDailyCap;
47
+ }
48
+ /** Either buy wire (v1 or v2). */
49
+ export type RunnerExecutionBuyRequest = RunnerExecutionRequest | RunnerExecutionRequestV2;
50
+ export declare const RUNNER_EXIT_TRIGGERS: readonly ["stop_loss", "take_profit", "trailing_stop", "manual"];
51
+ export type RunnerExitTrigger = typeof RUNNER_EXIT_TRIGGERS[number];
52
+ /** Buy builds an exit may name as the entries that opened the position. */
53
+ export declare const RUNNER_EXIT_MAX_ENTRY_BUILDS = 16;
54
+ /** The fresh, server-recorded sell assessment that observed the trigger: its digest, quote.outAmount and quote.observedAtMs. */
55
+ export interface RunnerExitTriggerObservation {
56
+ sellAssessmentDigest: string;
57
+ observedOutLamports: string;
58
+ observedAtMs: string;
59
+ }
60
+ /** Closed runner EXIT intent (key order is the digest order): sell grossTokenUnits of positionMint for WSOL. No signal provenance;
61
+ * bound to the engine position, the completed buy builds that opened it and a fresh sell assessment
62
+ * (assessmentDigest must equal triggerObservation.sellAssessmentDigest). Same nonce purpose and route as a buy. */
63
+ export interface RunnerExitRequest {
64
+ version: 1;
65
+ chain: "solana";
66
+ direction: "sell";
67
+ reservationId: string;
68
+ planDigest: string;
69
+ assessmentDigest: string;
70
+ positionMint: string;
71
+ grossTokenUnits: string;
72
+ exitTrigger: RunnerExitTrigger;
73
+ triggerObservation: RunnerExitTriggerObservation;
74
+ /** 1-16 distinct engine build digests of this agent's committed (completed) buys of positionMint on this wallet. */
75
+ entryBuildDigests: string[];
76
+ walletAddress: string;
77
+ slippageBps: number;
78
+ minOutBound: string;
79
+ maxPriorityFeeLamports: string;
80
+ feeRateBps: number;
81
+ feePolicyDigest: string;
82
+ }
83
+ export type RunnerExecutionIntent = RunnerExecutionBuyRequest | RunnerExitRequest;
84
+ export type RunnerExecutionExpectedTarget = RunnerExecutionTarget & {
85
+ epoch: number;
86
+ request: RunnerExecutionBuyRequest;
87
+ };
88
+ export type RunnerExitExpectedTarget = RunnerExecutionTarget & {
89
+ epoch: number;
90
+ request: RunnerExitRequest;
91
+ };
92
+ /** Either intent's pinned context (what the validators, the signer and the client accept). */
93
+ export type RunnerExecutionIntentTarget = RunnerExecutionTarget & {
94
+ epoch: number;
95
+ request: RunnerExecutionIntent;
96
+ };
97
+ export type RunnerExecutionNonce = RunnerProofNonce<"balchemy.local-agent.execution.build.v1">;
98
+ /** buy: fee_basis input_lamports (exact System transfer from the input). sell: fee_basis output_sol (Jupiter platform fee on the
99
+ * WSOL proceeds into the platform's WSOL ATA; netIn = grossIn; feeAmount is quote-derived). */
100
+ export interface RunnerExecutionExpected {
101
+ direction: "buy" | "sell";
102
+ wallet: string;
103
+ inputMint: string;
104
+ outputMint: string;
105
+ inputTokenProgram: string;
106
+ outputTokenProgram: string;
107
+ tokenDecimals: number;
108
+ grossIn: string;
109
+ feeAmount: string;
110
+ feeRateBps: number;
111
+ feeRecipient: string;
112
+ feeRecipientAccount: string;
113
+ feePolicyDigest: string;
114
+ netIn: string;
115
+ quotedOut: string;
116
+ minOut: string;
117
+ slippageBps: number;
118
+ maxPriorityFeeLamports: string;
119
+ /** Fixed by direction (buy: input_lamports, sell: output_sol); validated but not part of the engine buildDigest. */
120
+ feeBasis: "input_lamports" | "output_sol";
121
+ }
122
+ /** Unsigned v0 message facts. The runner still validates/simulates independently before any signature. */
123
+ export interface RunnerExecutionBuild {
124
+ walletBindingId: string;
125
+ unsignedMessageB64: string;
126
+ messageSha256: string;
127
+ blockhash: string;
128
+ lastValidBlockHeight: string;
129
+ addressLookupTables: readonly string[];
130
+ expected: Readonly<RunnerExecutionExpected>;
131
+ executionAvailable: false;
132
+ buildDigest: string;
133
+ /** Sell only (absent on a buy): digest of the engine position snapshot the exit was guarded against; not in buildDigest. */
134
+ positionDigest?: string;
135
+ builtAt: string;
136
+ expiresAt: string;
137
+ }
138
+ export interface RunnerExecutionReservation {
139
+ reservationId: string;
140
+ utcDay: string;
141
+ amountLamports: string;
142
+ dailyCapLamports: string;
143
+ state: "built";
144
+ }
145
+ /** A v2 buy's reservation echo: the request's own dailyCap instead of dailyCapLamports. */
146
+ export interface RunnerExecutionReservationV2 {
147
+ reservationId: string;
148
+ utcDay: string;
149
+ amountLamports: string;
150
+ dailyCap: RunnerDailyCap;
151
+ state: "built";
152
+ }
153
+ /** An exit reservation counts no SOL against the daily buy cap; it is an attempt record in the separate exit slots. */
154
+ export interface RunnerExitReservation {
155
+ reservationId: string;
156
+ utcDay: string;
157
+ direction: "sell";
158
+ grossTokenUnits: string;
159
+ state: "built";
160
+ }
161
+ interface RunnerExecutionBase {
162
+ version: 1;
163
+ requestDigest: string;
164
+ agentId: string;
165
+ bindingDigest: string;
166
+ instanceId: string;
167
+ epoch: number;
168
+ completedAt: string;
169
+ }
170
+ export interface RunnerExecutionRefused extends RunnerExecutionBase {
171
+ outcome: "refused";
172
+ reasonCode: string;
173
+ }
174
+ export interface RunnerExecutionBuilt extends RunnerExecutionBase {
175
+ outcome: "built";
176
+ reservation: Readonly<RunnerExecutionReservation | RunnerExecutionReservationV2 | RunnerExitReservation>;
177
+ build: Readonly<RunnerExecutionBuild>;
178
+ }
179
+ export type RunnerExecutionResponse = RunnerExecutionRefused | RunnerExecutionBuilt;
180
+ /** Runner key: sign only runnerExecutionNonceMessage after independently checking this context. Base64, 64 bytes. */
181
+ export type RunnerExecutionSigner = (nonce: Readonly<RunnerExecutionNonce>, expected: RunnerExecutionIntentTarget) => string | Promise<string>;
182
+ export interface RunnerExecutionBuildClientConfig extends RunnerExecutionTarget {
183
+ apiBaseUrl: string;
184
+ signer: RunnerExecutionSigner;
185
+ timeoutMs?: number;
186
+ fetchFn?: typeof fetch;
187
+ }
188
+ export declare const RUNNER_EXECUTION_REFUSALS: readonly ["direction_unavailable", "execution_not_armed", "runtime_heartbeat_stale", "owner_control_pending", "entries_paused", "trading_wallet_unbound", "trading_wallet_is_identity_wallet", "fee_policy_mismatch", "global_kill_switch_active", "chain_kill_switch_active", "provider_circuit_breaker_open", "user_trading_lock_active", "local_agent_kill_switch_active", "daily_cap_exceeded", "reservation_capacity_exhausted", "reservation_conflict", "reservation_in_progress", "reservation_build_expired", "reservation_released", "reservation_submitted", "reservation_committed", "invalid_local_swap_request", "fee_policy_unavailable", "fee_account_unavailable", "quote_below_min_out_bound", "local_swap_provider_unavailable", "local_swap_deadline_exceeded", "local_swap_busy", "local_swap_store_unavailable", "signal_event_mismatch", "source_authorization_changed", "source_approval_required", "evidence_stale", "evidence_mismatch", "exit_assessment_stale", "exit_assessment_mismatch", "exit_entry_mismatch", "position_insufficient", "position_conflict", "invalid_local_position_request", "local_position_unavailable", "local_position_store_unavailable", "owner_approval_missing", "owner_cap_exceeded"];
189
+ /** SHA256(UTF8(JSON.stringify([purpose, request]))): the v1 or v2 buy purpose for a buy (by its cap key), the exit purpose
190
+ * for an exit. */
191
+ export declare function runnerExecutionRequestDigest(value: RunnerExecutionIntent): string;
192
+ export declare function validateRunnerExecutionNonce(value: unknown, expectedTarget: RunnerExecutionIntentTarget, now?: number): RunnerExecutionNonce;
193
+ export declare function runnerExecutionNonceMessage(value: RunnerExecutionNonce, expectedTarget: RunnerExecutionIntentTarget, now?: number): string;
194
+ /** Mirrors the engine build_digest (blockchain.proto BuildLocalSolanaSwapResponse). */
195
+ export declare function runnerExecutionBuildDigest(b: Pick<RunnerExecutionBuild, "walletBindingId" | "unsignedMessageB64" | "messageSha256" | "blockhash" | "lastValidBlockHeight" | "addressLookupTables" | "expected">, requestDigest: string, req: Pick<RunnerExecutionRequest, "planDigest" | "assessmentDigest">, agentId: string): string;
196
+ export declare function validateRunnerExecutionResponse(value: unknown, expectedTarget: RunnerExecutionIntentTarget, now?: number): RunnerExecutionResponse;
197
+ export declare class RunnerExecutionBuildClient {
198
+ private readonly pinned;
199
+ private readonly signer;
200
+ private readonly timeoutMs;
201
+ private readonly transport;
202
+ constructor(config: RunnerExecutionBuildClientConfig);
203
+ /** A single bounded attempt. Retrying with the same reservationId returns the same reservation and unsigned message. */
204
+ build(input: RunnerExecutionIntent, epoch: number, callerSignal?: AbortSignal): Promise<RunnerExecutionResponse>;
205
+ }
206
+ export {};
207
+ //# sourceMappingURL=execution-build-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-build-client.d.ts","sourceRoot":"","sources":["../../src/local-runner/execution-build-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAE4C,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG3G,MAAM,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AACxD,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,kBAAkB,GAAG,aAAa,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;CAC7G;AACD,8GAA8G;AAC9G,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,KAAK,CAA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