Initial import

This commit is contained in:
how2ice
2026-04-21 03:33:23 +09:00
commit 9e4b70f1f1
495 changed files with 94680 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
import { db } from '../src/db/client.js';
import {
CHAT_CONVERSATION_MESSAGE_TABLE,
CHAT_CONVERSATION_REQUEST_TABLE,
} from '../src/services/chat-room-service.js';
const LEGACY_CHAT_RESOURCE_PREFIX = '/.codex_chat/';
const API_CHAT_RESOURCE_PREFIX = '/api/chat/resources/.codex_chat/';
const requestedSessionId = process.argv[2]?.trim() || null;
function rewriteLegacyChatResourceUrls(text: string) {
const normalized = String(text ?? '').replaceAll(LEGACY_CHAT_RESOURCE_PREFIX, API_CHAT_RESOURCE_PREFIX);
return normalized.replace(
/\((?:\/[^)\s]*?)?(\/api\/chat\/resources\/\.codex_chat\/[^)\s]*?)(?:\/api\/chat\/resources\/\.codex_chat\/[^)\s]*)?\)/g,
(_match, resourcePath) => `(${resourcePath})`,
);
}
async function backfillTable(
tableName: string,
textColumn: string,
) {
const rows = await db(tableName)
.modify((query) => {
if (requestedSessionId) {
query.where('session_id', requestedSessionId);
}
})
.where(textColumn, 'like', `%${LEGACY_CHAT_RESOURCE_PREFIX}%`)
.select('id', 'session_id', textColumn);
let updatedCount = 0;
const touchedSessionIds = new Set<string>();
for (const row of rows) {
const currentText = String(row[textColumn] ?? '');
const nextText = rewriteLegacyChatResourceUrls(currentText);
if (nextText === currentText) {
continue;
}
await db(tableName)
.where('id', row.id)
.update({
[textColumn]: nextText,
});
updatedCount += 1;
touchedSessionIds.add(String(row.session_id ?? ''));
}
return {
tableName,
textColumn,
updatedCount,
touchedSessionIds: Array.from(touchedSessionIds).filter(Boolean),
};
}
try {
const messageResult = await backfillTable(CHAT_CONVERSATION_MESSAGE_TABLE, 'text');
const requestResult = await backfillTable(CHAT_CONVERSATION_REQUEST_TABLE, 'response_text');
console.log(JSON.stringify({
requestedSessionId,
updatedRowCount: messageResult.updatedCount + requestResult.updatedCount,
tables: [messageResult, requestResult],
}, null, 2));
} catch (error) {
console.error(error);
process.exitCode = 1;
} finally {
await db.destroy();
}