@aivin-labs/cli 1.0.13 → 1.0.24
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/README.md +325 -304
- package/bin/cli.mjs +97 -18
- package/bin/lib/localPreview.mjs +437 -0
- package/bin/lib/openFile.mjs +235 -0
- package/bin/lib/previewCache.mjs +71 -0
- package/bin/lib/remote/atomicFile.mjs +32 -0
- package/bin/lib/remote/autoStart.mjs +2 -1
- package/bin/lib/remote/autoUpdate.mjs +153 -129
- package/bin/lib/remote/callLedger.mjs +21 -0
- package/bin/lib/remote/cdpPolicy.mjs +14 -2
- package/bin/lib/remote/client.mjs +1025 -889
- package/bin/lib/remote/codingAgents.mjs +2 -2
- package/bin/lib/remote/constants.mjs +263 -251
- package/bin/lib/remote/credentials.mjs +81 -4
- package/bin/lib/remote/daemonLock.mjs +57 -17
- package/bin/lib/remote/desktop/castInput.mjs +98 -0
- package/bin/lib/remote/desktop/desktopCast.mjs +337 -198
- package/bin/lib/remote/desktop/desktopCastCaptureSource.mjs +598 -0
- package/bin/lib/remote/desktop/desktopCastSource.mjs +880 -514
- package/bin/lib/remote/desktop/desktopWebRtc.mjs +251 -95
- package/bin/lib/remote/desktop/fileAssociation.mjs +108 -0
- package/bin/lib/remote/desktop/index.mjs +21 -7
- package/bin/lib/remote/desktop/linuxTraySource.mjs +1 -8
- package/bin/lib/remote/desktop/macTraySource.mjs +0 -2
- package/bin/lib/remote/desktop/strings.mjs +28 -2
- package/bin/lib/remote/desktop/traySource.mjs +380 -16
- package/bin/lib/remote/desktop/webrtcRuntime.mjs +137 -0
- package/bin/lib/remote/desktop/webrtcWorker.mjs +183 -0
- package/bin/lib/remote/deviceProfile.mjs +2 -4
- package/bin/lib/remote/fileIndexer.mjs +30 -14
- package/bin/lib/remote/folderRules.mjs +3 -0
- package/bin/lib/remote/gitSafe.mjs +31 -0
- package/bin/lib/remote/gui/index.mjs +66 -24
- package/bin/lib/remote/gui/officeHostSource.mjs +635 -393
- package/bin/lib/remote/gui/windowsHost.mjs +3 -1
- package/bin/lib/remote/gui/windowsHostSource.mjs +291 -60
- package/bin/lib/remote/httpTransfer.mjs +64 -3
- package/bin/lib/remote/localPolicy.mjs +73 -7
- package/bin/lib/remote/mascot/ask.mjs +956 -768
- package/bin/lib/remote/mascot/askBlocksSource.mjs +286 -0
- package/bin/lib/remote/mascot/askHostSource.mjs +658 -530
- package/bin/lib/remote/mascot/blocks.mjs +201 -0
- package/bin/lib/remote/mascot/bot.mjs +26 -2
- package/bin/lib/remote/mascot/chartLayout.mjs +382 -0
- package/bin/lib/remote/mascot/diagramRender.mjs +154 -0
- package/bin/lib/remote/mascot/emojiSource.mjs +273 -0
- package/bin/lib/remote/mascot/fileChips.mjs +62 -0
- package/bin/lib/remote/mascot/hostSource.mjs +328 -49
- package/bin/lib/remote/mascot/hotkey.mjs +31 -7
- package/bin/lib/remote/mascot/images.mjs +111 -0
- package/bin/lib/remote/mascot/index.mjs +663 -493
- package/bin/lib/remote/mascot/lucideIcons.mjs +32 -0
- package/bin/lib/remote/mascot/mermaidBundle.mjs +28 -0
- package/bin/lib/remote/mascot/mood.mjs +57 -0
- package/bin/lib/remote/mascot/rigSource.mjs +643 -609
- package/bin/lib/remote/mascot/safeUrl.mjs +29 -0
- package/bin/lib/remote/mascot/strings.mjs +459 -375
- package/bin/lib/remote/mascot/ui.mjs +27 -7
- package/bin/lib/remote/multiUser.mjs +7 -2
- package/bin/lib/remote/notify.mjs +4 -1
- package/bin/lib/remote/office/index.mjs +12 -6
- package/bin/lib/remote/processes.mjs +5 -2
- package/bin/lib/remote/sandbox.mjs +26 -0
- package/bin/lib/remote/secretPaths.mjs +21 -0
- package/bin/lib/remote/tokenRotation.mjs +28 -0
- package/bin/lib/remote/toolHandlers.mjs +79 -15
- package/bin/lib/remote/watchBatcher.mjs +56 -0
- package/bin/lib/selfUpdate.mjs +12 -2
- package/bin/lib/update/binarySwap.mjs +15 -1
- package/bin/lib/update/state.mjs +10 -0
- package/docs/CLI.md +1545 -1504
- package/docs/media/aivin-ecosystem.jpg +0 -0
- package/package.json +75 -71
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bảng, thẻ, ảnh trong ô hỏi của linh vật (03/11/2026) — mã PowerShell chèn vào ASK_PS1 (askHostSource.mjs), nhận `blocks` của lệnh `chat` (blocks.mjs).
|
|
3
|
+
* - Có khối thì ô hỏi nới rộng ra `ASK_WIDE_WIDTH` (chữ bình thường vẫn ô nhỏ), `chat_clear` thu về; vùng chat cao thêm để đọc được bảng.
|
|
4
|
+
* - Bảng: cột co giãn theo `weights`, ô dài xuống dòng rồi cắt bằng dấu "…". Thẻ: xếp dọc, ảnh nhỏ hoặc icon bên trái. Ảnh: giữ tỉ lệ, bấm mở trên trình duyệt.
|
|
5
|
+
* - Ảnh chờ daemon tải (`done` chưa có): ô xám; tải xong daemon gửi lại đúng dòng đó. Giải mã không được (máy thiếu codec WebP…) → nút mở link.
|
|
6
|
+
* - Biểu đồ: daemon tính sẵn từng hình (chartLayout.mjs), ở đây chỉ đặt lên canvas. Sơ đồ: ảnh do daemon dựng (diagramRender.mjs). Công cụ tương tác, tệp, video, link,
|
|
7
|
+
* phiên trình duyệt: thẻ bấm mở. Nguồn trích dẫn: chip nhỏ.
|
|
8
|
+
* Giữ toàn ASCII (xem hostSource.mjs).
|
|
9
|
+
*/
|
|
10
|
+
const ASK_NARROW_WIDTH = 240;
|
|
11
|
+
const ASK_WIDE_WIDTH = 320;
|
|
12
|
+
const CHAT_NARROW_HEIGHT = 220;
|
|
13
|
+
const CHAT_WIDE_HEIGHT = 380;
|
|
14
|
+
const BUBBLE_NARROW_WIDTH = 200;
|
|
15
|
+
const BUBBLE_WIDE_WIDTH = 276;
|
|
16
|
+
/** Bề rộng dùng được của khối trong ô đã nới rộng. */
|
|
17
|
+
const BLOCK_WIDTH = 288;
|
|
18
|
+
const IMAGE_MAX_HEIGHT = 180;
|
|
19
|
+
const IMAGE_PLACEHOLDER_HEIGHT = 110;
|
|
20
|
+
const THUMB_SIZE = 28;
|
|
21
|
+
const CARD_BG = '#F7F8FA';
|
|
22
|
+
const LINE = '#E5E6EB';
|
|
23
|
+
const CELL_LINE = '#EEF0F4';
|
|
24
|
+
const HEADER_BG = '#F7F8FA';
|
|
25
|
+
const PLACEHOLDER = '#F2F3F5';
|
|
26
|
+
const TAG_BG = '#EEF0FF';
|
|
27
|
+
const TAG_INK = '#5B50D6';
|
|
28
|
+
/** Ô icon của thẻ: nền pastel, icon cùng tông nhưng đậm hơn (hồng, tím, xanh trời, xanh bạc hà — xoay vòng như lựa chọn trong ô hỏi). */
|
|
29
|
+
const ICON_TINTS = Object.freeze(['#FCE7F3', '#EDE9FE', '#DBEAFE', '#D1FAE5']);
|
|
30
|
+
export const ICON_INKS = Object.freeze(['#DB2777', '#7C3AED', '#2563EB', '#059669']);
|
|
31
|
+
const CARD_ICON_SIZE = 14;
|
|
32
|
+
/** Sơ đồ thường cao hơn ảnh: thấp quá thì chữ không đọc được. */
|
|
33
|
+
const DIAGRAM_MAX_HEIGHT = 320;
|
|
34
|
+
|
|
35
|
+
export const ASK_BLOCKS_PS1 = String.raw`
|
|
36
|
+
# ---- Rich blocks in the ask box (askBlocksSource.mjs) ----
|
|
37
|
+
$script:askWide = $false; $script:bubbleMax = ${BUBBLE_NARROW_WIDTH}; $script:scrollRow = $null
|
|
38
|
+
function AskWidth($wide) {
|
|
39
|
+
if ([bool]$wide -eq $script:askWide) { return }
|
|
40
|
+
$script:askWide = [bool]$wide
|
|
41
|
+
$script:bubbleMax = if ($wide) { ${BUBBLE_WIDE_WIDTH} } else { ${BUBBLE_NARROW_WIDTH} }
|
|
42
|
+
foreach ($r in $script:chatRows.Values) { $r.box.MaxWidth = $script:bubbleMax }
|
|
43
|
+
(E 'ChatScroll').MaxHeight = if ($wide) { ${CHAT_WIDE_HEIGHT} } else { ${CHAT_NARROW_HEIGHT} }
|
|
44
|
+
$ease = New-Object Windows.Media.Animation.CubicEase; $ease.EasingMode = 'EaseOut'
|
|
45
|
+
$a = New-Object Windows.Media.Animation.DoubleAnimation ([double]$(if ($wide) { ${ASK_WIDE_WIDTH} } else { ${ASK_NARROW_WIDTH} })), ([TimeSpan]::FromMilliseconds(180))
|
|
46
|
+
$a.EasingFunction = $ease
|
|
47
|
+
# Text wraps again while the box grows: the answer's first line is only in its final place afterwards.
|
|
48
|
+
$a.Add_Completed({ if ($script:scrollRow) { ScrollToRow $script:scrollRow } })
|
|
49
|
+
(E 'Ask').BeginAnimation([Windows.FrameworkElement]::WidthProperty, $a)
|
|
50
|
+
}
|
|
51
|
+
# A table is read from the top: show the answer's first line, not the end of the list.
|
|
52
|
+
function ScrollToRow($row) {
|
|
53
|
+
$sv = E 'ChatScroll'; $sv.UpdateLayout()
|
|
54
|
+
$p = $row.box.TranslatePoint((New-Object Windows.Point 0, 0), (E 'ChatList'))
|
|
55
|
+
$sv.ScrollToVerticalOffset([Math]::Max(0, $p.Y - 2))
|
|
56
|
+
}
|
|
57
|
+
# Lucide icon outline from the daemon (lucideIcons.mjs): drawn on its 24 x 24 grid, stroke 2, round ends, like on the web. Clipped to the grid: a browser
|
|
58
|
+
# clips an svg to its box, and a few Lucide icons do have a stroke outside it (save-off).
|
|
59
|
+
function LucideIcon($path, $size, $ink) {
|
|
60
|
+
$p = New-Object Windows.Shapes.Path; $p.Data = [Windows.Media.Geometry]::Parse([string]$path); $p.Stroke = Brush $ink; $p.StrokeThickness = 2
|
|
61
|
+
$p.StrokeStartLineCap = 'Round'; $p.StrokeEndLineCap = 'Round'; $p.StrokeLineJoin = 'Round'
|
|
62
|
+
$grid = New-Object Windows.Controls.Canvas; $grid.Width = 24; $grid.Height = 24; $grid.ClipToBounds = $true; [void]$grid.Children.Add($p)
|
|
63
|
+
$box = New-Object Windows.Controls.Viewbox; $box.Width = $size; $box.Height = $size; $box.Child = $grid; $box
|
|
64
|
+
}
|
|
65
|
+
function BlockText($text, $size, $ink) {
|
|
66
|
+
$t = New-Object Windows.Controls.TextBlock; $t.TextWrapping = 'Wrap'; $t.FontSize = $size; $t.Foreground = Brush $ink; SetText $t $text; $t
|
|
67
|
+
}
|
|
68
|
+
function BlockTitle($text) { $t = BlockText $text 12 $P.muted; $t.FontWeight = 'SemiBold'; $t.Margin = '2,0,0,4'; $t }
|
|
69
|
+
function BlockNote($text) { $t = BlockText $text 11.5 $P.muted; $t.Margin = '2,3,0,0'; $t }
|
|
70
|
+
# Rounded corners for what is inside a border (a border does not clip its child). The radius rides on Tag: the handler is not a closure.
|
|
71
|
+
function RoundCorners($el, $radius) {
|
|
72
|
+
$el.Tag = [double]$radius
|
|
73
|
+
$el.Add_SizeChanged({ param($s)
|
|
74
|
+
$s.Clip = New-Object Windows.Media.RectangleGeometry -ArgumentList (New-Object Windows.Rect 0, 0, $s.ActualWidth, $s.ActualHeight), ([double]$s.Tag), ([double]$s.Tag)
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
function BlockTable($b) {
|
|
78
|
+
$wrap = New-Object Windows.Controls.StackPanel; $wrap.Margin = '0,0,0,6'
|
|
79
|
+
if ($b.title) { [void]$wrap.Children.Add((BlockTitle $b.title)) }
|
|
80
|
+
$grid = New-Object Windows.Controls.Grid; $grid.Background = Brush '#FFFFFF'; RoundCorners $grid 7
|
|
81
|
+
foreach ($weight in @($b.weights)) {
|
|
82
|
+
$cd = New-Object Windows.Controls.ColumnDefinition
|
|
83
|
+
$cd.Width = New-Object Windows.GridLength -ArgumentList ([double]$weight), ([Windows.GridUnitType]::Star)
|
|
84
|
+
[void]$grid.ColumnDefinitions.Add($cd)
|
|
85
|
+
}
|
|
86
|
+
$rows = @($b.rows); $cols = [int]$b.cols
|
|
87
|
+
for ($r = 0; $r -lt $rows.Count; $r++) {
|
|
88
|
+
$rd = New-Object Windows.Controls.RowDefinition; $rd.Height = [Windows.GridLength]::Auto; [void]$grid.RowDefinitions.Add($rd)
|
|
89
|
+
$isHeader = $b.header -and $r -eq 0
|
|
90
|
+
$col = 0
|
|
91
|
+
foreach ($cell in @($rows[$r])) {
|
|
92
|
+
if ($col -ge $cols) { break }
|
|
93
|
+
if ($cell.covered) { $col++; continue }
|
|
94
|
+
$span = [Math]::Min($(if ($cell.span) { [int]$cell.span } else { 1 }), $cols - $col)
|
|
95
|
+
$box = New-Object Windows.Controls.Border; $box.Padding = '7,4,7,4'; $box.BorderBrush = Brush '${CELL_LINE}'
|
|
96
|
+
$box.BorderThickness = if ($b.plain) { New-Object Windows.Thickness 0 } else { New-Object Windows.Thickness -ArgumentList 0, 0, $(if ($col + $span -lt $cols) { 1 } else { 0 }), $(if ($r -lt $rows.Count - 1) { 1 } else { 0 }) }
|
|
97
|
+
$box.Background = Brush $(if ($cell.bg) { [string]$cell.bg } elseif ($isHeader) { '${HEADER_BG}' } else { '#FFFFFF' })
|
|
98
|
+
$t = BlockText $cell.text 12 $(if ($cell.color) { [string]$cell.color } else { $P.ink })
|
|
99
|
+
$t.MaxHeight = 48; $t.TextTrimming = 'CharacterEllipsis'; $t.LineHeight = 16; $t.LineStackingStrategy = 'BlockLineHeight'
|
|
100
|
+
if ($isHeader -or $cell.bold) { $t.FontWeight = 'SemiBold' }
|
|
101
|
+
if ($cell.italic) { $t.FontStyle = 'Italic' }
|
|
102
|
+
$t.TextAlignment = switch ([string]$cell.align) { 'right' { 'Right' } 'center' { 'Center' } default { 'Left' } }
|
|
103
|
+
$box.Child = $t
|
|
104
|
+
[Windows.Controls.Grid]::SetRow($box, $r); [Windows.Controls.Grid]::SetColumn($box, $col)
|
|
105
|
+
if ($span -gt 1) { [Windows.Controls.Grid]::SetColumnSpan($box, $span) }
|
|
106
|
+
if ($cell.rowspan) { [Windows.Controls.Grid]::SetRowSpan($box, [int]$cell.rowspan) }
|
|
107
|
+
[void]$grid.Children.Add($box)
|
|
108
|
+
$col += $span
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
$frame = New-Object Windows.Controls.Border; $frame.CornerRadius = '8'; $frame.BorderThickness = $(if ($b.plain) { '0' } else { '1' }); $frame.BorderBrush = Brush '${LINE}'; $frame.Child = $grid
|
|
112
|
+
[void]$wrap.Children.Add($frame)
|
|
113
|
+
if ($b.note) { [void]$wrap.Children.Add((BlockNote $b.note)) }
|
|
114
|
+
$wrap
|
|
115
|
+
}
|
|
116
|
+
# Image file checked by the daemon (images.mjs) -> bitmap, or null when this machine cannot decode it.
|
|
117
|
+
function LoadBitmap($file, $width) {
|
|
118
|
+
try {
|
|
119
|
+
$bmp = New-Object Windows.Media.Imaging.BitmapImage; $bmp.BeginInit(); $bmp.UriSource = New-Object Uri ([string]$file); $bmp.CacheOption = 'OnLoad'
|
|
120
|
+
$bmp.CreateOptions = 'IgnoreColorProfile'; $bmp.DecodePixelWidth = [int]$width; $bmp.EndInit(); $bmp.Freeze(); return $bmp
|
|
121
|
+
} catch { Dbg "image: $($_.Exception.Message)"; return $null }
|
|
122
|
+
}
|
|
123
|
+
function PictureFill($bmp) {
|
|
124
|
+
$brush = New-Object Windows.Media.ImageBrush $bmp; $brush.Stretch = 'UniformToFill'; $brush.Freeze(); $brush
|
|
125
|
+
}
|
|
126
|
+
function CardThumb($c, $tint, $ink) {
|
|
127
|
+
$box = New-Object Windows.Controls.Border; $box.Width = ${THUMB_SIZE}; $box.Height = ${THUMB_SIZE}; $box.CornerRadius = '8'; $box.Margin = '0,1,8,0'; $box.VerticalAlignment = 'Top'
|
|
128
|
+
$bmp = if ($c.file) { LoadBitmap $c.file 160 } else { $null }
|
|
129
|
+
if ($bmp) { $box.Background = PictureFill $bmp; return $box }
|
|
130
|
+
# An image still loading: a grey square, the picture replaces it.
|
|
131
|
+
if ($c.image) { $box.Background = Brush '${PLACEHOLDER}'; return $box }
|
|
132
|
+
$box.Background = Brush $tint
|
|
133
|
+
if ($c.icon_path) { $icon = LucideIcon $c.icon_path ${CARD_ICON_SIZE} $ink; $icon.HorizontalAlignment = 'Center'; $icon.VerticalAlignment = 'Center'; $box.Child = $icon }
|
|
134
|
+
$box
|
|
135
|
+
}
|
|
136
|
+
function BlockCards($b) {
|
|
137
|
+
$wrap = New-Object Windows.Controls.StackPanel; $wrap.Margin = '0,0,0,6'
|
|
138
|
+
if ($b.title) { [void]$wrap.Children.Add((BlockTitle $b.title)) }
|
|
139
|
+
$tints = @(${ICON_TINTS.map((c) => `'${c}'`).join(', ')}); $inks = @(${ICON_INKS.map((c) => `'${c}'`).join(', ')}); $k = 0
|
|
140
|
+
foreach ($c in @($b.cards)) {
|
|
141
|
+
$card = New-Object Windows.Controls.Border; $card.CornerRadius = '10'; $card.Background = Brush '${CARD_BG}'; $card.Padding = '8,7,10,7'; $card.Margin = '0,0,0,4'
|
|
142
|
+
$dock = New-Object Windows.Controls.DockPanel
|
|
143
|
+
$thumb = CardThumb $c $tints[$k % $tints.Count] $inks[$k % $inks.Count]; $k++
|
|
144
|
+
[Windows.Controls.DockPanel]::SetDock($thumb, 'Left'); [void]$dock.Children.Add($thumb)
|
|
145
|
+
$sp = New-Object Windows.Controls.StackPanel
|
|
146
|
+
$title = BlockText $c.title 13 $P.ink; $title.FontWeight = 'SemiBold'; [void]$sp.Children.Add($title)
|
|
147
|
+
if ($c.text) { $d = BlockText $c.text 12 $P.muted; $d.MaxHeight = 50; $d.TextTrimming = 'CharacterEllipsis'; $d.Margin = '0,1,0,0'; [void]$sp.Children.Add($d) }
|
|
148
|
+
if ($c.tags) {
|
|
149
|
+
$tags = New-Object Windows.Controls.WrapPanel; $tags.Margin = '0,3,0,0'
|
|
150
|
+
foreach ($tag in @($c.tags)) {
|
|
151
|
+
$chip = New-Object Windows.Controls.Border; $chip.CornerRadius = '6'; $chip.Background = Brush '${TAG_BG}'; $chip.Padding = '6,1,6,2'; $chip.Margin = '0,0,4,2'
|
|
152
|
+
$chip.Child = BlockText $tag 11 '${TAG_INK}'; [void]$tags.Children.Add($chip)
|
|
153
|
+
}
|
|
154
|
+
[void]$sp.Children.Add($tags)
|
|
155
|
+
}
|
|
156
|
+
if ($c.footer) { $f = BlockText $c.footer 11 $P.muted; $f.Margin = '0,2,0,0'; [void]$sp.Children.Add($f) }
|
|
157
|
+
[void]$dock.Children.Add($sp); $card.Child = $dock; [void]$wrap.Children.Add($card)
|
|
158
|
+
}
|
|
159
|
+
if ($b.note) { [void]$wrap.Children.Add((BlockNote $b.note)) }
|
|
160
|
+
$wrap
|
|
161
|
+
}
|
|
162
|
+
function BlockImage($b, $maxHeight = ${IMAGE_MAX_HEIGHT}) {
|
|
163
|
+
$wrap = New-Object Windows.Controls.StackPanel; $wrap.Margin = '0,0,0,6'
|
|
164
|
+
if (-not $b.done) {
|
|
165
|
+
$wait = New-Object Windows.Controls.Border; $wait.CornerRadius = '8'; $wait.Height = ${IMAGE_PLACEHOLDER_HEIGHT}; $wait.Background = Brush '${PLACEHOLDER}'
|
|
166
|
+
[void]$wrap.Children.Add($wait)
|
|
167
|
+
} else {
|
|
168
|
+
$bmp = if ($b.file) { LoadBitmap $b.file ${BLOCK_WIDTH * 2} } else { $null }
|
|
169
|
+
if (-not $bmp) { if ($b.url) { [void]$wrap.Children.Add((LinkCard $b.open_text $b.url)) }; return $wrap }
|
|
170
|
+
# Keep the picture's shape: as wide as the box, unless that makes it too tall.
|
|
171
|
+
$width = [Math]::Min(${BLOCK_WIDTH}, [double]$bmp.PixelWidth); $height = $width * $bmp.PixelHeight / [Math]::Max(1, $bmp.PixelWidth)
|
|
172
|
+
if ($height -gt $maxHeight) { $width = $width * $maxHeight / $height; $height = $maxHeight }
|
|
173
|
+
$pic = New-Object Windows.Controls.Border; $pic.CornerRadius = '8'; $pic.Width = $width; $pic.Height = $height; $pic.HorizontalAlignment = 'Left'
|
|
174
|
+
$pic.Background = PictureFill $bmp
|
|
175
|
+
if ($b.url) {
|
|
176
|
+
$pic.Cursor = [Windows.Input.Cursors]::Hand; $pic.ToolTip = [string]$b.url; $pic.Tag = [string]$b.url
|
|
177
|
+
$pic.Add_MouseLeftButtonUp({ param($s) OpenWebUrl $s.Tag })
|
|
178
|
+
}
|
|
179
|
+
[void]$wrap.Children.Add($pic)
|
|
180
|
+
}
|
|
181
|
+
if ($b.caption) { [void]$wrap.Children.Add((BlockNote $b.caption)) }
|
|
182
|
+
$wrap
|
|
183
|
+
}
|
|
184
|
+
# Chart: the daemon works out every shape (chartLayout.mjs), here they are only placed on a canvas. k = r(ect), p(ath), c(ircle), t(ext).
|
|
185
|
+
function ChartShape($canvas, $s) {
|
|
186
|
+
$el = switch ([string]$s.k) {
|
|
187
|
+
'r' { $x = New-Object Windows.Shapes.Rectangle; $x.Width = [double]$s.w; $x.Height = [double]$s.h; $x.Fill = Brush $s.f; if ($s.rx) { $x.RadiusX = [double]$s.rx; $x.RadiusY = [double]$s.rx }; [Windows.Controls.Canvas]::SetLeft($x, [double]$s.x); [Windows.Controls.Canvas]::SetTop($x, [double]$s.y); $x }
|
|
188
|
+
'p' {
|
|
189
|
+
$x = New-Object Windows.Shapes.Path; $x.Data = [Windows.Media.Geometry]::Parse([string]$s.d)
|
|
190
|
+
if ($s.s) { $x.Stroke = Brush $s.s; $x.StrokeThickness = $(if ($s.sw) { [double]$s.sw } else { 1 }); $x.StrokeLineJoin = 'Round' }
|
|
191
|
+
if ($s.f) { $x.Fill = Brush $s.f }
|
|
192
|
+
$x
|
|
193
|
+
}
|
|
194
|
+
'c' {
|
|
195
|
+
$x = New-Object Windows.Shapes.Ellipse; $r = [double]$s.r; $x.Width = 2 * $r; $x.Height = 2 * $r
|
|
196
|
+
if ($s.f) { $x.Fill = Brush $s.f }
|
|
197
|
+
if ($s.s) { $x.Stroke = Brush $s.s; $x.StrokeThickness = 1.4 }
|
|
198
|
+
[Windows.Controls.Canvas]::SetLeft($x, [double]$s.x - $r); [Windows.Controls.Canvas]::SetTop($x, [double]$s.y - $r); $x
|
|
199
|
+
}
|
|
200
|
+
't' {
|
|
201
|
+
$x = New-Object Windows.Controls.TextBlock; $x.Text = [string]$s.t; $x.Width = [double]$s.w; $x.FontSize = $(if ($s.z) { [double]$s.z } else { 11 }); $x.TextTrimming = 'CharacterEllipsis'
|
|
202
|
+
$x.Foreground = Brush $(if ($s.c) { [string]$s.c } else { $P.ink }); if ($s.b) { $x.FontWeight = 'SemiBold' }
|
|
203
|
+
$x.TextAlignment = switch ([string]$s.a) { 'r' { 'Right' } 'c' { 'Center' } default { 'Left' } }
|
|
204
|
+
[Windows.Controls.Canvas]::SetLeft($x, [double]$s.x); [Windows.Controls.Canvas]::SetTop($x, [double]$s.y); $x
|
|
205
|
+
}
|
|
206
|
+
default { $null }
|
|
207
|
+
}
|
|
208
|
+
if ($el) { [void]$canvas.Children.Add($el) }
|
|
209
|
+
}
|
|
210
|
+
function BlockChart($b) {
|
|
211
|
+
$wrap = New-Object Windows.Controls.StackPanel; $wrap.Margin = '0,0,0,6'
|
|
212
|
+
if ($b.title) { [void]$wrap.Children.Add((BlockTitle $b.title)) }
|
|
213
|
+
$canvas = New-Object Windows.Controls.Canvas; $canvas.Width = [double]$b.layout.w; $canvas.Height = [double]$b.layout.h; $canvas.HorizontalAlignment = 'Left'
|
|
214
|
+
foreach ($s in @($b.layout.shapes)) { ChartShape $canvas $s }
|
|
215
|
+
[void]$wrap.Children.Add($canvas)
|
|
216
|
+
if ($b.layout.legend) {
|
|
217
|
+
$legend = New-Object Windows.Controls.WrapPanel; $legend.Margin = '2,5,0,0'
|
|
218
|
+
foreach ($l in @($b.layout.legend)) {
|
|
219
|
+
$item = New-Object Windows.Controls.StackPanel; $item.Orientation = 'Horizontal'; $item.Margin = '0,0,10,2'
|
|
220
|
+
$dot = New-Object Windows.Shapes.Rectangle; $dot.Width = 9; $dot.Height = 9; $dot.RadiusX = 2.5; $dot.RadiusY = 2.5; $dot.Fill = Brush $l.color; $dot.VerticalAlignment = 'Center'; $dot.Margin = '0,1,4,0'
|
|
221
|
+
[void]$item.Children.Add($dot)
|
|
222
|
+
$tb = BlockText $l.label 11.5 $P.muted; $tb.TextWrapping = 'NoWrap'; [void]$item.Children.Add($tb)
|
|
223
|
+
[void]$legend.Children.Add($item)
|
|
224
|
+
}
|
|
225
|
+
[void]$wrap.Children.Add($legend)
|
|
226
|
+
}
|
|
227
|
+
if ($b.note) { [void]$wrap.Children.Add((BlockNote $b.note)) }
|
|
228
|
+
$wrap
|
|
229
|
+
}
|
|
230
|
+
# A card that opens something: tool (webview: the daemon opens it in its own window), file, video, link, the AI browser session on the web.
|
|
231
|
+
function BlockActionCard($b) {
|
|
232
|
+
$btn = New-Object Windows.Controls.Button; $btn.Style = $w.FindResource('Btn'); $btn.Background = Brush '${CARD_BG}'; $btn.BorderThickness = '0'; $btn.Tag = Brush '#0A000000'
|
|
233
|
+
$btn.FontSize = 13; $btn.FontWeight = 'Normal'; $btn.Padding = '8,7,10,7'; $btn.Margin = '0,0,0,6'; $btn.HorizontalContentAlignment = 'Stretch'; $btn.HorizontalAlignment = 'Stretch'
|
|
234
|
+
$dock = New-Object Windows.Controls.DockPanel; $dock.Width = ${BLOCK_WIDTH - 20}
|
|
235
|
+
$thumb = CardThumb $b '${ICON_TINTS[2]}' '${ICON_INKS[2]}'
|
|
236
|
+
[Windows.Controls.DockPanel]::SetDock($thumb, 'Left'); [void]$dock.Children.Add($thumb)
|
|
237
|
+
$sp = New-Object Windows.Controls.StackPanel; $sp.VerticalAlignment = 'Center'
|
|
238
|
+
$title = BlockText $b.title 13 $P.ink; $title.FontWeight = 'SemiBold'; [void]$sp.Children.Add($title)
|
|
239
|
+
if ($b.text) { $d = BlockText $b.text 12 $P.muted; $d.MaxHeight = 34; $d.TextTrimming = 'CharacterEllipsis'; [void]$sp.Children.Add($d) }
|
|
240
|
+
if ($b.action) { $a = BlockText $b.action 12 '${ICON_INKS[2]}'; $a.Margin = '0,1,0,0'; [void]$sp.Children.Add($a) }
|
|
241
|
+
[void]$dock.Children.Add($sp); $btn.Content = $dock
|
|
242
|
+
if ([string]$b.type -eq 'webview') {
|
|
243
|
+
$btn.CommandParameter = @{ t = 'open_webview'; session_id = [string]$b.session_id; message_id = [string]$b.message_id; index = [int]$b.index; title = [string]$b.title }
|
|
244
|
+
$btn.Add_Click({ param($s) Send $s.CommandParameter })
|
|
245
|
+
} else {
|
|
246
|
+
$btn.CommandParameter = [string]$b.url; $btn.ToolTip = [string]$b.url
|
|
247
|
+
$btn.Add_Click({ param($s) OpenWebUrl $s.CommandParameter })
|
|
248
|
+
}
|
|
249
|
+
$btn
|
|
250
|
+
}
|
|
251
|
+
# Sources the answer cites: small chips, a click opens the page when the source has one.
|
|
252
|
+
function BlockSources($b) {
|
|
253
|
+
$wrap = New-Object Windows.Controls.WrapPanel; $wrap.Margin = '0,0,0,6'
|
|
254
|
+
$label = BlockText $b.label 11.5 $P.muted; $label.TextWrapping = 'NoWrap'; $label.Margin = '2,2,6,2'; $label.VerticalAlignment = 'Center'; [void]$wrap.Children.Add($label)
|
|
255
|
+
foreach ($i in @($b.items)) {
|
|
256
|
+
$chip = New-Object Windows.Controls.Border; $chip.CornerRadius = '6'; $chip.Background = Brush '${PLACEHOLDER}'; $chip.Padding = '6,1,6,2'; $chip.Margin = '0,0,4,3'; $chip.MaxWidth = 180
|
|
257
|
+
$tb = BlockText $i.name 11.5 $P.ink; $tb.TextWrapping = 'NoWrap'; $tb.TextTrimming = 'CharacterEllipsis'; $chip.Child = $tb
|
|
258
|
+
if ($i.url) {
|
|
259
|
+
$chip.Cursor = [Windows.Input.Cursors]::Hand; $chip.ToolTip = [string]$i.url; $chip.Tag = [string]$i.url
|
|
260
|
+
$chip.Add_MouseLeftButtonUp({ param($s) OpenWebUrl $s.Tag })
|
|
261
|
+
}
|
|
262
|
+
[void]$wrap.Children.Add($chip)
|
|
263
|
+
}
|
|
264
|
+
$wrap
|
|
265
|
+
}
|
|
266
|
+
function ChatBlocks($row, $blocks) {
|
|
267
|
+
$list = E 'ChatList'
|
|
268
|
+
if ($row.blocks) { [void]$list.Children.Remove($row.blocks); $row.blocks = $null }
|
|
269
|
+
$items = @(@($blocks) | Where-Object { $_ })
|
|
270
|
+
if (-not $items.Count) { return }
|
|
271
|
+
AskWidth $true
|
|
272
|
+
$sp = New-Object Windows.Controls.StackPanel; $sp.Margin = '0,2,0,0'
|
|
273
|
+
foreach ($b in $items) {
|
|
274
|
+
$el = $null
|
|
275
|
+
try {
|
|
276
|
+
$el = switch ([string]$b.type) {
|
|
277
|
+
'table' { BlockTable $b } 'cards' { BlockCards $b } 'image' { BlockImage $b } 'diagram' { BlockImage $b ${DIAGRAM_MAX_HEIGHT} } 'chart' { BlockChart $b }
|
|
278
|
+
'webview' { BlockActionCard $b } 'link_card' { BlockActionCard $b } 'sources' { BlockSources $b } default { $null }
|
|
279
|
+
}
|
|
280
|
+
} catch { Dbg "block: $($_.Exception.Message)" }
|
|
281
|
+
if ($el) { [void]$sp.Children.Add($el) }
|
|
282
|
+
}
|
|
283
|
+
$list.Children.Insert($list.Children.IndexOf($row.box) + 1, $sp); $row.blocks = $sp
|
|
284
|
+
}
|
|
285
|
+
# ---- end rich blocks ----
|
|
286
|
+
`;
|