mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
feat(chat): render Code Mode execute calls with a dedicated card
This commit is contained in:
1 parent
9075ab1101
commit
f67c3e33b2
6 files changed
+572
-58
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { clampDisplayText } from './clampDisplayText'
|
||||
|
||||
const line = (index: number) => `line ${index} ${'x'.repeat(20)}`
|
||||
|
||||
describe('clampDisplayText', () => {
|
||||
it('returns short text unchanged', () => {
|
||||
const text = 'short output\nwith two lines'
|
||||
|
||||
expect(clampDisplayText(text)).toBe(text)
|
||||
})
|
||||
|
||||
it('shortens text over the display limit while keeping the head and tail', () => {
|
||||
const lines = Array.from({ length: 2000 }, (_, index) => line(index))
|
||||
const text = lines.join('\n')
|
||||
|
||||
const clamped = clampDisplayText(text)
|
||||
|
||||
expect(clamped.length).toBeLessThan(text.length)
|
||||
expect(clamped).toContain('omitted — use the copy button')
|
||||
expect(clamped.startsWith(lines[0])).toBe(true)
|
||||
expect(clamped.endsWith(lines[lines.length - 1])).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,21 @@
|
||||
const DISPLAY_LIMIT = 30_000
|
||||
const DISPLAY_HEAD_LENGTH = 20_000
|
||||
const DISPLAY_TAIL_LENGTH = 10_000
|
||||
|
||||
function formatOmittedSize(size: number): string {
|
||||
return size < 1024 * 1024
|
||||
? `${(size / 1024).toFixed(1)} KB`
|
||||
: `${(size / (1024 * 1024)).toFixed(1)} MB`
|
||||
}
|
||||
|
||||
export function clampDisplayText(text: string): string {
|
||||
if (text.length <= DISPLAY_LIMIT) return text
|
||||
const headCut = text.lastIndexOf('\n', DISPLAY_HEAD_LENGTH)
|
||||
const head = headCut === -1 ? text.slice(0, DISPLAY_HEAD_LENGTH) : text.slice(0, headCut)
|
||||
const tailFrom = text.length - DISPLAY_TAIL_LENGTH
|
||||
const tailCut = text.indexOf('\n', tailFrom)
|
||||
const tail = tailCut === -1 ? text.slice(tailFrom) : text.slice(tailCut + 1)
|
||||
const omitted = formatOmittedSize(text.length - head.length - tail.length)
|
||||
const marker = `\n[… ${omitted} omitted — use the copy button for the full output …]\n`
|
||||
return head + marker + tail
|
||||
}
|
||||
Reference in new issue
Block a user