Skip to content

Commit 277441a

Browse files
committed
chore: fix format
1 parent 0a1dd6a commit 277441a

File tree

6 files changed

+38
-74
lines changed

6 files changed

+38
-74
lines changed

packages/llm/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export * from "./agent"
33
export * from "./langchain"
44
export * from "./prompt/index"
55
export * from "./types"
6-
export * from "./utils"
6+
export * from "./utils"

packages/llm/src/utils/tools.ts

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { KnownChainId } from "@polkadot-agent-kit/common"
22
import { convertAddress } from "@polkadot-agent-kit/core"
33
import type { ZodType } from "zod"
44

5-
import type { Action, ToolError, ToolResponse } from "../types"
5+
import { Action, ToolError, ToolNames, ToolResponse } from "../types"
66
import { ChainNotAvailableError, ErrorCodes, InvalidAddressError, isAnyToolError } from "../types"
77

88
/**
@@ -140,36 +140,6 @@ export const executeTool = async <T>(
140140
}
141141
}
142142

143-
/**
144-
* Utility function to create chain-specific error responses.
145-
*
146-
* @example
147-
* ```typescript
148-
* const response = createChainErrorResponse("invalid-chain", ["polkadot"], "check_balance");
149-
* ```
150-
*/
151-
export const createChainErrorResponse = (
152-
chain: string,
153-
availableChains: string[],
154-
toolName: string
155-
): ToolResponse => {
156-
const error = new ChainNotAvailableError(chain, availableChains)
157-
return createErrorResponse(error, toolName)
158-
}
159-
160-
/**
161-
* Utility function to create address-specific error responses.
162-
*
163-
* @example
164-
* ```typescript
165-
* const response = createAddressErrorResponse("invalid-address", "transfer");
166-
* ```
167-
*/
168-
export const createAddressErrorResponse = (address: string, toolName: string): ToolResponse => {
169-
const error = new InvalidAddressError(address)
170-
return createErrorResponse(error, toolName)
171-
}
172-
173143
export const createAction = <T>(
174144
tool: { invoke: (args: T) => Promise<unknown> },
175145
toolConfig: { name: string; description: string; schema: ZodType }
@@ -182,3 +152,37 @@ export const createAction = <T>(
182152
return typeof result === "string" ? result : JSON.stringify(result)
183153
}
184154
})
155+
156+
export function validateTools(actions: Action[], existingCustomActions: Action[]): void {
157+
const builtInToolNames = new Set(Object.values(ToolNames))
158+
159+
for (const action of actions) {
160+
if (!action.name || typeof action.name !== "string") {
161+
throw new Error("Action must have a valid 'name' property")
162+
}
163+
164+
if (!action.description || typeof action.description !== "string") {
165+
throw new Error(`Action '${action.name}' must have a valid 'description' property`)
166+
}
167+
168+
if (!action.schema) {
169+
throw new Error(`Action '${action.name}' must have a valid 'schema' property`)
170+
}
171+
172+
if (!action.invoke || typeof action.invoke !== "function") {
173+
throw new Error(`Action '${action.name}' must have a valid 'invoke' function`)
174+
}
175+
176+
if (builtInToolNames.has(action.name as ToolNames)) {
177+
throw new Error(
178+
`Action name '${action.name}' conflicts with a built-in tool. Please use a different name.`
179+
)
180+
}
181+
182+
if (existingCustomActions.some(existing => existing.name === action.name)) {
183+
throw new Error(
184+
`Action name '${action.name}' already exists in custom actions. Please use a unique name.`
185+
)
186+
}
187+
}
188+
}

packages/sdk/src/api.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import type {
1111
TransferTool,
1212
XcmTransferNativeAssetTool
1313
} from "@polkadot-agent-kit/llm"
14-
import { PolkadotAgentApi } from "@polkadot-agent-kit/llm"
14+
import { PolkadotAgentApi, validateTools } from "@polkadot-agent-kit/llm"
1515
import { type PolkadotSigner } from "polkadot-api/signer"
1616

17-
import { validateCustomTools } from "./utils"
18-
1917
export class PolkadotAgentKit implements IPolkadotApi, IPolkadotAgentApi {
2018
private polkadotApi: PolkadotApi
2119
private agentApi: PolkadotAgentApi
@@ -292,7 +290,7 @@ export class PolkadotAgentKit implements IPolkadotApi, IPolkadotAgentApi {
292290
*
293291
*/
294292
addCustomTools(tools: Action[]): void {
295-
validateCustomTools(tools, this.customTools)
293+
validateTools(tools, this.customTools)
296294
this.customTools.push(...tools)
297295
}
298296

packages/sdk/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from "./api"
22
export * from "./langchain"
33
export * from "./mcp"
4-
export * from "./utils"
54
export * from "./vercel"

packages/sdk/src/langchain.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ export function getLangChainTools(polkadotAgentKit: PolkadotAgentKit): Structure
3131
)
3232
)
3333
}
34-

packages/sdk/src/utils.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)