Skip to content

Commit 798b6be

Browse files
committed
cleanup
1 parent c002b69 commit 798b6be

12 files changed

+647
-3661
lines changed

integrations/cointoss/package-lock.json

-3,121
This file was deleted.

integrations/cointoss/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"name": "cointoss-agent",
33
"version": "1.0.0",
44
"description": "A coin toss betting agent using XMTP and CDP AgentKit",
5-
"main": "dist/index.js",
65
"type": "module",
6+
"main": "dist/index.js",
77
"scripts": {
88
"build": "tsc",
9-
"start": "node dist/index.js",
10-
"dev": "tsx watch src/index.ts",
11-
"gen:keys": "node dist/scripts/generate-keys.js"
9+
"dev": "tsx --env-file=.env src/index.ts",
10+
"gen:keys": "tsx ../../scripts/generateKeys.ts",
11+
"start": "tsx --env-file=.env src/index.ts"
1212
},
1313
"dependencies": {
1414
"@coinbase/agentkit": "^0.2.0",

integrations/cointoss/scripts/generate-keys.ts

-134
This file was deleted.

integrations/cointoss/src/cdp.ts

+49-34
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { HumanMessage } from "@langchain/core/messages";
1111
import { MemorySaver } from "@langchain/langgraph";
1212
import { createReactAgent } from "@langchain/langgraph/prebuilt";
1313
import { ChatOpenAI } from "@langchain/openai";
14-
import { StorageProvider } from "./types.js";
14+
import type { StorageProvider } from "./types";
1515

1616
// Interface for parsed bet information
1717
export interface ParsedBet {
@@ -22,16 +22,19 @@ export interface ParsedBet {
2222

2323
export async function getOrCreateWalletForUser(
2424
userId: string,
25-
storage: StorageProvider
25+
storage: StorageProvider,
2626
) {
2727
const walletDataStr = await storage.getUserWallet(userId);
2828

2929
let walletProvider;
3030

3131
// Configure CDP Wallet Provider
3232
const config = {
33-
apiKeyName: process.env.CDP_API_KEY_NAME!,
34-
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY?.replace(/\\n/g, "\n"),
33+
apiKeyName: process.env.CDP_API_KEY_NAME as string,
34+
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY?.replace(
35+
/\\n/g,
36+
"\n",
37+
),
3538
cdpWalletData: walletDataStr || undefined,
3639
networkId: process.env.NETWORK_ID,
3740
};
@@ -51,10 +54,13 @@ export async function getOrCreateWalletForUser(
5154
return { walletProvider, config };
5255
}
5356

54-
export async function createGameWallet(storage: StorageProvider) {
57+
export async function createGameWallet() {
5558
const config = {
56-
apiKeyName: process.env.CDP_API_KEY_NAME!,
57-
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY?.replace(/\\n/g, "\n"),
59+
apiKeyName: process.env.CDP_API_KEY_NAME as string,
60+
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY?.replace(
61+
/\\n/g,
62+
"\n",
63+
),
5864
networkId: process.env.NETWORK_ID || "base-mainnet",
5965
};
6066

@@ -68,29 +74,35 @@ export async function createGameWallet(storage: StorageProvider) {
6874
};
6975
}
7076

71-
export async function initializeAgent(userId: string, storage: StorageProvider) {
77+
export async function initializeAgent(
78+
userId: string,
79+
storage: StorageProvider,
80+
) {
7281
try {
7382
const llm = new ChatOpenAI({
7483
modelName: "gpt-4o-mini",
7584
});
7685

77-
const { walletProvider, config: walletConfig } = await getOrCreateWalletForUser(
78-
userId,
79-
storage
80-
);
86+
const { walletProvider } = await getOrCreateWalletForUser(userId, storage);
8187

8288
const agentkit = await AgentKit.from({
8389
walletProvider,
8490
actionProviders: [
8591
walletActionProvider(),
8692
erc20ActionProvider(),
8793
cdpApiActionProvider({
88-
apiKeyName: process.env.CDP_API_KEY_NAME!,
89-
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY?.replace(/\\n/g, "\n"),
94+
apiKeyName: process.env.CDP_API_KEY_NAME as string,
95+
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY?.replace(
96+
/\\n/g,
97+
"\n",
98+
),
9099
}),
91100
cdpWalletActionProvider({
92-
apiKeyName: process.env.CDP_API_KEY_NAME!,
93-
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY?.replace(/\\n/g, "\n"),
101+
apiKeyName: process.env.CDP_API_KEY_NAME as string,
102+
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY?.replace(
103+
/\\n/g,
104+
"\n",
105+
),
94106
}),
95107
],
96108
});
@@ -170,20 +182,20 @@ export async function initializeAgent(userId: string, storage: StorageProvider)
170182
export async function processMessage(
171183
agent: ReturnType<typeof createReactAgent>,
172184
config: { configurable: { thread_id: string } },
173-
message: string
185+
message: string,
174186
): Promise<string> {
175187
try {
176188
const stream = await agent.stream(
177189
{ messages: [new HumanMessage(message)] },
178-
config
190+
config,
179191
);
180192

181193
let response = "";
182194
for await (const chunk of stream) {
183195
if ("agent" in chunk) {
184-
response += chunk.agent.messages[0].content + "\n";
196+
response += (chunk.agent.messages[0].content as string) + "\n";
185197
} else if ("tools" in chunk) {
186-
response += chunk.tools.messages[0].content + "\n";
198+
response += (chunk.tools.messages[0].content as string) + "\n";
187199
}
188200
}
189201

@@ -204,22 +216,22 @@ export async function processMessage(
204216
export async function parseNaturalLanguageBet(
205217
agent: ReturnType<typeof createReactAgent>,
206218
config: { configurable: { thread_id: string } },
207-
prompt: string
219+
prompt: string,
208220
): Promise<ParsedBet> {
209221
try {
210222
// Default values in case parsing fails
211223
const defaultResult: ParsedBet = {
212224
topic: prompt,
213225
options: ["yes", "no"],
214-
amount: "0.1"
226+
amount: "0.1",
215227
};
216228

217229
if (!prompt || prompt.length < 3) {
218230
return defaultResult;
219231
}
220232

221233
console.log(`🔄 Parsing natural language bet: "${prompt}"`);
222-
234+
223235
// Format specific request for parsing
224236
const parsingRequest = `
225237
Parse this bet request into structured format: "${prompt}"
@@ -231,27 +243,30 @@ export async function parseNaturalLanguageBet(
231243
"amount": "bet amount"
232244
}
233245
`;
234-
246+
235247
// Process with the agent
236248
const response = await processMessage(agent, config, parsingRequest);
237-
249+
238250
// Try to extract JSON from the response
239251
try {
240252
// Find JSON in the response
241253
const jsonMatch = response.match(/\{[\s\S]*\}/);
242254
if (jsonMatch) {
243255
const parsedJson = JSON.parse(jsonMatch[0]);
244-
256+
245257
// Validate and provide defaults if needed
246258
const result: ParsedBet = {
247259
topic: parsedJson.topic || prompt,
248-
options: Array.isArray(parsedJson.options) && parsedJson.options.length >= 2
249-
? [parsedJson.options[0], parsedJson.options[1]]
250-
: ["yes", "no"],
251-
amount: parsedJson.amount || "0.1"
260+
options:
261+
Array.isArray(parsedJson.options) && parsedJson.options.length >= 2
262+
? [parsedJson.options[0], parsedJson.options[1]]
263+
: ["yes", "no"],
264+
amount: parsedJson.amount || "0.1",
252265
};
253-
254-
console.log(`✅ Parsed bet: "${result.topic}" with options [${result.options.join(', ')}] for ${result.amount} USDC`);
266+
267+
console.log(
268+
`✅ Parsed bet: "${result.topic}" with options [${result.options.join(", ")}] for ${result.amount} USDC`,
269+
);
255270
return result;
256271
}
257272
} catch (error) {
@@ -264,7 +279,7 @@ export async function parseNaturalLanguageBet(
264279
return {
265280
topic: prompt,
266281
options: ["yes", "no"],
267-
amount: "0.1"
282+
amount: "0.1",
268283
};
269284
}
270-
}
285+
}

0 commit comments

Comments
 (0)