diff --git a/packages/plugin-spheron/src/actions/deployment.ts b/packages/plugin-spheron/src/actions/deployment.ts index ba4b607fa46..743f72a48d2 100644 --- a/packages/plugin-spheron/src/actions/deployment.ts +++ b/packages/plugin-spheron/src/actions/deployment.ts @@ -21,33 +21,71 @@ import type { DeploymentContent } from "../types/index.ts"; import { AVAILABLE_GPU_MODELS } from "../utils/constants.ts"; import { DEPLOYMENT_TEMPLATES } from "../utils/template.ts"; -function isDeploymentContent(content: any): content is DeploymentContent { +function isDeploymentContent(content: unknown): content is DeploymentContent { elizaLogger.debug("Content for deployment operation:", content); + + // First, check if content is an object + if (typeof content !== 'object' || content === null) { + return false; + } + + // Type assertion to access properties safely + const contentObj = content as Record; + + // Check operation property if ( - typeof content.operation !== "string" || - !["create", "update", "close"].includes(content.operation) + typeof contentObj.operation !== "string" || + !["create", "update", "close"].includes(contentObj.operation) ) { return false; } - switch (content.operation) { + // Check properties based on operation + switch (contentObj.operation) { case "create": return ( - typeof content.template === "string" && - typeof content.customizations === "object" + typeof contentObj.template === "string" && + typeof contentObj.customizations === "object" ); case "update": return ( - typeof content.leaseId === "string" && - typeof content.template === "string" && - typeof content.customizations === "object" + typeof contentObj.leaseId === "string" && + typeof contentObj.template === "string" && + typeof contentObj.customizations === "object" ); case "close": - return typeof content.leaseId === "string"; + return typeof contentObj.leaseId === "string"; default: return false; } } +// function isDeploymentContent(content: any): content is DeploymentContent { +// elizaLogger.debug("Content for deployment operation:", content); +// if ( +// typeof content.operation !== "string" || +// !["create", "update", "close"].includes(content.operation) +// ) { +// return false; +// } + +// switch (content.operation) { +// case "create": +// return ( +// typeof content.template === "string" && +// typeof content.customizations === "object" +// ); +// case "update": +// return ( +// typeof content.leaseId === "string" && +// typeof content.template === "string" && +// typeof content.customizations === "object" +// ); +// case "close": +// return typeof content.leaseId === "string"; +// default: +// return false; +// } +// } // Generate template descriptions dynamically const templateDescriptions = Object.entries(DEPLOYMENT_TEMPLATES) @@ -157,11 +195,12 @@ export default { ) => { elizaLogger.log("Starting DEPLOYMENT_OPERATION handler..."); - // Initialize or update state - if (!state) { - state = (await runtime.composeState(message)) as State; + // Create local variable for state manipulation + let currentState = state; + if (!currentState) { + currentState = (await runtime.composeState(message)) as State; } else { - state = await runtime.updateRecentMessageState(state); + currentState = await runtime.updateRecentMessageState(currentState); } // Filter only "just now" and last couple of user messages @@ -175,7 +214,7 @@ export default { // Compose deployment context const deploymentContext = composeContext({ - state, + state: currentState, template: deploymentTemplate, }); diff --git a/packages/plugin-spheron/src/actions/escrow.ts b/packages/plugin-spheron/src/actions/escrow.ts index 919e09d89d3..827b3898bad 100644 --- a/packages/plugin-spheron/src/actions/escrow.ts +++ b/packages/plugin-spheron/src/actions/escrow.ts @@ -19,16 +19,38 @@ import { import type { EscrowContent } from "../types/index.ts"; import { SUPPORTED_TOKENS } from "../utils/constants.ts"; -function isEscrowContent(content: any): content is EscrowContent { +// function isEscrowContent(content: any): content is EscrowContent { +// console.log("Content for escrow operation:", content); +// return ( +// typeof content.token === "string" && +// (content.operation === "deposit" || content.operation === "withdraw" +// ? typeof content.amount === "number" && content.amount > 0 +// : content.operation === "check") && +// (content.operation === "deposit" || +// content.operation === "withdraw" || +// content.operation === "check") +// ); +// } + +function isEscrowContent(content: unknown): content is EscrowContent { console.log("Content for escrow operation:", content); + + // First, check if content is an object + if (typeof content !== 'object' || content === null) { + return false; + } + + // Type assertion to access properties safely + const contentObj = content as Record; + return ( - typeof content.token === "string" && - (content.operation === "deposit" || content.operation === "withdraw" - ? typeof content.amount === "number" && content.amount > 0 - : content.operation === "check") && - (content.operation === "deposit" || - content.operation === "withdraw" || - content.operation === "check") + typeof contentObj.token === "string" && + (contentObj.operation === "deposit" || contentObj.operation === "withdraw" + ? typeof contentObj.amount === "number" && contentObj.amount > 0 + : contentObj.operation === "check") && + (contentObj.operation === "deposit" || + contentObj.operation === "withdraw" || + contentObj.operation === "check") ); } @@ -109,11 +131,12 @@ export default { ) => { elizaLogger.log("Starting ESCROW_OPERATION handler..."); - // Initialize or update state - if (!state) { - state = (await runtime.composeState(message)) as State; + // Create local variable for state manipulation + let currentState = state; + if (!currentState) { + currentState = (await runtime.composeState(message)) as State; } else { - state = await runtime.updateRecentMessageState(state); + currentState = await runtime.updateRecentMessageState(currentState); } // Filter only "just now" and last couple of user messages @@ -127,7 +150,7 @@ export default { // Compose escrow context const escrowContext = composeContext({ - state, + state: currentState, template: escrowTemplate, }); diff --git a/packages/plugin-spheron/src/utils/index.ts b/packages/plugin-spheron/src/utils/index.ts index f33e01b08d3..761a24aa7c0 100644 --- a/packages/plugin-spheron/src/utils/index.ts +++ b/packages/plugin-spheron/src/utils/index.ts @@ -28,7 +28,7 @@ export const depositBalance = async ( runtime: IAgentRuntime, token: string, amount: number -): Promise => { +): Promise => { // Replace any with unknown const sdk = await getSDKInstance(runtime); return await sdk.escrow.depositBalance({ token, @@ -44,7 +44,7 @@ export const withdrawBalance = async ( runtime: IAgentRuntime, token: string, amount: number -): Promise => { +): Promise => { // Replace any with unknown const sdk = await getSDKInstance(runtime); return await sdk.escrow.withdrawBalance({ token, @@ -229,7 +229,7 @@ export const getDeployment = async ( export const closeDeployment = async ( runtime: IAgentRuntime, leaseId: string -): Promise => { +): Promise => { // Replace any with unknown const sdk = await getSDKInstance(runtime); return await sdk.deployment.closeDeployment(leaseId); };