cortico-world-bottle 0.7.2 → 0.8.0

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.
@@ -1,13 +1,15 @@
1
1
  /** Shared semantic colors for the mailbox and its native desktop cards. */
2
2
  import type { MailboxTheme } from './theme.ts';
3
- export type ThemeChoice = 'ocean' | 'paper' | 'coopanion' | 'custom';
3
+ export type ThemeChoice = 'ocean' | 'paper' | 'epistle' | 'coopanion' | 'custom';
4
4
  export type AppearanceMode = 'system' | 'light' | 'dark';
5
+ /** 页面与桌面卡片共用的主题清单;顺序即菜单顺序。 */
6
+ export const THEME_CHOICES: readonly ThemeChoice[] = ['ocean', 'paper', 'epistle', 'coopanion', 'custom'];
5
7
  export interface ThemePreference { theme: ThemeChoice; mode: AppearanceMode; customColor?: string; background?: string | null; backgroundTransparency?: number; myFont?: string | null; myFontName?: string }
6
8
  export const DEFAULT_APPEARANCE: ThemePreference = { theme: 'ocean', mode: 'system' };
7
9
  export function isThemePreference(value: unknown): value is ThemePreference {
8
10
  if (!value || typeof value !== 'object') return false;
9
11
  const pref = value as ThemePreference;
10
- return ['ocean','paper','coopanion','custom'].includes(pref.theme) && ['system','light','dark'].includes(pref.mode)
12
+ return THEME_CHOICES.includes(pref.theme) && ['system','light','dark'].includes(pref.mode)
11
13
  && (pref.customColor === undefined || (typeof pref.customColor === 'string' && /^#[0-9a-f]{6}$/i.test(pref.customColor)))
12
14
  && (pref.backgroundTransparency === undefined || (typeof pref.backgroundTransparency === 'number' && Number.isFinite(pref.backgroundTransparency) && pref.backgroundTransparency >= 0 && pref.backgroundTransparency <= 100))
13
15
  && (pref.myFont === undefined || pref.myFont === null || (typeof pref.myFont === 'string' && /^[a-f0-9]{64}\.(ttf|otf|woff2?)$/.test(pref.myFont)))
@@ -51,18 +53,56 @@ export const MAILBOX_PALETTES = {
51
53
  "danger-text": "#f0b2ae"
52
54
  }
53
55
  },
56
+ "epistle": {
57
+ "light": {
58
+ "paper": "#f5f3ec",
59
+ "card": "#fdfbf5",
60
+ "ink": "#2c2a42",
61
+ "muted": "#6e6a80",
62
+ "line": "#e2dccf",
63
+ "accent": "#3f4a8c",
64
+ "seal": "#9c3b30",
65
+ "sea": "#2f6a60",
66
+ "soft": "#eeebe0",
67
+ "panel": "#faf8f1",
68
+ "on-accent": "#ffffff",
69
+ "warning-bg": "#fbf2df",
70
+ "warning-line": "#e7d5b0",
71
+ "warning-text": "#775623",
72
+ "danger-text": "#8f3a32",
73
+ "accent-text": "#3f4a8c"
74
+ },
75
+ "dark": {
76
+ "paper": "#1a1a20",
77
+ "card": "#23232b",
78
+ "ink": "#e9e6dd",
79
+ "muted": "#b0ab9f",
80
+ "line": "#3b3a45",
81
+ "accent": "#aab6f2",
82
+ "seal": "#e89a8f",
83
+ "sea": "#93cfc0",
84
+ "soft": "#2b2b33",
85
+ "panel": "#202027",
86
+ "on-accent": "#1a1c33",
87
+ "warning-bg": "#3a2f21",
88
+ "warning-line": "#6b5638",
89
+ "warning-text": "#edcb8e",
90
+ "danger-text": "#f0b2ae",
91
+ "accent-text": "#aab6f2"
92
+ }
93
+ },
54
94
  "paper": {
55
95
  "light": {
56
- "paper": "#f6f1e6",
57
- "card": "#fffdf7",
58
- "ink": "#352f28",
59
- "muted": "#7d7467",
60
- "line": "#e3d9c8",
61
- "accent": "#8a6540",
62
- "seal": "#a8453c",
63
- "sea": "#527981",
64
- "soft": "#f4efe4",
65
- "panel": "#fffaf1",
96
+ "paper": "#f2e6cc",
97
+ "card": "#fff8e8",
98
+ "ink": "#3d3023",
99
+ "muted": "#756147",
100
+ "line": "#d9c6a2",
101
+ "accent": "#885c24",
102
+ "seal": "#946327",
103
+ "sea": "#70663c",
104
+ "soft": "#ebddbf",
105
+ "panel": "#f9efd9",
66
106
  "on-accent": "#ffffff",
67
107
  "warning-bg": "#fbf2df",
68
108
  "warning-line": "#e9d9b5",
@@ -70,17 +110,17 @@ export const MAILBOX_PALETTES = {
70
110
  "danger-text": "#92483f"
71
111
  },
72
112
  "dark": {
73
- "paper": "#211e19",
74
- "card": "#2c2822",
75
- "ink": "#f0e7d9",
76
- "muted": "#c1b29c",
77
- "line": "#4a4135",
78
- "accent": "#dbb48b",
79
- "seal": "#eba69c",
80
- "sea": "#a3cacf",
81
- "soft": "#362f26",
82
- "panel": "#29251f",
83
- "on-accent": "#34241d",
113
+ "paper": "#251e16",
114
+ "card": "#32281d",
115
+ "ink": "#f6e9d0",
116
+ "muted": "#d0b997",
117
+ "line": "#594832",
118
+ "accent": "#e6bc78",
119
+ "seal": "#e6bc78",
120
+ "sea": "#c5c18c",
121
+ "soft": "#403322",
122
+ "panel": "#2e241a",
123
+ "on-accent": "#302310",
84
124
  "warning-bg": "#3c3021",
85
125
  "warning-line": "#70583a",
86
126
  "warning-text": "#ebce92",
@@ -90,7 +130,7 @@ export const MAILBOX_PALETTES = {
90
130
  } as const;
91
131
  export type MailboxPalette = Record<keyof typeof MAILBOX_PALETTES.ocean.light, string> & { 'accent-text'?: string };
92
132
  export interface CardAppearance { preference: ThemePreference; palettes: Record<'light' | 'dark', MailboxPalette> }
93
- export function paletteDeclarations(theme: 'ocean' | 'paper', mode: 'light' | 'dark'): string {
133
+ export function paletteDeclarations(theme: 'ocean' | 'paper' | 'epistle', mode: 'light' | 'dark'): string {
94
134
  return Object.entries(MAILBOX_PALETTES[theme][mode]).map(([key,value]) => `--${key}:${value};`).join(' ');
95
135
  }
96
136
  function mixColor(a: string, b: string, weight: number): string {
@@ -98,7 +138,9 @@ function mixColor(a: string, b: string, weight: number): string {
98
138
  }
99
139
  export function cardAppearance(preference: ThemePreference, host: MailboxTheme): CardAppearance {
100
140
  if (preference.theme === 'custom') return { preference, palettes: customPalettes(preference.customColor ?? '#4b62a0') };
101
- const palettes = preference.theme === 'paper' ? MAILBOX_PALETTES.paper : MAILBOX_PALETTES.ocean;
141
+ const palettes = preference.theme === 'paper' ? MAILBOX_PALETTES.paper
142
+ : preference.theme === 'epistle' ? MAILBOX_PALETTES.epistle
143
+ : MAILBOX_PALETTES.ocean;
102
144
  if (preference.theme !== 'coopanion' || !host.available || !host.palettes) return { preference, palettes };
103
145
  const map = (mode: 'light' | 'dark'): MailboxPalette => {
104
146
  const p = host.palettes![mode];
@@ -0,0 +1,70 @@
1
+ import { readingCount, type LocalStore, type SentLetter, type ReceivedLetter, type LocalReply } from './store.ts';
2
+ import type { LetterStars } from './stars.ts';
3
+ import type { LetterbookArchive } from '../shared/contract.ts';
4
+ export const ARCHIVE_MAX_BYTES = 32 * 1024 * 1024;
5
+ const kinds = ['sent','received','reply','star'];
6
+ const time = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v) && v >= 0 && v <= 8.64e15;
7
+ const text = (v: unknown, max = 65536): v is string => typeof v === 'string' && v.length <= max;
8
+ const id = (v: unknown): v is string => text(v,256) && v.length > 0;
9
+ /** This download is the only extra copy: user owns/deletes it. No server/cloud upload. */
10
+ export function exportArchive(store: LocalStore, stars: LetterStars): LetterbookArchive {
11
+ const entries: LetterbookArchive['entries'] = [];
12
+ for (const kind of ['sent','received','reply'] as const) {
13
+ const rows = kind === 'sent' ? store.sent : kind === 'received' ? store.received : store.replies;
14
+ for (const row of rows) entries.push({ kind, value: { ...row } });
15
+ }
16
+ for (const star of stars.all()) entries.push({ kind:'star', value:{letterId:star.letterId,starredAt:star.starredAt} });
17
+ return { schemaVersion:1, exportedAt:new Date().toISOString(), entries };
18
+ }
19
+ /** Validate the ENTIRE file before touching any local data; only allow known fields. */
20
+ export function parseArchive(raw: unknown): LetterbookArchive {
21
+ if (!raw || typeof raw !== 'object') throw Error('这不是有效的信册文件。');
22
+ const doc = raw as Partial<LetterbookArchive>;
23
+ if (doc.schemaVersion !== 1) throw Error('这份信册的格式版本暂不支持,原有信件没有改动。');
24
+ if (!text(doc.exportedAt,64) || !Number.isFinite(Date.parse(doc.exportedAt)) || !Array.isArray(doc.entries) || doc.entries.length > 20000)
25
+ throw Error('信册格式不完整或文件过大。');
26
+ const entries: LetterbookArchive['entries'] = [];
27
+ for (const entry of doc.entries) {
28
+ if (!entry || !kinds.includes(entry.kind) || !entry.value || typeof entry.value !== 'object' || Array.isArray(entry.value)) throw Error('信册中有损坏的条目。');
29
+ const r = entry.value, value: Record<string,unknown> = {};
30
+ if (!id(r.letterId)) throw Error('信件编号不完整。');
31
+ value.letterId = r.letterId;
32
+ if (entry.kind === 'star') {
33
+ if (!time(r.starredAt)) throw Error('星标时间不完整。'); value.starredAt = r.starredAt;
34
+ } else {
35
+ if (!text(r.body) || !time(r.at)) throw Error('信件正文或时间不完整。');
36
+ value.body = r.body; value.at = r.at;
37
+ if (entry.kind !== 'sent') {
38
+ if (!text(r.from,256)) throw Error('信件署名不完整。'); value.from = r.from;
39
+ value.readCount = readingCount(r.readCount);
40
+ if (r.lastReadAt !== undefined) { if (!time(r.lastReadAt)) throw Error('共读时间不正确。'); value.lastReadAt = r.lastReadAt; }
41
+ }
42
+ if (entry.kind === 'received') {
43
+ if (!['caught','replied','dismissed','sank','expired','kept'].includes(String(r.outcome))) throw Error('来信状态不正确。');
44
+ value.outcome = r.outcome;
45
+ for (const k of ['myReply','signature']) if (r[k] !== undefined) { if (!text(r[k])) throw Error('信件条目不完整。'); value[k] = r[k]; }
46
+ if (r.seed === true) value.seed = true;
47
+ if (r.lastCaughtAt !== undefined) { if (!time(r.lastCaughtAt)) throw Error('打捞时间不正确。'); value.lastCaughtAt = r.lastCaughtAt; }
48
+ }
49
+ if (entry.kind !== 'reply' && r.topic !== undefined) { if (!text(r.topic,256)) throw Error('信题不正确。'); value.topic = r.topic; }
50
+ if (entry.kind === 'sent' && r.pickedNoticed === true) value.pickedNoticed = true;
51
+ }
52
+ entries.push({kind:entry.kind,value});
53
+ }
54
+ return {schemaVersion:1,exportedAt:doc.exportedAt,entries};
55
+ }
56
+ export function importArchive(store: LocalStore, stars: LetterStars, raw: unknown): number {
57
+ const doc = parseArchive(raw);
58
+ const sent = [...store.sent], received = [...store.received], replies = [...store.replies];
59
+ const rows = {sent,received,reply:replies}; let added=0;
60
+ const newStars: Array<{id:string;at:number}> = [];
61
+ for (const e of doc.entries) {
62
+ const id = e.value.letterId as string;
63
+ if (e.kind === 'star') { if (!stars.get(id) && !newStars.some(n=>n.id===id)) newStars.push({id,at:e.value.starredAt as number}); continue; }
64
+ const target=rows[e.kind]; if (target.some(r=>r.letterId===id)) continue;
65
+ (target as any[]).push(e.value); added++;
66
+ }
67
+ store.commitImported(sent as SentLetter[],received as ReceivedLetter[],replies as LocalReply[]);
68
+ for (const star of newStars) stars.set(star.id,true,star.at); // Only collection metadata. Never restore memory consent.
69
+ return added;
70
+ }
@@ -111,19 +111,25 @@ $shell.Margin = [System.Windows.Thickness]::new(26)
111
111
 
112
112
  $card = New-Object System.Windows.Controls.Border
113
113
  $card.Background = Brush '@card'
114
- $card.CornerRadius = [System.Windows.CornerRadius]::new(14)
114
+ $card.CornerRadius = [System.Windows.CornerRadius]::new(16)
115
115
  $card.BorderBrush = Brush '@line'
116
116
  $card.BorderThickness = [System.Windows.Thickness]::new(1)
117
- $card.Padding = [System.Windows.Thickness]::new(24, 20, 24, 18)
117
+ $card.Padding = [System.Windows.Thickness]::new(26, 22, 26, 20)
118
118
  $shadow = New-Object System.Windows.Media.Effects.DropShadowEffect
119
- $shadow.BlurRadius = 22
120
- $shadow.ShadowDepth = 6
119
+ $shadow.BlurRadius = 32
120
+ $shadow.ShadowDepth = 8
121
121
  $shadow.Direction = 270
122
- $shadow.Opacity = 0.17
123
- $shadow.Color = [System.Windows.Media.Color][System.Windows.Media.ColorConverter]::ConvertFromString('#3C2D19')
122
+ $shadow.Opacity = 0.25
123
+ $shadow.Color = [System.Windows.Media.Color][System.Windows.Media.ColorConverter]::ConvertFromString('#1A1A1A')
124
124
  $card.Effect = $shadow
125
- $slide = [System.Windows.Media.TranslateTransform]::new(0, 10)
126
- $card.RenderTransform = $slide
125
+ $transformGroup = New-Object System.Windows.Media.TransformGroup
126
+ $slide = [System.Windows.Media.TranslateTransform]::new(0, 12)
127
+ $scale = [System.Windows.Media.ScaleTransform]::new(0.96, 0.96)
128
+ $transformGroup.Children.Add($scale) | Out-Null
129
+ $transformGroup.Children.Add($slide) | Out-Null
130
+ $card.RenderTransform = $transformGroup
131
+ $card.RenderTransformOrigin = [System.Windows.Point]::new(0.5, 0.5)
132
+ $script:cardScale = $scale
127
133
 
128
134
  $stack = New-Object System.Windows.Controls.StackPanel
129
135
 
@@ -141,15 +147,23 @@ $eyebrow.Foreground = Brush '@accent-text'
141
147
  $eyebrow.VerticalAlignment = 'Center'
142
148
  $head.Children.Add($eyebrow) | Out-Null
143
149
 
144
- $close = New-Object System.Windows.Controls.TextBlock
145
- $close.Text = '×'
146
- $close.FontFamily = 'Segoe UI'
147
- $close.FontSize = 15
148
- $close.Foreground = Brush '@muted'
150
+ $close = New-Object System.Windows.Controls.Border
151
+ $close.Background = [System.Windows.Media.Brushes]::Transparent
152
+ $close.CornerRadius = [System.Windows.CornerRadius]::new(12)
153
+ $close.Width = 24
154
+ $close.Height = 24
149
155
  $close.Cursor = 'Hand'
150
156
  $close.Margin = [System.Windows.Thickness]::new(10, -4, 0, 0)
151
157
  $close.VerticalAlignment = 'Top'
152
158
  [System.Windows.Controls.Grid]::SetColumn($close, 1)
159
+ $closeText = New-Object System.Windows.Controls.TextBlock
160
+ $closeText.Text = '×'
161
+ $closeText.FontFamily = 'Segoe UI'
162
+ $closeText.FontSize = 16
163
+ $closeText.Foreground = Brush '@muted'
164
+ $closeText.HorizontalAlignment = 'Center'
165
+ $closeText.VerticalAlignment = 'Center'
166
+ $close.Child = $closeText
153
167
  $script:brushInk = Brush '@seal'
154
168
  $script:brushInkHover = Brush '@accent'
155
169
  $script:brushGhost = Brush '#00FFFFFF'
@@ -158,8 +172,14 @@ $script:brushMuted = Brush '@muted'
158
172
  $script:brushFaint = Brush '@muted'
159
173
 
160
174
  $close.Add_MouseLeftButtonUp({ param($s, $e) $script:win.Close() })
161
- $close.Add_MouseEnter({ param($s, $e) $s.Foreground = $script:brushMuted })
162
- $close.Add_MouseLeave({ param($s, $e) $s.Foreground = $script:brushFaint })
175
+ $close.Add_MouseEnter({ param($s, $e)
176
+ $s.Background = Brush '@soft'
177
+ $s.Child.Foreground = Brush '@accent'
178
+ })
179
+ $close.Add_MouseLeave({ param($s, $e)
180
+ $s.Background = [System.Windows.Media.Brushes]::Transparent
181
+ $s.Child.Foreground = $script:brushMuted
182
+ })
163
183
  $head.Children.Add($close) | Out-Null
164
184
  $stack.Children.Add($head) | Out-Null
165
185
 
@@ -323,11 +343,14 @@ function New-Pill([string]$label, [string]$tone, [string]$id) {
323
343
  $pill = New-Object System.Windows.Controls.Border
324
344
  $pill.Tag = $id
325
345
  $pill.Uid = $tone
326
- $pill.CornerRadius = [System.Windows.CornerRadius]::new(17)
327
- $pill.Padding = [System.Windows.Thickness]::new(18, 8, 18, 8)
328
- $pill.Margin = [System.Windows.Thickness]::new(0, 0, 8, 0)
346
+ $pill.CornerRadius = [System.Windows.CornerRadius]::new(18)
347
+ $pill.Padding = [System.Windows.Thickness]::new(20, 9, 20, 9)
348
+ $pill.Margin = [System.Windows.Thickness]::new(0, 0, 10, 0)
329
349
  $pill.BorderThickness = [System.Windows.Thickness]::new(1)
330
350
  $pill.Cursor = 'Hand'
351
+ $pillTransform = [System.Windows.Media.ScaleTransform]::new(1, 1)
352
+ $pill.RenderTransform = $pillTransform
353
+ $pill.RenderTransformOrigin = [System.Windows.Point]::new(0.5, 0.5)
331
354
  if ($tone -eq 'primary') {
332
355
  $pill.Background = $script:brushInk
333
356
  $pill.BorderBrush = $script:brushInk
@@ -340,17 +363,30 @@ function New-Pill([string]$label, [string]$tone, [string]$id) {
340
363
  $text = New-Object System.Windows.Controls.TextBlock
341
364
  $text.Text = $label
342
365
  $text.FontFamily = 'Microsoft YaHei'
343
- $text.FontSize = 13
366
+ $text.FontSize = 13.5
367
+ $text.FontWeight = 'Medium'
344
368
  $text.Foreground = Brush $fg
345
369
  $pill.Child = $text
346
370
  $pill.Add_MouseLeftButtonUp({ param($s, $e) Invoke-CardAction ([string]$s.Tag) })
347
371
  $pill.Add_MouseEnter({ param($s, $e)
348
372
  if ($script:busy) { return }
349
373
  if ($s.Uid -eq 'primary') { $s.Background = $script:brushInkHover } else { $s.Background = $script:brushGhostHover }
374
+ if ([System.Windows.SystemParameters]::ClientAreaAnimation) {
375
+ $hoverScale = [System.Windows.Media.Animation.DoubleAnimation]::new(1.0, 1.05, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(150)))
376
+ $hoverScale.EasingFunction = New-Object System.Windows.Media.Animation.CubicEase
377
+ $s.RenderTransform.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleXProperty, $hoverScale)
378
+ $s.RenderTransform.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleYProperty, $hoverScale)
379
+ }
350
380
  })
351
381
  $pill.Add_MouseLeave({ param($s, $e)
352
382
  if ($script:busy) { return }
353
383
  if ($s.Uid -eq 'primary') { $s.Background = $script:brushInk } else { $s.Background = $script:brushGhost }
384
+ if ([System.Windows.SystemParameters]::ClientAreaAnimation) {
385
+ $leaveScale = [System.Windows.Media.Animation.DoubleAnimation]::new(1.05, 1.0, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(150)))
386
+ $leaveScale.EasingFunction = New-Object System.Windows.Media.Animation.CubicEase
387
+ $s.RenderTransform.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleXProperty, $leaveScale)
388
+ $s.RenderTransform.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleYProperty, $leaveScale)
389
+ }
354
390
  })
355
391
  [void]$script:buttons.Add($pill)
356
392
  return $pill
@@ -379,14 +415,24 @@ $win.Add_ContentRendered({
379
415
  $script:win.Left = [Math]::Max($wa.Left + 12, $wa.Right - $script:win.ActualWidth - 20)
380
416
  $script:win.Top = [Math]::Max($wa.Top + 12, $wa.Bottom - $script:win.ActualHeight - 20)
381
417
 
382
- $fade = [System.Windows.Media.Animation.DoubleAnimation]::new(0, 1, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(180)))
418
+ $fade = [System.Windows.Media.Animation.DoubleAnimation]::new(0, 1, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(300)))
419
+ $easeOpacity = New-Object System.Windows.Media.Animation.CubicEase
420
+ $easeOpacity.EasingMode = 'EaseOut'
421
+ $fade.EasingFunction = $easeOpacity
383
422
  $script:win.BeginAnimation([System.Windows.Window]::OpacityProperty, $fade)
384
423
 
385
424
  $ease = New-Object System.Windows.Media.Animation.CubicEase
386
425
  $ease.EasingMode = 'EaseOut'
387
- $rise = [System.Windows.Media.Animation.DoubleAnimation]::new(10, 0, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(240)))
426
+ $rise = [System.Windows.Media.Animation.DoubleAnimation]::new(12, 0, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(400)))
388
427
  $rise.EasingFunction = $ease
389
428
  $slide.BeginAnimation([System.Windows.Media.TranslateTransform]::YProperty, $rise)
429
+
430
+ $scaleEase = New-Object System.Windows.Media.Animation.CubicEase
431
+ $scaleEase.EasingMode = 'EaseOut'
432
+ $scaleIn = [System.Windows.Media.Animation.DoubleAnimation]::new(0.96, 1.0, [System.Windows.Duration]::new([TimeSpan]::FromMilliseconds(400)))
433
+ $scaleIn.EasingFunction = $scaleEase
434
+ $script:cardScale.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleXProperty, $scaleIn)
435
+ $script:cardScale.BeginAnimation([System.Windows.Media.ScaleTransform]::ScaleYProperty, $scaleIn)
390
436
  })
391
437
 
392
438
  # Poll only the local appearance endpoint. Async IO never blocks reading or button clicks.
package/world/cards.ts CHANGED
@@ -143,7 +143,7 @@ export function replyDraftCard(input: {
143
143
  version: 1,
144
144
  base: base(input.base),
145
145
  eyebrow: '漂流瓶 · 回信写好了',
146
- from: '等你决定',
146
+ from: input.draft.autoSendAt ? '已安排自动寄出,可在信箱查看倒计时' : input.draft.autoSendKey ? '确认自动寄出时间中' : '等你决定',
147
147
  ...(input.held
148
148
  ? { quote: { label: `原来那一封(来自 ${input.held.from})`, body: input.held.body } }
149
149
  : {}),
@@ -171,13 +171,13 @@ export function replyArrivedCard(input: { base: string; reply: LocalReply; more:
171
171
  }
172
172
 
173
173
  /** 人类点了回信、Coo 还没写完:占位,等回信草稿把它替换掉。 */
174
- export function waitingCard(baseUrl: string): CardSpec {
174
+ export function waitingCard(baseUrl: string, botName = '桌宠', intent: 'read' | 'reply' = 'reply'): CardSpec {
175
175
  return {
176
176
  version: 1,
177
177
  base: base(baseUrl),
178
- eyebrow: '漂流瓶 · 它正在读',
179
- body: '读完就会把回信放到这里。',
180
- meta: '要是它没动笔,收起卡片再点一次「回信」',
178
+ eyebrow: `漂流瓶 · ${botName}${intent === 'reply' ? '正在写回信' : '正在读信'}`,
179
+ body: intent === 'reply' ? '写好后,回信草稿就会放到这里。' : '一起读读这封信,聊聊读后的感受。',
180
+ meta: intent === 'reply' ? '若这轮没能写好,可在信箱里再次点「写回信」' : '共读之后,可以在信箱里选择是否写回信',
181
181
  actions: [{ id: 'close', label: '收起', tone: 'ghost' }],
182
182
  };
183
183
  }
package/world/client.ts CHANGED
@@ -121,8 +121,11 @@ export class BottleClient {
121
121
  return this.call<LetterRes>('GET', `/letter/${encodeURIComponent(letterId)}`);
122
122
  }
123
123
 
124
- reply(letterId: string, body: string): Promise<OkRes> {
125
- return this.call<OkRes>('POST', '/reply', { letterId, body });
124
+ reply(letterId: string, body: string, draftKey?:string): Promise<OkRes> {
125
+ return this.call<OkRes>('POST', '/reply', { letterId, body, ...(draftKey?{draftKey}:{}) });
126
+ }
127
+ reserveReplyDraft(letterId:string,draftKey:string,cancel=false):Promise<import('../shared/contract.ts').ReplyDraftRes>{
128
+ return this.call('POST','/reply/draft',{letterId,draftKey,...(cancel?{cancel:true}:{})});
126
129
  }
127
130
 
128
131
  dismiss(letterId: string): Promise<DismissRes> {
@@ -151,6 +154,15 @@ export class BottleClient {
151
154
  return this.call<MailTakeRes>('POST', '/mail/take', {});
152
155
  }
153
156
 
157
+ notes(): Promise<import('../shared/contract.ts').NotesRes> { return this.call('GET', '/notes'); }
158
+ note(letterId: string, body: string): Promise<import('../shared/contract.ts').NoteRes> { return this.call('POST', '/note', { letterId, body }); }
159
+ ackNote(id: string): Promise<{ ok: true }> { return this.call('POST', '/note/ack', { id }); }
160
+ repost(letterId: string, body: string, topic?: string): Promise<import('../shared/contract.ts').RepostRes> {
161
+ return this.call('POST', '/repost', { letterId, body, ...(topic ? { topic } : {}) });
162
+ }
163
+ readHeld(letterId: string): Promise<OkRes> { return this.call('POST', '/read', { letterId }); }
164
+ keepHeld(letterId: string): Promise<OkRes> { return this.call('POST', '/keep', { letterId }); }
165
+
154
166
  quota(): Promise<Quota> {
155
167
  return this.call<Quota>('GET', '/quota');
156
168
  }
package/world/config.ts CHANGED
@@ -22,6 +22,8 @@ export interface BottleWakeSettings {
22
22
  /** Older deployments may omit the invitation settings; constructor migration retains their preferences. */
23
23
  export interface BottleConfigSection extends Partial<BottleWakeSettings>, SoundConfig {
24
24
  enabled: boolean;
25
+ /** Opt-in only; a separate per-letter consent is also required. */
26
+ starMemoryEnabled?: boolean;
25
27
  /** 随机邀请只提供机会,Bot 可明确暂不做。 */
26
28
  randomWake?: boolean;
27
29
  /** 海在哪。改地址要重启 World。 */
@@ -97,6 +99,7 @@ export const BOTTLE_DEFAULTS: BottleConfigSection = {
97
99
  cardAutoCloseSec: 10,
98
100
  debug: false,
99
101
  tsunamiNotice: true,
102
+ starMemoryEnabled: false,
100
103
  soundEnabled: true, soundVolume: 70, soundFadeOutMs: 250,
101
104
  soundIncomingSource: 'pack', soundIncomingPack: DEFAULT_SOUND_PACK.incoming, soundIncomingFile: '',
102
105
  soundReplySource: 'pack', soundReplyPack: DEFAULT_SOUND_PACK.reply, soundReplyFile: '',
@@ -105,6 +108,11 @@ export const BOTTLE_DEFAULTS: BottleConfigSection = {
105
108
 
106
109
  /** Field declarations stay at the same config paths; grouping is presentation only. */
107
110
  export const BOTTLE_CONFIG_FIELDS: Record<string, ConfigProperty> = {
111
+ 'worlds.bottle.starMemoryEnabled': {
112
+ type: 'boolean', title: '允许星笺记忆',
113
+ description: '默认关闭。开启后还需在网页的星笺匣逐封勾选,才会把完整往来交给桌宠并允许后续重读;仅星标不会读正文。关闭会清除全部逐封授权,已进入上下文或摘要的内容无法追回。不修改核心记忆。',
114
+ 'x-hot': true,
115
+ },
108
116
  'worlds.bottle.server': {
109
117
  type: 'string',
110
118
  title: '服务端地址',
@@ -224,6 +232,8 @@ function configGroup(id: string, title: string, description: string, fields: rea
224
232
  }
225
233
 
226
234
  export const BOTTLE_CONFIG_GROUPS: ConfigGroup[] = [
235
+ configGroup('world:bottle:stars', '星笺匣与记忆',
236
+ '星标表示喜欢;确认邀请后才允许正文长期重读,关闭可撤回授权。', ['starMemoryEnabled']),
227
237
  configGroup('world:bottle:display', '显示与通知',
228
238
  '先选信件显示的位置,再调整桌面卡片和海啸提醒。',
229
239
  ['surface', 'cardAutoCloseSec', 'tsunamiNotice']),
@@ -19,11 +19,11 @@ export const BOTTLE: WorldDefinition<BottleConfigSection> = {
19
19
  en: 'Drafts a letter of at most 120 characters into the human\'s mailbox page. Never sends it.',
20
20
  },
21
21
  bottle_catch: {
22
- zh: '捞一只瓶子。回执只说来自谁和剩余次数,不含正文;正文只在人类的信箱页上。',
23
- en: 'Fishes one bottle. The receipt names the writer and the quota, never the text.',
22
+ zh: '捞一只瓶子。回执包含署名、已有标题和额度;无标题不补正文,全文仍在信箱页。',
23
+ en: 'Fishes a bottle; returns the signature, existing title and quota, never a body excerpt.',
24
24
  },
25
25
  bottle_reply: {
26
- zh: '给人类刚点开的那一封起草回信,只需正文,信箱自动对应原信。只有人类点了回信的那一轮可用,写完仍是草稿。',
26
+ zh: '给人类刚点开的那一封起草回信,只需正文,信箱自动对应原信。仅人在信箱点写回信的轮次可用;有效草稿确认后两小时自动寄出,也可提前寄出或放弃(需新版海边支持)。',
27
27
  en: 'Drafts a body-only answer to the letter the human just opened; the mailbox keeps track of the target. Only available in that turn.',
28
28
  },
29
29
  bottle_wake_choice: {
@@ -36,6 +36,10 @@ export const BOTTLE: WorldDefinition<BottleConfigSection> = {
36
36
  },
37
37
  }),
38
38
  events: [
39
+ { type:'bottle.note-arrived', description:{zh:'收到小纸条,自动递上纸条正文,请桌宠转告人;不自动附上原信和原回信,不授权起草。',en:'A short note arrived. Its text is delivered automatically; tell the human and share a thought. Original correspondence is not attached and no drafting is authorized.'} },
40
+ { type:'bottle.note-reading', description:{zh:'人点击小纸条下的一起看,单次递上小纸条、原信与原回信,只读和聊感想,不起草回信或纸条。',en:'The human chose to look at a short note together with the original letter and reply. Read and share thoughts only; do not draft a reply or note.'} },
41
+ {type:'bottle.note-request',description:{zh:'人收到自己信件的回信后,邀请桌宠起草 40 字小纸条;人只能确认寄出或放弃。',en:'The author received a reply and invited a companion-written note draft; the human confirms sending.'}},
42
+ {type:'bottle.star-memory',description:{zh:'人明确允许将一段星标往来纳入可撤回的长期信件记忆;投递前重验开关。',en:'Explicit revocable permission to remember starred correspondence, rechecked at delivery.'}},
39
43
  {
40
44
  type: 'bottle.request',
41
45
  description: {
@@ -53,8 +57,8 @@ export const BOTTLE: WorldDefinition<BottleConfigSection> = {
53
57
  {
54
58
  type: 'bottle.reading',
55
59
  description: {
56
- zh: '人类点了回信,这一封的正文被授权给模型;按外部事件推送。',
57
- en: 'The human asked to reply; this letter\'s text is authorised and delivered as an external event.',
60
+ zh: '人点击一起读或写回信,这一封正文按对应意图单次授权,作为外部事件投递。',
61
+ en: 'The human clicked read together or write reply; only that letter is authorized for the chosen intent.',
58
62
  },
59
63
  },
60
64
  {
@@ -67,8 +71,8 @@ export const BOTTLE: WorldDefinition<BottleConfigSection> = {
67
71
  {
68
72
  type: 'bottle.mail',
69
73
  description: {
70
- zh: '有新的回信漂回来了,只有数量。',
71
- en: 'New answers drifted back; count only.',
74
+ zh: '有新的回信漂回来了,带数量与原信投海距今多久,不含正文。',
75
+ en: 'New answers drifted back; count and relative sending times only, without letter text.',
72
76
  },
73
77
  },
74
78
  {
@@ -95,8 +99,8 @@ export const BOTTLE: WorldDefinition<BottleConfigSection> = {
95
99
  {
96
100
  type: 'bottle.picked',
97
101
  description: {
98
- zh: '我写的信被人捡起来了。只播报第一次(这个状态会来回抖),而且不带任何化名。',
99
- en: 'Someone picked up a letter I wrote. Announced once only (the state flaps), and it carries no pseudonym.',
102
+ zh: '我写的信被人捡起来了,带原信投海距今多久。只播报第一次(这个状态会来回抖),而且不带任何化名。',
103
+ en: 'Someone picked up a letter I wrote; includes how long ago it was sent. Announced once only (the state flaps), and it carries no pseudonym.',
100
104
  },
101
105
  },
102
106
  {
@@ -0,0 +1,76 @@
1
+ import { mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, existsSync } from 'node:fs';
2
+ import { join, dirname } from 'node:path';
3
+ import { NOTE_TTL_MS, type ReceivedNote } from '../shared/contract.ts';
4
+ import { checkNote } from '../shared/text.ts';
5
+
6
+ /** expiresAt describes server retention only; it never expires this local copy. */
7
+ export interface LocalNote extends ReceivedNote { readAt?: number }
8
+ interface ForgottenNote { id:string; letterId:string; expiresAt:string }
9
+
10
+ /** Local archive: body and readAt remain until the human deletes the correspondence or
11
+ * clears the letterbook. Server expiry is transport metadata, never a local deadline.
12
+ * Body-free deletion receipts prevent a failed server ACK from restoring removed notes;
13
+ * these receipts alone expire at the server's original seven-day deadline.
14
+ * Neither notes nor these receipts are included in letterbook exports or star memory. */
15
+ export class NoteCache {
16
+ readonly file:string;
17
+ private records = new Map<string,LocalNote>();
18
+ private forgotten = new Map<string,ForgottenNote>();
19
+ constructor(dir:string,private readonly now:()=>number){this.file=join(dir,'bottle-notes.json');}
20
+ load():void {
21
+ this.records.clear();this.forgotten.clear();
22
+ try {
23
+ const data=JSON.parse(readFileSync(this.file,'utf8'));
24
+ if(data.schemaVersion!==1)return;
25
+ for(const value of Array.isArray(data.notes)?data.notes:[]) {
26
+ const note=this.valid(value);if(!note)continue;
27
+ this.records.set(note.id,{...note,...(typeof value.readAt==='number'&&Number.isFinite(value.readAt)&&value.readAt>0?{readAt:value.readAt}:{})});
28
+ }
29
+ for(const value of Array.isArray(data.forgotten)?data.forgotten:[]){
30
+ if(value&&this.id(value.id)&&this.id(value.letterId)&&typeof value.expiresAt==='string'&&Date.parse(value.expiresAt)>this.now()){
31
+ this.forgotten.set(value.id,{id:value.id,letterId:value.letterId,expiresAt:value.expiresAt});this.records.delete(value.id);
32
+ }
33
+ }
34
+ // Migrate older seven-day caches without expiring any locally archived paper.
35
+ this.save();
36
+ } catch(error) { if(existsSync(this.file)&&!(error instanceof SyntaxError))throw error; }
37
+ }
38
+ private id(value:unknown):value is string{return typeof value==='string'&&value.length>0&&value.length<=256;}
39
+ private valid(value:unknown,fromServer=false):ReceivedNote|null {
40
+ if(!value||typeof value!=='object')return null;
41
+ const n=value as Record<string,unknown>;
42
+ if(!this.id(n.id)||!this.id(n.letterId)||typeof n.from!=='string'||typeof n.body!=='string'||!checkNote(n.body).ok||typeof n.at!=='string'||typeof n.expiresAt!=='string')return null;
43
+ const at=Date.parse(n.at),expires=Date.parse(n.expiresAt);
44
+ if(!Number.isFinite(at)||!Number.isFinite(expires)||(fromServer&&expires<=this.now())||expires<=at||expires>at+NOTE_TTL_MS)return null;
45
+ return {id:n.id,letterId:n.letterId,from:n.from,body:n.body,at:n.at,expiresAt:n.expiresAt};
46
+ }
47
+ receive(value:unknown):string|null {
48
+ const note=this.valid(value,true);if(!note)return null;
49
+ // Save even an existing note again before ACK: a previous disk write may have failed.
50
+ const added=!this.forgotten.has(note.id)&&!this.records.has(note.id);
51
+ if(added)this.records.set(note.id,note);
52
+ try{this.save();}catch(error){if(added)this.records.delete(note.id);throw error;}return note.id;
53
+ }
54
+ all():LocalNote[]{this.prune();return [...this.records.values()].map(n=>({...n})).sort((a,b)=>Date.parse(a.at)-Date.parse(b.at));}
55
+ get(id:string):LocalNote|undefined{this.prune();const note=this.records.get(id);return note?{...note}:undefined;}
56
+ read(id:string):void {
57
+ const note=this.records.get(id);if(!note)return;
58
+ if(!note.readAt)note.readAt=this.now();this.save();
59
+ }
60
+ forget(letterId?:string):void {
61
+ for(const [id,note] of this.records){if(letterId&&note.letterId!==letterId)continue;
62
+ this.forgotten.set(id,{id,letterId:note.letterId,expiresAt:note.expiresAt});this.records.delete(id);
63
+ }
64
+ this.prune();this.save();
65
+ }
66
+ prune():void {
67
+ let changed=false;
68
+ for(const [id,note] of this.forgotten){if(Date.parse(note.expiresAt)<=this.now()){this.forgotten.delete(id);changed=true;}}
69
+ if(changed)this.save();
70
+ }
71
+ private save():void {
72
+ mkdirSync(dirname(this.file),{recursive:true});const temporary=this.file+'.tmp';
73
+ try{writeFileSync(temporary,JSON.stringify({schemaVersion:1,notes:[...this.records.values()],forgotten:[...this.forgotten.values()]})+'\n',{encoding:'utf8',mode:0o600});renameSync(temporary,this.file);}
74
+ finally{try{unlinkSync(temporary);}catch{/* No partial note bodies left in a temporary file. */}}
75
+ }
76
+ }