ai_co_discuss 0.5.35 → 0.5.36

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.
package/backend/server.py CHANGED
@@ -52,6 +52,7 @@ from .room_trace import message_trace
52
52
  from .free_room import review_capability, review_roster, checked_review_plan, save_review_plan, check_review_retry
53
53
  from .free_room import review_ready, advance_review, late_answer, execution_changes, execution_changes_batch, execution_diffs
54
54
  from .free_room import checked_sequence, continue_sequence, sequence_view
55
+ from .windows_thumbnail import encode_preview
55
56
  from . import questions
56
57
  from .visual_fences import fold_message_visuals
57
58
  from .identity import MAX_ROOM_AGENTS, PARTICIPANTS, default_label_text, is_ai, is_participant
@@ -2485,7 +2486,7 @@ def thumbnail_path(database, attachment):
2485
2486
  def store_attachment_thumbnail(connection, database, room_id, identifier, token, data):
2486
2487
  """Keep the smaller copy of an image attachment a room participant's page made; the first one stored stays.
2487
2488
 
2488
- The site cannot decode images, so it checks what it can read from the headers: a WebP or JPEG no larger than
2489
+ Validate a client-supplied preview using its headers: a WebP or JPEG no larger than
2489
2490
  MAX_THUMBNAIL_SIDE pixels, smaller than the original, with the original's shape.
2490
2491
 
2491
2492
  Returns:
@@ -2514,6 +2515,45 @@ def store_attachment_thumbnail(connection, database, room_id, identifier, token,
2514
2515
  return {"attachment": get_attachment(connection, room_id, identifier), "duplicate": False}
2515
2516
 
2516
2517
 
2518
+ def generate_attachment_thumbnail(connection, database, attachment):
2519
+ """Keep a smaller PNG attachment preview, if the local codec and original are available."""
2520
+ if (os.name != "nt" or attachment["content_type"] != "image/png"
2521
+ or attachment.get("thumbnail_type")):
2522
+ return False
2523
+ path = attachment_path(database, attachment)
2524
+ try:
2525
+ with path.open("rb") as source:
2526
+ width, height = image_size(source)
2527
+ data = encode_preview(path, width, height)
2528
+ if data and data.startswith(b"\x89PNG") and len(data) > MAX_THUMBNAIL_BYTES:
2529
+ data = encode_preview(path, width, height, max_width=360)
2530
+ if not data or len(data) > MAX_THUMBNAIL_BYTES or len(data) * 2 >= attachment["size"]:
2531
+ return False
2532
+ with connection:
2533
+ begin_write(connection)
2534
+ updated = connection.execute("UPDATE attachments SET thumbnail_type=? "
2535
+ "WHERE id=? AND thumbnail_type IS NULL", (attachment_content_type(data), attachment["id"]))
2536
+ if not updated.rowcount:
2537
+ return False
2538
+ thumbnail_path(database, attachment).write_bytes(data)
2539
+ return True
2540
+ except (OSError, ValueError, sqlite3.Error):
2541
+ logging.debug("Preview unavailable for %s", attachment["id"], exc_info=True)
2542
+ return False
2543
+
2544
+
2545
+ def backfill_thumbnails(database, room_id):
2546
+ """Generate missing previews in one room, one file at a time outside the write lock."""
2547
+ with closing(connect_db(database)) as connection:
2548
+ require_room(connection, room_id)
2549
+ rows = connection.execute("SELECT id,content_type,size,thumbnail_type FROM attachments "
2550
+ "WHERE room_id=? AND content_type='image/png' AND thumbnail_type IS NULL "
2551
+ "AND message_id IS NOT NULL",
2552
+ (room_id,)).fetchall()
2553
+ generated = sum(generate_attachment_thumbnail(connection, database, dict(row)) for row in rows)
2554
+ logging.info("Generated %d of %d missing PNG previews", generated, len(rows))
2555
+
2556
+
2517
2557
  def store_attachment(connection, database, room_id, metadata, data):
2518
2558
  """Persist one immutable upload; exact retries return the original file."""
2519
2559
  begin_write(connection)
@@ -2542,6 +2582,7 @@ def store_attachment(connection, database, room_id, metadata, data):
2542
2582
  except Exception:
2543
2583
  path.unlink(missing_ok=True)
2544
2584
  raise
2585
+ generate_attachment_thumbnail(connection, database, record)
2545
2586
  return {"attachment": get_attachment(connection, room_id, record["id"]), "duplicate": False}
2546
2587
 
2547
2588
 
@@ -5151,8 +5192,12 @@ def main():
5151
5192
  parser.add_argument("--no-demo", action="store_true", help="Do not seed sample data in a new database")
5152
5193
  parser.add_argument("--local-launch", action="store_true", help="Enable local AI launch and configuration (127.0.0.1 only)")
5153
5194
  parser.add_argument("--reset-admin", action="store_true", help="Delete the administrator account and sessions, then exit")
5195
+ parser.add_argument("--backfill-thumbnails", metavar="ROOM", help="Generate missing PNG previews / 补齐房间 PNG 预览图")
5154
5196
  args = parser.parse_args()
5155
5197
  logging.basicConfig(level=logging.INFO, format="%(asctime)s %(message)s")
5198
+ if args.backfill_thumbnails:
5199
+ backfill_thumbnails(args.database, args.backfill_thumbnails)
5200
+ return
5156
5201
  init_database(args.database, seed=not args.no_demo)
5157
5202
  retry_destruction(args.database)
5158
5203
  if args.reset_admin:
@@ -0,0 +1,88 @@
1
+ """Generate PNG or JPEG previews with the Windows system GDI+ codec."""
2
+ import ctypes
3
+ from contextlib import ExitStack
4
+ from functools import lru_cache
5
+ from pathlib import Path
6
+ from tempfile import TemporaryDirectory
7
+ from uuid import UUID
8
+
9
+ from ctypes import byref, c_int, c_uint, c_void_p, c_size_t, Structure
10
+
11
+
12
+ class StartupInput(Structure):
13
+ _fields_ = [("version", c_uint), ("callback", c_void_p), ("no_thread", c_int), ("no_codec", c_int)]
14
+
15
+
16
+ class BitmapData(Structure):
17
+ _fields_ = [("width", c_uint), ("height", c_uint), ("stride", c_int), ("format", c_int),
18
+ ("pixels", c_void_p), ("reserved", c_size_t)]
19
+
20
+
21
+ ARGB32 = 0x26200A
22
+ PNG_ENCODER = UUID("557cf406-1a04-11d3-9a73-0000f81ef32e").bytes_le
23
+ JPEG_ENCODER = UUID("557cf401-1a04-11d3-9a73-0000f81ef32e").bytes_le
24
+ MAX_SOURCE_PIXELS = 24_000_000
25
+
26
+
27
+ def checked(status):
28
+ """Raise when the native image operation fails."""
29
+ if status:
30
+ raise ValueError(f"GDI+ status {status}")
31
+
32
+
33
+ @lru_cache(maxsize=1)
34
+ def graphics_library():
35
+ """Initialize the system codec for the process lifetime."""
36
+ library = ctypes.WinDLL("gdiplus", winmode=0x800)
37
+ token = c_size_t()
38
+ checked(library.GdiplusStartup(byref(token), byref(StartupInput(1)), None))
39
+ return library
40
+
41
+
42
+ def encode_preview(path, width, height, max_width=720):
43
+ """Resize a bounded image, preserving transparency."""
44
+ if not width or not height or width * height > MAX_SOURCE_PIXELS:
45
+ return None
46
+ library = graphics_library()
47
+ scale = min(1, max_width / width, 1600 / height)
48
+ width, height = max(1, round(width * scale)), max(1, round(height * scale))
49
+ with ExitStack() as cleanup:
50
+ source, bitmap, graphics = c_void_p(), c_void_p(), c_void_p()
51
+ checked(library.GdipLoadImageFromFile(str(path), byref(source)))
52
+ cleanup.callback(library.GdipDisposeImage, source)
53
+ checked(library.GdipCreateBitmapFromScan0(width, height, 0, ARGB32, None, byref(bitmap)))
54
+ cleanup.callback(library.GdipDisposeImage, bitmap)
55
+ checked(library.GdipGetImageGraphicsContext(bitmap, byref(graphics)))
56
+ cleanup.callback(library.GdipDeleteGraphics, graphics)
57
+ checked(library.GdipSetInterpolationMode(graphics, 7))
58
+ # TileFlipXY extends the edge pixels during bicubic filtering.
59
+ attributes = c_void_p()
60
+ checked(library.GdipCreateImageAttributes(byref(attributes)))
61
+ cleanup.callback(library.GdipDisposeImageAttributes, attributes)
62
+ checked(library.GdipSetImageAttributesWrapMode(attributes, 3, 0, 0))
63
+ source_width, source_height = c_uint(), c_uint()
64
+ checked(library.GdipGetImageWidth(source, byref(source_width)))
65
+ checked(library.GdipGetImageHeight(source, byref(source_height)))
66
+ if source_width.value * source_height.value > MAX_SOURCE_PIXELS:
67
+ return None
68
+ checked(library.GdipDrawImageRectRectI(graphics, source, 0, 0, width, height, 0, 0,
69
+ source_width, source_height, 2, attributes, None, None))
70
+ encoder = preview_encoder(library, bitmap, width, height)
71
+ with TemporaryDirectory() as directory:
72
+ output = Path(directory) / "preview"
73
+ checked(library.GdipSaveImageToFile(bitmap, str(output), encoder, None))
74
+ return output.read_bytes()
75
+
76
+
77
+ def preview_encoder(library, bitmap, width, height):
78
+ """Keep transparency in PNG, otherwise use the system JPEG encoder."""
79
+ pixels = BitmapData()
80
+ checked(library.GdipBitmapLockBits(bitmap, None, 1, ARGB32, byref(pixels)))
81
+ try:
82
+ if pixels.stride == width * 4:
83
+ alpha = ctypes.string_at(pixels.pixels, pixels.stride * height)[3::4]
84
+ if alpha.count(255) == len(alpha):
85
+ return JPEG_ENCODER
86
+ return PNG_ENCODER
87
+ finally:
88
+ library.GdipBitmapUnlockBits(bitmap, byref(pixels))
@@ -56,4 +56,5 @@ Phones support portrait layout only. Tablets support both portrait and landscape
56
56
  - **Rooms are unavailable when the computer is offline:** If the computer is off, asleep, or its local service is stopped, the room list shows **Rooms (computer offline)** or **Rooms (computer not connected)**. It reconnects when the computer comes back online.
57
57
  - **Timed-out requests are not resent automatically:** If the computer does not respond in time, the page says “Result unconfirmed.”. Check the room to see whether the action took effect before trying again.
58
58
  - **Some changes require the computer:** Changing software executable paths, browsing outside Saved projects, and adding a new device must be done at the computer.
59
+ - **Attachment cache:** Pictures and files viewed through the relay are cached in this device’s browser and cleared when you unpair on this device.
59
60
  - **Clearing browser data requires pairing again:** Clearing browser data removes the device key. The handoff command also expires after 10 minutes, so keep the phone's clock reasonably accurate.
@@ -53,8 +53,8 @@ Rooms created by a host inherit its folder. Select the arrow to the left of the
53
53
 
54
54
  ### 4. Send and view attachments
55
55
 
56
- - **Attach files.** Paste or drag files into the composer, or use the paperclip button at the bottom-left. Each message can contain up to 10 files, 20 MiB each. Thumbnails appear above the composer. A placeholder such as `[Image #1]` or `[File #2]` is inserted at the cursor. Removing the thumbnail or deleting its placeholder with Backspace removes both. After sending, images first referenced in a paragraph or list item appear right below it in a two-column half-width grid (full width for a single image on phones, two columns for multiple, with `#n` badges when a message carries more than one image) and are not listed again below; other attachments stay listed under the message. The site automatically clears uploads left unsent for more than 24 hours. Attachments in sent or queued messages are kept.
57
- - **View attachments.** After sending a message, select its placeholder or attachment card. Images can be enlarged full-screen, zoomed, rotated, and saved; when the room has several images, the side buttons or the left and right arrow keys step between them. Audio and video play in the message. Documents and code open in the file preview.
56
+ - **Attach files.** Paste or drag files into the composer, or use the paperclip button at the bottom-left. Each message can contain up to 10 files, 20 MiB each. Thumbnails appear above the composer. A placeholder such as `[Image #1]` or `[File #2]` is inserted at the cursor. Removing the thumbnail or deleting its placeholder with Backspace removes both. After sending, images first referenced in a paragraph or list item appear right below it in a two-column half-width grid (full width for a single image on phones, two columns for multiple, with `#n` badges when a message carries more than one image) and are not listed again below; other attachments stay listed under the message. Windows sites automatically generate smaller previews for eligible PNG uploads. Open the image to view the original. The site automatically clears uploads left unsent for more than 24 hours. Attachments in sent or queued messages are kept.
57
+ - **View attachments.** After sending a message, select its placeholder or attachment card. Images can be enlarged full-screen, zoomed, rotated, and saved; when the room has several images, the side buttons, the left and right arrow keys, or a sideways swipe on a phone step between them (the side buttons hide when idle and return when you move the mouse or tap the image). Audio and video play in the message. Documents and code open in the file preview.
58
58
  - **Interactive visualizations.** A member can place a small web page you can operate (drag a slider, press a button, watch the result change) inside the answer text. It appears at that point in the answer, follows the room theme and light or dark mode, and also appears in place on a phone. It starts running when you scroll near it. The row below lets you “Collapse” it (your choice is remembered), view the “Source”, “Open larger preview” in the file preview, open it in a “New tab”, or “Download” it as an `.html` file. Read-only share pages, read-aloud, and collapsed message previews show a single “Interactive visualization” line instead, so rely on the member's written conclusion. `.html` attachments do not run inside messages; select the file card to open them in the preview or a new tab. Some visualizations are question panels: after you rank, allocate, or adjust and press the panel's submit button, the result is added above the message box as a quote rather than sent. You can edit or remove it, and it counts as your reply only when you send it. Submitting the same panel again replaces its earlier result.
59
59
  - **Member access to attachments.** For supported automatic runs, the local service downloads the file and passes its information to the receiving member. Claude Code and Codex CLI can view images directly. For API members, enable “Images” on the member card to view images. UTF-8 text attachments can be read on request. Members will say when they cannot read a format such as PDF.
60
60
 
@@ -57,4 +57,5 @@ npm 安装默认提供本机站点,没有随包可直接使用的公共线上
57
57
  - **电脑离线时看不到房间**:电脑关机、休眠或本机服务未运行时,手机目录标题会显示“协作房间(电脑离线)”或“协作房间(电脑未连接)”;电脑恢复在线后页面自动重连。
58
58
  - **超时不自动重发**:电脑没及时答复时,页面会提示“结果待确认”,不会自动重发;先看房间确认是否已生效。
59
59
  - **只能在电脑上改的项**:软件可执行路径、常用项目范围之外的目录、以及添加新设备,都只能在电脑前操作。
60
+ - **附件缓存**:经中转看过的图片和文件会缓存在这台设备的浏览器里,在这台设备上解除配对时清除。
60
61
  - **清除浏览器数据需重配**:手机清理浏览器数据会删掉设备密钥,需回到电脑前重新配对;另外转交命令 10 分钟后作废,请保持手机系统时间大致准确。
@@ -51,8 +51,8 @@
51
51
 
52
52
  ### 4. 发送与查看附件
53
53
 
54
- - **添加附件**:在输入框粘贴、拖入文件,或点左下角回形针按钮选择文件(每条消息最多 10 个,单个最多 20 MiB)。添加后输入框上方出现缩略图,正文光标处插入 `[图片 #1]`、`[文件 #2]` 等房间内连续编号的占位标签;删掉缩略图或按退格删掉占位,两边同步移除。发出后,正文里首次写到 `[图片 #n]` 的图片会紧跟在所在段落或列表项下方以半宽两列排布显示(手机上单张占满整宽、多张两列并排,多图消息附带 `#n` 角标),附件列表不再重复列出;其他附件仍列在消息下方。 已上传但一直未发送的附件超过 24 小时后会自动清理;已发送或仍在排队消息里的附件会保留。
55
- - **查看附件**:消息发出后点正文占位或附件卡片即可打开;图片支持全屏缩放、旋转与保存,房间里有多张图片时可用两侧按钮或键盘左右方向键切换,音视频直接在消息里播放,文档与代码在文件预览窗口打开。
54
+ - **添加附件**:在输入框粘贴、拖入文件,或点左下角回形针按钮选择文件(每条消息最多 10 个,单个最多 20 MiB)。添加后输入框上方出现缩略图,正文光标处插入 `[图片 #1]`、`[文件 #2]` 等房间内连续编号的占位标签;删掉缩略图或按退格删掉占位,两边同步移除。发出后,正文里首次写到 `[图片 #n]` 的图片会紧跟在所在段落或列表项下方以半宽两列排布显示(手机上单张占满整宽、多张两列并排,多图消息附带 `#n` 角标),附件列表不再重复列出;其他附件仍列在消息下方。 Windows 站点会为上传的 PNG 自动生成较小的预览,点击图片可读原图。 已上传但一直未发送的附件超过 24 小时后会自动清理;已发送或仍在排队消息里的附件会保留。
55
+ - **查看附件**:消息发出后点正文占位或附件卡片即可打开;图片支持全屏缩放、旋转与保存,房间里有多张图片时可用两侧按钮、键盘左右方向键或手机上左右滑动切换(两侧按钮无操作时自动隐藏,移动鼠标或轻点图片即重新出现),音视频直接在消息里播放,文档与代码在文件预览窗口打开。
56
56
  - **交互式可视化**:成员可以在回答正文里放一段可以操作的网页(拖动滑块、点按钮看结果变化),它显示在正文中的原位置,跟随房间主题和深浅色,手机上同样直接显示。滚到它附近才开始运行。下方一行可“收起”(会记住选择)、看“源码”、“放大”到文件预览窗口、在“新标签页”打开或“下载”为 `.html` 文件。只读分享页、朗读和消息折叠时的预览只显示“交互式可视化”一行,结论以成员写在正文里的文字为准。`.html` 附件不在消息内显示,点文件卡片在预览窗口或新标签页打开。有的可视化是提问面板:你在里面排序、分配或调整后点它的提交按钮,结果会作为引用放到输入框上方,不会直接发出;你可以删改,点发送才算回答。同一面板再次提交会替换上一次的结果。
57
57
  - **成员读取附件**:本机服务为支持附件的自动执行下载文件,并把文件信息交给接收任务的成员。Claude Code 和 Codex CLI 可直接看图;API 成员需在卡片设置中打开“看图”才能看图,UTF-8 文本附件可按需读取,PDF 等其他文件读不到时会如实说明。
58
58
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai_co_discuss",
3
- "version": "0.5.35",
3
+ "version": "0.5.36",
4
4
  "bin": {
5
5
  "codiscuss": "runner/codiscuss.mjs"
6
6
  },
@@ -38,6 +38,7 @@
38
38
  "@vue-flow/core": "1.48.2",
39
39
  "@vue-flow/minimap": "1.5.4",
40
40
  "docx-preview": "0.4.1",
41
+ "fake-indexeddb": "6.2.8",
41
42
  "fflate": "0.8.3",
42
43
  "jsqr": "1.4.0",
43
44
  "katex": "0.18.10",