Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix ensu lint issues and align desktop CI dependencies

Prateek Sunalb3a741299fbb
diff --git a/.github/workflows/ensu-desktop-lint.yml b/.github/workflows/ensu-desktop-lint.yml
index 840919f568..b8cf9333e7 100644
--- a/.github/workflows/ensu-desktop-lint.yml
+++ b/.github/workflows/ensu-desktop-lint.yml
@@ -22,7 +22,7 @@ env:
jobs:
lint:
- runs-on: ubuntu-24.04
+ runs-on: ubuntu-22.04
defaults:
run:
working-directory: rust/apps/ensu/src-tauri
@@ -42,7 +42,7 @@ jobs:
- name: Install system dependencies
run: |
sudo apt-get update
- sudo apt-get install -y libwebkit2gtk-4.1-dev libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev
+ sudo apt-get install -y libwebkit2gtk-4.0-dev libsoup2.4-dev libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev
- name: Fetch Rust dependencies
run: cargo fetch
diff --git a/web/apps/ensu/src/components/MarkdownRenderer.tsx b/web/apps/ensu/src/components/MarkdownRenderer.tsx
index 2bce7f0d64..42c6b68713 100644
--- a/web/apps/ensu/src/components/MarkdownRenderer.tsx
+++ b/web/apps/ensu/src/components/MarkdownRenderer.tsx
@@ -123,7 +123,12 @@ const openExternalUrl = async (url: string) => {
type AnchorProps = React.ComponentPropsWithoutRef<"a"> & { node?: unknown };
-const ExternalLink = ({ node: _node, href, children, ...rest }: AnchorProps) => (
+const ExternalLink = ({
+ node: _node,
+ href,
+ children,
+ ...rest
+}: AnchorProps) => (
<a
{...rest}
href={href}
diff --git a/web/apps/ensu/src/pages/chat.tsx b/web/apps/ensu/src/pages/chat.tsx
index cc7f83e4bd..e1fdc530e4 100644
--- a/web/apps/ensu/src/pages/chat.tsx
+++ b/web/apps/ensu/src/pages/chat.tsx
@@ -1057,7 +1057,7 @@ const Page: React.FC = () => {
}
}
};
- run();
+ void run();
return () => {
cancelled = true;
@@ -1271,7 +1271,7 @@ const Page: React.FC = () => {
setContextLength(clampedContextLength);
setMaxTokens(parsed.maxTokens ?? "");
})
- .catch((error) => {
+ .catch((error: unknown) => {
log.error("Failed to read model settings", error);
});
return () => {
@@ -1816,7 +1816,7 @@ const Page: React.FC = () => {
setBranchSelections(selections);
}
})
- .catch((error) => {
+ .catch((error: unknown) => {
log.error("Failed to load branch selections", error);
if (!cancelled) {
setBranchSelections({});
@@ -1916,7 +1916,7 @@ const Page: React.FC = () => {
for (const message of displayMessages) {
for (const attachment of message.attachments ?? []) {
if (attachment.kind === "image") {
- loadAttachmentPreview(attachment, message.sessionUuid);
+ void loadAttachmentPreview(attachment, message.sessionUuid);
}
}
}
@@ -2854,7 +2854,7 @@ const Page: React.FC = () => {
parentMessageUuid,
);
- updateBranchSelectionState(
+ void updateBranchSelectionState(
parentMessageUuid,
assistantMessage.messageUuid,
);
@@ -2869,7 +2869,7 @@ const Page: React.FC = () => {
} catch (error) {
log.error("Failed to finalize stopped generation", error);
if (last?.previousSelection) {
- updateBranchSelectionState(
+ void updateBranchSelectionState(
last.parentMessageUuid,
last.previousSelection,
);
@@ -2880,7 +2880,7 @@ const Page: React.FC = () => {
})();
} else {
if (last?.previousSelection) {
- updateBranchSelectionState(
+ void updateBranchSelectionState(
last.parentMessageUuid,
last.previousSelection,
);
@@ -2966,7 +2966,7 @@ const Page: React.FC = () => {
previousSelection,
};
- updateBranchSelectionState(
+ void updateBranchSelectionState(
parentMessageUuid,
STREAMING_SELECTION_KEY,
false,
@@ -3027,7 +3027,7 @@ const Page: React.FC = () => {
stopRequestedRef.current = false;
provider.cancelGeneration(-1);
if (previousSelection) {
- updateBranchSelectionState(
+ void updateBranchSelectionState(
parentMessageUuid,
previousSelection,
);
@@ -3105,7 +3105,7 @@ const Page: React.FC = () => {
});
}
if (previousSelection) {
- updateBranchSelectionState(
+ void updateBranchSelectionState(
parentMessageUuid,
previousSelection,
);
@@ -3132,7 +3132,7 @@ const Page: React.FC = () => {
parentMessageUuid,
);
- updateBranchSelectionState(
+ void updateBranchSelectionState(
parentMessageUuid,
assistantMessage.messageUuid,
);
@@ -3152,7 +3152,7 @@ const Page: React.FC = () => {
const message = formatErrorMessage(error);
showMiniDialog({ title: "Model error", message });
if (previousSelection) {
- updateBranchSelectionState(
+ void updateBranchSelectionState(
parentMessageUuid,
previousSelection,
);
@@ -3257,7 +3257,7 @@ const Page: React.FC = () => {
(switcher.currentIndex - 1 + switcher.total) % switcher.total;
const target = switcher.targets[nextIndex];
if (!target) return;
- updateBranchSelectionState(switcher.selectionKey, target);
+ void updateBranchSelectionState(switcher.selectionKey, target);
},
[updateBranchSelectionState],
);
@@ -3268,7 +3268,7 @@ const Page: React.FC = () => {
const nextIndex = (switcher.currentIndex + 1) % switcher.total;
const target = switcher.targets[nextIndex];
if (!target) return;
- updateBranchSelectionState(switcher.selectionKey, target);
+ void updateBranchSelectionState(switcher.selectionKey, target);
},
[updateBranchSelectionState],
);
@@ -3975,7 +3975,7 @@ const Page: React.FC = () => {
attachments,
);
- updateBranchSelectionState(
+ void updateBranchSelectionState(
selectionKey,
newUserMessage.messageUuid,
);
@@ -4012,7 +4012,10 @@ const Page: React.FC = () => {
attachments,
);
- updateBranchSelectionState(selectionKey, userMessage.messageUuid);
+ void updateBranchSelectionState(
+ selectionKey,
+ userMessage.messageUuid,
+ );
appendMessageToState(userMessage);
updateSessionAfterMessage(userMessage);
setPendingDocuments([]);
diff --git a/web/apps/ensu/src/services/chat/chatKey.ts b/web/apps/ensu/src/services/chat/chatKey.ts
index f1155e5f97..ed77eb1e60 100644
--- a/web/apps/ensu/src/services/chat/chatKey.ts
+++ b/web/apps/ensu/src/services/chat/chatKey.ts
@@ -1,12 +1,12 @@
import { HTTPError } from "ente-base/http";
-import { ensureCryptoInit, enteWasm } from "../wasm";
-import { ChatKeyNotFoundError, createChatKey, getChatKey } from "./gateway";
import {
isTauriAppRuntime,
secureStorageDelete,
secureStorageGet,
secureStorageSet,
} from "../secure-storage";
+import { ensureCryptoInit, enteWasm } from "../wasm";
+import { ChatKeyNotFoundError, createChatKey, getChatKey } from "./gateway";
const CHAT_KEY_LOCAL_STORAGE_KEY = "ensu.chatKey";
const LOCAL_CHAT_KEY_LOCAL_STORAGE_KEY = "ensu.chatKey.local";
@@ -14,10 +14,7 @@ const CHAT_KEY_FILE_NAME = "chat-keys.json";
const REMOTE_CHAT_KEY_SECURE_STORAGE_KEY = "remoteChatKey";
const LOCAL_CHAT_KEY_SECURE_STORAGE_KEY = "localChatKey";
-type PersistedChatKeys = {
- remoteChatKey?: string;
- localChatKey?: string;
-};
+type PersistedChatKeys = { remoteChatKey?: string; localChatKey?: string };
let _persistedChatKeys: PersistedChatKeys = {};
let _chatKeyStoreInitPromise: Promise<void> | undefined;
@@ -83,7 +80,9 @@ const persistNativeChatKeys = async () => {
),
);
} else {
- operations.push(secureStorageDelete(REMOTE_CHAT_KEY_SECURE_STORAGE_KEY));
+ operations.push(
+ secureStorageDelete(REMOTE_CHAT_KEY_SECURE_STORAGE_KEY),
+ );
}
if (_persistedChatKeys.localChatKey) {
@@ -112,12 +111,12 @@ export const initChatKeyStore = async () => {
_chatKeyStoreInitPromise ??= (async () => {
const [secureRemoteChatKey, secureLocalChatKey, nativeKeys] =
await Promise.all([
- secureStorageGet(
- REMOTE_CHAT_KEY_SECURE_STORAGE_KEY,
- ).catch(() => undefined),
- secureStorageGet(
- LOCAL_CHAT_KEY_SECURE_STORAGE_KEY,
- ).catch(() => undefined),
+ secureStorageGet(REMOTE_CHAT_KEY_SECURE_STORAGE_KEY).catch(
+ () => undefined,
+ ),
+ secureStorageGet(LOCAL_CHAT_KEY_SECURE_STORAGE_KEY).catch(
+ () => undefined,
+ ),
readNativeChatKeys(),
]);
const remoteChatKey =
@@ -154,7 +153,7 @@ export const initChatKeyStore = async () => {
} catch {
// ignore missing legacy file
}
- })().catch((error) => {
+ })().catch((error: unknown) => {
_chatKeyStoreInitPromise = undefined;
throw error;
});
diff --git a/web/apps/ensu/src/services/chat/store.ts b/web/apps/ensu/src/services/chat/store.ts
index 825d291e8a..e730631656 100644
--- a/web/apps/ensu/src/services/chat/store.ts
+++ b/web/apps/ensu/src/services/chat/store.ts
@@ -1,5 +1,5 @@
-import log from "ente-base/log";
import { getKV, removeKV, setKV } from "ente-base/kv";
+import log from "ente-base/log";
import { deleteDB, openDB, type DBSchema, type IDBPDatabase } from "idb";
import { base64ToBytes } from "services/base64";
import { decryptAttachmentBytes, encryptAttachmentBytes } from "./attachments";
@@ -74,10 +74,7 @@ interface ChatDbSchema {
type ChatStoreName = keyof ChatDbSchema;
-type PersistedAttachmentBytes = {
- id: string;
- data: string;
-};
+type PersistedAttachmentBytes = { id: string; data: string };
type PersistedChatStore = {
sessions: StoredSession[];
@@ -92,18 +89,9 @@ type ChatStoreState = {
};
interface IndexedChatDBSchema extends DBSchema {
- sessions: {
- key: string;
- value: StoredSession;
- };
- messages: {
- key: string;
- value: StoredMessage;
- };
- attachmentBytes: {
- key: string;
- value: StoredAttachmentBytes;
- };
+ sessions: { key: string; value: StoredSession };
+ messages: { key: string; value: StoredMessage };
+ attachmentBytes: { key: string; value: StoredAttachmentBytes };
}
interface ChatObjectStore<K extends ChatStoreName> {
@@ -124,8 +112,11 @@ interface ChatDbLike {
key: string,
) => Promise<ChatDbSchema[K] | undefined>;
getAll: <K extends ChatStoreName>(name: K) => Promise<ChatDbSchema[K][]>;
- put: <K extends ChatStoreName>(name: K, value: ChatDbSchema[K]) => Promise<void>;
- delete: <K extends ChatStoreName>(name: K, key: string) => Promise<void>;
+ put: <K extends ChatStoreName>(
+ name: K,
+ value: ChatDbSchema[K],
+ ) => Promise<void>;
+ delete: (name: ChatStoreName, key: string) => Promise<void>;
transaction: (names: ChatStoreName[], mode: "readwrite") => ChatTransaction;
close: () => void;
}
@@ -326,10 +317,12 @@ const loadChatStoreState = (): ChatStoreState => {
message.deletedAt ??
(message.isDeleted ? message.createdAt : null),
})),
- attachmentBytes: (parsed.attachmentBytes ?? []).map((attachment) => ({
- id: attachment.id,
- data: base64ToBytes(attachment.data),
- })),
+ attachmentBytes: (parsed.attachmentBytes ?? []).map(
+ (attachment) => ({
+ id: attachment.id,
+ data: base64ToBytes(attachment.data),
+ }),
+ ),
};
} catch (error) {
log.error("Failed to parse chat store", error);
@@ -349,7 +342,7 @@ const cloneStoreEntry = <K extends ChatStoreName>(
} as ChatDbSchema[K];
}
- const cloned = { ...value } as ChatDbSchema[K];
+ const cloned = { ...value };
if (name === "messages") {
const message = cloned as StoredMessage;
message.attachments = message.attachments?.map((attachment) => ({
@@ -384,10 +377,14 @@ const normalizeStoreEntry = <K extends ChatStoreName>(
value: ChatDbSchema[K],
): ChatDbSchema[K] => {
if (name === "sessions") {
- return normalizeStoredSession(value as StoredSession) as ChatDbSchema[K];
+ return normalizeStoredSession(
+ value as StoredSession,
+ ) as ChatDbSchema[K];
}
if (name === "messages") {
- return normalizeStoredMessage(value as StoredMessage) as ChatDbSchema[K];
+ return normalizeStoredMessage(
+ value as StoredMessage,
+ ) as ChatDbSchema[K];
}
return value;
};
@@ -417,22 +414,31 @@ const createIndexedDbChatDb = (
transaction: (names, mode) => {
const tx = db.transaction(names, mode);
return {
- objectStore: <K extends ChatStoreName>(name: K): ChatObjectStore<K> => ({
+ objectStore: <K extends ChatStoreName>(
+ name: K,
+ ): ChatObjectStore<K> => ({
get: async (key) => {
- const entry = (await tx.objectStore(name).get(
- key,
- )) as ChatDbSchema[K] | undefined;
+ const entry = (await tx.objectStore(name).get(key)) as
+ | ChatDbSchema[K]
+ | undefined;
if (!entry) return undefined;
- return cloneStoreEntry(name, normalizeStoreEntry(name, entry));
+ return cloneStoreEntry(
+ name,
+ normalizeStoreEntry(name, entry),
+ );
},
getAll: async () => {
- const entries = (await tx.objectStore(name).getAll()) as ChatDbSchema[K][];
+ const entries = (await tx
+ .objectStore(name)
+ .getAll()) as ChatDbSchema[K][];
return entries.map((entry) =>
cloneStoreEntry(name, normalizeStoreEntry(name, entry)),
);
},
put: async (value: ChatDbSchema[K]) => {
- await tx.objectStore(name).put(cloneStoreEntry(name, value));
+ await tx
+ .objectStore(name)
+ .put(cloneStoreEntry(name, value));
},
delete: async (key: string) => {
await tx.objectStore(name).delete(key);
@@ -669,10 +675,9 @@ const migrateLegacyLocalChatStoreToIndexedDb = async () => {
}
for (const attachment of legacy.attachmentBytes) {
- await tx.objectStore("attachmentBytes").put({
- id: attachment.id,
- data: new Uint8Array(attachment.data),
- });
+ await tx
+ .objectStore("attachmentBytes")
+ .put({ id: attachment.id, data: new Uint8Array(attachment.data) });
}
await tx.done;
@@ -712,18 +717,24 @@ const migrateLegacyIndexedDbChatStore = async () => {
);
for (const session of sessions) {
- await tx.objectStore("sessions").put(normalizeStoredSession(session));
+ await tx
+ .objectStore("sessions")
+ .put(normalizeStoredSession(session));
}
for (const message of messages) {
- await tx.objectStore("messages").put(normalizeStoredMessage(message));
+ await tx
+ .objectStore("messages")
+ .put(normalizeStoredMessage(message));
}
for (const attachment of attachmentBytes) {
- await tx.objectStore("attachmentBytes").put({
- id: attachment.id,
- data: new Uint8Array(attachment.data),
- });
+ await tx
+ .objectStore("attachmentBytes")
+ .put({
+ id: attachment.id,
+ data: new Uint8Array(attachment.data),
+ });
}
await tx.done;
@@ -854,7 +865,7 @@ export const initializeChatStorePersistence = async (chatKey: string) => {
}
await migrateLegacyIndexedDbChatStore();
- })().catch((error) => {
+ })().catch((error: unknown) => {
if (_chatPersistenceInitPromise === initPromise) {
_chatPersistenceInitPromise = undefined;
_chatPersistenceInitKey = undefined;
diff --git a/web/apps/ensu/src/services/session.ts b/web/apps/ensu/src/services/session.ts
index 8b5f1181e8..f603120af1 100644
--- a/web/apps/ensu/src/services/session.ts
+++ b/web/apps/ensu/src/services/session.ts
@@ -1,11 +1,11 @@
import log from "ente-base/log";
-import { ensureCryptoInit, enteWasm } from "./wasm";
import {
isTauriAppRuntime,
secureStorageDelete,
secureStorageGet,
secureStorageSet,
} from "./secure-storage";
+import { ensureCryptoInit, enteWasm } from "./wasm";
/**
* Session storage key used to store the encrypted master key.