Skip to content

Commit 64ff0a9

Browse files
committed
fix(stacks): explicit Tool types on bare tool exports for isolated-declarations
1 parent b48981d commit 64ff0a9

2 files changed

Lines changed: 44 additions & 21 deletions

File tree

packages/stacks/src/tools/btc/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
* await step.generateText("research", { tools: { btcConfirmations, btcBalance }, … })
1212
*/
1313

14-
import { tool } from "ai";
14+
import { type Tool, tool } from "ai";
1515
import { z } from "zod";
1616

17+
// biome-ignore lint/suspicious/noExplicitAny: Tool's input-schema generic is too
18+
// precise for isolated-declarations output — we pass tools through to AI SDK
19+
// which validates at runtime.
20+
type LooseTool = Tool<any, any>;
21+
1722
function baseUrl(): string {
1823
return (process.env.BTC_MEMPOOL_URL ?? "https://mempool.space").replace(
1924
/\/$/,
@@ -42,7 +47,7 @@ const BTC_ADDRESS = z
4247
.string()
4348
.describe("Bitcoin address (legacy, segwit, or taproot)");
4449

45-
export const btcConfirmations = tool({
50+
export const btcConfirmations: LooseTool = tool({
4651
description:
4752
"Number of confirmations for a Bitcoin transaction. Returns { confirmations, confirmed }.",
4853
inputSchema: z.object({ txid: BTC_TXID }),
@@ -62,7 +67,7 @@ export const btcConfirmations = tool({
6267
},
6368
});
6469

65-
export const btcBalance = tool({
70+
export const btcBalance: LooseTool = tool({
6671
description:
6772
"Bitcoin balance for an address, in satoshis. Returns { confirmedSat, unconfirmedSat }.",
6873
inputSchema: z.object({ address: BTC_ADDRESS }),
@@ -80,7 +85,7 @@ export const btcBalance = tool({
8085
},
8186
});
8287

83-
export const btcUtxos = tool({
88+
export const btcUtxos: LooseTool = tool({
8489
description:
8590
"List of unspent outputs for a Bitcoin address (truncated to `limit`).",
8691
inputSchema: z.object({
@@ -100,7 +105,7 @@ export const btcUtxos = tool({
100105
},
101106
});
102107

103-
export const btcFeeEstimate = tool({
108+
export const btcFeeEstimate: LooseTool = tool({
104109
description:
105110
"Current Bitcoin fee estimates in sat/vB across priority tiers (fastest, 30-min, hour, economy).",
106111
inputSchema: z.object({}),
@@ -116,7 +121,7 @@ export const btcFeeEstimate = tool({
116121
},
117122
});
118123

119-
export const btcBlockHeight = tool({
124+
export const btcBlockHeight: LooseTool = tool({
120125
description: "Current Bitcoin chain tip height.",
121126
inputSchema: z.object({}),
122127
execute: async () => ({

packages/stacks/src/tools/index.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929
* ```
3030
*/
3131

32-
import { tool } from "ai";
32+
import { type Tool, tool } from "ai";
3333
import { z } from "zod";
34+
35+
// biome-ignore lint/suspicious/noExplicitAny: Tool's input-schema generic is
36+
// too precise for isolated-declarations output — AI SDK validates at runtime.
37+
type LooseTool = Tool<any, any>;
3438
import { estimateFee as _estimateFee } from "../actions/public/estimateFee.ts";
3539
import { getAccountInfo as _getAccountInfo } from "../actions/public/getAccountInfo.ts";
3640
import { getBalance as _getBalance } from "../actions/public/getBalance.ts";
@@ -159,7 +163,22 @@ async function nftHoldings(
159163

160164
// --- Factory: bind tools to an explicit client ---
161165

162-
export function createStacksTools(client: StacksReadClient) {
166+
export interface StacksTools {
167+
getStxBalance: LooseTool;
168+
getAccountInfo: LooseTool;
169+
getBlock: LooseTool;
170+
getBlockHeight: LooseTool;
171+
readContract: LooseTool;
172+
estimateFee: LooseTool;
173+
bnsResolve: LooseTool;
174+
bnsReverse: LooseTool;
175+
getTransaction: LooseTool;
176+
getAccountHistory: LooseTool;
177+
getMempoolStats: LooseTool;
178+
getNftHoldings: LooseTool;
179+
}
180+
181+
export function createStacksTools(client: StacksReadClient): StacksTools {
163182
return {
164183
getStxBalance: tool({
165184
description: "Get the STX balance (in micro-STX) for a Stacks principal.",
@@ -258,25 +277,24 @@ export function createStacksTools(client: StacksReadClient) {
258277
};
259278
}
260279

261-
export type StacksTools = ReturnType<typeof createStacksTools>;
262280

263281
// --- Bare exports using the default (env-configured) client ---
264282

265-
export const getStxBalance = tool({
283+
export const getStxBalance: LooseTool = tool({
266284
description:
267285
"Get the STX balance (in micro-STX) for a Stacks principal. Uses default client.",
268286
inputSchema: z.object({ principal: PRINCIPAL }),
269287
execute: ({ principal }) => stxBalance(getDefaultPublicClient(), principal),
270288
});
271289

272-
export const getAccountInfo = tool({
290+
export const getAccountInfo: LooseTool = tool({
273291
description:
274292
"Get account info (balance, locked, nonce) for a Stacks principal.",
275293
inputSchema: z.object({ principal: PRINCIPAL }),
276294
execute: ({ principal }) => accountInfo(getDefaultPublicClient(), principal),
277295
});
278296

279-
export const getBlock = tool({
297+
export const getBlock: LooseTool = tool({
280298
description:
281299
"Fetch a Stacks block by height or hash. Omit both for the latest block.",
282300
inputSchema: z.object({
@@ -286,13 +304,13 @@ export const getBlock = tool({
286304
execute: (args) => block(getDefaultPublicClient(), args),
287305
});
288306

289-
export const getBlockHeight = tool({
307+
export const getBlockHeight: LooseTool = tool({
290308
description: "Get the current Stacks chain tip height.",
291309
inputSchema: z.object({}),
292310
execute: () => blockHeight(getDefaultPublicClient()),
293311
});
294312

295-
export const readContract = tool({
313+
export const readContract: LooseTool = tool({
296314
description:
297315
"Call a read-only Clarity function. Returns the decoded value as JSON.",
298316
inputSchema: z.object({
@@ -303,37 +321,37 @@ export const readContract = tool({
303321
execute: (args) => contractRead(getDefaultPublicClient(), args),
304322
});
305323

306-
export const estimateFee = tool({
324+
export const estimateFee: LooseTool = tool({
307325
description:
308326
"Estimate fee range (low / medium / high) for a serialized Stacks transaction.",
309327
inputSchema: z.object({ serializedTxHex: z.string() }),
310328
execute: ({ serializedTxHex }) =>
311329
fee(getDefaultPublicClient(), serializedTxHex),
312330
});
313331

314-
export const bnsResolve = tool({
332+
export const bnsResolve: LooseTool = tool({
315333
description:
316334
"Resolve a BNS name (e.g. 'satoshi.btc') to its owning Stacks principal.",
317335
inputSchema: z.object({ name: z.string() }),
318336
execute: ({ name }) => bnsResolveImpl(getDefaultPublicClient(), name),
319337
});
320338

321-
export const bnsReverse = tool({
339+
export const bnsReverse: LooseTool = tool({
322340
description:
323341
"Reverse-lookup the primary BNS name for a Stacks principal, if set.",
324342
inputSchema: z.object({ principal: PRINCIPAL }),
325343
execute: ({ principal }) =>
326344
bnsReverseImpl(getDefaultPublicClient(), principal),
327345
});
328346

329-
export const getTransaction = tool({
347+
export const getTransaction: LooseTool = tool({
330348
description:
331349
"Fetch a confirmed Stacks transaction by txId (Hiro extended API).",
332350
inputSchema: z.object({ txId: z.string() }),
333351
execute: ({ txId }) => transactionByTxId(getDefaultPublicClient(), txId),
334352
});
335353

336-
export const getAccountHistory = tool({
354+
export const getAccountHistory: LooseTool = tool({
337355
description:
338356
"Paginated transaction history for a Stacks principal (Hiro extended API).",
339357
inputSchema: z.object({
@@ -344,14 +362,14 @@ export const getAccountHistory = tool({
344362
accountHistory(getDefaultPublicClient(), principal, limit),
345363
});
346364

347-
export const getMempoolStats = tool({
365+
export const getMempoolStats: LooseTool = tool({
348366
description:
349367
"Current mempool statistics: pending count, fee distribution, age buckets (Hiro extended API).",
350368
inputSchema: z.object({}),
351369
execute: () => mempoolStats(getDefaultPublicClient()),
352370
});
353371

354-
export const getNftHoldings = tool({
372+
export const getNftHoldings: LooseTool = tool({
355373
description:
356374
"NFT holdings for a Stacks principal across all collections (Hiro extended API).",
357375
inputSchema: z.object({

0 commit comments

Comments
 (0)