Files
zn-ai/electron/utils/token-usage-writer.ts
duanshuwen ee72cf7261 feat: refactor HomePage to integrate agents store and update related components
feat: add runtime event handling for providers in ProvidersSection

feat: update routing to include Channels and Agents pages

feat: extend route types and navigation items for Channels and Agents

feat: implement agents store for managing agent data and interactions

fix: update chat store to utilize agents store for agent-related functionality

chore: export agents store from index

fix: enhance runtime types for better event handling

fix: update Vite config to handle dev server URL correctly
2026-04-18 14:56:32 +08:00

42 lines
1.4 KiB
TypeScript

import * as fs from 'fs';
import * as path from 'path';
import { parseSessionKey } from '@runtime/lib/models';
import { getUserDataDir } from './paths';
const PRIMARY_TRANSCRIPT_ROOT_DIR = 'models';
const LEGACY_TRANSCRIPT_ROOT_DIR = 'agents';
function buildTranscriptFilePath(sessionKey: string, rootDirName: string): string {
const parsed = parseSessionKey(sessionKey);
const agentId = parsed.isAgentSession ? parsed.agentId : 'default';
let sessionId = parsed.isAgentSession ? parsed.sessionId : sessionKey;
if (!sessionId) {
sessionId = 'unknown';
}
const baseDir = path.join(getUserDataDir(), rootDirName, agentId, 'sessions');
return path.join(baseDir, `${sessionId}.jsonl`);
}
export function getTranscriptFilePath(sessionKey: string): string {
return buildTranscriptFilePath(sessionKey, PRIMARY_TRANSCRIPT_ROOT_DIR);
}
export function getLegacyTranscriptFilePath(sessionKey: string): string {
return buildTranscriptFilePath(sessionKey, LEGACY_TRANSCRIPT_ROOT_DIR);
}
export function getTranscriptPathCandidates(sessionKey: string): string[] {
return Array.from(new Set([
getTranscriptFilePath(sessionKey),
getLegacyTranscriptFilePath(sessionKey),
]));
}
export function appendTranscriptLine(sessionKey: string, lineObject: any): void {
const filePath = getTranscriptFilePath(sessionKey);
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.appendFileSync(filePath, JSON.stringify(lineObject) + '\n', 'utf-8');
}