diff-chat 0.1.0__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.
Files changed (91) hide show
  1. adapters/README.md +28 -0
  2. adapters/__init__.py +48 -0
  3. adapters/_base.py +102 -0
  4. adapters/_cli.py +405 -0
  5. adapters/claude.py +141 -0
  6. adapters/gemini.py +323 -0
  7. adapters/gpt.py +217 -0
  8. adapters/local.py +146 -0
  9. adapters/registry.py +33 -0
  10. api_fallback.py +189 -0
  11. app.py +827 -0
  12. app_preferences.py +205 -0
  13. archive_schema.py +142 -0
  14. attachments.py +129 -0
  15. chat_titles.py +60 -0
  16. connection_handoff.py +64 -0
  17. context_engine.py +256 -0
  18. conversation_actions.py +160 -0
  19. diff_chat-0.1.0.dist-info/METADATA +101 -0
  20. diff_chat-0.1.0.dist-info/RECORD +91 -0
  21. diff_chat-0.1.0.dist-info/WHEEL +4 -0
  22. diff_chat-0.1.0.dist-info/entry_points.txt +2 -0
  23. diff_chat-0.1.0.dist-info/licenses/LICENSE +21 -0
  24. diff_chat_assets/memory.example.md +1 -0
  25. diff_chat_assets/prompts/about_you_export.md +19 -0
  26. diff_chat_assets/settings.json +6 -0
  27. diff_chat_assets/static/about-you-parser.js +46 -0
  28. diff_chat_assets/static/about-you.js +171 -0
  29. diff_chat_assets/static/actions.css +275 -0
  30. diff_chat_assets/static/actions.js +650 -0
  31. diff_chat_assets/static/app.css +345 -0
  32. diff_chat_assets/static/app.js +1344 -0
  33. diff_chat_assets/static/attachments.js +80 -0
  34. diff_chat_assets/static/brand/favicon-32.png +0 -0
  35. diff_chat_assets/static/brand/icon.svg +11 -0
  36. diff_chat_assets/static/brand/wordmark-dark.svg +15 -0
  37. diff_chat_assets/static/brand/wordmark-light.svg +13 -0
  38. diff_chat_assets/static/characters/CREDITS.md +7 -0
  39. diff_chat_assets/static/characters/characters.css +37 -0
  40. diff_chat_assets/static/characters/claude.json +507 -0
  41. diff_chat_assets/static/characters/claude.png +0 -0
  42. diff_chat_assets/static/characters/claude.webp +0 -0
  43. diff_chat_assets/static/characters/gemini.json +54 -0
  44. diff_chat_assets/static/characters/gemini.png +0 -0
  45. diff_chat_assets/static/characters/gemini.webp +0 -0
  46. diff_chat_assets/static/characters/gpt.json +507 -0
  47. diff_chat_assets/static/characters/gpt.png +0 -0
  48. diff_chat_assets/static/characters/gpt.webp +0 -0
  49. diff_chat_assets/static/characters/local.json +387 -0
  50. diff_chat_assets/static/characters/local.png +0 -0
  51. diff_chat_assets/static/characters/local.webp +0 -0
  52. diff_chat_assets/static/characters/player.js +318 -0
  53. diff_chat_assets/static/chat-filing.js +84 -0
  54. diff_chat_assets/static/controls.js +194 -0
  55. diff_chat_assets/static/corners.css +59 -0
  56. diff_chat_assets/static/craft.css +246 -0
  57. diff_chat_assets/static/drafts.js +41 -0
  58. diff_chat_assets/static/index.html +208 -0
  59. diff_chat_assets/static/library.css +30 -0
  60. diff_chat_assets/static/library.js +181 -0
  61. diff_chat_assets/static/memory.js +81 -0
  62. diff_chat_assets/static/preference-dialog.js +21 -0
  63. diff_chat_assets/static/preferences.css +56 -0
  64. diff_chat_assets/static/session.js +46 -0
  65. diff_chat_assets/static/settings.css +111 -0
  66. diff_chat_assets/static/settings.js +463 -0
  67. diff_chat_assets/static/setup.js +238 -0
  68. diff_chat_assets/static/utility.js +64 -0
  69. diff_chat_assets/static/vendor/LICENSES.txt +531 -0
  70. diff_chat_assets/static/vendor/highlight.min.js +1262 -0
  71. diff_chat_assets/static/vendor/markdown-it.min.js +13 -0
  72. diff_chat_assets/static/vendor/plex-mono.woff2 +0 -0
  73. diff_chat_assets/static/vendor/plex-sans.woff2 +0 -0
  74. diff_launcher.py +93 -0
  75. discussion.py +239 -0
  76. history_search.py +68 -0
  77. library_manager.py +251 -0
  78. model_options.py +132 -0
  79. plan_usage.py +72 -0
  80. private_store.py +71 -0
  81. probe.py +195 -0
  82. runtime_paths.py +195 -0
  83. server_security.py +100 -0
  84. setup_status.py +123 -0
  85. shared_memory.py +189 -0
  86. storage.py +185 -0
  87. usage_budget.py +77 -0
  88. usage_claude.py +110 -0
  89. usage_codex.py +170 -0
  90. usage_gemini.py +70 -0
  91. utility_models.py +104 -0
@@ -0,0 +1,387 @@
1
+ {
2
+ "version": 1,
3
+ "character": "local",
4
+ "frameSize": [
5
+ 256,
6
+ 256
7
+ ],
8
+ "baseline": 232,
9
+ "atlas": {
10
+ "width": 1024,
11
+ "height": 2560,
12
+ "webp": "local.webp",
13
+ "png": "local.png"
14
+ },
15
+ "states": {
16
+ "idle": {
17
+ "fps": 1.5,
18
+ "loop": true,
19
+ "staticFrame": 0,
20
+ "portrait": [
21
+ 0,
22
+ 0,
23
+ 256,
24
+ 256
25
+ ],
26
+ "frames": [
27
+ [
28
+ 0,
29
+ 0,
30
+ 256,
31
+ 256
32
+ ],
33
+ [
34
+ 256,
35
+ 0,
36
+ 256,
37
+ 256
38
+ ],
39
+ [
40
+ 512,
41
+ 0,
42
+ 256,
43
+ 256
44
+ ],
45
+ [
46
+ 768,
47
+ 0,
48
+ 256,
49
+ 256
50
+ ]
51
+ ]
52
+ },
53
+ "thinking": {
54
+ "fps": 3,
55
+ "loop": true,
56
+ "staticFrame": 2,
57
+ "portrait": [
58
+ 0,
59
+ 0,
60
+ 256,
61
+ 256
62
+ ],
63
+ "frames": [
64
+ [
65
+ 0,
66
+ 256,
67
+ 256,
68
+ 256
69
+ ],
70
+ [
71
+ 256,
72
+ 256,
73
+ 256,
74
+ 256
75
+ ],
76
+ [
77
+ 512,
78
+ 256,
79
+ 256,
80
+ 256
81
+ ],
82
+ [
83
+ 768,
84
+ 256,
85
+ 256,
86
+ 256
87
+ ]
88
+ ]
89
+ },
90
+ "writing": {
91
+ "fps": 4,
92
+ "loop": true,
93
+ "staticFrame": 2,
94
+ "portrait": [
95
+ 0,
96
+ 0,
97
+ 256,
98
+ 256
99
+ ],
100
+ "frames": [
101
+ [
102
+ 0,
103
+ 512,
104
+ 256,
105
+ 256
106
+ ],
107
+ [
108
+ 256,
109
+ 512,
110
+ 256,
111
+ 256
112
+ ],
113
+ [
114
+ 512,
115
+ 512,
116
+ 256,
117
+ 256
118
+ ],
119
+ [
120
+ 768,
121
+ 512,
122
+ 256,
123
+ 256
124
+ ]
125
+ ]
126
+ },
127
+ "done": {
128
+ "fps": 4,
129
+ "loop": false,
130
+ "staticFrame": 2,
131
+ "portrait": [
132
+ 0,
133
+ 0,
134
+ 256,
135
+ 256
136
+ ],
137
+ "frames": [
138
+ [
139
+ 0,
140
+ 768,
141
+ 256,
142
+ 256
143
+ ],
144
+ [
145
+ 256,
146
+ 768,
147
+ 256,
148
+ 256
149
+ ],
150
+ [
151
+ 512,
152
+ 768,
153
+ 256,
154
+ 256
155
+ ],
156
+ [
157
+ 768,
158
+ 768,
159
+ 256,
160
+ 256
161
+ ]
162
+ ]
163
+ },
164
+ "agree": {
165
+ "fps": 4,
166
+ "loop": false,
167
+ "staticFrame": 2,
168
+ "portrait": [
169
+ 0,
170
+ 0,
171
+ 256,
172
+ 256
173
+ ],
174
+ "frames": [
175
+ [
176
+ 0,
177
+ 1024,
178
+ 256,
179
+ 256
180
+ ],
181
+ [
182
+ 256,
183
+ 1024,
184
+ 256,
185
+ 256
186
+ ],
187
+ [
188
+ 512,
189
+ 1024,
190
+ 256,
191
+ 256
192
+ ],
193
+ [
194
+ 768,
195
+ 1024,
196
+ 256,
197
+ 256
198
+ ]
199
+ ]
200
+ },
201
+ "disagree": {
202
+ "fps": 4,
203
+ "loop": false,
204
+ "staticFrame": 2,
205
+ "portrait": [
206
+ 0,
207
+ 0,
208
+ 256,
209
+ 256
210
+ ],
211
+ "frames": [
212
+ [
213
+ 0,
214
+ 1280,
215
+ 256,
216
+ 256
217
+ ],
218
+ [
219
+ 256,
220
+ 1280,
221
+ 256,
222
+ 256
223
+ ],
224
+ [
225
+ 512,
226
+ 1280,
227
+ 256,
228
+ 256
229
+ ],
230
+ [
231
+ 768,
232
+ 1280,
233
+ 256,
234
+ 256
235
+ ]
236
+ ]
237
+ },
238
+ "waiting": {
239
+ "fps": 4,
240
+ "loop": true,
241
+ "staticFrame": 2,
242
+ "portrait": [
243
+ 0,
244
+ 0,
245
+ 256,
246
+ 256
247
+ ],
248
+ "frames": [
249
+ [
250
+ 0,
251
+ 1536,
252
+ 256,
253
+ 256
254
+ ],
255
+ [
256
+ 256,
257
+ 1536,
258
+ 256,
259
+ 256
260
+ ],
261
+ [
262
+ 512,
263
+ 1536,
264
+ 256,
265
+ 256
266
+ ],
267
+ [
268
+ 768,
269
+ 1536,
270
+ 256,
271
+ 256
272
+ ]
273
+ ]
274
+ },
275
+ "stopped": {
276
+ "fps": 4,
277
+ "loop": false,
278
+ "staticFrame": 2,
279
+ "portrait": [
280
+ 0,
281
+ 0,
282
+ 256,
283
+ 256
284
+ ],
285
+ "frames": [
286
+ [
287
+ 0,
288
+ 1792,
289
+ 256,
290
+ 256
291
+ ],
292
+ [
293
+ 256,
294
+ 1792,
295
+ 256,
296
+ 256
297
+ ],
298
+ [
299
+ 512,
300
+ 1792,
301
+ 256,
302
+ 256
303
+ ],
304
+ [
305
+ 768,
306
+ 1792,
307
+ 256,
308
+ 256
309
+ ]
310
+ ]
311
+ },
312
+ "error": {
313
+ "fps": 4,
314
+ "loop": true,
315
+ "staticFrame": 2,
316
+ "portrait": [
317
+ 0,
318
+ 0,
319
+ 256,
320
+ 256
321
+ ],
322
+ "frames": [
323
+ [
324
+ 0,
325
+ 2048,
326
+ 256,
327
+ 256
328
+ ],
329
+ [
330
+ 256,
331
+ 2048,
332
+ 256,
333
+ 256
334
+ ],
335
+ [
336
+ 512,
337
+ 2048,
338
+ 256,
339
+ 256
340
+ ],
341
+ [
342
+ 768,
343
+ 2048,
344
+ 256,
345
+ 256
346
+ ]
347
+ ]
348
+ },
349
+ "sleep": {
350
+ "fps": 1.5,
351
+ "loop": true,
352
+ "staticFrame": 2,
353
+ "portrait": [
354
+ 0,
355
+ 0,
356
+ 256,
357
+ 256
358
+ ],
359
+ "frames": [
360
+ [
361
+ 0,
362
+ 2304,
363
+ 256,
364
+ 256
365
+ ],
366
+ [
367
+ 256,
368
+ 2304,
369
+ 256,
370
+ 256
371
+ ],
372
+ [
373
+ 512,
374
+ 2304,
375
+ 256,
376
+ 256
377
+ ],
378
+ [
379
+ 768,
380
+ 2304,
381
+ 256,
382
+ 256
383
+ ]
384
+ ]
385
+ }
386
+ }
387
+ }
@@ -0,0 +1,318 @@
1
+ /* Sprite clocks belong to participants. Scrolling through history never starts a new animation. */
2
+ (() => {
3
+ const manifests = new Map();
4
+ const resources = new Map();
5
+ const unavailable = new Set();
6
+ const players = new Set();
7
+ const visible = new Set();
8
+ const byCanvas = new WeakMap();
9
+ const reduced = matchMedia("(prefers-reduced-motion: reduce)");
10
+ const actors = new Map();
11
+ function register(id, manifest) {
12
+ if (!manifest || actors.has(id)) return;
13
+ manifests.set(id, new URL(manifest, location.origin));
14
+ actors.set(id, {state:"idle", since:0, next:"idle", messageId:"", slotKey:"", pending:null});
15
+ }
16
+ const sleepDelay = 10 * 60 * 1000;
17
+ let enabled = true, frameRequest = 0, frameTimer = 0, sleepTimer = 0;
18
+ let lastActivity = Date.now(), hiddenSince = document.hidden ? performance.now() : null;
19
+ let currentRun = null, discussionRound = 0;
20
+
21
+ async function load(name) {
22
+ if (resources.has(name) || unavailable.has(name)) return;
23
+ const resource = {};
24
+ resources.set(name, resource);
25
+ const manifestUrl = manifests.get(name);
26
+ try {
27
+ const response = await fetch(manifestUrl);
28
+ if (!response.ok) throw Error("Sprite manifest unavailable");
29
+ const manifest = await response.json();
30
+ const atlas = new Image();
31
+ atlas.src = new URL(manifest.atlas.webp, manifestUrl);
32
+ try { await atlas.decode(); }
33
+ catch { atlas.src = new URL(manifest.atlas.png, manifestUrl); await atlas.decode(); }
34
+ Object.assign(resource, {manifest, atlas});
35
+ schedule();
36
+ } catch {
37
+ // A failed asset leaves the speaker's color dot in place.
38
+ resources.delete(name);
39
+ unavailable.add(name);
40
+ for (const player of players) if (player.provider === name) detach(player);
41
+ }
42
+ }
43
+
44
+ const intersection = new IntersectionObserver(entries => {
45
+ for (const entry of entries) {
46
+ const player = byCanvas.get(entry.target);
47
+ if (!player) continue;
48
+ if (entry.isIntersecting) visible.add(player);
49
+ else visible.delete(player);
50
+ }
51
+ schedule();
52
+ });
53
+
54
+ function detach(player) {
55
+ intersection.unobserve(player.canvas);
56
+ players.delete(player);
57
+ visible.delete(player);
58
+ byCanvas.delete(player.canvas);
59
+ player.canvas.remove();
60
+ }
61
+
62
+ // A chat switch discards its rows. Moving a row into a comparison preserves its player.
63
+ const observer = new MutationObserver(changes => {
64
+ for (const change of changes) for (const node of change.removedNodes) {
65
+ if (node.nodeType !== 1 || node.isConnected) continue;
66
+ if (byCanvas.has(node)) detach(byCanvas.get(node));
67
+ else if (node.childElementCount) {
68
+ for (const canvas of node.querySelectorAll("canvas.diff-character")) {
69
+ const player = byCanvas.get(canvas);
70
+ if (player) detach(player);
71
+ }
72
+ }
73
+ }
74
+ });
75
+
76
+ function mount(label, provider, inChat) {
77
+ const canvas = document.createElement("canvas");
78
+ canvas.className = "diff-character " + (inChat ? "character-head" : "character-body");
79
+ canvas.setAttribute("aria-hidden", "true");
80
+ label.prepend(canvas);
81
+ const player = {canvas, provider, inChat, id: "", resting: "idle", painted: ""};
82
+ players.add(player);
83
+ byCanvas.set(canvas, player);
84
+ intersection.observe(canvas);
85
+ if (enabled) load(provider);
86
+ return player;
87
+ }
88
+
89
+ function panel(heading, provider) {
90
+ const label = heading.querySelector("h3");
91
+ if (label && actors.has(provider) && !unavailable.has(provider) && !label.querySelector(".diff-character")) mount(label, provider, false);
92
+ }
93
+
94
+ function message(record, entry) {
95
+ const container = record.article;
96
+ let player = record.characterPlayer;
97
+ if (player && (player.provider !== entry.speaker || player.canvas.parentElement !== container)) {
98
+ detach(player);
99
+ player = record.characterPlayer = null;
100
+ }
101
+ if (!actors.has(entry.speaker) || unavailable.has(entry.speaker)) return;
102
+ if (!player) player = record.characterPlayer = mount(container, entry.speaker, true);
103
+ const resting = entry.error && !/\bstopp?ed\b/i.test(entry.error.message || "") ? "error" : "idle";
104
+ if (player.id !== entry.message_id || player.resting !== resting) {
105
+ player.id = entry.message_id || "";
106
+ player.resting = resting;
107
+ player.painted = "";
108
+ schedule();
109
+ }
110
+ }
111
+
112
+ function draw(player, resource, state, index) {
113
+ const {canvas} = player;
114
+ const scale = Math.min(3, devicePixelRatio || 1);
115
+ const pixels = Math.round(canvas.clientWidth * scale);
116
+ if (!pixels) return;
117
+ const key = state + "/" + index + "/" + pixels;
118
+ if (player.painted === key) return;
119
+ const clip = resource.manifest.states[state];
120
+ const [sx, sy, sw, sh] = clip.frames[index];
121
+ if (canvas.width !== pixels || canvas.height !== pixels) canvas.width = canvas.height = pixels;
122
+ const ctx = canvas.getContext("2d");
123
+ ctx.clearRect(0, 0, pixels, pixels);
124
+ ctx.imageSmoothingEnabled = true;
125
+ ctx.imageSmoothingQuality = "high";
126
+ ctx.drawImage(resource.atlas, sx, sy, sw, sh, 0, 0, pixels, pixels);
127
+ player.painted = key;
128
+ canvas.dataset.pose = state;
129
+ canvas.dataset.frame = String(index);
130
+ canvas.dataset.ready = "true";
131
+ }
132
+
133
+ function stopClock() {
134
+ if (frameRequest) cancelAnimationFrame(frameRequest);
135
+ clearTimeout(frameTimer);
136
+ frameRequest = frameTimer = 0;
137
+ }
138
+
139
+ function schedule() {
140
+ if (!enabled || document.hidden || !visible.size) { stopClock(); return; }
141
+ clearTimeout(frameTimer);
142
+ frameTimer = 0;
143
+ if (!frameRequest) frameRequest = requestAnimationFrame(paint);
144
+ }
145
+
146
+ function pose(actor, state, next = "idle") {
147
+ actor.state = state;
148
+ actor.since = performance.now();
149
+ actor.next = next;
150
+ }
151
+
152
+ function paint(now) {
153
+ frameRequest = 0;
154
+ let wait = Infinity;
155
+ // Long-hidden or offscreen one-shot gestures settle before the next visible draw.
156
+ for (const [provider, actor] of actors) {
157
+ const states = resources.get(provider)?.manifest?.states;
158
+ if (!states) continue;
159
+ const clip = states[actor.state];
160
+ if (!clip) {
161
+ // Partial atlases use idle. An unillustrated gesture must not hold up the next pose.
162
+ const pending = actor.pending;
163
+ actor.pending = null;
164
+ pose(actor, pending && states[pending.state] ? pending.state : "idle", pending?.next);
165
+ continue;
166
+ }
167
+ if (clip.loop) continue;
168
+ const remaining = clip.frames.length * 1000 / clip.fps - (now - actor.since);
169
+ if (remaining <= 0) {
170
+ const intent = actor.pending;
171
+ actor.pending = null;
172
+ pose(actor, intent?.state || actor.next, intent?.next);
173
+ } else wait = Math.min(wait, remaining);
174
+ }
175
+ for (const player of visible) {
176
+ const resource = resources.get(player.provider);
177
+ if (!resource?.atlas) continue;
178
+ const actor = actors.get(player.provider);
179
+ const live = !player.inChat || (player.id && player.id === actor.messageId);
180
+ const requested = live ? actor.state : player.resting;
181
+ const state = resource.manifest.states[requested] ? requested : "idle";
182
+ const clip = resource.manifest.states[state];
183
+ const tick = 1000 / clip.fps;
184
+ const elapsed = Math.max(0, now - actor.since);
185
+ let index = clip.staticFrame || 0;
186
+ if (live && !reduced.matches) {
187
+ const raw = Math.floor(elapsed / tick);
188
+ index = clip.loop ? raw % clip.frames.length : Math.min(raw, clip.frames.length - 1);
189
+ wait = Math.min(wait, tick - elapsed % tick);
190
+ }
191
+ draw(player, resource, state, index);
192
+ }
193
+ // rAF drives presentation; low-fps poses leave the browser idle between frames.
194
+ if (Number.isFinite(wait)) frameTimer = setTimeout(schedule, Math.max(1, wait));
195
+ }
196
+
197
+ function setEnabled(value) {
198
+ enabled = value !== false;
199
+ document.documentElement.dataset.characters = enabled ? "on" : "off";
200
+ if (enabled) for (const player of players) load(player.provider);
201
+ schedule();
202
+ }
203
+
204
+ function wake() {
205
+ const now = Date.now();
206
+ if (now - lastActivity < 500 && sleepTimer) return;
207
+ lastActivity = now;
208
+ for (const actor of actors.values()) if (actor.state === "sleep") pose(actor, actor.next);
209
+ armSleep();
210
+ schedule();
211
+ }
212
+
213
+ function armSleep() {
214
+ clearTimeout(sleepTimer);
215
+ sleepTimer = 0;
216
+ if (currentRun) return;
217
+ sleepTimer = setTimeout(() => {
218
+ sleepTimer = 0;
219
+ for (const actor of actors.values()) {
220
+ if (actor.state === "idle" || actor.state === "waiting") pose(actor, "sleep", actor.state);
221
+ }
222
+ schedule();
223
+ }, Math.max(0, lastActivity + sleepDelay - Date.now()));
224
+ }
225
+
226
+ function intent(actor, key, state, next = "idle") {
227
+ if (actor.slotKey === key) return;
228
+ actor.slotKey = key;
229
+ if (actor.pending && actor.state === "disagree") actor.pending = {state, next};
230
+ else pose(actor, state, next);
231
+ }
232
+
233
+ function updateRun(event) {
234
+ const {runId, kind, stopped, done, discussion} = event.detail;
235
+ if (!runId) return;
236
+ const isNew = currentRun !== runId;
237
+ if (isNew) {
238
+ discussionRound = 0;
239
+ currentRun = runId;
240
+ }
241
+ lastActivity = Date.now();
242
+ armSleep();
243
+ const list = event.detail.slots || [];
244
+ const all = done && !list.length ? (event.detail.finishedSlots ||
245
+ (event.detail.messages || []).filter(entry => entry.turn_id === runId)) : list;
246
+ const advanced = discussionRound > 0 && discussion?.round > discussionRound;
247
+ if (discussion?.round) discussionRound = discussion.round;
248
+ for (const [name, actor] of actors) {
249
+ const slot = all.findLast(entry => entry.speaker === name);
250
+ if (isNew) actor.pending = null;
251
+ if (slot) {
252
+ actor.runId = runId;
253
+ actor.messageId = slot.message_id || "";
254
+ }
255
+ if (done && discussion && actor.runId === runId && ["agreed", "limit"].includes(discussion.status)) {
256
+ actor.pending = null;
257
+ intent(actor, runId + discussion.status, discussion.status === "agreed" ? "agree" : "disagree");
258
+ continue;
259
+ }
260
+ if (stopped && (actor.runId === runId)) {
261
+ actor.pending = null;
262
+ intent(actor, runId + "stopped", "stopped");
263
+ continue;
264
+ }
265
+ if (!slot && (!done || actor.runId !== runId)) continue;
266
+ let state;
267
+ if (slot?.error || slot?.status === "error") state = "error";
268
+ else if (slot?.status === "queued") state = "waiting";
269
+ else if (slot?.status === "thinking") state = slot.text ? "writing" : "thinking";
270
+ else if (!slot && done && actor.state === "error") state = "error";
271
+ else state = "done";
272
+ const next = kind === "respond" && state === "done" ? "waiting" : "idle";
273
+ if (advanced && !done) {
274
+ pose(actor, "disagree");
275
+ actor.pending = {state, next};
276
+ }
277
+ intent(actor, runId + "/" + actor.messageId + "/" + state, state, next);
278
+ }
279
+ if (done) { currentRun = null; armSleep(); }
280
+ schedule();
281
+ }
282
+
283
+ document.addEventListener("transcript:run-state", updateRun);
284
+ document.addEventListener("transcript:chat-opened", () => {
285
+ currentRun = null;
286
+ for (const actor of actors.values()) {
287
+ actor.messageId = actor.slotKey = "";
288
+ actor.runId = actor.pending = null;
289
+ pose(actor, "idle");
290
+ }
291
+ lastActivity = Date.now();
292
+ armSleep();
293
+ schedule();
294
+ });
295
+ document.addEventListener("visibilitychange", () => {
296
+ if (document.hidden) {
297
+ hiddenSince = performance.now();
298
+ stopClock();
299
+ } else {
300
+ if (hiddenSince !== null) {
301
+ const now = performance.now();
302
+ for (const actor of actors.values()) actor.since += now - Math.max(hiddenSince, actor.since);
303
+ hiddenSince = null;
304
+ }
305
+ armSleep();
306
+ schedule();
307
+ }
308
+ });
309
+ for (const event of ["pointerdown", "pointermove", "keydown", "input", "scroll"]) {
310
+ document.addEventListener(event, wake, {passive: true, capture: true});
311
+ }
312
+ reduced.addEventListener("change", schedule);
313
+ window.addEventListener("resize", schedule);
314
+ observer.observe(document.body, {childList: true, subtree: true});
315
+ armSleep();
316
+ setEnabled(true);
317
+ window.DiffCharacters = {register, message, panel, setEnabled};
318
+ })();