tabby-ai-assistant 1.0.4 → 1.0.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tabby-ai-assistant",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Tabby终端AI助手插件 - 支持多AI提供商(OpenAI、Anthropic、Minimax、GLM)",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -26,12 +26,15 @@ export function generateIV(): string {
26
26
  * 使用AES加密字符串
27
27
  */
28
28
  export function encrypt(text: string, key: string): string {
29
- if (!text || !key) {
29
+ if (text === null || text === undefined || key === null || key === undefined) {
30
30
  throw new Error('文本和密钥不能为空');
31
31
  }
32
32
 
33
33
  try {
34
- const encrypted = CryptoJS.AES.encrypt(text, key);
34
+ // 确保输入是字符串
35
+ const strText = String(text);
36
+ const strKey = String(key);
37
+ const encrypted = CryptoJS.AES.encrypt(strText, strKey);
35
38
  return encrypted.toString();
36
39
  } catch (error) {
37
40
  throw new Error(`加密失败: ${error instanceof Error ? error.message : String(error)}`);
@@ -42,12 +45,15 @@ export function encrypt(text: string, key: string): string {
42
45
  * 使用AES解密字符串
43
46
  */
44
47
  export function decrypt(encryptedText: string, key: string): string {
45
- if (!encryptedText || !key) {
48
+ if (encryptedText === null || encryptedText === undefined || key === null || key === undefined) {
46
49
  throw new Error('加密文本和密钥不能为空');
47
50
  }
48
51
 
49
52
  try {
50
- const decrypted = CryptoJS.AES.decrypt(encryptedText, key);
53
+ // 确保输入是字符串
54
+ const strEncryptedText = String(encryptedText);
55
+ const strKey = String(key);
56
+ const decrypted = CryptoJS.AES.decrypt(strEncryptedText, strKey);
51
57
  return decrypted.toString(CryptoJS.enc.Utf8);
52
58
  } catch (error) {
53
59
  throw new Error(`解密失败: ${error instanceof Error ? error.message : String(error)}`);
@@ -151,12 +157,14 @@ export function generateToken(length: number = 32): string {
151
157
  * Base64编码
152
158
  */
153
159
  export function base64Encode(text: string): string {
154
- if (!text) {
160
+ if (text === null || text === undefined) {
155
161
  throw new Error('文本不能为空');
156
162
  }
157
163
 
158
164
  try {
159
- return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(text));
165
+ // 确保输入是字符串
166
+ const str = String(text);
167
+ return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(str));
160
168
  } catch (error) {
161
169
  throw new Error(`Base64编码失败: ${error instanceof Error ? error.message : String(error)}`);
162
170
  }
@@ -166,12 +174,14 @@ export function base64Encode(text: string): string {
166
174
  * Base64解码
167
175
  */
168
176
  export function base64Decode(encodedText: string): string {
169
- if (!encodedText) {
177
+ if (encodedText === null || encodedText === undefined) {
170
178
  throw new Error('编码文本不能为空');
171
179
  }
172
180
 
173
181
  try {
174
- return CryptoJS.enc.Base64.parse(encodedText).toString(CryptoJS.enc.Utf8);
182
+ // 确保输入是字符串
183
+ const str = String(encodedText);
184
+ return CryptoJS.enc.Base64.parse(str).toString(CryptoJS.enc.Utf8);
175
185
  } catch (error) {
176
186
  throw new Error(`Base64解码失败: ${error instanceof Error ? error.message : String(error)}`);
177
187
  }