Skip to content

Commit

Permalink
Merge branch 'develop' into fix-plugin-asterai-clean
Browse files Browse the repository at this point in the history
  • Loading branch information
tcm390 authored Jan 31, 2025
2 parents 3bd6b5c + 8a77f91 commit 4477481
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
18 changes: 10 additions & 8 deletions packages/plugin-icp/src/actions/createToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function generateTokenLogo(
height: 512,
count: 1,
},
runtime as any
runtime
);

if (result.success && result.data && result.data.length > 0) {
Expand All @@ -96,7 +96,7 @@ export const executeCreateToken: Action = {
],
description:
"Create a new meme token on PickPump platform (Internet Computer). This action helps users create and launch tokens specifically on the PickPump platform.",
validate: async (runtime: IAgentRuntime, message: Memory) => {
validate: async (_runtime: IAgentRuntime, message: Memory) => {
const keywords = [
"pickpump",
"pp",
Expand Down Expand Up @@ -137,14 +137,16 @@ export const executeCreateToken: Action = {
type: "processing",
});

if (!state) {
state = (await runtime.composeState(message)) as State;
// Initialize or update state
let currentState = state;
if (!currentState) {
currentState = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
currentState = await runtime.updateRecentMessageState(currentState);
}

const createTokenContext = composeContext({
state,
state: currentState,
template: createTokenTemplate,
});

Expand Down Expand Up @@ -200,9 +202,9 @@ export const executeCreateToken: Action = {
type: "success",
};
callback?.(responseMsg);
} catch (error: any) {
} catch (error: unknown) {
const responseMsg = {
text: `Failed to create token: ${error.message}`,
text: `Failed to create token: ${error instanceof Error ? error.message : "Unknown error"}`,
action: "CREATE_TOKEN",
type: "error",
};
Expand Down
22 changes: 18 additions & 4 deletions packages/plugin-icp/src/providers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export class WalletProvider {
if (privateKeyBytes.length !== 32) {
throw new Error("Invalid private key length");
}
return Ed25519KeyIdentity.fromSecretKey(privateKeyBytes);
const arrayBuffer = privateKeyBytes.buffer.slice(
privateKeyBytes.byteOffset,
privateKeyBytes.byteOffset + privateKeyBytes.length
);
return Ed25519KeyIdentity.fromSecretKey(arrayBuffer);
} catch {
throw new Error("Failed to create ICP identity");
}
Expand Down Expand Up @@ -62,13 +66,23 @@ export class WalletProvider {
};
}

// Add interface for the wallet provider return type
interface ICPWalletResponse {
wallet: WalletProvider | null;
identity: Ed25519KeyIdentity | null;
principal: string | null;
isAuthenticated: boolean;
createActor?: typeof WalletProvider.prototype.createActor;
error?: string;
}

// Add the new provider instance
export const icpWalletProvider: Provider = {
async get(
runtime: IAgentRuntime,
_message: Memory,
_state?: State
): Promise<any> {
): Promise<ICPWalletResponse> {
try {
const privateKey = runtime.getSetting(
"INTERNET_COMPUTER_PRIVATE_KEY"
Expand All @@ -86,13 +100,13 @@ export const icpWalletProvider: Provider = {
isAuthenticated: true,
createActor: wallet.createActor,
};
} catch (error: any) {
} catch (error: unknown) {
return {
wallet: null,
identity: null,
principal: null,
isAuthenticated: false,
error: error.message,
error: error instanceof Error ? error.message : "Unknown error",
};
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-icp/src/utils/common/types/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Variant6<A, B, C, D, E, F> = Record<

// Unwrap and extract only the key
export const unwrapVariantKey = <T extends string>(
v: Record<string, any>
v: Record<string, unknown>
): T => {
const keys = Object.keys(v);
if (keys.length === 0) throw new Error("variant must has a key");
Expand Down

0 comments on commit 4477481

Please sign in to comment.