| 224 | const offset = parseOptionalNumber(params.offset) |
| 225 | const limit = parseOptionalNumber(params.limit) |
| 226 | const applyWindow = <T extends { content: string; totalLines: number }>(result: T): T => { |
| 227 | if (offset === undefined && limit === undefined) return result |
| 228 | const lines = result.content.split('\n') |
| 229 | const start = Math.max(0, Math.min(result.totalLines, offset ?? 0)) |
| 230 | const endRaw = limit !== undefined ? start + Math.max(0, limit) : result.totalLines |
| 231 | const end = Math.max(start, Math.min(result.totalLines, endRaw)) |
| 232 | return { |
| 233 | ...result, |
| 234 | content: lines.slice(start, end).join('\n'), |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // Handle chat-scoped uploads via the uploads/ virtual prefix. |
| 239 | // Uploads are flat and have no metadata/content split like files/ — the upload |