From 51c05f98ee32d611cff8bbb00a80fbdada8cde57 Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 6 Feb 2026 08:10:40 -0800 Subject: [PATCH] fix(agents): resolve ContextInjectorService DI error by replacing interface with concrete class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace IKnowledgeClient TypeScript interface (erased at runtime) with KnowledgeClientService concrete class injection - Fix method signatures to match KnowledgeClientService API: - getUserMemories() → getUserTopMemories(), field type → memoryType - retrieveForPrompt(query, userId) → retrieveForPrompt({ query, userId }) - getRelevantExperiences(query, n) → searchExperiences({ query, limit: n }), field type → experienceType - Remove unused ContextData import Co-Authored-By: Claude Opus 4.6 --- .../coordinator/context-injector.service.ts | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/packages/services/conversation-service/src/infrastructure/agents/coordinator/context-injector.service.ts b/packages/services/conversation-service/src/infrastructure/agents/coordinator/context-injector.service.ts index 94f18f9..809ac97 100644 --- a/packages/services/conversation-service/src/infrastructure/agents/coordinator/context-injector.service.ts +++ b/packages/services/conversation-service/src/infrastructure/agents/coordinator/context-injector.service.ts @@ -17,7 +17,6 @@ import { Injectable, Logger } from '@nestjs/common'; import Anthropic from '@anthropic-ai/sdk'; import { ContextType, - ContextData, ContextInjectionBlock, ContextInjectionResult, ContextInjectorConfig, @@ -27,13 +26,7 @@ import { DEFAULT_CONTEXT_CONFIG, } from '../types/context.types'; import { ClaudeMessage } from '../types/agent.types'; - -/** Dependency: knowledge service client */ -export interface IKnowledgeClient { - retrieveForPrompt(query: string, userId: string, category?: string): Promise; - getUserMemories(userId: string, limit?: number): Promise>; - getRelevantExperiences(query: string, limit?: number): Promise>; -} +import { KnowledgeClientService } from '../../knowledge/knowledge-client.service'; @Injectable() export class ContextInjectorService { @@ -42,7 +35,7 @@ export class ContextInjectorService { private config: ContextInjectorConfig = DEFAULT_CONTEXT_CONFIG; constructor( - private readonly knowledgeClient: IKnowledgeClient, + private readonly knowledgeClient: KnowledgeClientService, ) {} /** @@ -220,14 +213,14 @@ export class ContextInjectorService { } try { - const memories = await this.knowledgeClient.getUserMemories(ctx.userId, 10); + const memories = await this.knowledgeClient.getUserTopMemories(ctx.userId, 10); if (!memories || memories.length === 0) return null; const content = [ ``, `用户历史记忆 (${memories.length} 条):`, ...memories.map(m => - ` - [${m.type}] ${m.content} (重要度: ${m.importance})` + ` - [${m.memoryType}] ${m.content} (重要度: ${m.importance})` ), ``, ].join('\n'); @@ -294,9 +287,9 @@ export class ContextInjectorService { } try { - const knowledge = await this.knowledgeClient.retrieveForPrompt( - query, ctx.userId, - ); + const knowledge = await this.knowledgeClient.retrieveForPrompt({ + query, userId: ctx.userId, + }); if (!knowledge) return null; const content = [ @@ -335,14 +328,14 @@ export class ContextInjectorService { if (!query) return null; try { - const experiences = await this.knowledgeClient.getRelevantExperiences(query, 3); + const experiences = await this.knowledgeClient.searchExperiences({ query, limit: 3 }); if (!experiences || experiences.length === 0) return null; const content = [ ``, `相关系统经验:`, ...experiences.map(e => - ` - [${e.type}] ${e.content} (置信度: ${e.confidence}%)` + ` - [${e.experienceType}] ${e.content} (置信度: ${e.confidence}%)` ), ``, ].join('\n');