@aivin-labs/cli 1.0.11 → 1.0.21
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 -288
- package/bin/cli.mjs +163 -17
- 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 +12 -0
- package/bin/lib/remote/browserTunnel.mjs +47 -8
- package/bin/lib/remote/callLedger.mjs +94 -14
- package/bin/lib/remote/cdpPolicy.mjs +14 -2
- package/bin/lib/remote/client.mjs +1024 -808
- package/bin/lib/remote/cloudFiles.mjs +53 -0
- package/bin/lib/remote/codingAgents.mjs +2 -2
- package/bin/lib/remote/constants.mjs +261 -234
- package/bin/lib/remote/credentials.mjs +81 -4
- package/bin/lib/remote/daemonLock.mjs +57 -17
- package/bin/lib/remote/dailyBrowser.mjs +8 -2
- package/bin/lib/remote/desktop/castInput.mjs +98 -0
- package/bin/lib/remote/desktop/desktopCast.mjs +334 -0
- package/bin/lib/remote/desktop/desktopCastCaptureSource.mjs +598 -0
- package/bin/lib/remote/desktop/desktopCastSource.mjs +798 -0
- package/bin/lib/remote/desktop/desktopWebRtc.mjs +242 -0
- package/bin/lib/remote/desktop/fileAssociation.mjs +108 -0
- package/bin/lib/remote/desktop/index.mjs +58 -7
- package/bin/lib/remote/desktop/linux.mjs +1 -1
- package/bin/lib/remote/desktop/linuxTraySource.mjs +427 -427
- package/bin/lib/remote/desktop/mac.mjs +2 -2
- package/bin/lib/remote/desktop/macTraySource.mjs +293 -292
- package/bin/lib/remote/desktop/strings.mjs +28 -2
- package/bin/lib/remote/desktop/traySource.mjs +905 -527
- package/bin/lib/remote/desktop/webrtcRuntime.mjs +137 -0
- package/bin/lib/remote/desktop/webrtcWorker.mjs +181 -0
- package/bin/lib/remote/deviceProfile.mjs +1 -0
- package/bin/lib/remote/docText.mjs +85 -0
- package/bin/lib/remote/fileIndexer.mjs +773 -399
- package/bin/lib/remote/folderRules.mjs +143 -0
- package/bin/lib/remote/gitSafe.mjs +31 -0
- package/bin/lib/remote/gui/index.mjs +170 -19
- package/bin/lib/remote/gui/officeHostSource.mjs +635 -393
- package/bin/lib/remote/gui/windowsHost.mjs +12 -3
- package/bin/lib/remote/gui/windowsHostSource.mjs +461 -87
- package/bin/lib/remote/httpTransfer.mjs +64 -3
- package/bin/lib/remote/idempotency.mjs +49 -20
- package/bin/lib/remote/localPolicy.mjs +81 -9
- package/bin/lib/remote/mascot/ask.mjs +207 -42
- package/bin/lib/remote/mascot/askBlocksSource.mjs +286 -0
- package/bin/lib/remote/mascot/askHostSource.mjs +658 -512
- package/bin/lib/remote/mascot/blocks.mjs +201 -0
- package/bin/lib/remote/mascot/bot.mjs +54 -5
- 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 +331 -52
- 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 +648 -609
- package/bin/lib/remote/mascot/safeUrl.mjs +29 -0
- package/bin/lib/remote/mascot/strings.mjs +456 -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/osSearch.mjs +107 -0
- 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/sqliteDb.mjs +51 -0
- package/bin/lib/remote/tokenRotation.mjs +28 -0
- package/bin/lib/remote/toolHandlers.mjs +852 -741
- package/bin/lib/remote/watchBatcher.mjs +56 -0
- package/bin/lib/remoteControl.mjs +26 -26
- 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/AIVIN_MASCOT.md +14 -0
- package/docs/CLI.md +1545 -1484
- package/docs/media/aivin-ecosystem.jpg +0 -0
- package/docs/media/aivin-mascot-live.gif +0 -0
- package/docs/media/aivin-mascot-live.png +0 -0
- package/docs/media/aivin-remote-architecture.svg +102 -0
- package/package.json +75 -71
- package/docs/media/aivin-mascot-states.mp4 +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AIVIN_BRAND } from '../brand.mjs';
|
|
2
2
|
import { BOT_FACES, BOT_LAYER_FILES, BOT_XAML } from './bot.mjs';
|
|
3
|
+
import { EMOJI_CS } from './emojiSource.mjs';
|
|
3
4
|
import { RIG_CS, RIG_REFERENCES_PS } from './rigSource.mjs';
|
|
4
5
|
import { VOICE_CS } from './voiceSource.mjs';
|
|
5
6
|
|
|
@@ -9,8 +10,9 @@ import { VOICE_CS } from './voiceSource.mjs';
|
|
|
9
10
|
*
|
|
10
11
|
* - Không viền, nền trong suốt (vùng trong suốt bấm xuyên qua), luôn nằm trên, không có trên thanh tác vụ / Alt+Tab.
|
|
11
12
|
* - KHÔNG cướp focus (WS_EX_NOACTIVATE): người dùng đang gõ, hoặc AI đang điều khiển một ứng dụng, không bị cửa sổ này giật phím.
|
|
12
|
-
* -
|
|
13
|
-
*
|
|
13
|
+
* - CÓ trong ảnh chụp màn hình (từ 01/11/2026, commit efa202c): WDA_EXCLUDEFROMCAPTURE trên cửa sổ layered trong suốt làm linh vật vô
|
|
14
|
+
* hình ngay trên màn hình thật ở một số máy, nên đã tắt. Ảnh AI chụp / chia sẻ màn hình khi họp / Desktop Cast thấy linh vật; khi AI
|
|
15
|
+
* bấm / chụp cửa sổ (lệnh `gui`) linh vật tự tránh đường. AIVIN_MASCOT_CAPTURABLE không còn tác dụng.
|
|
14
16
|
* - Kéo để di chuyển (nhớ chỗ), bấm để mở / thu bảng nhật ký; bảng mở về phía còn chỗ trên màn hình, kẹp trong vùng màn hình.
|
|
15
17
|
* - Chuyển động của bot: rigSource.mjs (C#, theo nhịp màn hình) — PowerShell chỉ báo trạng thái / rê chuột / nhấn / kéo cho rig.
|
|
16
18
|
* Lệnh vào: state | main | log | gui | show | quit. Sự kiện ra: ready | pos | pause | resume | hide | off.
|
|
@@ -23,8 +25,8 @@ const B = AIVIN_BRAND;
|
|
|
23
25
|
// The rendered bot is a MASCOT_BOX-sized Viewbox. Keep the hit/layout box equally large so the rounded lower body is not clipped.
|
|
24
26
|
const MASCOT_BOX = { w: 60, h: 60 };
|
|
25
27
|
export const MASCOT_CENTER = Object.freeze({ x: 30, y: 28.5 });
|
|
26
|
-
/** Rảnh (idle) liền chừng này
|
|
27
|
-
const
|
|
28
|
+
/** Rảnh (idle) liền chừng này giây mà không ai rê chuột → bot ngủ gật; có việc / rê chuột vào thì thức. */
|
|
29
|
+
const MASCOT_DOZE_SEC = 60;
|
|
28
30
|
/** Không chạm chuột / bàn phím chừng này phút = chủ máy đi vắng (khoá máy, đi họp…) → daemon gom việc xảy ra để báo khi quay lại. */
|
|
29
31
|
const MASCOT_AWAY_MIN = 10;
|
|
30
32
|
/** Lề trong cửa sổ quanh bot / các hộp (chỗ cho bóng đổ). */
|
|
@@ -40,9 +42,9 @@ const DROP_ZONE_R = 90;
|
|
|
40
42
|
|
|
41
43
|
/** Màu từng trạng thái: `fg` chấm / chữ, `bg` nền chip. */
|
|
42
44
|
export const MASCOT_PALETTE = Object.freeze({
|
|
43
|
-
idle: { fg: '#
|
|
45
|
+
idle: { fg: '#14C9C9', bg: '#E6FFFB' },
|
|
44
46
|
working: { fg: B.brand, bg: '#E8F3FF' },
|
|
45
|
-
thinking: { fg:
|
|
47
|
+
thinking: { fg: '#722ED1', bg: '#F9F0FF' },
|
|
46
48
|
waiting: { fg: B.warn, bg: B.warnBg },
|
|
47
49
|
paused: { fg: B.muted, bg: '#F2F3F5' },
|
|
48
50
|
offline: { fg: B.muted, bg: '#F2F3F5' },
|
|
@@ -116,19 +118,52 @@ export const MASCOT_XAML = `<Window xmlns="http://schemas.microsoft.com/winfx/20
|
|
|
116
118
|
${motion('BubbleIn', 1, 1, 160, 'EaseOut')}
|
|
117
119
|
${motion('BubbleOut', 0, 0.94, 140, 'EaseIn')}
|
|
118
120
|
<Style TargetType="ScrollBar">
|
|
119
|
-
<Setter Property="Width" Value="
|
|
120
|
-
<Setter Property="MinWidth" Value="
|
|
121
|
+
<Setter Property="Width" Value="5"/>
|
|
122
|
+
<Setter Property="MinWidth" Value="5"/>
|
|
121
123
|
<Setter Property="Template"><Setter.Value>
|
|
122
124
|
<ControlTemplate TargetType="ScrollBar">
|
|
123
125
|
<Track x:Name="PART_Track" IsDirectionReversed="True">
|
|
124
126
|
<Track.Thumb><Thumb><Thumb.Template><ControlTemplate TargetType="Thumb">
|
|
125
|
-
<Border x:Name="ThumbBar" CornerRadius="
|
|
126
|
-
<ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter TargetName="ThumbBar" Property="Background" Value="#
|
|
127
|
+
<Border x:Name="ThumbBar" CornerRadius="2.5" Background="#D5D8DE" Margin="0,1"/>
|
|
128
|
+
<ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter TargetName="ThumbBar" Property="Background" Value="#9EA4AF"/></Trigger></ControlTemplate.Triggers>
|
|
127
129
|
</ControlTemplate></Thumb.Template></Thumb></Track.Thumb>
|
|
128
130
|
</Track>
|
|
129
131
|
</ControlTemplate>
|
|
130
132
|
</Setter.Value></Setter>
|
|
131
133
|
</Style>
|
|
134
|
+
<Style TargetType="ScrollViewer">
|
|
135
|
+
<Setter Property="Template"><Setter.Value>
|
|
136
|
+
<ControlTemplate TargetType="ScrollViewer">
|
|
137
|
+
<Grid>
|
|
138
|
+
<Grid.ColumnDefinitions>
|
|
139
|
+
<ColumnDefinition Width="*"/>
|
|
140
|
+
<ColumnDefinition Width="Auto"/>
|
|
141
|
+
</Grid.ColumnDefinitions>
|
|
142
|
+
<ScrollContentPresenter Grid.Column="0"/>
|
|
143
|
+
<ScrollBar x:Name="PART_VerticalScrollBar" Grid.Column="1"
|
|
144
|
+
Value="{TemplateBinding VerticalOffset}"
|
|
145
|
+
Maximum="{TemplateBinding ScrollableHeight}"
|
|
146
|
+
ViewportSize="{TemplateBinding ViewportHeight}"
|
|
147
|
+
Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
|
|
148
|
+
Width="5" Margin="0,2,1,2" Opacity="0"/>
|
|
149
|
+
</Grid>
|
|
150
|
+
<ControlTemplate.Triggers>
|
|
151
|
+
<Trigger Property="IsMouseOver" Value="True">
|
|
152
|
+
<Trigger.EnterActions>
|
|
153
|
+
<BeginStoryboard>
|
|
154
|
+
<Storyboard><DoubleAnimation Storyboard.TargetName="PART_VerticalScrollBar" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.180"/></Storyboard>
|
|
155
|
+
</BeginStoryboard>
|
|
156
|
+
</Trigger.EnterActions>
|
|
157
|
+
<Trigger.ExitActions>
|
|
158
|
+
<BeginStoryboard>
|
|
159
|
+
<Storyboard><DoubleAnimation Storyboard.TargetName="PART_VerticalScrollBar" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.250"/></Storyboard>
|
|
160
|
+
</BeginStoryboard>
|
|
161
|
+
</Trigger.ExitActions>
|
|
162
|
+
</Trigger>
|
|
163
|
+
</ControlTemplate.Triggers>
|
|
164
|
+
</ControlTemplate>
|
|
165
|
+
</Setter.Value></Setter>
|
|
166
|
+
</Style>
|
|
132
167
|
<Storyboard x:Key="WindowIn"><DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.250"/></Storyboard>
|
|
133
168
|
<Storyboard x:Key="WindowOut">
|
|
134
169
|
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.220">${ease('EaseIn')}</DoubleAnimation>
|
|
@@ -162,23 +197,38 @@ export const MASCOT_XAML = `<Window xmlns="http://schemas.microsoft.com/winfx/20
|
|
|
162
197
|
</DockPanel>
|
|
163
198
|
<TextBlock x:Name="NowLabel" DockPanel.Dock="Top" Margin="0,14,0,4" FontSize="11" FontWeight="SemiBold" Foreground="${B.muted}"/>
|
|
164
199
|
<TextBlock x:Name="NowText" DockPanel.Dock="Top" Margin="0,0,6,0" FontSize="14" Foreground="${B.ink}" TextWrapping="Wrap" LineHeight="20"/>
|
|
200
|
+
<!-- Tần suất thông báo: 3 nấc (Ít = phiên này + cần xử lý, Vừa = thêm việc trên máy, Tất cả), khối trắng trượt tới nấc đang chọn -->
|
|
201
|
+
<TextBlock x:Name="NotifyFreqLabel" DockPanel.Dock="Top" Margin="0,14,0,6" FontSize="11" FontWeight="SemiBold" Foreground="${B.muted}"/>
|
|
202
|
+
<Grid x:Name="NotifySteps" DockPanel.Dock="Top" Margin="0,0,6,0" Height="30">
|
|
203
|
+
<Border CornerRadius="9" Background="#F2F3F5"/>
|
|
204
|
+
<Border x:Name="NotifyThumb" HorizontalAlignment="Left" Margin="2" CornerRadius="7" Background="#FFFFFF" BorderBrush="#E5E6EB" BorderThickness="1">
|
|
205
|
+
<Border.Effect><DropShadowEffect BlurRadius="6" ShadowDepth="1" Direction="270" Opacity="0.10" Color="#0B1B3F"/></Border.Effect>
|
|
206
|
+
<Border.RenderTransform><TranslateTransform/></Border.RenderTransform>
|
|
207
|
+
</Border>
|
|
208
|
+
<UniformGrid Rows="1" Columns="3">
|
|
209
|
+
${[0, 1, 2].map((i) => ` <Border x:Name="NotifyStep${i}" Tag="${i}" Background="Transparent" Cursor="Hand">
|
|
210
|
+
<TextBlock x:Name="NotifyStepText${i}" FontSize="11.5" FontWeight="SemiBold" Foreground="${B.muted}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
|
211
|
+
</Border>`).join('\n')}
|
|
212
|
+
</UniformGrid>
|
|
213
|
+
</Grid>
|
|
214
|
+
<TextBlock x:Name="NotifyFreqValue" DockPanel.Dock="Top" Margin="2,6,6,6" FontSize="11" Foreground="${B.muted}" TextWrapping="Wrap"/>
|
|
165
215
|
<!-- Hàng nút: phiên chat mới (nút chính); "Cho AI làm tiếp" chỉ hiện khi AI đang tạm dừng (dừng bằng aivin remote pause); tắt linh vật (đỏ). -->
|
|
166
216
|
<DockPanel DockPanel.Dock="Bottom" Margin="0,12,6,0" LastChildFill="False">
|
|
167
|
-
<Button x:Name="NewChatBtn" Style="{StaticResource Btn}" Height="
|
|
217
|
+
<Button x:Name="NewChatBtn" Style="{StaticResource Btn}" Height="28" FontSize="12" Padding="9,0,11,0" Background="${B.brand}" Foreground="White"
|
|
168
218
|
BorderThickness="0" Tag="#1F000000">
|
|
169
219
|
<StackPanel Orientation="Horizontal">
|
|
170
220
|
<Path Data="${ICON_NEW_CHAT}" Stroke="White" StrokeThickness="1.8" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round"
|
|
171
|
-
Width="
|
|
221
|
+
Width="12" Height="12" Stretch="Uniform" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
|
172
222
|
<TextBlock x:Name="NewChatText" VerticalAlignment="Center"/>
|
|
173
223
|
</StackPanel>
|
|
174
224
|
</Button>
|
|
175
|
-
<Button x:Name="PauseBtn" Style="{StaticResource Btn}" Height="
|
|
225
|
+
<Button x:Name="PauseBtn" Style="{StaticResource Btn}" Height="28" FontSize="12" Padding="10,0" Margin="8,0,0,0" Background="White" Foreground="${B.ink}"
|
|
176
226
|
BorderBrush="#C9CDD4" BorderThickness="1" Tag="#0F000000" Visibility="Collapsed"/>
|
|
177
|
-
<Button x:Name="OffBtn" DockPanel.Dock="Right" Style="{StaticResource Btn}" Height="
|
|
227
|
+
<Button x:Name="OffBtn" DockPanel.Dock="Right" Style="{StaticResource Btn}" Height="28" FontSize="12" Padding="8,0" Background="Transparent"
|
|
178
228
|
Foreground="${OFF_RED}" BorderThickness="0" Tag="#FFECE8" FontWeight="Normal">
|
|
179
229
|
<StackPanel Orientation="Horizontal">
|
|
180
230
|
<Path Data="${ICON_POWER}" Stroke="${OFF_RED}" StrokeThickness="2" StrokeStartLineCap="Round" StrokeEndLineCap="Round"
|
|
181
|
-
Width="
|
|
231
|
+
Width="12" Height="12" Stretch="Uniform" Margin="0,0,5,0" VerticalAlignment="Center"/>
|
|
182
232
|
<TextBlock x:Name="OffText" VerticalAlignment="Center"/>
|
|
183
233
|
</StackPanel>
|
|
184
234
|
</Button>
|
|
@@ -187,7 +237,7 @@ export const MASCOT_XAML = `<Window xmlns="http://schemas.microsoft.com/winfx/20
|
|
|
187
237
|
<Border CornerRadius="10" Background="#F7F8FA" BorderBrush="#EEF0F4" BorderThickness="1" Margin="0,0,6,0">
|
|
188
238
|
<Grid>
|
|
189
239
|
<TextBlock x:Name="Empty" Margin="12,14" FontSize="12.5" Foreground="${B.muted}" TextWrapping="Wrap"/>
|
|
190
|
-
<ScrollViewer Height="
|
|
240
|
+
<ScrollViewer Height="210" VerticalScrollBarVisibility="Auto"><StackPanel x:Name="LogList" Margin="0,4"/></ScrollViewer>
|
|
191
241
|
</Grid>
|
|
192
242
|
</Border>
|
|
193
243
|
</DockPanel>
|
|
@@ -205,11 +255,15 @@ export const MASCOT_XAML = `<Window xmlns="http://schemas.microsoft.com/winfx/20
|
|
|
205
255
|
<Border.RenderTransform><ScaleTransform ScaleX="0.96" ScaleY="0.96"/></Border.RenderTransform>
|
|
206
256
|
<Border.Effect><DropShadowEffect BlurRadius="12" ShadowDepth="1" Direction="270" Opacity="0.10" Color="#6B5CE7"/></Border.Effect>
|
|
207
257
|
<StackPanel Margin="12,8,7,7">
|
|
208
|
-
<ScrollViewer x:Name="ChatScroll" MaxHeight="
|
|
209
|
-
<StackPanel
|
|
258
|
+
<ScrollViewer x:Name="ChatScroll" MaxHeight="220" VerticalScrollBarVisibility="Auto" Visibility="Collapsed" Margin="0,3,-4,5">
|
|
259
|
+
<StackPanel Margin="0,0,10,0">
|
|
260
|
+
<StackPanel x:Name="ChatList"/>
|
|
261
|
+
<!-- Nút trả lời nhanh khi Aivin hỏi lại (thẻ chọn của agent) — askHostSource.mjs dựng theo lệnh ask_choices. -->
|
|
262
|
+
<StackPanel x:Name="Choices" Visibility="Collapsed" Margin="0,2,0,2"/>
|
|
263
|
+
</StackPanel>
|
|
210
264
|
</ScrollViewer>
|
|
211
|
-
<!--
|
|
212
|
-
<
|
|
265
|
+
<!-- Tệp thả vào bot, chờ đi kèm câu kế tiếp: chip icon + màu theo loại tệp, nút x để bỏ (askHostSource.mjs dựng theo ask_files). -->
|
|
266
|
+
<WrapPanel x:Name="AttachBar" Visibility="Collapsed" Margin="-4,0,0,5"/>
|
|
213
267
|
<DockPanel>
|
|
214
268
|
<Button x:Name="MicBtn" DockPanel.Dock="Right" Style="{StaticResource IconBtn}" Width="26" Height="26" Margin="6,0,0,0" VerticalAlignment="Bottom"
|
|
215
269
|
Background="${ASK_BTN.bg}" BorderThickness="0" Tag="#14000000">
|
|
@@ -222,12 +276,12 @@ export const MASCOT_XAML = `<Window xmlns="http://schemas.microsoft.com/winfx/20
|
|
|
222
276
|
</Grid>
|
|
223
277
|
</Button>
|
|
224
278
|
<Grid MinHeight="40">
|
|
225
|
-
<TextBox x:Name="AskBox" BorderThickness="0" Background="Transparent" FontSize="
|
|
279
|
+
<TextBox x:Name="AskBox" BorderThickness="0" Background="Transparent" FontSize="14" Foreground="${B.ink}" TextWrapping="Wrap"
|
|
226
280
|
MaxHeight="60" VerticalScrollBarVisibility="Hidden" CaretBrush="#8B7CF6" MaxLength="2000" Padding="0,1,0,1"/>
|
|
227
|
-
<TextBlock x:Name="AskHint" IsHitTestVisible="False" FontSize="
|
|
281
|
+
<TextBlock x:Name="AskHint" IsHitTestVisible="False" FontSize="14" Foreground="#A9AEB8" Margin="2,1,0,0" TextTrimming="CharacterEllipsis"/>
|
|
228
282
|
</Grid>
|
|
229
283
|
</DockPanel>
|
|
230
|
-
<TextBlock x:Name="AskStatus" Visibility="Collapsed" FontSize="
|
|
284
|
+
<TextBlock x:Name="AskStatus" Visibility="Collapsed" FontSize="13" Foreground="${B.muted}" Margin="0,2,4,1" TextTrimming="CharacterEllipsis"/>
|
|
231
285
|
</StackPanel>
|
|
232
286
|
</Border>
|
|
233
287
|
<Grid x:Name="Bubble" Visibility="Collapsed" Opacity="0" RenderTransformOrigin="0.5,1">
|
|
@@ -237,7 +291,7 @@ export const MASCOT_XAML = `<Window xmlns="http://schemas.microsoft.com/winfx/20
|
|
|
237
291
|
<DockPanel>
|
|
238
292
|
<!-- Chấm trạng thái đã có ở quả cầu ăng-ten trên đầu bot — bong bóng không lặp lại (giữ phần tử ẩn vì SetState còn tô màu nó). -->
|
|
239
293
|
<Ellipse x:Name="BubbleDot" Width="6" Height="6" Margin="0,5,7,0" VerticalAlignment="Top" Visibility="Collapsed"/>
|
|
240
|
-
<TextBlock x:Name="BubbleText" FontSize="
|
|
294
|
+
<TextBlock x:Name="BubbleText" FontSize="13" Foreground="${B.ink}" TextWrapping="Wrap" MaxHeight="36" TextTrimming="CharacterEllipsis" LineHeight="18"/>
|
|
241
295
|
</DockPanel>
|
|
242
296
|
</Border>
|
|
243
297
|
<Path x:Name="Tail" Data="M0,0 L14,0 L7,7 Z" Fill="#D9DCE1" VerticalAlignment="Bottom" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5"/>
|
|
@@ -254,8 +308,27 @@ export const MASCOT_XAML = `<Window xmlns="http://schemas.microsoft.com/winfx/20
|
|
|
254
308
|
</Window>`;
|
|
255
309
|
|
|
256
310
|
export const MASCOT_PS1 = String.raw`$ErrorActionPreference = 'Stop'
|
|
311
|
+
# Single mascot instance check
|
|
312
|
+
try {
|
|
313
|
+
# Only mascot hosts (any version: each lives in <mascot dir>\<hash>\host.ps1, an orphan of an old version would hold the mutex), same Windows
|
|
314
|
+
# session: a bare 'host.ps1' match also killed the user's localhost.ps1, ghost.ps1...
|
|
315
|
+
$myPid = $PID; $mySession = (Get-Process -Id $PID).SessionId
|
|
316
|
+
$mascotBase = if ($PSCommandPath) { Split-Path (Split-Path $PSCommandPath -Parent) -Parent } else { $null }
|
|
317
|
+
if ($mascotBase) {
|
|
318
|
+
Get-CimInstance Win32_Process -Filter "Name = 'powershell.exe'" -ErrorAction SilentlyContinue | ForEach-Object {
|
|
319
|
+
if ($_.ProcessId -ne $myPid -and $_.SessionId -eq $mySession -and $_.CommandLine -and $_.CommandLine.IndexOf($mascotBase, [StringComparison]::OrdinalIgnoreCase) -ge 0 -and $_.CommandLine.IndexOf('host.ps1', [StringComparison]::OrdinalIgnoreCase) -ge 0) {
|
|
320
|
+
Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
} catch {}
|
|
325
|
+
$createdNew = $false
|
|
326
|
+
$script:mascotMutex = New-Object System.Threading.Mutex($true, "Local\AivinMascotSingleInstance", [ref]$createdNew)
|
|
327
|
+
if (-not $createdNew) { exit 0 }
|
|
257
328
|
Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase, System.Xaml
|
|
258
329
|
$utf8 = New-Object Text.UTF8Encoding $false
|
|
330
|
+
# stderr (errors, Dbg) in UTF-8: the daemon reads it as UTF-8 (stdout has its own UTF-8 writer, AivinMascot.Output).
|
|
331
|
+
try { [Console]::OutputEncoding = $utf8 } catch {}
|
|
259
332
|
$dir = $env:AIVIN_MASCOT_DIR
|
|
260
333
|
function ReadText($name) { [IO.File]::ReadAllText((Join-Path $dir $name), $utf8) }
|
|
261
334
|
$cfg = ReadText 'config.json' | ConvertFrom-Json
|
|
@@ -264,6 +337,15 @@ $T = $cfg.strings; $P = $cfg.palette
|
|
|
264
337
|
function Send($o) { [AivinMascot.Output]::Line(($o | ConvertTo-Json -Compress)) }
|
|
265
338
|
# Debug trace: stderr + debug.log in the host folder (stderr is only kept as the last error line by the daemon).
|
|
266
339
|
function Dbg($text) { if ($env:AIVIN_MASCOT_DEBUG) { $line = "$([DateTime]::Now.ToString('HH:mm:ss.fff')) $text"; [Console]::Error.WriteLine("mascot: $line"); try { [IO.File]::AppendAllText((Join-Path $dir 'debug.log'), ($line + [Environment]::NewLine), $utf8) } catch {} } }
|
|
340
|
+
# Clicking a bubble / log row / chat row opens its link: http(s), or a call / mail / text from an answer's button (the daemon filters too) - Process.Start
|
|
341
|
+
# would run file:, shell: or a program path as is.
|
|
342
|
+
function OpenWebUrl($u) {
|
|
343
|
+
$s = [string]$u; if (-not $s) { return }
|
|
344
|
+
$uri = $null
|
|
345
|
+
if ([Uri]::TryCreate($s, [UriKind]::Absolute, [ref]$uri) -and @('http', 'https', 'mailto', 'tel', 'sms') -contains $uri.Scheme) {
|
|
346
|
+
try { [void][System.Diagnostics.Process]::Start($uri.AbsoluteUri) } catch {}
|
|
347
|
+
} else { Dbg "open url refused: $s" }
|
|
348
|
+
}
|
|
267
349
|
# Win32 calls + a background thread that reads stdin lines into a queue (stream ReadLineAsync faults on a console pipe in .NET Framework)
|
|
268
350
|
# + the bot's per-frame motion rig (C#, see rigSource.mjs) + live voice: mic / speaker streaming (C#, see voiceSource.mjs).
|
|
269
351
|
Add-Type -ReferencedAssemblies ${RIG_REFERENCES_PS} -TypeDefinition @'
|
|
@@ -312,6 +394,30 @@ namespace AivinMascot {
|
|
|
312
394
|
return IntPtr.Zero;
|
|
313
395
|
}
|
|
314
396
|
}
|
|
397
|
+
/** Global hotkeys (RegisterHotKey): the first free combination of each list (the daemon writes the lists into config.json). WM_HOTKEY is
|
|
398
|
+
picked out here in C# and only then handed to PowerShell (a PowerShell hook would run for every window message). */
|
|
399
|
+
public static class HotKeys {
|
|
400
|
+
[DllImport("user32.dll")] static extern bool RegisterHotKey(IntPtr h, int id, uint mods, uint vk);
|
|
401
|
+
static Action<int> pressed; static System.Windows.Interop.HwndSourceHook hook;
|
|
402
|
+
public static void Start(IntPtr h, Action<int> onPressed) {
|
|
403
|
+
if (hook != null) return;
|
|
404
|
+
pressed = onPressed; hook = Hook;
|
|
405
|
+
System.Windows.Interop.HwndSource.FromHwnd(h).AddHook(hook);
|
|
406
|
+
}
|
|
407
|
+
/** Registers the first combination that is free; returns its index in the list, -1 = none (all taken / empty list). */
|
|
408
|
+
public static int RegisterFirst(IntPtr h, int id, uint[] mods, uint[] vks) {
|
|
409
|
+
if (mods == null || vks == null) return -1;
|
|
410
|
+
for (int i = 0; i < mods.Length && i < vks.Length; i++) if (RegisterHotKey(h, id, mods[i], vks[i])) return i;
|
|
411
|
+
return -1;
|
|
412
|
+
}
|
|
413
|
+
static IntPtr Hook(IntPtr h, int msg, IntPtr wp, IntPtr lp, ref bool handled) {
|
|
414
|
+
if (msg == 0x0312 && pressed != null) {
|
|
415
|
+
int id = wp.ToInt32(); var cb = pressed; handled = true;
|
|
416
|
+
System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() => cb(id)));
|
|
417
|
+
}
|
|
418
|
+
return IntPtr.Zero;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
315
421
|
/** Keep the mascot above the taskbar: the taskbar is topmost too and jumps to the front when it (or any window) is activated, so
|
|
316
422
|
re-assert HWND_TOPMOST right at each foreground change and once more shortly after (the shell raises itself a beat later). */
|
|
317
423
|
public static class TopKeeper {
|
|
@@ -374,11 +480,15 @@ namespace AivinMascot {
|
|
|
374
480
|
}
|
|
375
481
|
${RIG_CS}
|
|
376
482
|
${VOICE_CS}
|
|
483
|
+
${EMOJI_CS}
|
|
377
484
|
}
|
|
378
485
|
'@
|
|
379
486
|
|
|
380
487
|
$w = [Windows.Markup.XamlReader]::Parse((ReadText 'mascot.xaml'))
|
|
381
488
|
function E($n) { $w.FindName($n) }
|
|
489
|
+
# Text that may hold emoji from the AI: WPF draws color fonts in one color, AivinMascot.Emoji (emojiSource.mjs) draws them in color. Read back with
|
|
490
|
+
# [AivinMascot.Emoji]::Text - TextBlock.Text does not return the same string once it holds pictures.
|
|
491
|
+
function SetText($el, $text) { [AivinMascot.Emoji]::Set($el, [string]$text) }
|
|
382
492
|
$conv = New-Object Windows.Media.BrushConverter
|
|
383
493
|
function Brush($hex) { $conv.ConvertFromString($hex) }
|
|
384
494
|
function Img($file) { $b = New-Object Windows.Media.Imaging.BitmapImage; $b.BeginInit(); $b.UriSource = New-Object Uri (Join-Path $dir $file); $b.CacheOption = 'OnLoad'; $b.EndInit(); $b.Freeze(); $b }
|
|
@@ -387,13 +497,56 @@ $script:rig = [AivinMascot.Rig]::new($w)
|
|
|
387
497
|
$w.Title = $T.window_title; (E 'Mascot').ToolTip = $T.tooltip; (E 'PanelTitle').Text = $T.panel_title
|
|
388
498
|
(E 'NowLabel').Text = $T.now_label; (E 'LogLabel').Text = $T.log_label; (E 'Empty').Text = $T.nothing_yet; (E 'NowText').Text = $T.ready
|
|
389
499
|
(E 'OffText').Text = $T.turn_off; (E 'PanelClose').ToolTip = $T.close
|
|
500
|
+
(E 'NotifyFreqLabel').Text = $T.notify_freq_label
|
|
501
|
+
(E 'NotifyStepText0').Text = $T.notify_step_min; (E 'NotifyStepText1').Text = $T.notify_step_mid; (E 'NotifyStepText2').Text = $T.notify_step_max
|
|
502
|
+
# Notification level: 3 steps; the white thumb slides to the chosen step (width = a third of the track, set on resize).
|
|
503
|
+
function PlaceNotifyThumb([bool]$animate) {
|
|
504
|
+
$track = E 'NotifySteps'; $thumb = E 'NotifyThumb'
|
|
505
|
+
$w3 = [Math]::Max(0, ($track.ActualWidth - 4) / 3)
|
|
506
|
+
if ($w3 -le 0) { return }
|
|
507
|
+
$thumb.Width = $w3
|
|
508
|
+
$x = $w3 * $script:notifyFreq
|
|
509
|
+
$tt = $thumb.RenderTransform
|
|
510
|
+
if ($animate) {
|
|
511
|
+
$a = New-Object Windows.Media.Animation.DoubleAnimation $x, ([TimeSpan]::FromMilliseconds(180))
|
|
512
|
+
$ce = New-Object Windows.Media.Animation.CubicEase; $ce.EasingMode = 'EaseOut'; $a.EasingFunction = $ce
|
|
513
|
+
$tt.BeginAnimation([Windows.Media.TranslateTransform]::XProperty, $a)
|
|
514
|
+
} else {
|
|
515
|
+
$tt.BeginAnimation([Windows.Media.TranslateTransform]::XProperty, $null); $tt.X = $x
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function SyncNotifyDesc($val, [bool]$animate = $true) {
|
|
519
|
+
(E 'NotifyFreqValue').Text = switch ([int]$val) {
|
|
520
|
+
0 { $T.notify_freq_min }
|
|
521
|
+
1 { $T.notify_freq_mid }
|
|
522
|
+
default { $T.notify_freq_max }
|
|
523
|
+
}
|
|
524
|
+
for ($i = 0; $i -lt 3; $i++) { (E "NotifyStepText$i").Foreground = if ($i -eq [int]$val) { Brush $P.working.fg } else { Brush $P.muted } }
|
|
525
|
+
PlaceNotifyThumb $animate
|
|
526
|
+
}
|
|
527
|
+
$script:notifyFreq = if ($cfg.notify_freq -ne $null) { [int]$cfg.notify_freq } else { 1 }
|
|
528
|
+
SyncNotifyDesc $script:notifyFreq $false
|
|
529
|
+
(E 'NotifySteps').Add_SizeChanged({ PlaceNotifyThumb $false })
|
|
530
|
+
for ($i = 0; $i -lt 3; $i++) {
|
|
531
|
+
$step = E "NotifyStep$i"
|
|
532
|
+
$step.Add_MouseEnter({ param($s, $e) if ([int]$s.Tag -ne $script:notifyFreq) { $s.Child.Foreground = Brush $P.ink } })
|
|
533
|
+
$step.Add_MouseLeave({ param($s, $e) if ([int]$s.Tag -ne $script:notifyFreq) { $s.Child.Foreground = Brush $P.muted } })
|
|
534
|
+
$step.Add_MouseLeftButtonUp({ param($s, $e)
|
|
535
|
+
$v = [int]$s.Tag
|
|
536
|
+
if ($v -ne $script:notifyFreq) {
|
|
537
|
+
$script:notifyFreq = $v
|
|
538
|
+
SyncNotifyDesc $v
|
|
539
|
+
Send @{ t = 'notify_freq'; value = $v }
|
|
540
|
+
}
|
|
541
|
+
})
|
|
542
|
+
}
|
|
390
543
|
|
|
391
|
-
# No focus stealing + no Alt+Tab entry
|
|
544
|
+
# No focus stealing + no Alt+Tab entry. NOT hidden from screen capture: SetWindowDisplayAffinity(WDA_EXCLUDEFROMCAPTURE = 0x11) on this
|
|
545
|
+
# transparent layered window made the bot invisible on the real desktop on some machines (commit efa202c, 01/11/2026), so it stays off.
|
|
392
546
|
$w.Add_SourceInitialized({
|
|
393
547
|
$h = (New-Object Windows.Interop.WindowInteropHelper $w).Handle
|
|
394
548
|
$ex = [AivinMascot.Native]::GetWindowLong($h, -20)
|
|
395
549
|
[void][AivinMascot.Native]::SetWindowLong($h, -20, ($ex -bor 0x08000000 -bor 0x00000080))
|
|
396
|
-
if (-not $env:AIVIN_MASCOT_CAPTURABLE) { [void][AivinMascot.Native]::SetWindowDisplayAffinity($h, 0x11) }
|
|
397
550
|
$script:hwnd = $h
|
|
398
551
|
[AivinMascot.TopKeeper]::Start($h)
|
|
399
552
|
[AivinMascot.DisplayWatch]::Start($h, [Action]{ Dbg 'display changed'; Place })
|
|
@@ -433,7 +586,7 @@ function Place {
|
|
|
433
586
|
# inside it instead. One SetWindowPos (device pixels) - setting Left then Top moved the window twice.
|
|
434
587
|
$px = [Math]::Round((Clamp ($script:cx - ${WINDOW.w / 2}) $ml ($mr - ${WINDOW.w})) * $k)
|
|
435
588
|
$py = [Math]::Round((Clamp ($script:cy - ${WINDOW.h - ROOT_MARGIN - (MASCOT_BOX.h - MASCOT_CENTER.y)}) $mt ($mb - ${WINDOW.h})) * $k)
|
|
436
|
-
if ($script:hwnd) { [void][AivinMascot.Native]::SetWindowPos($script:hwnd, [IntPtr]::Zero, [int]$px, [int]$py, 0, 0,
|
|
589
|
+
if ($script:hwnd) { [void][AivinMascot.Native]::SetWindowPos($script:hwnd, [IntPtr]::Zero, [int]$px, [int]$py, 0, 0, 0x0055) }
|
|
437
590
|
else { $w.Left = $px / $k; $w.Top = $py / $k }
|
|
438
591
|
$script:mx = $script:cx - $px / $k; $script:my = $script:cy - $py / $k
|
|
439
592
|
$m = E 'Mascot'; [Windows.Controls.Canvas]::SetLeft($m, $script:mx - ${MASCOT_CENTER.x}); [Windows.Controls.Canvas]::SetTop($m, $script:my - ${MASCOT_CENTER.y})
|
|
@@ -488,7 +641,7 @@ function React($prev, $s) {
|
|
|
488
641
|
if ($s -eq 'waiting' -and ($prev -eq 'working' -or $prev -eq 'thinking')) { $script:rig.Play('startle') }
|
|
489
642
|
elseif ($s -eq 'done') {
|
|
490
643
|
if (($now - $script:errorAt).TotalMinutes -lt 5) { $script:errorAt = [DateTime]::MinValue; PlayFace 'relief' 'relief' 1.3 }
|
|
491
|
-
elseif ($busyFor -ge 60) {
|
|
644
|
+
elseif ($busyFor -ge 60) { PlayFace 'cheer' 'star' 2.2 }
|
|
492
645
|
elseif ($busyFor -gt 0 -and $busyFor -lt 10) { $script:rig.Play('small') }
|
|
493
646
|
}
|
|
494
647
|
}
|
|
@@ -510,17 +663,40 @@ function SetState($s) {
|
|
|
510
663
|
|
|
511
664
|
# Pointer: the rig follows the cursor with its eyes on its own (anywhere near the bot). Hovering greets with a happy face and a lean-in.
|
|
512
665
|
function IsBusy { $script:state -eq 'working' -or $script:state -eq 'thinking' }
|
|
513
|
-
(E 'Mascot').Add_MouseEnter({
|
|
666
|
+
(E 'Mascot').Add_MouseEnter({
|
|
667
|
+
$startled = Wake $true
|
|
668
|
+
$script:rig.Hover = $true
|
|
669
|
+
if ($startled) { return }
|
|
670
|
+
if (-not (IsBusy) -and -not $script:rig.Dizzy) { if ((Get-Random -Minimum 0 -Maximum 10) -lt 3) { PlayFace 'wink' 'wink' 1.4 } else { SetFace 'hello' } }
|
|
671
|
+
})
|
|
514
672
|
|
|
515
|
-
# Doze: idle for a
|
|
673
|
+
# Doze: idle for a short while with nobody around -> the bot nods off (closed eyes, zzz); new work or the pointer wakes it up.
|
|
516
674
|
$script:lastActive = Get-Date
|
|
517
|
-
function Wake
|
|
518
|
-
$
|
|
675
|
+
function Wake($fromHover = $false) {
|
|
676
|
+
$wasSleeping = $script:rig.Dozing -or $script:yawned
|
|
677
|
+
$script:lastActive = Get-Date
|
|
678
|
+
$script:yawned = $false
|
|
679
|
+
if ($wasSleeping) {
|
|
680
|
+
if ($script:rig.Dozing) { $script:rig.Doze($false) }
|
|
681
|
+
if ($fromHover) {
|
|
682
|
+
$script:rig.Play('startle')
|
|
683
|
+
SetFace 'waiting'
|
|
684
|
+
$script:faceTimer.Stop()
|
|
685
|
+
$script:faceTimer.Interval = [TimeSpan]::FromSeconds(0.85)
|
|
686
|
+
$script:faceTimer.Start()
|
|
687
|
+
return $true
|
|
688
|
+
} else {
|
|
689
|
+
SetFace $script:state
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return $false
|
|
693
|
+
}
|
|
694
|
+
$script:dozeTimer = New-Object Windows.Threading.DispatcherTimer; $script:dozeTimer.Interval = [TimeSpan]::FromSeconds(3)
|
|
519
695
|
$script:dozeTimer.Add_Tick({
|
|
520
|
-
if ($script:state -eq 'idle' -and -not $script:rig.Dozing -and -not $script:rig.Hover -and ((Get-Date) - $script:lastActive).
|
|
521
|
-
# A yawn first, nodding off
|
|
522
|
-
if (-not $script:yawned) { $script:rig.Play('yawn'); SetFace 'yawn'; $script:faceTimer.Stop(); $script:faceTimer.Interval = [TimeSpan]::FromSeconds(2); $script:faceTimer.Start()
|
|
523
|
-
|
|
696
|
+
if ($script:state -eq 'idle' -and -not $script:rig.Dozing -and -not $script:rig.Hover -and (E 'AskBox').Visibility -ne 'Visible' -and (E 'Panel').Visibility -ne 'Visible' -and ((Get-Date) - $script:lastActive).TotalSeconds -ge ${MASCOT_DOZE_SEC}) {
|
|
697
|
+
# A yawn first, nodding off when yawn finishes (or on next tick).
|
|
698
|
+
if (-not $script:yawned) { $script:yawned = $true; $script:rig.Play('yawn'); SetFace 'yawn'; $script:faceTimer.Stop(); $script:faceTimer.Interval = [TimeSpan]::FromSeconds(2.2); $script:faceTimer.Start() }
|
|
699
|
+
elseif (-not $script:faceTimer.IsEnabled) { $script:rig.Doze($true); SetFace 'offline' }
|
|
524
700
|
}
|
|
525
701
|
})
|
|
526
702
|
$script:dozeTimer.Start()
|
|
@@ -528,7 +704,14 @@ $script:dozeTimer.Start()
|
|
|
528
704
|
|
|
529
705
|
# Play: a one-shot face for a reaction, then back to the normal face (hello while hovered and free, else the state's face).
|
|
530
706
|
$script:faceTimer = New-Object Windows.Threading.DispatcherTimer
|
|
531
|
-
$script:faceTimer.Add_Tick({
|
|
707
|
+
$script:faceTimer.Add_Tick({
|
|
708
|
+
$script:faceTimer.Stop()
|
|
709
|
+
if ($script:yawned -and -not $script:rig.Dozing -and -not $script:rig.Hover -and $script:state -eq 'idle') {
|
|
710
|
+
$script:rig.Doze($true); SetFace 'offline'
|
|
711
|
+
} else {
|
|
712
|
+
SetFace $(if ($script:rig.Hover -and -not (IsBusy)) { 'hello' } else { $script:state })
|
|
713
|
+
}
|
|
714
|
+
})
|
|
532
715
|
function PlayFace($gesture, $face, $sec) {
|
|
533
716
|
Wake; $script:rig.Play($gesture); SetFace $face
|
|
534
717
|
$script:faceTimer.Stop(); $script:faceTimer.Interval = [TimeSpan]::FromSeconds($sec); $script:faceTimer.Start()
|
|
@@ -615,50 +798,95 @@ function HideBubble {
|
|
|
615
798
|
$b = E 'Bubble'; if ($b.Visibility -ne 'Visible') { return }
|
|
616
799
|
$sb = $w.FindResource('BubbleOut').Clone(); $sb.Add_Completed({ (E 'Bubble').Visibility = 'Collapsed' }); $sb.Begin($b)
|
|
617
800
|
}
|
|
618
|
-
|
|
619
|
-
|
|
801
|
+
$script:bubbleUrl = $null
|
|
802
|
+
function ShowBubble($text, $url = $null) {
|
|
803
|
+
$script:bubbleUrl = $url
|
|
804
|
+
SetText (E 'NowText') $text
|
|
620
805
|
if ((E 'Panel').Visibility -eq 'Visible') { return }
|
|
621
|
-
(E 'BubbleText')
|
|
806
|
+
SetText (E 'BubbleText') $text
|
|
807
|
+
(E 'BubbleBox').Cursor = if ($url) { [Windows.Input.Cursors]::Hand } else { [Windows.Input.Cursors]::Arrow }
|
|
622
808
|
$b = E 'Bubble'
|
|
623
809
|
if ($b.Visibility -ne 'Visible') { $b.Visibility = 'Visible'; $w.FindResource('BubbleIn').Begin($b) }
|
|
624
810
|
$script:bubbleTimer.Stop()
|
|
625
811
|
if ($script:state -ne 'working' -and $script:state -ne 'thinking' -and $script:state -ne 'waiting') { $script:bubbleTimer.Start() }
|
|
626
812
|
}
|
|
813
|
+
(E 'BubbleBox').Add_MouseLeftButtonUp({
|
|
814
|
+
if ($script:bubbleUrl) { OpenWebUrl $script:bubbleUrl }
|
|
815
|
+
})
|
|
627
816
|
|
|
628
817
|
$script:rows = @{}; $script:order = New-Object System.Collections.Generic.Queue[string]
|
|
629
818
|
function LogEntry($m) {
|
|
630
819
|
$row = $null; if ($m.id) { $row = $script:rows[[string]$m.id] }
|
|
631
820
|
if (-not $row) {
|
|
632
|
-
$dp = New-Object Windows.Controls.DockPanel; $dp.Margin = '10,
|
|
821
|
+
$dp = New-Object Windows.Controls.DockPanel; $dp.Margin = '10,3,10,3'
|
|
633
822
|
$g = New-Object Windows.Controls.TextBlock; $g.Width = 16; $g.FontSize = 12; $g.FontWeight = 'Bold'; $g.Margin = '0,1,6,0'; [Windows.Controls.DockPanel]::SetDock($g, 'Left')
|
|
634
823
|
$tm = New-Object Windows.Controls.TextBlock; $tm.FontSize = 11; $tm.Foreground = Brush $P.muted; $tm.Margin = '8,2,0,0'; [Windows.Controls.DockPanel]::SetDock($tm, 'Right')
|
|
635
824
|
$sp = New-Object Windows.Controls.StackPanel
|
|
636
825
|
$ti = New-Object Windows.Controls.TextBlock; $ti.FontSize = 13; $ti.Foreground = Brush $P.ink; $ti.TextWrapping = 'Wrap'
|
|
637
|
-
$sub = New-Object Windows.Controls.TextBlock; $sub.FontSize = 11.5; $sub.Foreground = Brush $P.muted; $sub.TextWrapping = 'Wrap'; $sub.MaxHeight = 32; $sub.TextTrimming = 'CharacterEllipsis'; $sub.Margin = '0,1,0,0'
|
|
826
|
+
$sub = New-Object Windows.Controls.TextBlock; $sub.FontSize = 11.5; $sub.Foreground = Brush $P.muted; $sub.TextWrapping = 'Wrap'; $sub.MaxHeight = 32; $sub.TextTrimming = 'CharacterEllipsis'; $sub.Margin = '0,1,0,0'; $sub.Visibility = 'Collapsed'
|
|
638
827
|
[void]$sp.Children.Add($ti); [void]$sp.Children.Add($sub)
|
|
639
828
|
[void]$dp.Children.Add($g); [void]$dp.Children.Add($tm); [void]$dp.Children.Add($sp)
|
|
640
829
|
$list = E 'LogList'; $list.Children.Insert(0, $dp); (E 'Empty').Visibility = 'Collapsed'
|
|
641
|
-
$row = @{ glyph = $g; time = $tm; title = $ti; sub = $sub }
|
|
830
|
+
$row = @{ glyph = $g; time = $tm; title = $ti; sub = $sub; url = [string]$m.url }
|
|
831
|
+
if ($m.url) {
|
|
832
|
+
$dp.Cursor = [Windows.Input.Cursors]::Hand
|
|
833
|
+
$dp.ToolTip = [string]$m.url; $dp.Tag = [string]$m.url
|
|
834
|
+
# The link rides on the row itself (Tag): the handler is not a closure, $row at click time is not this row.
|
|
835
|
+
$dp.Add_MouseLeftButtonUp({ param($s) OpenWebUrl $s.Tag })
|
|
836
|
+
}
|
|
642
837
|
if ($m.id) { $script:rows[[string]$m.id] = $row; $script:order.Enqueue([string]$m.id) }
|
|
643
838
|
while ($list.Children.Count -gt 150) { $list.Children.RemoveAt($list.Children.Count - 1) }
|
|
644
839
|
while ($script:order.Count -gt 150) { $script:rows.Remove($script:order.Dequeue()) }
|
|
645
840
|
}
|
|
646
841
|
if ($m.status) { $row.glyph.Text = $cfg.glyphs.($m.status); $row.glyph.Foreground = Brush $P.log.($m.status) }
|
|
647
|
-
if ($m.title) { $row.title
|
|
648
|
-
if ($m.PSObject.Properties['sub']) { $row.sub
|
|
842
|
+
if ($m.title) { SetText $row.title $m.title }
|
|
843
|
+
if ($m.PSObject.Properties['sub']) { SetText $row.sub $m.sub; $row.sub.Visibility = if ($m.sub) { 'Visible' } else { 'Collapsed' } }
|
|
649
844
|
if ($m.time) { $row.time.Text = $m.time }
|
|
650
845
|
}
|
|
651
846
|
|
|
652
|
-
function
|
|
847
|
+
function ClosePanel {
|
|
653
848
|
$p = E 'Panel'
|
|
654
849
|
if ($p.Visibility -eq 'Visible') {
|
|
850
|
+
if ($script:panelHideTimer) { $script:panelHideTimer.Stop() }
|
|
655
851
|
$sb = $w.FindResource('PanelOut').Clone(); $sb.Add_Completed({ (E 'Panel').Visibility = 'Collapsed' }); $sb.Begin($p)
|
|
656
|
-
}
|
|
657
|
-
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function OpenPanel {
|
|
856
|
+
$script:bubbleTimer.Stop(); (E 'Bubble').Visibility = 'Collapsed'; (E 'Bubble').Opacity = 0
|
|
857
|
+
$p = E 'Panel'
|
|
858
|
+
if ($p.Visibility -ne 'Visible') {
|
|
658
859
|
$p.Visibility = 'Visible'; $w.FindResource('PanelIn').Begin($p)
|
|
659
860
|
}
|
|
660
861
|
}
|
|
661
862
|
|
|
863
|
+
function TogglePanel {
|
|
864
|
+
$p = E 'Panel'
|
|
865
|
+
if ($p.Visibility -eq 'Visible') { ClosePanel }
|
|
866
|
+
else { OpenPanel }
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
# Auto-hide panel when mouse leaves panel area
|
|
870
|
+
$script:panelHideTimer = New-Object Windows.Threading.DispatcherTimer
|
|
871
|
+
$script:panelHideTimer.Interval = [TimeSpan]::FromMilliseconds(500)
|
|
872
|
+
$script:panelHideTimer.Add_Tick({
|
|
873
|
+
$script:panelHideTimer.Stop()
|
|
874
|
+
if ((E 'Panel').Visibility -eq 'Visible') {
|
|
875
|
+
if (-not (E 'Panel').IsMouseOver -and -not (E 'Mascot').IsMouseOver) {
|
|
876
|
+
ClosePanel
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
})
|
|
880
|
+
|
|
881
|
+
(E 'Panel').Add_MouseEnter({ $script:panelHideTimer.Stop() })
|
|
882
|
+
(E 'Mascot').Add_MouseEnter({ $script:panelHideTimer.Stop() })
|
|
883
|
+
|
|
884
|
+
(E 'Panel').Add_MouseLeave({
|
|
885
|
+
if ((E 'Panel').Visibility -eq 'Visible') {
|
|
886
|
+
$script:panelHideTimer.Start()
|
|
887
|
+
}
|
|
888
|
+
})
|
|
889
|
+
|
|
662
890
|
$script:userHidden = $false; $script:guiHidden = $false
|
|
663
891
|
function ApplyVisibility { $w.Visibility = if ($script:userHidden -or $script:guiHidden) { 'Hidden' } else { 'Visible' } }
|
|
664
892
|
|
|
@@ -726,12 +954,19 @@ function Handle($m) {
|
|
|
726
954
|
if ($env:AIVIN_MASCOT_DEBUG) { Dbg "recv $($m.t) $($m.state)$($m.text)$($m.title)" }
|
|
727
955
|
switch ($m.t) {
|
|
728
956
|
'state' { SetState $m.state }
|
|
729
|
-
'
|
|
957
|
+
'notify_freq' {
|
|
958
|
+
$script:notifyFreq = [int]$m.value
|
|
959
|
+
SyncNotifyDesc $script:notifyFreq
|
|
960
|
+
}
|
|
961
|
+
'main' { if ($m.quiet) { SetText (E 'NowText') $m.text } else { ShowBubble $m.text $m.url } }
|
|
730
962
|
'log' { LogEntry $m }
|
|
731
963
|
'gui' { $script:guiHidden = [bool]$m.active; ApplyVisibility }
|
|
732
964
|
'show' { $script:userHidden = $false; ApplyVisibility }
|
|
733
|
-
# Daemon-driven reaction, e.g. 'wave' when the user comes back.
|
|
734
|
-
'gesture' {
|
|
965
|
+
# Daemon-driven reaction, e.g. 'wave' when the user comes back, or the mood of an answer's emoji (mood.mjs: its own face + time).
|
|
966
|
+
'gesture' {
|
|
967
|
+
$face = if ($m.face) { [string]$m.face } else { 'hello' }; $sec = if ($m.sec) { [double]$m.sec } else { 1.6 }
|
|
968
|
+
if (-not (IsBusy)) { PlayFace ([string]$m.g) $face $sec } else { $script:rig.Play([string]$m.g) }
|
|
969
|
+
}
|
|
735
970
|
# Files dropped on the bot still waiting for the next question (0 = sent / cleared): the tray in the bot's arms + its badge.
|
|
736
971
|
'ask_files' { $script:files = [int]$m.n; if (-not $script:dragFiles) { TrayRest } }
|
|
737
972
|
'quit' { CloseAnimated }
|
|
@@ -739,10 +974,51 @@ function Handle($m) {
|
|
|
739
974
|
}
|
|
740
975
|
|
|
741
976
|
# @ASK_HOOK
|
|
977
|
+
# Watch mascot-hide and mascot.json so toggling from system tray closes the mascot immediately.
|
|
978
|
+
$script:aivinHome = if ($dir) { Split-Path (Split-Path $dir) } else { $null }
|
|
979
|
+
if (-not $script:aivinHome -or -not [System.IO.Directory]::Exists($script:aivinHome)) {
|
|
980
|
+
$script:aivinHome = Join-Path ([Environment]::GetFolderPath('UserProfile')) '.aivin'
|
|
981
|
+
}
|
|
982
|
+
$script:hideFile = Join-Path $script:aivinHome 'mascot-hide'
|
|
983
|
+
$script:mascotJson = Join-Path $script:aivinHome 'mascot.json'
|
|
984
|
+
$script:lastHideTime = [DateTime]::UtcNow
|
|
985
|
+
if ([System.IO.File]::Exists($script:hideFile)) {
|
|
986
|
+
try { $script:lastHideTime = [System.IO.File]::GetLastWriteTimeUtc($script:hideFile) } catch {}
|
|
987
|
+
}
|
|
988
|
+
$script:lastMascotJsonTime = [DateTime]::UtcNow
|
|
989
|
+
if ([System.IO.File]::Exists($script:mascotJson)) {
|
|
990
|
+
try { $script:lastMascotJsonTime = [System.IO.File]::GetLastWriteTimeUtc($script:mascotJson) } catch {}
|
|
991
|
+
}
|
|
992
|
+
|
|
742
993
|
# Commands arrive as JSON lines on stdin (background thread -> queue); the UI drains the queue. stdin closed = daemon gone -> close.
|
|
743
994
|
[AivinMascot.Input]::Start()
|
|
744
995
|
$pump = New-Object Windows.Threading.DispatcherTimer; $pump.Interval = [TimeSpan]::FromMilliseconds(80)
|
|
745
996
|
$pump.Add_Tick({
|
|
997
|
+
if ($script:hideFile -and [System.IO.File]::Exists($script:hideFile)) {
|
|
998
|
+
try {
|
|
999
|
+
$ht = [System.IO.File]::GetLastWriteTimeUtc($script:hideFile)
|
|
1000
|
+
if ($ht -gt $script:lastHideTime) {
|
|
1001
|
+
$script:lastHideTime = $ht
|
|
1002
|
+
Send @{ t = 'off' }
|
|
1003
|
+
CloseAnimated
|
|
1004
|
+
return
|
|
1005
|
+
}
|
|
1006
|
+
} catch {}
|
|
1007
|
+
}
|
|
1008
|
+
if ($script:mascotJson -and [System.IO.File]::Exists($script:mascotJson)) {
|
|
1009
|
+
try {
|
|
1010
|
+
$mj = [System.IO.File]::GetLastWriteTimeUtc($script:mascotJson)
|
|
1011
|
+
if ($mj -gt $script:lastMascotJsonTime) {
|
|
1012
|
+
$script:lastMascotJsonTime = $mj
|
|
1013
|
+
$txt = [System.IO.File]::ReadAllText($script:mascotJson)
|
|
1014
|
+
if ($txt -match '"enabled"\s*:\s*false') {
|
|
1015
|
+
Send @{ t = 'off' }
|
|
1016
|
+
CloseAnimated
|
|
1017
|
+
return
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
} catch {}
|
|
1021
|
+
}
|
|
746
1022
|
$line = $null
|
|
747
1023
|
while ([AivinMascot.Input]::Lines.TryDequeue([ref]$line)) {
|
|
748
1024
|
if ($line) { try { Handle ($line | ConvertFrom-Json) } catch { [Console]::Error.WriteLine($_.Exception.Message) } }
|
|
@@ -752,7 +1028,10 @@ $pump.Add_Tick({
|
|
|
752
1028
|
$w.Add_ContentRendered({
|
|
753
1029
|
SetState 'idle'; Place; $w.FindResource('WindowIn').Begin($w); $script:rig.Start(); $script:rig.Intro(); $pump.Start(); Send @{ t = 'ready' }
|
|
754
1030
|
})
|
|
755
|
-
$w.Add_Closed({
|
|
1031
|
+
$w.Add_Closed({
|
|
1032
|
+
try { if ($script:mascotMutex) { $script:mascotMutex.ReleaseMutex(); $script:mascotMutex.Dispose() } } catch {}
|
|
1033
|
+
$script:rig.Stop()
|
|
1034
|
+
})
|
|
756
1035
|
$app = New-Object Windows.Application
|
|
757
1036
|
$app.ShutdownMode = 'OnMainWindowClose'
|
|
758
1037
|
[void]$app.Run($w)
|