@usabledev/usable-chat 1.165.1 → 1.166.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/cli.js +36 -3
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -285711,6 +285711,16 @@ var init_file_storage_service = __esm({
285711
285711
  });
285712
285712
  this.totalCacheBytes += size2;
285713
285713
  }
285714
+ clearFileCache(fileId, userId) {
285715
+ for (const ensureCompressed of [false, true]) {
285716
+ const key = this.makeCacheKey(fileId, userId, ensureCompressed);
285717
+ const cached2 = this.cache.get(key);
285718
+ if (cached2) {
285719
+ this.cache.delete(key);
285720
+ this.totalCacheBytes -= cached2.size;
285721
+ }
285722
+ }
285723
+ }
285714
285724
  /**
285715
285725
  * Estimate tokens from content (rough estimation: 4 chars/token for text, size-based for images)
285716
285726
  */
@@ -285724,12 +285734,13 @@ var init_file_storage_service = __esm({
285724
285734
  /**
285725
285735
  * Store a file's extracted content with rotating storage
285726
285736
  * Automatically removes oldest files if user exceeds limit
285727
- * For images: stores both original (full quality) and compressed (for LLM) versions
285737
+ * For images: stores both original (full quality) and compressed (for LLM) versions.
285738
+ * For documents: keeps extractedContent as text and optional originalContent as base64 bytes.
285728
285739
  */
285729
285740
  async storeFile(params) {
285730
285741
  const fileId = randomUUID4();
285731
285742
  let extractedContent = params.extractedContent;
285732
- let originalContent = null;
285743
+ let originalContent = params.originalContent ?? null;
285733
285744
  if (params.fileType === "image" && params.contentType === "base64") {
285734
285745
  originalContent = params.extractedContent;
285735
285746
  try {
@@ -285885,6 +285896,28 @@ var init_file_storage_service = __esm({
285885
285896
  ).orderBy(desc(fileStorage.createdAt)).limit(1);
285886
285897
  return existing || null;
285887
285898
  }
285899
+ /**
285900
+ * Backfill original uploaded bytes onto a legacy duplicate row.
285901
+ * This preserves the rotating-storage dedupe behaviour while making older
285902
+ * text-only rows usable by file_to_sandbox after a user re-uploads the file.
285903
+ */
285904
+ async ensureOriginalContent(file2, userId, originalContent) {
285905
+ if (!originalContent || file2.originalContent) {
285906
+ return file2;
285907
+ }
285908
+ const [updatedFile] = await db.update(fileStorage).set({
285909
+ originalContent,
285910
+ lastUsedAt: /* @__PURE__ */ new Date()
285911
+ }).where(and(eq(fileStorage.id, file2.id), eq(fileStorage.userId, userId))).returning();
285912
+ this.clearFileCache(file2.id, userId);
285913
+ logger.info("FileStorage", "backfilled original bytes for duplicate upload", {
285914
+ fileId: file2.id,
285915
+ fileName: file2.fileName,
285916
+ fileType: file2.fileType,
285917
+ fileSize: file2.fileSize
285918
+ });
285919
+ return updatedFile || file2;
285920
+ }
285888
285921
  /**
285889
285922
  * Check if a file exists by ID
285890
285923
  */
@@ -308939,7 +308972,7 @@ init_tui_select();
308939
308972
  init_model_registry();
308940
308973
 
308941
308974
  // package.json
308942
- var version2 = "1.165.1";
308975
+ var version2 = "1.166.0";
308943
308976
 
308944
308977
  // src/adapters/cli/model-catalog.ts
308945
308978
  init_codex_auth();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usabledev/usable-chat",
3
- "version": "1.165.1",
3
+ "version": "1.166.0",
4
4
  "description": "usable-chat — terminal harness for usable-chat (headless + TUI)",
5
5
  "type": "module",
6
6
  "bin": {