(payload: GetCodeResult)
| 29 | } |
| 30 | |
| 31 | export function utf8Bytes(value: unknown): number { |
| 32 | const serialized = |
| 33 | typeof value === 'string' ? value : (JSON.stringify(value, null, 0) ?? 'undefined') |
| 34 | return ENCODER.encode(serialized).length |
| 35 | } |
| 36 | |
| 37 | export function measureCallToolResultBytes(result: ToolResponseLike): number { |
| 38 | return utf8Bytes(result) |
| 39 | } |
| 40 | |
| 41 | export function buildGetCodeToolResult(payload: GetCodeResult): ToolResponseLike { |
| 42 | const summary: string[] = [] |
| 43 | const codeSize = utf8Bytes(payload.code) |
| 44 | summary.push(`Generated \`${payload.lang}\` snippet (${formatBytes(codeSize)}).`) |
| 45 | |
| 46 | if (payload.warnings?.length) { |
| 47 | summary.push(...payload.warnings.map((warning) => warning.message)) |
| 48 | } |
| 49 | |
| 50 | summary.push( |
| 51 | payload.assets?.length |
| 52 | ? `Assets attached: ${payload.assets.length}. Use asset.localPath directly when present; otherwise download asset.url.` |
| 53 | : 'No binary assets were attached to this response.' |
| 54 | ) |
| 55 | |
| 56 | const tokenCount = payload.tokens ? Object.keys(payload.tokens).length : 0 |
| 57 | if (tokenCount) { |
no test coverage detected