chore(server): add detail for error (#13151)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Error messages for unavailable copilot providers now include specific
model IDs for clearer context.
* Added new detailed error messages for embedding generation failures
specifying provider and error details.
* The API and GraphQL schema have been extended with new error types
reflecting these detailed error cases.

* **Bug Fixes**
* Enhanced error handling to detect and report incomplete or missing
embeddings from providers.
* Added safeguards to skip embedding insertions when no embeddings are
provided, preventing unnecessary processing.

* **Documentation**
* Updated localization and translation keys to support dynamic error
messages with model IDs and provider details.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2025-07-11 13:55:10 +08:00
committed by GitHub
parent b79439b01d
commit 2052a34d19
13 changed files with 100 additions and 12 deletions

View File

@@ -125,7 +125,10 @@ export class CopilotContextService implements OnApplicationBootstrap {
async get(id: string): Promise<ContextSession> {
if (!this.embeddingClient) {
throw new NoCopilotProviderAvailable('embedding client not configured');
throw new NoCopilotProviderAvailable(
{ modelId: 'embedding' },
'embedding client not configured'
);
}
const context = await this.getCachedSession(id);

View File

@@ -124,7 +124,7 @@ export class CopilotController implements BeforeApplicationShutdown {
modelId: model,
});
if (!provider) {
throw new NoCopilotProviderAvailable();
throw new NoCopilotProviderAvailable({ modelId: model });
}
return { provider, model, hasAttachment };

View File

@@ -5,6 +5,7 @@ import {
CopilotPromptNotFound,
CopilotProviderNotSupported,
} from '../../../base';
import { CopilotFailedToGenerateEmbedding } from '../../../base/error/errors.gen';
import { ChunkSimilarity, Embedding } from '../../../models';
import { PromptService } from '../prompt';
import {
@@ -74,6 +75,12 @@ class ProductionEmbeddingClient extends EmbeddingClient {
input,
{ dimensions: EMBEDDING_DIMENSIONS }
);
if (embeddings.length !== input.length) {
throw new CopilotFailedToGenerateEmbedding({
provider: provider.type,
message: `Expected ${input.length} embeddings, got ${embeddings.length}`,
});
}
return Array.from(embeddings.entries()).map(([index, embedding]) => ({
index,

View File

@@ -569,7 +569,7 @@ export class ChatSessionService {
});
if (!provider) {
throw new NoCopilotProviderAvailable();
throw new NoCopilotProviderAvailable({ modelId: prompt.model });
}
return provider.text(cond, [...prompt.finish({}), msg], config);

View File

@@ -171,7 +171,7 @@ export class CopilotTranscriptionService {
);
if (!provider) {
throw new NoCopilotProviderAvailable();
throw new NoCopilotProviderAvailable({ modelId });
}
return provider;