|
| 1 | +import { Chatbot } from '../types/chatbot' |
| 2 | +import { |
| 3 | + add_apply_response_button, |
| 4 | + observe_for_responses |
| 5 | +} from '../utils/add-apply-response-button' |
| 6 | +import { |
| 7 | + InitializationError, |
| 8 | + report_initialization_error |
| 9 | +} from '../utils/report-initialization-error' |
| 10 | + |
| 11 | +export const hugging_chat: Chatbot = { |
| 12 | + wait_until_ready: async () => { |
| 13 | + await new Promise((resolve) => setTimeout(resolve, 500)) |
| 14 | + }, |
| 15 | + inject_apply_response_button: ( |
| 16 | + client_id: number, |
| 17 | + raw_instructions?: string, |
| 18 | + edit_format?: string |
| 19 | + ) => { |
| 20 | + const add_buttons = (footer: Element) => { |
| 21 | + add_apply_response_button({ |
| 22 | + client_id, |
| 23 | + raw_instructions, |
| 24 | + edit_format, |
| 25 | + footer, |
| 26 | + get_chat_turn: (f) => f.closest('div[data-message-role="assistant"]'), |
| 27 | + perform_copy: (f) => { |
| 28 | + const copy_button = f.querySelector( |
| 29 | + 'button:nth-child(3)' |
| 30 | + ) as HTMLElement |
| 31 | + if (!copy_button) { |
| 32 | + report_initialization_error({ |
| 33 | + function_name: 'hugging_chat.perform_copy', |
| 34 | + log_message: 'Copy button not found', |
| 35 | + alert_message: InitializationError.UNABLE_TO_COPY_RESPONSE |
| 36 | + }) |
| 37 | + return |
| 38 | + } |
| 39 | + copy_button.click() |
| 40 | + }, |
| 41 | + insert_button: (f, b) => f.insertBefore(b, f.children[1]) |
| 42 | + }) |
| 43 | + } |
| 44 | + |
| 45 | + observe_for_responses({ |
| 46 | + chatbot_name: 'Hugging Chat', |
| 47 | + is_generating: () => |
| 48 | + !!document.querySelector('button.stop-generating-btn'), |
| 49 | + footer_selector: 'div[data-message-role="assistant"] > div:nth-child(3)', |
| 50 | + add_buttons |
| 51 | + }) |
| 52 | + } |
| 53 | +} |
0 commit comments