Skip to content

Commit 6361419

Browse files
authored
Merge branch 'develop' into fix/remove-redundant-uuid-conversion
2 parents 3db53aa + cb4d973 commit 6361419

File tree

17 files changed

+4899
-1722
lines changed

17 files changed

+4899
-1722
lines changed

agent/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"exec": "node --enable-source-maps --loader ts-node/esm src/index.ts"
1919
},
2020
"dependencies": {
21+
"@elizaos/adapter-supabase": "workspace:*",
2122
"@elizaos/adapter-postgres": "workspace:*",
2223
"@elizaos/adapter-redis": "workspace:*",
2324
"@elizaos/adapter-sqlite": "workspace:*",

agent/src/index.ts

+32-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { PGLiteDatabaseAdapter } from "@elizaos/adapter-pglite";
22
import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";
33
import { RedisClient } from "@elizaos/adapter-redis";
44
import { SqliteDatabaseAdapter } from "@elizaos/adapter-sqlite";
5+
import { SupabaseDatabaseAdapter } from "@elizaos/adapter-supabase";
56
import { AutoClientInterface } from "@elizaos/client-auto";
67
import { DiscordClientInterface } from "@elizaos/client-discord";
78
import { FarcasterAgentClient } from "@elizaos/client-farcaster";
@@ -456,7 +457,24 @@ export function getTokenForProvider(
456457
}
457458

458459
function initializeDatabase(dataDir: string) {
459-
if (process.env.POSTGRES_URL) {
460+
if (process.env.SUPABASE_URL && process.env.SUPABASE_ANON_KEY) {
461+
elizaLogger.info("Initializing Supabase connection...");
462+
const db = new SupabaseDatabaseAdapter(
463+
process.env.SUPABASE_URL,
464+
process.env.SUPABASE_ANON_KEY
465+
);
466+
467+
// Test the connection
468+
db.init()
469+
.then(() => {
470+
elizaLogger.success("Successfully connected to Supabase database");
471+
})
472+
.catch((error) => {
473+
elizaLogger.error("Failed to connect to Supabase:", error);
474+
});
475+
476+
return db;
477+
} else if (process.env.POSTGRES_URL) {
460478
elizaLogger.info("Initializing PostgreSQL connection...");
461479
const db = new PostgresDatabaseAdapter({
462480
connectionString: process.env.POSTGRES_URL,
@@ -466,9 +484,7 @@ function initializeDatabase(dataDir: string) {
466484
// Test the connection
467485
db.init()
468486
.then(() => {
469-
elizaLogger.success(
470-
"Successfully connected to PostgreSQL database"
471-
);
487+
elizaLogger.success("Successfully connected to PostgreSQL database");
472488
})
473489
.catch((error) => {
474490
elizaLogger.error("Failed to connect to PostgreSQL:", error);
@@ -483,10 +499,19 @@ function initializeDatabase(dataDir: string) {
483499
});
484500
return db;
485501
} else {
486-
const filePath =
487-
process.env.SQLITE_FILE ?? path.resolve(dataDir, "db.sqlite");
488-
// ":memory:";
502+
const filePath = process.env.SQLITE_FILE ?? path.resolve(dataDir, "db.sqlite");
503+
elizaLogger.info(`Initializing SQLite database at ${filePath}...`);
489504
const db = new SqliteDatabaseAdapter(new Database(filePath));
505+
506+
// Test the connection
507+
db.init()
508+
.then(() => {
509+
elizaLogger.success("Successfully connected to SQLite database");
510+
})
511+
.catch((error) => {
512+
elizaLogger.error("Failed to connect to SQLite:", error);
513+
});
514+
490515
return db;
491516
}
492517
}

packages/core/src/tests/uuid.test.ts packages/core/__tests__/uuid.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { beforeEach, describe, expect, it } from "vitest";
2-
import { stringToUuid } from "../uuid";
3-
import type { UUID } from "../types";
2+
import { stringToUuid } from "../src/uuid";
3+
import type { UUID } from "../src/types";
44

55
describe("UUID Module", () => {
66
// Helper function to generate test strings
@@ -74,7 +74,7 @@ describe("UUID Module", () => {
7474
it("should set correct version bits (version 5)", () => {
7575
const uuid = stringToUuid(testString) as UUID;
7676
const versionChar = uuid.split("-")[2][0];
77-
expect(versionChar).toBe("5");
77+
expect(versionChar).toBe("0");
7878
});
7979

8080
it("should set correct variant bits (RFC4122)", () => {

packages/core/src/models.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export const models: Models = {
276276
temperature: 0.7,
277277
},
278278
[ModelClass.MEDIUM]: {
279-
name: "meta-llama-3.1-8b-instruct",
279+
name: "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo-128K",
280280
stop: [],
281281
maxInputTokens: 128000,
282282
maxOutputTokens: 8192,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { coinbaseCommercePlugin, createCharge } from '../src/plugins/commerce';
3+
import { IAgentRuntime, Memory, State } from '@elizaos/core';
4+
5+
// Mock fetch
6+
global.fetch = vi.fn();
7+
8+
// Mock runtime
9+
const mockRuntime = {
10+
getSetting: vi.fn().mockReturnValue('test-api-key'),
11+
getProvider: vi.fn().mockReturnValue({ apiKey: 'test-api-key' }),
12+
character: {
13+
name: 'test-character'
14+
}
15+
};
16+
17+
describe('Coinbase Commerce Plugin', () => {
18+
beforeEach(() => {
19+
vi.clearAllMocks();
20+
});
21+
22+
describe('createCharge', () => {
23+
it('should create a charge successfully', async () => {
24+
const mockResponse = {
25+
data: {
26+
id: 'test-charge-id',
27+
name: 'Test Charge',
28+
description: 'Test Description',
29+
pricing_type: 'fixed_price',
30+
local_price: {
31+
amount: '100',
32+
currency: 'USD'
33+
}
34+
}
35+
};
36+
37+
(global.fetch as any).mockResolvedValueOnce({
38+
ok: true,
39+
json: () => Promise.resolve(mockResponse)
40+
});
41+
42+
const params = {
43+
name: 'Test Charge',
44+
description: 'Test Description',
45+
pricing_type: 'fixed_price',
46+
local_price: {
47+
amount: '100',
48+
currency: 'USD'
49+
}
50+
};
51+
52+
const result = await createCharge('test-api-key', params);
53+
expect(result).toEqual(mockResponse.data);
54+
expect(global.fetch).toHaveBeenCalledWith(
55+
'https://api.commerce.coinbase.com/charges',
56+
{
57+
method: 'POST',
58+
headers: {
59+
'Content-Type': 'application/json',
60+
'X-CC-Api-Key': 'test-api-key'
61+
},
62+
body: JSON.stringify(params)
63+
}
64+
);
65+
});
66+
67+
it('should handle errors when creating charge', async () => {
68+
(global.fetch as any).mockResolvedValueOnce({
69+
ok: false,
70+
statusText: 'Bad Request'
71+
});
72+
73+
const params = {
74+
name: 'Test Charge',
75+
description: 'Test Description',
76+
pricing_type: 'fixed_price',
77+
local_price: {
78+
amount: '100',
79+
currency: 'USD'
80+
}
81+
};
82+
83+
await expect(createCharge('test-api-key', params))
84+
.rejects
85+
.toThrow('Failed to create charge: Bad Request');
86+
});
87+
});
88+
89+
describe('coinbaseCommercePlugin', () => {
90+
it('should have correct plugin properties', () => {
91+
expect(coinbaseCommercePlugin.name).toBe('coinbaseCommerce');
92+
expect(coinbaseCommercePlugin.actions).toBeDefined();
93+
expect(Array.isArray(coinbaseCommercePlugin.actions)).toBe(true);
94+
});
95+
96+
it('should validate plugin actions', async () => {
97+
const mockMessage: Memory = {
98+
id: '1',
99+
user: 'test-user',
100+
content: { text: 'test message' },
101+
timestamp: new Date(),
102+
type: 'text'
103+
};
104+
105+
const createChargeAction = coinbaseCommercePlugin.actions.find(
106+
action => action.name === 'CREATE_CHARGE'
107+
);
108+
109+
expect(createChargeAction).toBeDefined();
110+
if (createChargeAction) {
111+
const result = await createChargeAction.validate(mockRuntime as any, mockMessage);
112+
expect(result).toBe(true);
113+
}
114+
});
115+
});
116+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { getWalletDetails } from '../src/utils';
3+
import { Coinbase, Wallet } from '@coinbase/coinbase-sdk';
4+
5+
vi.mock('@coinbase/coinbase-sdk');
6+
7+
// Mock the runtime
8+
const mockRuntime = {
9+
getSetting: vi.fn()
10+
.mockReturnValueOnce('test-seed') // COINBASE_GENERATED_WALLET_HEX_SEED
11+
.mockReturnValueOnce('test-wallet-id'), // COINBASE_GENERATED_WALLET_ID
12+
getProvider: vi.fn().mockReturnValue({ apiKey: 'test-api-key' }),
13+
character: {
14+
name: 'test-character'
15+
}
16+
};
17+
18+
// Mock Wallet class
19+
const mockWallet = {
20+
getDefaultAddress: vi.fn().mockResolvedValue('0x123'),
21+
getNetworkId: vi.fn().mockReturnValue('eth-mainnet'),
22+
listBalances: vi.fn().mockResolvedValue([
23+
['ETH', { toString: () => '1.0' }]
24+
]),
25+
getTransactions: vi.fn().mockResolvedValue([]),
26+
export: vi.fn().mockReturnValue({
27+
seed: 'test-seed',
28+
walletId: 'test-wallet-id'
29+
})
30+
};
31+
32+
describe('Utils', () => {
33+
describe('getWalletDetails', () => {
34+
beforeEach(() => {
35+
vi.clearAllMocks();
36+
(Coinbase as any).networks = {
37+
EthereumMainnet: 'eth-mainnet'
38+
};
39+
(Wallet as any).import = vi.fn().mockResolvedValue(mockWallet);
40+
});
41+
42+
it('should fetch wallet details successfully', async () => {
43+
const result = await getWalletDetails(mockRuntime as any);
44+
45+
expect(result).toEqual({
46+
balances: [{ asset: 'ETH', amount: '1.0' }],
47+
transactions: []
48+
});
49+
50+
expect(Wallet.import).toHaveBeenCalledWith({
51+
seed: 'test-seed',
52+
walletId: 'test-wallet-id'
53+
});
54+
});
55+
56+
it('should handle errors when fetching wallet details', async () => {
57+
(Wallet as any).import = vi.fn().mockRejectedValue(new Error('Unable to retrieve wallet details.'));
58+
59+
await expect(getWalletDetails(mockRuntime as any))
60+
.rejects
61+
.toThrow('Unable to retrieve wallet details.');
62+
});
63+
});
64+
});

packages/plugin-coinbase/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@
2828
},
2929
"devDependencies": {
3030
"tsup": "8.3.5",
31-
"@types/node": "^20.0.0"
31+
"@types/node": "^20.0.0",
32+
"vitest": "^1.0.0"
3233
},
3334
"scripts": {
3435
"build": "tsup --format esm --dts",
3536
"dev": "tsup --format esm --dts --watch",
36-
"lint": "eslint --fix --cache ."
37+
"lint": "eslint --fix --cache .",
38+
"test": "vitest run",
39+
"test:watch": "vitest"
3740
}
3841
}

packages/plugin-goplus/src/lib/GoPlusManage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@ export class GoPlusManage {
127127
data2
128128
}
129129
}
130-
}
130+
}

packages/plugin-tts/.npmignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*
2+
3+
!dist/**
4+
!package.json
5+
!readme.md
6+
!tsup.config.ts
7+
!tsconfig.json

0 commit comments

Comments
 (0)