🔄 refactor: Convert OCR Tool Resource to Context (#9699)

* WIP: conversion of `ocr` to `context`

* refactor: make `primeResources` backwards-compatible for `ocr` tool_resources

* refactor: Convert legacy `ocr` tool resource to `context` in agent updates

- Implemented conversion logic to replace `ocr` with `context` in both incoming updates and existing agent data.
- Merged file IDs and files from `ocr` into `context` while ensuring deduplication.
- Updated tools array to reflect the change from `ocr` to `context`.

* refactor: Enhance context file handling in agent processing

- Updated the logic for managing context files by consolidating file IDs from both `ocr` and `context` resources.
- Improved backwards compatibility by ensuring that context files are correctly populated and handled.
- Simplified the iteration over context files for better readability and maintainability.

* refactor: Enhance tool_resources handling in primeResources

- Added tests to verify the deletion behavior of tool_resources fields, ensuring original objects remain unchanged.
- Implemented logic to delete `ocr` and `context` fields after fetching and re-categorizing files.
- Preserved context field when the context capability is disabled, ensuring correct behavior in various scenarios.

* refactor: Replace `ocrEnabled` with `contextEnabled` in AgentConfig

* refactor: Adjust legacy tool handling order for improved clarity

* refactor: Implement OCR to context conversion functions and remove original conversion logic in update agent handling

* refactor: Move contextEnabled declaration to maintain consistent order in capabilities

* refactor: Update localization keys for file context to improve clarity and accuracy

* chore: Update localization key for file context information to improve clarity
This commit is contained in:
Danny Avila 2025-09-18 20:06:59 -04:00 committed by GitHub
parent 89d12a8ccd
commit 81139046e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 1281 additions and 76 deletions

View file

@ -253,7 +253,7 @@ export const validateFiles = ({
}
let mimeTypesToCheck = supportedMimeTypes;
if (toolResource === EToolResources.ocr) {
if (toolResource === EToolResources.context) {
mimeTypesToCheck = [
...(fileConfig?.text?.supportedMimeTypes || []),
...(fileConfig?.ocr?.supportedMimeTypes || []),

View file

@ -62,14 +62,19 @@ export const processAgentOption = ({
fileMap?: Record<string, TFile | undefined>;
}): TAgentOption => {
const isGlobal = _agent?.isPublic ?? false;
const context_files = _agent?.tool_resources?.context?.file_ids ?? [];
if (_agent?.tool_resources?.ocr?.file_ids) {
/** Backwards-compatibility */
context_files.push(..._agent.tool_resources.ocr.file_ids);
}
const agent: TAgentOption = {
...(_agent ?? ({} as Agent)),
label: _agent?.name ?? '',
value: _agent?.id ?? '',
icon: isGlobal ? <EarthIcon className="icon-md text-green-400" /> : null,
context_files: _agent?.tool_resources?.ocr?.file_ids
? ([] as Array<[string, ExtendedFile]>)
: undefined,
context_files: context_files.length > 0 ? ([] as Array<[string, ExtendedFile]>) : undefined,
knowledge_files: _agent?.tool_resources?.file_search?.file_ids
? ([] as Array<[string, ExtendedFile]>)
: undefined,
@ -130,12 +135,12 @@ export const processAgentOption = ({
}
};
if (agent.context_files && _agent?.tool_resources?.ocr?.file_ids) {
_agent.tool_resources.ocr.file_ids.forEach((file_id) =>
if (agent.context_files && context_files.length > 0) {
context_files.forEach((file_id) =>
handleFile({
file_id,
list: agent.context_files,
tool_resource: EToolResources.ocr,
tool_resource: EToolResources.context,
}),
);
}