refactor: restructured hash API and cache tracking across TypeScript and Rust

- Migrated hash API calls from Bun.hash.xxHash64() to Bun.hash() across TypeScript packages for simplified hash generation.
- Consolidated mermaid cache failure tracking by replacing separate failed Set with null values in cache Map.
- Refactored schema-based child extraction in Rust by introducing promotion_fields tracking and schema_wrapper_child() helper function.
- Updated TypeScript configuration files with reformatted arrays and added compiler options for consistency.
This commit is contained in:
can1357
2026-04-10 14:26:06 +02:00
parent b60c0cc3ce
commit d60ee622a4
17 changed files with 133 additions and 61 deletions
@@ -1,7 +1,6 @@
import { extractMermaidBlocks, logger, renderMermaidAsciiSafe } from "@oh-my-pi/pi-utils";
const cache = new Map<bigint, string>();
const failed = new Set<bigint>();
const cache = new Map<bigint | number, string | null>();
let onRenderNeeded: (() => void) | null = null;
@@ -16,7 +15,7 @@ export function setMermaidRenderCallback(callback: (() => void) | null): void {
* Get a pre-rendered mermaid ASCII diagram by hash.
* Returns null if not cached or rendering failed.
*/
export function getMermaidAscii(hash: bigint): string | null {
export function getMermaidAscii(hash: bigint | number): string | null {
return cache.get(hash) ?? null;
}
@@ -31,14 +30,14 @@ export function prerenderMermaid(markdown: string): void {
let hasNew = false;
for (const { source, hash } of blocks) {
if (cache.has(hash) || failed.has(hash)) continue;
if (cache.has(hash)) continue;
const ascii = renderMermaidAsciiSafe(source);
if (ascii) {
cache.set(hash, ascii);
hasNew = true;
} else {
failed.add(hash);
cache.set(hash, null);
}
}
@@ -58,7 +57,7 @@ export function prerenderMermaid(markdown: string): void {
*/
export function hasPendingMermaid(markdown: string): boolean {
const blocks = extractMermaidBlocks(markdown);
return blocks.some(({ hash }) => !cache.has(hash) && !failed.has(hash));
return blocks.some(({ hash }) => !cache.has(hash));
}
/**
@@ -66,5 +65,4 @@ export function hasPendingMermaid(markdown: string): boolean {
*/
export function clearMermaidCache(): void {
cache.clear();
failed.clear();
}
@@ -761,7 +761,7 @@ function buildOpenAiNativeHistory(
if (!msgId) {
msgId = `msg_${msgIndex}`;
} else if (msgId.length > 64) {
msgId = `msg_${Bun.hash.xxHash64(msgId).toString(36)}`;
msgId = `msg_${Bun.hash(msgId).toString(36)}`;
}
input.push({
type: "message",