Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
bash bash-scripts/prevent-main-develop-push.sh
6 changes: 6 additions & 0 deletions bash-scripts/prevent-main-develop-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$branch" == "main" || "$branch" == "develop" ]]; then
echo "\e[31mDirect push to $branch is forbidden! Use PRs and merge only from allowed branches.\e[0m"
exit 1
fi
2 changes: 1 addition & 1 deletion chrome-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chrome-extension",
"version": "0.5.164",
"version": "0.5.169",
"description": "chrome extension - core settings",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion chrome-extension/public/pyodide/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pyodide",
"version": "0.27.171",
"version": "0.27.176",
"description": "The Pyodide JavaScript package",
"keywords": [
"python",
Expand Down
33 changes: 29 additions & 4 deletions chrome-extension/src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,35 @@ chrome.runtime.onMessage.addListener(
if (msg.type === 'GET_PLUGIN_CHAT' && msg.pluginId && msg.pageKey) {
const { pluginId, pageKey } = msg;
const chatKey = `${pluginId}::${getPageKey(pageKey)}`;
pluginChatApi.getOrLoadChat(chatKey).then(chat => {
console.log('[background] sendResponse(GET_PLUGIN_CHAT):', chat);
sendResponse(chat || { messages: [] });
});
pluginChatApi
.getOrLoadChat(chatKey)
.then(chat => {
let safeChat = chat;
if (chat && Array.isArray(chat.messages) && chat.messages.length > 50) {
safeChat = { ...chat, messages: chat.messages.slice(-50) };
}
try {
const serializable = JSON.parse(JSON.stringify(safeChat));
console.log(
'[background] sendResponse(GET_PLUGIN_CHAT):',
serializable,
'chatKey:',
chatKey,
'pageKey:',
pageKey,
);
sendResponse(serializable || { messages: [] });
} catch (err) {
console.error('[background] Ошибка сериализации чата:', err, safeChat);
sendResponse({ error: 'serialization failed', details: String(err) });
}
console.log('[background] return true после sendResponse(GET_PLUGIN_CHAT)');
})
.catch(err => {
console.error('[background] Ошибка в getOrLoadChat:', err);
sendResponse({ error: String(err) });
console.log('[background] return true после sendResponse(GET_PLUGIN_CHAT) [catch]');
});
return true;
}

Expand Down
55 changes: 37 additions & 18 deletions chrome-extension/src/background/plugin-chat-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const pluginChatApi = {
return new Promise(resolve => {
chrome.storage.local.get([chatKey], result => {
const chat = result[chatKey] || null;
console.log('[pluginChatApi] getOrLoadChat:', chatKey, chat);
console.log('[pluginChatApi] getOrLoadChat:', chatKey, chat, chat?.messages);
resolve(chat);
});
});
Expand All @@ -48,17 +48,29 @@ const pluginChatApi = {
// Сохранить сообщение в чат
async saveMessage(pluginId: string, pageKey: string, message: ChatMessage): Promise<{ success: boolean }> {
const chatKey = `${pluginId}::${getPageKey(pageKey)}`;
const chat = await this.getOrLoadChat(chatKey);
console.log('[pluginChatApi][saveMessage] BEFORE', { chatKey, pluginId, pageKey, message });
let chat = await this.getOrLoadChat(chatKey);
if (!chat) {
console.warn('[pluginChatApi] saveMessage: чат не найден, создаём новый');
console.warn('[pluginChatApi][saveMessage] чат не найден, создаём новый');
await this.createChatIfNotExists(pluginId, pageKey);
return this.saveMessage(pluginId, pageKey, message);
// После создания чата — получить его снова
chat = await this.getOrLoadChat(chatKey);
if (!chat) {
// Если всё равно не найден — ошибка
console.error('[pluginChatApi][saveMessage] не удалось создать чат!');
return { success: false };
}
}
chat.messages.push(message);
console.log('[pluginChatApi][saveMessage] chat.messages после push:', chat.messages);
chat.updatedAt = Date.now();
await new Promise<void>(resolve => {
chrome.storage.local.set({ [chatKey]: chat }, () => {
console.log('[pluginChatApi] saveMessage: добавляем сообщение в чат', chat);
console.log('[pluginChatApi][saveMessage] AFTER set:', { chatKey, chat });
// Проверка: что реально лежит в storage после set
chrome.storage.local.get([chatKey], result => {
console.log('[pluginChatApi][saveMessage] ПРОВЕРКА storage после set:', result[chatKey]);
});
resolve();
});
});
Expand Down Expand Up @@ -87,9 +99,10 @@ const pluginChatApi = {
text,
updatedAt: Date.now(),
};
console.log('[pluginChatApi][saveDraft] BEFORE', { draftKey, pluginId, pageKey, text });
await new Promise<void>(resolve => {
chrome.storage.local.set({ [draftKey]: draft }, () => {
console.log('[pluginChatApi] saveDraft:', draft);
console.log('[pluginChatApi][saveDraft] AFTER', { draftKey, pluginId, pageKey, text, draft });
resolve();
});
});
Expand All @@ -99,11 +112,12 @@ const pluginChatApi = {
// Получить черновик
async getDraft(pluginId: string, pageKey: string): Promise<{ draftText: string }> {
const draftKey = `${pluginId}::${getPageKey(pageKey)}::draft`;
console.log('[pluginChatApi][getDraft] BEFORE', { draftKey, pluginId, pageKey });
return new Promise(resolve => {
chrome.storage.local.get([draftKey], result => {
const draft = result[draftKey];
const draftText = draft && typeof draft.text === 'string' ? draft.text : '';
console.log('[pluginChatApi] getDraft:', draftKey, draft, 'draftText:', draftText);
console.log('[pluginChatApi][getDraft] AFTER', { draftKey, pluginId, pageKey, draft, draftText });
resolve({ draftText });
});
});
Expand All @@ -112,9 +126,10 @@ const pluginChatApi = {
// Удалить черновик
async deleteDraft(pluginId: string, pageKey: string): Promise<{ success: boolean }> {
const draftKey = `${pluginId}::${getPageKey(pageKey)}::draft`;
console.log('[pluginChatApi][deleteDraft] BEFORE', { draftKey, pluginId, pageKey });
await new Promise<void>(resolve => {
chrome.storage.local.remove([draftKey], () => {
console.log('[pluginChatApi] deleteDraft:', draftKey);
console.log('[pluginChatApi][deleteDraft] AFTER', { draftKey, pluginId, pageKey });
resolve();
});
});
Expand All @@ -127,11 +142,13 @@ const pluginChatApi = {
chrome.storage.local.get(null, result => {
const drafts = Object.values(result).filter(
(item: unknown): item is ChatDraft =>
item &&
typeof item === 'object' &&
'draftKey' in item &&
'pluginId' in item &&
(item as ChatDraft).pluginId === pluginId,
!!(
item &&
typeof item === 'object' &&
'draftKey' in item &&
'pluginId' in item &&
(item as ChatDraft).pluginId === pluginId
),
);
console.log('[pluginChatApi] listDraftsForPlugin:', pluginId, drafts);
resolve(drafts);
Expand All @@ -145,11 +162,13 @@ const pluginChatApi = {
chrome.storage.local.get(null, result => {
const chats = Object.values(result).filter(
(item: unknown): item is PluginChat =>
item &&
typeof item === 'object' &&
'chatKey' in item &&
'pluginId' in item &&
(item as PluginChat).pluginId === pluginId,
!!(
item &&
typeof item === 'object' &&
'chatKey' in item &&
'pluginId' in item &&
(item as PluginChat).pluginId === pluginId
),
);
console.log('[pluginChatApi] listChatsForPlugin:', pluginId, chats);
resolve(chats as PluginChat[]);
Expand Down
Loading
Loading