2929 * ```
3030 */
3131
32- import { tool } from "ai" ;
32+ import { type Tool , tool } from "ai" ;
3333import { 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 > ;
3438import { estimateFee as _estimateFee } from "../actions/public/estimateFee.ts" ;
3539import { getAccountInfo as _getAccountInfo } from "../actions/public/getAccountInfo.ts" ;
3640import { 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