feat(server): add hints for context files (#13444)

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

* **New Features**
* Attachments (files) are now included in the conversation context,
allowing users to reference files during chat sessions.
* Added a new "blobRead" tool enabling secure, permission-checked
reading of attachment content in chat sessions.

* **Improvements**
* Enhanced chat session preparation to always include relevant context
files.
* System messages now clearly display attached files and selected
content only when available, improving context clarity for users.
* Updated tool-calling guidelines to ensure user workspace is searched
even when attachment content suffices.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2025-08-08 17:32:52 +08:00
committed by GitHub
parent 4005f40b16
commit 3cfb0a43af
9 changed files with 172 additions and 14 deletions
@@ -45,6 +45,7 @@ import {
UnsplashIsNotConfigured,
} from '../../base';
import { CurrentUser, Public } from '../../core/auth';
import { CopilotContextService } from './context';
import {
CopilotProvider,
CopilotProviderFactory,
@@ -75,6 +76,7 @@ export class CopilotController implements BeforeApplicationShutdown {
constructor(
private readonly config: Config,
private readonly chatSession: ChatSessionService,
private readonly context: CopilotContextService,
private readonly provider: CopilotProviderFactory,
private readonly workflow: CopilotWorkflowService,
private readonly storage: CopilotStorage
@@ -204,14 +206,24 @@ export class CopilotController implements BeforeApplicationShutdown {
retry
);
if (latestMessage) {
params = Object.assign({}, params, latestMessage.params, {
content: latestMessage.content,
attachments: latestMessage.attachments,
});
}
const context = await this.context.getBySessionId(sessionId);
const contextParams =
Array.isArray(context?.files) && context.files.length > 0
? { contextFiles: context.files }
: {};
const lastParams = latestMessage
? {
...latestMessage.params,
content: latestMessage.content,
attachments: latestMessage.attachments,
}
: {};
const finalMessage = session.finish(params);
const finalMessage = session.finish({
...params,
...lastParams,
...contextParams,
});
return {
provider,