pylogue 0.3__py3-none-any.whl → 0.3.30__py3-none-any.whl

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.
@@ -0,0 +1,199 @@
1
+
2
+ document.documentElement.classList.remove('dark');
3
+ const STOP_PREFIX = '__PYLOGUE_STOP__:';
4
+ const decodeCopyB64 = (value) => {
5
+ if (!value) return '';
6
+ try {
7
+ const binary = atob(value);
8
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
9
+ return new TextDecoder('utf-8').decode(bytes);
10
+ } catch {
11
+ return '';
12
+ }
13
+ };
14
+ document.addEventListener('click', async (event) => {
15
+ const btn = event.target.closest('.copy-btn');
16
+ if (!btn) return;
17
+ const targetId = btn.getAttribute('data-copy-target');
18
+ if (!targetId) return;
19
+ const el = document.getElementById(targetId);
20
+ if (!el) return;
21
+ const rawB64 = el.getAttribute('data-raw-b64');
22
+ const text = rawB64 ? decodeCopyB64(rawB64) : (el.getAttribute('data-raw') || el.innerText);
23
+ try {
24
+ await navigator.clipboard.writeText(text);
25
+ btn.dataset.copied = 'true';
26
+ setTimeout(() => { btn.dataset.copied = 'false'; }, 1200);
27
+ } catch (err) {
28
+ const textarea = document.createElement('textarea');
29
+ textarea.value = text;
30
+ document.body.appendChild(textarea);
31
+ textarea.select();
32
+ document.execCommand('copy');
33
+ document.body.removeChild(textarea);
34
+ btn.dataset.copied = 'true';
35
+ setTimeout(() => { btn.dataset.copied = 'false'; }, 1200);
36
+ }
37
+ });
38
+ document.addEventListener('click', async (event) => {
39
+ const btn = event.target.closest('.copy-chat-btn');
40
+ if (!btn) return;
41
+ if (event.defaultPrevented) return;
42
+ if (document.body?.dataset?.disableCoreDownload === 'true') return;
43
+ console.log('[pylogue-core] download handler fired');
44
+ const exportInput = document.getElementById('chat-export');
45
+ const input = exportInput || document.getElementById('chat-data');
46
+ if (!input) return;
47
+ const text = input.value || '[]';
48
+ const blob = new Blob([text], { type: 'application/json' });
49
+ const url = URL.createObjectURL(blob);
50
+ const link = document.createElement('a');
51
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
52
+ const rawTitle = document.body?.dataset?.activeChatTitle
53
+ || document.querySelector('.chat-item.is-active [data-chat-title="true"]')?.textContent
54
+ || '';
55
+ const slug = String(rawTitle)
56
+ .trim()
57
+ .toLowerCase()
58
+ .replace(/[^a-z0-9]+/g, '-')
59
+ .replace(/^-+|-+$/g, '');
60
+ link.href = url;
61
+ link.download = `${slug || 'pylogue-conversation'}-${timestamp}.json`;
62
+ document.body.appendChild(link);
63
+ link.click();
64
+ document.body.removeChild(link);
65
+ URL.revokeObjectURL(url);
66
+ btn.dataset.copied = 'true';
67
+ setTimeout(() => { btn.dataset.copied = 'false'; }, 1200);
68
+ });
69
+ document.addEventListener('click', (event) => {
70
+ const btn = event.target.closest('.upload-chat-btn');
71
+ if (!btn) return;
72
+ const input = document.getElementById('chat-upload');
73
+ if (!input) return;
74
+ input.click();
75
+ });
76
+ document.addEventListener('change', async (event) => {
77
+ const input = event.target;
78
+ if (!input || input.id !== 'chat-upload') return;
79
+ const file = input.files && input.files[0];
80
+ if (!file) return;
81
+ try {
82
+ const text = await file.text();
83
+ const data = JSON.parse(text);
84
+ const payload = JSON.stringify(data);
85
+ const msgInput = document.getElementById('msg');
86
+ const form = document.getElementById('form');
87
+ if (!msgInput || !form) return;
88
+ msgInput.value = `__PYLOGUE_IMPORT__:${payload}`;
89
+ form.requestSubmit();
90
+ } finally {
91
+ input.value = '';
92
+ }
93
+ });
94
+ document.body.addEventListener('htmx:wsAfterSend', () => {
95
+ const input = document.getElementById('msg');
96
+ if (!input) return;
97
+ input.value = '';
98
+ });
99
+ const setSendMode = (mode) => {
100
+ const btn = document.getElementById('chat-send-btn');
101
+ if (!btn) return;
102
+ if (mode === 'stop') {
103
+ btn.dataset.mode = 'stop';
104
+ btn.textContent = 'Stop';
105
+ } else {
106
+ btn.dataset.mode = 'send';
107
+ btn.textContent = 'Send';
108
+ }
109
+ };
110
+ document.body.addEventListener('htmx:wsBeforeSend', (event) => {
111
+ const form = event.detail && event.detail.elt;
112
+ if (!form || form.id !== 'form') return;
113
+ const input = document.getElementById('msg');
114
+ if (input && input.value && input.value.startsWith(STOP_PREFIX)) {
115
+ setSendMode('send');
116
+ return;
117
+ }
118
+ setSendMode('stop');
119
+ });
120
+ document.body.addEventListener('htmx:afterSwap', (event) => {
121
+ const target = event.detail && event.detail.target;
122
+ if (target && target.id === 'chat-export') {
123
+ setSendMode('send');
124
+ }
125
+ });
126
+ document.addEventListener('click', (event) => {
127
+ const btn = event.target.closest('#chat-send-btn');
128
+ if (!btn) return;
129
+ if (btn.dataset.mode !== 'stop') return;
130
+ event.preventDefault();
131
+ event.stopPropagation();
132
+ const form = document.getElementById('form');
133
+ const input = document.getElementById('msg');
134
+ if (!form || !input) return;
135
+ input.value = STOP_PREFIX;
136
+ htmx.trigger(form, 'submit');
137
+ });
138
+ document.addEventListener('keydown', (event) => {
139
+ if (event.key !== 'Enter') return;
140
+ const isSubmitCombo = event.metaKey || event.ctrlKey;
141
+ if (!isSubmitCombo) return;
142
+ const form = document.getElementById('form');
143
+ if (!form) return;
144
+ event.preventDefault();
145
+ form.requestSubmit();
146
+ });
147
+ (function initScrollDebug() {
148
+ const debug = [];
149
+ const maxEntries = 300;
150
+ const getScrollTop = () => {
151
+ const el = document.scrollingElement || document.documentElement;
152
+ return el ? el.scrollTop : 0;
153
+ };
154
+ const getActive = () => {
155
+ const el = document.activeElement;
156
+ if (!el) return null;
157
+ return { tag: el.tagName, id: el.id || '', cls: el.className || '' };
158
+ };
159
+ const push = (type, data) => {
160
+ debug.push({
161
+ t: Date.now(),
162
+ type,
163
+ scrollTop: getScrollTop(),
164
+ active: getActive(),
165
+ ...data,
166
+ });
167
+ if (debug.length > maxEntries) debug.shift();
168
+ };
169
+ window.__scrollDebug = debug;
170
+ window.__dumpScrollDebug = () => JSON.stringify(debug, null, 2);
171
+
172
+ let lastScrollTop = getScrollTop();
173
+ let scrollTimer = null;
174
+ document.addEventListener('scroll', () => {
175
+ if (scrollTimer) return;
176
+ scrollTimer = requestAnimationFrame(() => {
177
+ scrollTimer = null;
178
+ const current = getScrollTop();
179
+ if (current !== lastScrollTop) {
180
+ lastScrollTop = current;
181
+ push('scroll', {});
182
+ }
183
+ });
184
+ }, { passive: true });
185
+
186
+ const logSwap = (label, event) => {
187
+ const target = event && event.detail && event.detail.target;
188
+ push(label, {
189
+ targetId: target ? (target.id || '') : '',
190
+ targetTag: target ? target.tagName : '',
191
+ });
192
+ };
193
+ document.body.addEventListener('htmx:beforeSwap', (e) => logSwap('beforeSwap', e));
194
+ document.body.addEventListener('htmx:afterSwap', (e) => logSwap('afterSwap', e));
195
+ document.body.addEventListener('htmx:wsBeforeMessage', (e) => logSwap('wsBeforeMessage', e));
196
+ document.body.addEventListener('htmx:wsAfterMessage', (e) => logSwap('wsAfterMessage', e));
197
+ document.body.addEventListener('focusin', () => push('focusin', {}));
198
+ })();
199
+