fix(agents): resolve ContextInjectorService DI error by replacing interface with concrete class

- 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 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-06 08:10:40 -08:00
parent 691a3523e8
commit 51c05f98ee
1 changed files with 9 additions and 16 deletions

View File

@ -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<string>;
getUserMemories(userId: string, limit?: number): Promise<Array<{ type: string; content: string; importance: number; createdAt: string }>>;
getRelevantExperiences(query: string, limit?: number): Promise<Array<{ type: string; content: string; confidence: number }>>;
}
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 = [
`<user_memory>`,
`用户历史记忆 (${memories.length} 条):`,
...memories.map(m =>
` - [${m.type}] ${m.content} (重要度: ${m.importance})`
` - [${m.memoryType}] ${m.content} (重要度: ${m.importance})`
),
`</user_memory>`,
].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 = [
`<system_experiences>`,
`相关系统经验:`,
...experiences.map(e =>
` - [${e.type}] ${e.content} (置信度: ${e.confidence}%)`
` - [${e.experienceType}] ${e.content} (置信度: ${e.confidence}%)`
),
`</system_experiences>`,
].join('\n');