Initial import
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { db } from '../src/db/client.js';
|
||||
import { repairChatConversationRequestLinks } from '../src/services/chat-room-service.js';
|
||||
|
||||
const requestedSessionId = process.argv[2]?.trim() || null;
|
||||
|
||||
try {
|
||||
const result = await repairChatConversationRequestLinks(requestedSessionId);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
} finally {
|
||||
await db.destroy();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
21
etc/servers/work-server/scripts/write-build-info.mjs
Executable file
21
etc/servers/work-server/scripts/write-build-info.mjs
Executable file
@@ -0,0 +1,21 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
const projectRoot = process.cwd();
|
||||
const packageJsonPath = path.join(projectRoot, 'package.json');
|
||||
const distDirectoryPath = path.join(projectRoot, 'dist');
|
||||
const buildInfoPath = path.join(distDirectoryPath, 'build-info.json');
|
||||
|
||||
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
|
||||
const builtAt = new Date().toISOString();
|
||||
|
||||
const buildInfo = {
|
||||
version: typeof packageJson.version === 'string' ? packageJson.version : '0.0.0',
|
||||
buildId: `${typeof packageJson.version === 'string' ? packageJson.version : '0.0.0'}@${builtAt}`,
|
||||
builtAt,
|
||||
};
|
||||
|
||||
await fs.mkdir(distDirectoryPath, { recursive: true });
|
||||
await fs.writeFile(buildInfoPath, JSON.stringify(buildInfo, null, 2));
|
||||
|
||||
console.log(`work-server build info written to ${buildInfoPath}`);
|
||||
Reference in New Issue
Block a user