oc-tweaks 0.8.2 → 0.9.0

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/dist/index.js +68 -28
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -834,12 +834,21 @@ function parseJsonBlob(value) {
834
834
  return JSON.parse(String(value));
835
835
  }
836
836
  function queryMessages(db, sessionId) {
837
- const rows = db.query("SELECT data FROM message WHERE session_id = ? ORDER BY time_created ASC").all(sessionId);
838
- return rows.map((row) => parseJsonBlob(row.data));
837
+ const rows = db.query("SELECT id, data FROM message WHERE session_id = ? ORDER BY time_created ASC").all(sessionId);
838
+ return rows.map((row) => {
839
+ const parsed = parseJsonBlob(row.data);
840
+ parsed._messageId = row.id;
841
+ return parsed;
842
+ });
839
843
  }
840
844
  function queryParts(db, sessionId) {
841
- const rows = db.query("SELECT data FROM part WHERE session_id = ? ORDER BY id ASC").all(sessionId);
842
- return rows.map((row) => parseJsonBlob(row.data));
845
+ const rows = db.query("SELECT data, message_id FROM part WHERE session_id = ? ORDER BY id ASC").all(sessionId);
846
+ return rows.map((row) => {
847
+ const parsed = parseJsonBlob(row.data);
848
+ if (row.message_id)
849
+ parsed._messageId = row.message_id;
850
+ return parsed;
851
+ });
843
852
  }
844
853
  function isRecoverableBlobError(error) {
845
854
  if (error instanceof SyntaxError)
@@ -1300,31 +1309,62 @@ function formatTranscript(sessionId, messages, parts) {
1300
1309
  lines.push(`Messages: ${messages.length}`);
1301
1310
  lines.push(`Parts: ${parts.length}`);
1302
1311
  lines.push("");
1303
- for (const message of messages) {
1304
- const role = typeof message?.role === "string" ? message.role : "unknown";
1305
- const text = getMessageText(message?.content, role === "assistant" ? 320 : 520);
1306
- if (text) {
1307
- lines.push(`[${role === "user" ? "User" : role === "assistant" ? "Assistant" : "Message"}] ${text}`);
1312
+ const hasPartBasedText = parts.some((part) => part.type === "text" && typeof part.text === "string" && part.text.trim().length > 0 || part.type === "reasoning" && typeof part.reasoning === "string" && part.reasoning.trim().length > 0);
1313
+ if (hasPartBasedText) {
1314
+ const roleByMessageId = new Map;
1315
+ for (const message of messages) {
1316
+ if (message._messageId && typeof message.role === "string") {
1317
+ roleByMessageId.set(message._messageId, message.role);
1318
+ }
1319
+ }
1320
+ for (const part of parts) {
1321
+ if (part.type === "text" && typeof part.text === "string" && part.text.trim().length > 0) {
1322
+ const role = part._messageId ? roleByMessageId.get(part._messageId) ?? "unknown" : "unknown";
1323
+ const label = role === "user" ? "User" : role === "assistant" ? "Assistant" : "Message";
1324
+ const maxChars = role === "assistant" ? 320 : 520;
1325
+ lines.push(`[${label}] ${toLimitedText(part.text, maxChars)}`);
1326
+ } else if (part.type === "reasoning" && typeof part.reasoning === "string" && part.reasoning.trim().length > 0) {
1327
+ lines.push(`[Reasoning] ${toLimitedText(part.reasoning, 320)}`);
1328
+ } else if (part.type === "tool" && part.tool) {
1329
+ const toolName = typeof part.tool === "string" ? part.tool : "unknown";
1330
+ const inputText = safeStringify(part.state?.input, 260);
1331
+ const outputText = safeStringify(part.state?.output, 260);
1332
+ const errorText = safeStringify(part.state?.error, 180);
1333
+ lines.push(`[Tool: ${toolName}]`);
1334
+ if (inputText)
1335
+ lines.push(` input: ${inputText}`);
1336
+ if (outputText)
1337
+ lines.push(` output: ${outputText}`);
1338
+ if (errorText)
1339
+ lines.push(` error: ${errorText}`);
1340
+ }
1341
+ }
1342
+ } else {
1343
+ for (const message of messages) {
1344
+ const role = typeof message?.role === "string" ? message.role : "unknown";
1345
+ const text = getMessageText(message?.content, role === "assistant" ? 320 : 520);
1346
+ if (text) {
1347
+ lines.push(`[${role === "user" ? "User" : role === "assistant" ? "Assistant" : "Message"}] ${text}`);
1348
+ }
1349
+ }
1350
+ const toolParts = parts.filter((p) => p?.type === "tool");
1351
+ if (toolParts.length > 0) {
1352
+ lines.push("");
1353
+ lines.push("[Tool Parts]");
1354
+ for (const part of toolParts) {
1355
+ const toolName = typeof part.tool === "string" ? part.tool : "unknown";
1356
+ const inputText = safeStringify(part.state?.input, 260);
1357
+ const outputText = safeStringify(part.state?.output, 260);
1358
+ const errorText = safeStringify(part.state?.error, 180);
1359
+ lines.push(`[Tool: ${toolName}]`);
1360
+ if (inputText)
1361
+ lines.push(` input: ${inputText}`);
1362
+ if (outputText)
1363
+ lines.push(` output: ${outputText}`);
1364
+ if (errorText)
1365
+ lines.push(` error: ${errorText}`);
1366
+ }
1308
1367
  }
1309
- }
1310
- if (parts.length > 0) {
1311
- lines.push("");
1312
- lines.push("[Tool Parts]");
1313
- }
1314
- for (const part of parts) {
1315
- if (part?.type !== "tool")
1316
- continue;
1317
- const toolName = typeof part.tool === "string" ? part.tool : "unknown";
1318
- const inputText = safeStringify(part.state?.input, 260);
1319
- const outputText = safeStringify(part.state?.output, 260);
1320
- const errorText = safeStringify(part.state?.error, 180);
1321
- lines.push(`[Tool: ${toolName}]`);
1322
- if (inputText)
1323
- lines.push(` input: ${inputText}`);
1324
- if (outputText)
1325
- lines.push(` output: ${outputText}`);
1326
- if (errorText)
1327
- lines.push(` error: ${errorText}`);
1328
1368
  }
1329
1369
  return lines.join(`
1330
1370
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-tweaks",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js"