* Strips internal fields (keys starting with `__`) from tool output before * returning to users. The double-underscore prefix is reserved for transient * data (e.g. `__costDollars`) and will never collide with legitimate API * fields like `_id`.
(output: Record<string, unknown>)
| 616 | * fields like `_id`. |
| 617 | */ |
| 618 | function stripInternalFields(output: Record<string, unknown>): Record<string, unknown> { |
| 619 | if (typeof output !== 'object' || output === null || Array.isArray(output)) { |
| 620 | return output |
| 621 | } |
| 622 | const result: Record<string, unknown> = {} |
| 623 | for (const [key, value] of Object.entries(output)) { |
| 624 | if (!key.startsWith('__')) { |
| 625 | result[key] = value |
| 626 | } |
| 627 | } |
| 628 | return result |
| 629 | } |
| 630 | |
| 631 | export function postProcessToolOutput(toolId: string, output: Record<string, unknown>) { |
| 632 | return isCustomTool(toolId) ? output : stripInternalFields(output) |
no outgoing calls
no test coverage detected