From bf5b84b68d0c2e7a61eca7a81d06762d4be582d0 Mon Sep 17 00:00:00 2001 From: wyh Date: Wed, 26 Feb 2025 18:45:09 +0800 Subject: [PATCH] fix: replacing Node's Buffer with npm's buffer package. --- package-lock.json | 2 ++ package.json | 1 + src/LLMProviders/brevilabsClient.ts | 1 + src/components/Chat.tsx | 1 + src/encryptionService.test.ts | 1 + src/encryptionService.ts | 1 + src/utils.ts | 1 + 7 files changed, 8 insertions(+) diff --git a/package-lock.json b/package-lock.json index 71c055750..c0852de0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,7 @@ "@radix-ui/react-tooltip": "^1.1.6", "@tabler/icons-react": "^2.14.0", "axios": "^1.3.4", + "buffer": "^6.0.3", "chrono-node": "^2.7.7", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", @@ -9473,6 +9474,7 @@ "url": "https://feross.org/support" } ], + "license": "MIT", "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.2.1" diff --git a/package.json b/package.json index 8174d7db0..6d17b76ec 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,7 @@ "@radix-ui/react-tooltip": "^1.1.6", "@tabler/icons-react": "^2.14.0", "axios": "^1.3.4", + "buffer": "^6.0.3", "chrono-node": "^2.7.7", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", diff --git a/src/LLMProviders/brevilabsClient.ts b/src/LLMProviders/brevilabsClient.ts index 56dc444bc..80cafa79e 100644 --- a/src/LLMProviders/brevilabsClient.ts +++ b/src/LLMProviders/brevilabsClient.ts @@ -5,6 +5,7 @@ import { turnOffPlus, turnOnPlus } from "@/plusUtils"; import { getSettings } from "@/settings/model"; import { extractErrorDetail } from "@/utils"; import { Notice } from "obsidian"; +import { Buffer } from "buffer"; export interface BrocaResponse { response: { diff --git a/src/components/Chat.tsx b/src/components/Chat.tsx index 9a0765ee1..1ed9640b8 100644 --- a/src/components/Chat.tsx +++ b/src/components/Chat.tsx @@ -18,6 +18,7 @@ import { FileParserManager } from "@/tools/FileParserManager"; import { err2String, formatDateTime } from "@/utils"; import { Notice, TFile } from "obsidian"; import React, { useCallback, useContext, useEffect, useRef, useState } from "react"; +import { Buffer } from "buffer"; interface ChatProps { sharedState: SharedState; diff --git a/src/encryptionService.test.ts b/src/encryptionService.test.ts index ecd25ffcf..d9e422578 100644 --- a/src/encryptionService.test.ts +++ b/src/encryptionService.test.ts @@ -22,6 +22,7 @@ global.TextDecoder = TextDecoder as any; import { encryptAllKeys, getDecryptedKey, getEncryptedKey } from "@/encryptionService"; import { type CopilotSettings } from "@/settings/model"; import { Platform } from "obsidian"; +import { Buffer } from "buffer"; // Mock window.btoa and window.atob for base64 encoding/decoding global.btoa = jest.fn().mockImplementation((str) => Buffer.from(str).toString("base64")); diff --git a/src/encryptionService.ts b/src/encryptionService.ts index c28ddedae..951961c46 100644 --- a/src/encryptionService.ts +++ b/src/encryptionService.ts @@ -1,5 +1,6 @@ import { type CopilotSettings } from "@/settings/model"; import { Platform } from "obsidian"; +import { Buffer } from "buffer"; // @ts-ignore let safeStorageInternal: Electron.SafeStorage | null = null; diff --git a/src/utils.ts b/src/utils.ts index 69e093fc3..d931690d3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -20,6 +20,7 @@ import { BaseChain, RetrievalQAChain } from "langchain/chains"; import moment from "moment"; import { MarkdownView, Notice, TFile, Vault, requestUrl } from "obsidian"; import { CustomModel } from "./aiParams"; +import { Buffer } from "buffer"; // Add custom error type at the top of the file interface APIError extends Error {