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:
parent
691a3523e8
commit
51c05f98ee
|
|
@ -17,7 +17,6 @@ import { Injectable, Logger } from '@nestjs/common';
|
||||||
import Anthropic from '@anthropic-ai/sdk';
|
import Anthropic from '@anthropic-ai/sdk';
|
||||||
import {
|
import {
|
||||||
ContextType,
|
ContextType,
|
||||||
ContextData,
|
|
||||||
ContextInjectionBlock,
|
ContextInjectionBlock,
|
||||||
ContextInjectionResult,
|
ContextInjectionResult,
|
||||||
ContextInjectorConfig,
|
ContextInjectorConfig,
|
||||||
|
|
@ -27,13 +26,7 @@ import {
|
||||||
DEFAULT_CONTEXT_CONFIG,
|
DEFAULT_CONTEXT_CONFIG,
|
||||||
} from '../types/context.types';
|
} from '../types/context.types';
|
||||||
import { ClaudeMessage } from '../types/agent.types';
|
import { ClaudeMessage } from '../types/agent.types';
|
||||||
|
import { KnowledgeClientService } from '../../knowledge/knowledge-client.service';
|
||||||
/** 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 }>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ContextInjectorService {
|
export class ContextInjectorService {
|
||||||
|
|
@ -42,7 +35,7 @@ export class ContextInjectorService {
|
||||||
private config: ContextInjectorConfig = DEFAULT_CONTEXT_CONFIG;
|
private config: ContextInjectorConfig = DEFAULT_CONTEXT_CONFIG;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly knowledgeClient: IKnowledgeClient,
|
private readonly knowledgeClient: KnowledgeClientService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -220,14 +213,14 @@ export class ContextInjectorService {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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;
|
if (!memories || memories.length === 0) return null;
|
||||||
|
|
||||||
const content = [
|
const content = [
|
||||||
`<user_memory>`,
|
`<user_memory>`,
|
||||||
`用户历史记忆 (${memories.length} 条):`,
|
`用户历史记忆 (${memories.length} 条):`,
|
||||||
...memories.map(m =>
|
...memories.map(m =>
|
||||||
` - [${m.type}] ${m.content} (重要度: ${m.importance})`
|
` - [${m.memoryType}] ${m.content} (重要度: ${m.importance})`
|
||||||
),
|
),
|
||||||
`</user_memory>`,
|
`</user_memory>`,
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
@ -294,9 +287,9 @@ export class ContextInjectorService {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const knowledge = await this.knowledgeClient.retrieveForPrompt(
|
const knowledge = await this.knowledgeClient.retrieveForPrompt({
|
||||||
query, ctx.userId,
|
query, userId: ctx.userId,
|
||||||
);
|
});
|
||||||
if (!knowledge) return null;
|
if (!knowledge) return null;
|
||||||
|
|
||||||
const content = [
|
const content = [
|
||||||
|
|
@ -335,14 +328,14 @@ export class ContextInjectorService {
|
||||||
if (!query) return null;
|
if (!query) return null;
|
||||||
|
|
||||||
try {
|
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;
|
if (!experiences || experiences.length === 0) return null;
|
||||||
|
|
||||||
const content = [
|
const content = [
|
||||||
`<system_experiences>`,
|
`<system_experiences>`,
|
||||||
`相关系统经验:`,
|
`相关系统经验:`,
|
||||||
...experiences.map(e =>
|
...experiences.map(e =>
|
||||||
` - [${e.type}] ${e.content} (置信度: ${e.confidence}%)`
|
` - [${e.experienceType}] ${e.content} (置信度: ${e.confidence}%)`
|
||||||
),
|
),
|
||||||
`</system_experiences>`,
|
`</system_experiences>`,
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue