tftsr-devops_investigation/node_modules/b4a/lib/utf8.js

142 lines
2.6 KiB
JavaScript
Raw Normal View History

feat: initial implementation of TFTSR IT Triage & RCA application Implements Phases 1-8 of the TFTSR implementation plan. Rust backend (Tauri 2.x, src-tauri/): - Multi-provider AI: OpenAI-compatible, Anthropic, Gemini, Mistral, Ollama - PII detection engine: 11 regex patterns with overlap resolution - SQLCipher AES-256 encrypted database with 10 versioned migrations - 28 Tauri IPC commands for triage, analysis, document, and system ops - Ollama: hardware probe, model recommendations, pull/delete with events - RCA and blameless post-mortem Markdown document generators - PDF export via printpdf - Audit log: SHA-256 hash of every external data send - Integration stubs for Confluence, ServiceNow, Azure DevOps (v0.2) Frontend (React 18 + TypeScript + Vite, src/): - 9 pages: full triage workflow NewIssue→LogUpload→Triage→Resolution→RCA→Postmortem→History+Settings - 7 components: ChatWindow, TriageProgress, PiiDiffViewer, DocEditor, HardwareReport, ModelSelector, UI primitives - 3 Zustand stores: session, settings (persisted), history - Type-safe tauriCommands.ts matching Rust backend types exactly - 8 IT domain system prompts (Linux, Windows, Network, K8s, DB, Virt, HW, Obs) DevOps: - .woodpecker/test.yml: rustfmt, clippy, cargo test, tsc, vitest on every push - .woodpecker/release.yml: linux/amd64 + linux/arm64 builds, Gogs release upload Verified: - cargo check: zero errors - tsc --noEmit: zero errors - vitest run: 13/13 unit tests passing Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 03:36:25 +00:00
function byteLength(string) {
let length = 0
for (let i = 0, n = string.length; i < n; i++) {
const code = string.charCodeAt(i)
if (code >= 0xd800 && code <= 0xdbff && i + 1 < n) {
const code = string.charCodeAt(i + 1)
if (code >= 0xdc00 && code <= 0xdfff) {
length += 4
i++
continue
}
}
if (code <= 0x7f) length += 1
else if (code <= 0x7ff) length += 2
else length += 3
}
return length
}
let toString
if (typeof TextDecoder !== 'undefined') {
const decoder = new TextDecoder()
toString = function toString(buffer) {
return decoder.decode(buffer)
}
} else {
toString = function toString(buffer) {
const len = buffer.byteLength
let output = ''
let i = 0
while (i < len) {
let byte = buffer[i]
if (byte <= 0x7f) {
output += String.fromCharCode(byte)
i++
continue
}
let bytesNeeded = 0
let codePoint = 0
if (byte <= 0xdf) {
bytesNeeded = 1
codePoint = byte & 0x1f
} else if (byte <= 0xef) {
bytesNeeded = 2
codePoint = byte & 0x0f
} else if (byte <= 0xf4) {
bytesNeeded = 3
codePoint = byte & 0x07
}
if (len - i - bytesNeeded > 0) {
let k = 0
while (k < bytesNeeded) {
byte = buffer[i + k + 1]
codePoint = (codePoint << 6) | (byte & 0x3f)
k += 1
}
} else {
codePoint = 0xfffd
bytesNeeded = len - i
}
output += String.fromCodePoint(codePoint)
i += bytesNeeded + 1
}
return output
}
}
let write
if (typeof TextEncoder !== 'undefined') {
const encoder = new TextEncoder()
write = function write(buffer, string) {
return encoder.encodeInto(string, buffer).written
}
} else {
write = function write(buffer, string) {
const len = buffer.byteLength
let i = 0
let j = 0
while (i < string.length) {
const code = string.codePointAt(i)
if (code <= 0x7f) {
buffer[j++] = code
i++
continue
}
let count = 0
let bits = 0
if (code <= 0x7ff) {
count = 6
bits = 0xc0
} else if (code <= 0xffff) {
count = 12
bits = 0xe0
} else if (code <= 0x1fffff) {
count = 18
bits = 0xf0
}
buffer[j++] = bits | (code >> count)
count -= 6
while (count >= 0) {
buffer[j++] = 0x80 | ((code >> count) & 0x3f)
count -= 6
}
i += code >= 0x10000 ? 2 : 1
}
return len
}
}
module.exports = {
byteLength,
toString,
write
}