summaryrefslogtreecommitdiff
path: root/packages/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server/src')
-rw-r--r--packages/server/src/core/client.ts19
-rw-r--r--packages/server/src/utils/BackgroundTerminalAnalyzer.ts5
2 files changed, 13 insertions, 11 deletions
diff --git a/packages/server/src/core/client.ts b/packages/server/src/core/client.ts
index e65e58a7..e930be6c 100644
--- a/packages/server/src/core/client.ts
+++ b/packages/server/src/core/client.ts
@@ -12,15 +12,16 @@ import {
SchemaUnion,
PartListUnion,
Content,
- FunctionDeclaration,
Tool,
} from '@google/genai';
import { CoreSystemPrompt } from './prompts.js';
import process from 'node:process';
import { getFolderStructure } from '../utils/getFolderStructure.js';
-import { Turn, ServerTool, ServerGeminiStreamEvent } from './turn.js';
+import { Turn, ServerGeminiStreamEvent } from './turn.js';
+import { Config } from '../config/config.js';
export class GeminiClient {
+ private config: Config;
private client: GoogleGenAI;
private model: string;
private generateContentConfig: GenerateContentConfig = {
@@ -29,9 +30,10 @@ export class GeminiClient {
};
private readonly MAX_TURNS = 100;
- constructor(apiKey: string, model: string) {
- this.client = new GoogleGenAI({ apiKey: apiKey });
- this.model = model;
+ constructor(config: Config) {
+ this.client = new GoogleGenAI({ apiKey: config.getApiKey() });
+ this.config = config;
+ this.model = config.getModel();
}
private async getEnvironment(): Promise<Part> {
@@ -54,8 +56,11 @@ export class GeminiClient {
return { text: context };
}
- async startChat(toolDeclarations: FunctionDeclaration[]): Promise<Chat> {
+ async startChat(): Promise<Chat> {
const envPart = await this.getEnvironment();
+ const toolDeclarations = this.config
+ .getToolRegistry()
+ .getFunctionDeclarations();
const tools: Tool[] = [{ functionDeclarations: toolDeclarations }];
try {
return this.client.chats.create({
@@ -86,10 +91,10 @@ export class GeminiClient {
async *sendMessageStream(
chat: Chat,
request: PartListUnion,
- availableTools: ServerTool[],
signal?: AbortSignal,
): AsyncGenerator<ServerGeminiStreamEvent> {
let turns = 0;
+ const availableTools = this.config.getToolRegistry().getAllTools();
try {
while (turns < this.MAX_TURNS) {
turns++;
diff --git a/packages/server/src/utils/BackgroundTerminalAnalyzer.ts b/packages/server/src/utils/BackgroundTerminalAnalyzer.ts
index 625b06b6..c63fbb57 100644
--- a/packages/server/src/utils/BackgroundTerminalAnalyzer.ts
+++ b/packages/server/src/utils/BackgroundTerminalAnalyzer.ts
@@ -78,10 +78,7 @@ export class BackgroundTerminalAnalyzer {
) {
try {
// Initialize Gemini client using config
- this.geminiClient = new GeminiClient(
- config.getApiKey(),
- config.getModel(),
- );
+ this.geminiClient = new GeminiClient(config);
} catch (error) {
console.error(
'Failed to initialize GeminiClient in BackgroundTerminalAnalyzer:',