@ailuntz/minilink 0.9.14 → 0.9.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/history.mjs +7 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ailuntz/minilink",
3
- "version": "0.9.14",
3
+ "version": "0.9.15",
4
4
  "description": "Use your Codex profiles in the Desktop model menu.",
5
5
  "type": "module",
6
6
  "license": "MIT AND Apache-2.0",
package/src/history.mjs CHANGED
@@ -26,7 +26,7 @@ function checkedPath(path, home, threadId) {
26
26
  // may refer to a response that was never stored. Replace its journal record
27
27
  // with a harmless event of the same byte length and remove the indexed item.
28
28
  // Keep private backups so a failed switch can restore both stores.
29
- export function repairThreadHistory(path, { threadId, home = codexHome(), backupDir = defaultBackups(home) } = {}) {
29
+ export function repairThreadHistory(path, { threadId, home = codexHome(), backupDir = defaultBackups(home), onlyOrphaned = false } = {}) {
30
30
  if (!existsSync(path)) return null;
31
31
  if (!/^[0-9a-f-]{36}$/.test(threadId || '')) throw new Error('任务 ID 无效,无法备份历史。');
32
32
  if (!checkedPath(path, home, threadId)) return null;
@@ -40,7 +40,7 @@ export function repairThreadHistory(path, { threadId, home = codexHome(), backup
40
40
  let record;
41
41
  try { record = JSON.parse(original.toString('utf8')); }
42
42
  catch { throw new Error('任务历史包含无法解析的记录,未修改原文件。'); }
43
- if (record.type === 'response_item' && record.payload?.type === 'reasoning') {
43
+ if (record.type === 'response_item' && record.payload?.type === 'reasoning' && (!onlyOrphaned || (!record.payload.content?.length && !record.payload.encrypted_content))) {
44
44
  const compact = Buffer.from(JSON.stringify({ timestamp: record.timestamp, type: 'event_msg', payload: { type: 'token_count', info: null, rate_limits: null } }));
45
45
  if (compact.length > original.length) throw new Error('任务历史记录无法等长修复,未修改原文件。');
46
46
  const replacement = Buffer.alloc(original.length, 32);
@@ -55,7 +55,11 @@ export function repairThreadHistory(path, { threadId, home = codexHome(), backup
55
55
  const database = existsSync(databasePath) ? new DatabaseSync(databasePath) : null;
56
56
  let rows = [];
57
57
  try {
58
- if (database) rows = database.prepare("SELECT rowid, * FROM thread_items WHERE thread_id = ? AND item_type = 'reasoning'").all(threadId);
58
+ if (database) rows = database.prepare("SELECT rowid, * FROM thread_items WHERE thread_id = ? AND item_type = 'reasoning'").all(threadId).filter(row => {
59
+ if (!onlyOrphaned) return true;
60
+ const item = JSON.parse(row.item_json);
61
+ return !item.content?.length && !item.encrypted_content;
62
+ });
59
63
  if (!patches.length && !rows.length) return null;
60
64
  mkdirSync(backupDir, { recursive: true, mode: 0o700 });
61
65
  const stem = `${threadId}-${randomUUID()}`;