GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — claude-code-source-code/src/utils/contentArray.ts at main · memoryblade/claude-code-source-code Expand file tree/ Copy pathcontentArray.tsMore file actions 51 lines (49 loc) · 1.58 KB / Copy pathcontentArray.tsFile metadata and controls51 lines (49 loc) · 1.58 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 /** * Utility for inserting a block into a content array relative to tool_result * blocks. Used by the API layer to position supplementary content (e.g., * cache editing directives) correctly within user messages. * * Placement rules: * - If tool_result blocks exist: insert after the last one * - Otherwise: insert before the last block * - If the inserted block would be the final element, a text continuation * block is appended (some APIs require the prompt not to end with * non-text content) */ /** * Inserts a block into the content array after the last tool_result block. * Mutates the array in place. * * @param content - The content array to modify * @param block - The block to insert */ export function insertBlockAfterToolResults( content: unknown[], block: unknown, ): void { // Find position after the last tool_result block let lastToolResultIndex = -1 for (let i = 0; i < content.length; i++) { const item = content[i] if ( item && typeof item === 'object' && 'type' in item && (item as { type: string }).type === 'tool_result' ) { lastToolResultIndex = i } } if (lastToolResultIndex >= 0) { const insertPos = lastToolResultIndex + 1 content.splice(insertPos, 0, block) // Append a text continuation if the inserted block is now last if (insertPos === content.length - 1) { content.push({ type: 'text', text: '.' }) } } else { // No tool_result blocks — insert before the last block const insertIndex = Math.max(0, content.length - 1) content.splice(insertIndex, 0, block) } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |