Skip to content

Commit 84466c4

Browse files
committed
Merge branch 'fix/character-voice-settings' of https://github.com/augchan42/eliza into HEAD
2 parents 9acc0fb + 607daa9 commit 84466c4

File tree

6 files changed

+201
-155
lines changed

6 files changed

+201
-155
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "eliza",
33
"scripts": {
44
"preinstall": "npx only-allow pnpm",
5-
"build": "turbo check-types build",
5+
"build": "turbo run build --filter=@ai16z/plugin-bootstrap^... --filter=@ai16z/eliza^...",
66
"start": "pnpm --filter \"@ai16z/agent\" start --isRoot",
77
"start:client": "pnpm --dir client start --isRoot",
88
"start:debug": "cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@ai16z/agent\" start --isRoot",
@@ -63,4 +63,4 @@
6363
"workspaces": [
6464
"packages/*"
6565
]
66-
}
66+
}

packages/adapter-postgres/src/index.ts

+33-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { v4 } from "uuid";
22

3-
// Import the entire module as default
4-
import pg from "pg";
5-
type Pool = pg.Pool;
3+
import postgres from "pg";
4+
const { Pool } = postgres;
5+
type PoolType = typeof postgres.Pool;
66

77
import {
88
QueryConfig,
@@ -32,10 +32,10 @@ const __filename = fileURLToPath(import.meta.url); // get the resolved path to t
3232
const __dirname = path.dirname(__filename); // get the name of the directory
3333

3434
export class PostgresDatabaseAdapter
35-
extends DatabaseAdapter<Pool>
35+
extends DatabaseAdapter<PoolType>
3636
implements IDatabaseCacheAdapter
3737
{
38-
private pool: Pool;
38+
private pool: InstanceType<PoolType>;
3939
private readonly maxRetries: number = 3;
4040
private readonly baseDelay: number = 1000; // 1 second
4141
private readonly maxDelay: number = 10000; // 10 seconds
@@ -51,7 +51,7 @@ export class PostgresDatabaseAdapter
5151
connectionTimeoutMillis: this.connectionTimeout,
5252
};
5353

54-
this.pool = new pg.Pool({
54+
this.pool = new Pool({
5555
...defaultConfig,
5656
...connectionConfig, // Allow overriding defaults
5757
});
@@ -137,7 +137,7 @@ export class PostgresDatabaseAdapter
137137
await this.pool.end();
138138

139139
// Create new pool
140-
this.pool = new pg.Pool({
140+
this.pool = new Pool({
141141
...this.pool.options,
142142
connectionTimeoutMillis: this.connectionTimeout,
143143
});
@@ -174,12 +174,33 @@ export class PostgresDatabaseAdapter
174174
async init() {
175175
await this.testConnection();
176176

177-
const schema = fs.readFileSync(
178-
path.resolve(__dirname, "../schema.sql"),
179-
"utf8"
180-
);
177+
const client = await this.pool.connect();
178+
try {
179+
await client.query("BEGIN");
180+
181+
// Check if schema already exists (check for a core table)
182+
const { rows } = await client.query(`
183+
SELECT EXISTS (
184+
SELECT FROM information_schema.tables
185+
WHERE table_name = 'rooms'
186+
);
187+
`);
188+
189+
if (!rows[0].exists) {
190+
const schema = fs.readFileSync(
191+
path.resolve(__dirname, "../schema.sql"),
192+
"utf8"
193+
);
194+
await client.query(schema);
195+
}
181196

182-
await this.query(schema);
197+
await client.query("COMMIT");
198+
} catch (error) {
199+
await client.query("ROLLBACK");
200+
throw error;
201+
} finally {
202+
client.release();
203+
}
183204
}
184205

185206
async close() {

packages/core/src/types.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,17 @@ export type Character = {
680680
secrets?: { [key: string]: string };
681681
buttplug?: boolean;
682682
voice?: {
683-
model?: string;
684-
url?: string;
683+
model?: string; // For VITS
684+
url?: string; // Legacy VITS support
685+
elevenlabs?: {
686+
// New structured ElevenLabs config
687+
voiceId: string;
688+
model?: string;
689+
stability?: string;
690+
similarityBoost?: string;
691+
style?: string;
692+
useSpeakerBoost?: string;
693+
};
685694
};
686695
model?: string;
687696
embeddingModel?: string;

packages/plugin-node/src/enviroment.ts

+55-44
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,21 @@ import { z } from "zod";
33

44
export const nodeEnvSchema = z.object({
55
OPENAI_API_KEY: z.string().min(1, "OpenAI API key is required"),
6+
7+
// Core settings
68
ELEVENLABS_XI_API_KEY: z.string().optional(),
7-
ELEVENLABS_MODEL_ID: z.string().min(1, "ElevenLabs model ID is required"),
8-
ELEVENLABS_VOICE_ID: z.string().min(1, "ElevenLabs voice ID is required"),
9-
ELEVENLABS_VOICE_STABILITY: z
10-
.string()
11-
.min(1, "ElevenLabs voice stability is required"),
12-
ELEVENLABS_VOICE_SIMILARITY_BOOST: z
13-
.string()
14-
.min(1, "ElevenLabs voice similarity boost is required"),
15-
ELEVENLABS_VOICE_STYLE: z
16-
.string()
17-
.min(1, "ElevenLabs voice style is required"),
18-
ELEVENLABS_VOICE_USE_SPEAKER_BOOST: z
19-
.string()
20-
.min(1, "ElevenLabs voice speaker boost setting is required"),
21-
ELEVENLABS_OPTIMIZE_STREAMING_LATENCY: z
22-
.string()
23-
.min(1, "ElevenLabs streaming latency optimization is required"),
24-
ELEVENLABS_OUTPUT_FORMAT: z
25-
.string()
26-
.min(1, "ElevenLabs output format is required"),
9+
10+
// All other settings optional with defaults
11+
ELEVENLABS_MODEL_ID: z.string().optional(),
12+
ELEVENLABS_VOICE_ID: z.string().optional(),
13+
ELEVENLABS_VOICE_STABILITY: z.string().optional(),
14+
ELEVENLABS_VOICE_SIMILARITY_BOOST: z.string().optional(),
15+
ELEVENLABS_VOICE_STYLE: z.string().optional(),
16+
ELEVENLABS_VOICE_USE_SPEAKER_BOOST: z.string().optional(),
17+
ELEVENLABS_OPTIMIZE_STREAMING_LATENCY: z.string().optional(),
18+
ELEVENLABS_OUTPUT_FORMAT: z.string().optional(),
19+
VITS_VOICE: z.string().optional(),
20+
VITS_MODEL: z.string().optional(),
2721
});
2822

2923
export type NodeConfig = z.infer<typeof nodeEnvSchema>;
@@ -32,34 +26,51 @@ export async function validateNodeConfig(
3226
runtime: IAgentRuntime
3327
): Promise<NodeConfig> {
3428
try {
29+
const voiceSettings = runtime.character.settings?.voice;
30+
const elevenlabs = voiceSettings?.elevenlabs;
31+
32+
// Only include what's absolutely required
3533
const config = {
3634
OPENAI_API_KEY:
3735
runtime.getSetting("OPENAI_API_KEY") ||
3836
process.env.OPENAI_API_KEY,
39-
ELEVENLABS_MODEL_ID:
40-
runtime.getSetting("ELEVENLABS_MODEL_ID") ||
41-
process.env.ELEVENLABS_MODEL_ID,
42-
ELEVENLABS_VOICE_ID:
43-
runtime.getSetting("ELEVENLABS_VOICE_ID") ||
44-
process.env.ELEVENLABS_VOICE_ID,
45-
ELEVENLABS_VOICE_STABILITY:
46-
runtime.getSetting("ELEVENLABS_VOICE_STABILITY") ||
47-
process.env.ELEVENLABS_VOICE_STABILITY,
48-
ELEVENLABS_VOICE_SIMILARITY_BOOST:
49-
runtime.getSetting("ELEVENLABS_VOICE_SIMILARITY_BOOST") ||
50-
process.env.ELEVENLABS_VOICE_SIMILARITY_BOOST,
51-
ELEVENLABS_VOICE_STYLE:
52-
runtime.getSetting("ELEVENLABS_VOICE_STYLE") ||
53-
process.env.ELEVENLABS_VOICE_STYLE,
54-
ELEVENLABS_VOICE_USE_SPEAKER_BOOST:
55-
runtime.getSetting("ELEVENLABS_VOICE_USE_SPEAKER_BOOST") ||
56-
process.env.ELEVENLABS_VOICE_USE_SPEAKER_BOOST,
57-
ELEVENLABS_OPTIMIZE_STREAMING_LATENCY:
58-
runtime.getSetting("ELEVENLABS_OPTIMIZE_STREAMING_LATENCY") ||
59-
process.env.ELEVENLABS_OPTIMIZE_STREAMING_LATENCY,
60-
ELEVENLABS_OUTPUT_FORMAT:
61-
runtime.getSetting("ELEVENLABS_OUTPUT_FORMAT") ||
62-
process.env.ELEVENLABS_OUTPUT_FORMAT,
37+
ELEVENLABS_XI_API_KEY:
38+
runtime.getSetting("ELEVENLABS_XI_API_KEY") ||
39+
process.env.ELEVENLABS_XI_API_KEY,
40+
41+
// Use character card settings first, fall back to env vars, then defaults
42+
...(runtime.getSetting("ELEVENLABS_XI_API_KEY") && {
43+
ELEVENLABS_MODEL_ID:
44+
elevenlabs?.model ||
45+
process.env.ELEVENLABS_MODEL_ID ||
46+
"eleven_monolingual_v1",
47+
ELEVENLABS_VOICE_ID:
48+
elevenlabs?.voiceId || process.env.ELEVENLABS_VOICE_ID,
49+
ELEVENLABS_VOICE_STABILITY:
50+
elevenlabs?.stability ||
51+
process.env.ELEVENLABS_VOICE_STABILITY ||
52+
"0.5",
53+
ELEVENLABS_VOICE_SIMILARITY_BOOST:
54+
elevenlabs?.similarityBoost ||
55+
process.env.ELEVENLABS_VOICE_SIMILARITY_BOOST ||
56+
"0.75",
57+
ELEVENLABS_VOICE_STYLE:
58+
elevenlabs?.style ||
59+
process.env.ELEVENLABS_VOICE_STYLE ||
60+
"0",
61+
ELEVENLABS_VOICE_USE_SPEAKER_BOOST:
62+
elevenlabs?.useSpeakerBoost ||
63+
process.env.ELEVENLABS_VOICE_USE_SPEAKER_BOOST ||
64+
"true",
65+
ELEVENLABS_OPTIMIZE_STREAMING_LATENCY:
66+
process.env.ELEVENLABS_OPTIMIZE_STREAMING_LATENCY || "0",
67+
ELEVENLABS_OUTPUT_FORMAT:
68+
process.env.ELEVENLABS_OUTPUT_FORMAT || "pcm_16000",
69+
}),
70+
71+
// VITS settings
72+
VITS_VOICE: voiceSettings?.model || process.env.VITS_VOICE,
73+
VITS_MODEL: process.env.VITS_MODEL,
6374
};
6475

6576
return nodeEnvSchema.parse(config);

0 commit comments

Comments
 (0)