Skip to content

Commit

Permalink
Merge pull request #2870 from AIFlowML/fix-plugin-spheron
Browse files Browse the repository at this point in the history
fix: plugin-spheron
  • Loading branch information
shakkernerd authored Jan 28, 2025
2 parents 045161f + 49d7eb2 commit 1f0bbde
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 31 deletions.
69 changes: 54 additions & 15 deletions packages/plugin-spheron/src/actions/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;

// 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)
Expand Down Expand Up @@ -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
Expand All @@ -175,7 +214,7 @@ export default {

// Compose deployment context
const deploymentContext = composeContext({
state,
state: currentState,
template: deploymentTemplate,
});

Expand Down
49 changes: 36 additions & 13 deletions packages/plugin-spheron/src/actions/escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;

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")
);
}

Expand Down Expand Up @@ -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
Expand All @@ -127,7 +150,7 @@ export default {

// Compose escrow context
const escrowContext = composeContext({
state,
state: currentState,
template: escrowTemplate,
});

Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-spheron/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const depositBalance = async (
runtime: IAgentRuntime,
token: string,
amount: number
): Promise<any> => {
): Promise<unknown> => { // Replace any with unknown

Check warning on line 31 in packages/plugin-spheron/src/utils/index.ts

View check run for this annotation

codefactor.io / CodeFactor

packages/plugin-spheron/src/utils/index.ts#L31

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
const sdk = await getSDKInstance(runtime);
return await sdk.escrow.depositBalance({
token,
Expand All @@ -44,7 +44,7 @@ export const withdrawBalance = async (
runtime: IAgentRuntime,
token: string,
amount: number
): Promise<any> => {
): Promise<unknown> => { // Replace any with unknown

Check warning on line 47 in packages/plugin-spheron/src/utils/index.ts

View check run for this annotation

codefactor.io / CodeFactor

packages/plugin-spheron/src/utils/index.ts#L47

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
const sdk = await getSDKInstance(runtime);
return await sdk.escrow.withdrawBalance({
token,
Expand Down Expand Up @@ -229,7 +229,7 @@ export const getDeployment = async (
export const closeDeployment = async (
runtime: IAgentRuntime,
leaseId: string
): Promise<any> => {
): Promise<unknown> => { // Replace any with unknown
const sdk = await getSDKInstance(runtime);
return await sdk.deployment.closeDeployment(leaseId);
};
Expand Down

0 comments on commit 1f0bbde

Please sign in to comment.