chatluna-plugin-onebot-sandbox 1.1.5 → 1.2.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.
Files changed (71) hide show
  1. package/client/chat/chat-pane.tsx +19 -7
  2. package/client/chat/composer.tsx +4 -4
  3. package/client/chat/forward.tsx +11 -12
  4. package/client/chat/media-attachments.tsx +236 -0
  5. package/client/chat/message-list.tsx +54 -37
  6. package/client/chat/messages.css +203 -19
  7. package/client/environment/avatar-picker.tsx +4 -0
  8. package/client/locales/en.yml +10 -3
  9. package/client/locales/zh.yml +10 -3
  10. package/client/mcp/credential-manager.tsx +5 -9
  11. package/client/test-space/spaces.css +2 -0
  12. package/client/webqq/composer-draft.ts +0 -1
  13. package/client/webqq/forward-dialog-stack.ts +11 -3
  14. package/client/webqq/media-attachment.ts +72 -0
  15. package/client/webqq/message-cluster.ts +9 -29
  16. package/client/workspace/context.tsx +1 -1
  17. package/client/workspace/overlay-host.tsx +26 -17
  18. package/client/workspace/store.ts +75 -39
  19. package/dist/.vite/manifest.json +1 -1
  20. package/dist/app-Cubeh6IM.js +85 -0
  21. package/dist/client.css +2 -2
  22. package/dist/client.js +1 -1
  23. package/lib/base64.d.ts +3 -0
  24. package/lib/base64.d.ts.map +1 -0
  25. package/lib/bot.d.ts.map +1 -1
  26. package/lib/builtin-avatar-png.d.ts +0 -1
  27. package/lib/builtin-avatar-png.d.ts.map +1 -1
  28. package/lib/builtin-avatars.d.ts +0 -1
  29. package/lib/builtin-avatars.d.ts.map +1 -1
  30. package/lib/chatluna/state.d.ts.map +1 -1
  31. package/lib/chatluna/thinking.d.ts.map +1 -1
  32. package/lib/console-contract.d.ts +5 -5
  33. package/lib/console-contract.d.ts.map +1 -1
  34. package/lib/console.d.ts +1 -3
  35. package/lib/console.d.ts.map +1 -1
  36. package/lib/control-service.d.ts +4 -3
  37. package/lib/control-service.d.ts.map +1 -1
  38. package/lib/conversation-resolution.d.ts +0 -2
  39. package/lib/conversation-resolution.d.ts.map +1 -1
  40. package/lib/inbound-delivery.d.ts.map +1 -1
  41. package/lib/index.d.ts +1 -0
  42. package/lib/index.d.ts.map +1 -1
  43. package/lib/index.js +529 -549
  44. package/lib/index.js.map +1 -1
  45. package/lib/mcp/call-records.d.ts.map +1 -1
  46. package/lib/mcp/http-api.d.ts +3 -4
  47. package/lib/mcp/http-api.d.ts.map +1 -1
  48. package/lib/mcp/server.d.ts.map +1 -1
  49. package/lib/mcp/service.d.ts +8 -7
  50. package/lib/mcp/service.d.ts.map +1 -1
  51. package/lib/mcp/types.d.ts +1 -4
  52. package/lib/mcp/types.d.ts.map +1 -1
  53. package/lib/media-download.d.ts +3 -0
  54. package/lib/media-download.d.ts.map +1 -0
  55. package/lib/media-limits.d.ts +6 -0
  56. package/lib/media-limits.d.ts.map +1 -0
  57. package/lib/media-preview.d.ts +4 -0
  58. package/lib/media-preview.d.ts.map +1 -0
  59. package/lib/media-storage.d.ts +2 -3
  60. package/lib/media-storage.d.ts.map +1 -1
  61. package/lib/onebot-debug.d.ts.map +1 -1
  62. package/lib/record-store.d.ts +0 -2
  63. package/lib/record-store.d.ts.map +1 -1
  64. package/lib/test-spaces.d.ts +1 -0
  65. package/lib/test-spaces.d.ts.map +1 -1
  66. package/lib/types.d.ts +16 -3
  67. package/lib/types.d.ts.map +1 -1
  68. package/lib/user-authority.d.ts +1 -1
  69. package/lib/user-authority.d.ts.map +1 -1
  70. package/package.json +5 -2
  71. package/dist/app-CpJLSY0S.js +0 -85
@@ -115,8 +115,8 @@
115
115
  }
116
116
 
117
117
  .sandbox-message-row.is-recalled .sandbox-message-media img,
118
- .sandbox-message-row.is-recalled .sandbox-message-media audio,
119
118
  .sandbox-message-row.is-recalled .sandbox-message-media video,
119
+ .sandbox-message-row.is-recalled .sandbox-message-voice,
120
120
  .sandbox-message-row.is-recalled .sandbox-message-file {
121
121
  opacity: 0.72;
122
122
  filter: grayscale(0.15);
@@ -535,56 +535,240 @@
535
535
  object-fit: contain;
536
536
  }
537
537
 
538
- .sandbox-message-media audio {
539
- width: min(260px, 100%);
540
- height: 36px;
538
+ /* 语音条:圆形播放键 + 波形 + 时长。波形是两层同样的竖条,上层按播放进度裁剪成强调色。 */
539
+ .sandbox-message-voice {
540
+ display: flex;
541
+ width: 232px;
542
+ max-width: 100%;
543
+ align-items: center;
544
+ gap: 10px;
545
+ padding: 1px 0;
546
+ white-space: normal;
547
+ }
548
+
549
+ .sandbox-message-voice audio {
550
+ display: none;
551
+ }
552
+
553
+ .sandbox-message-voice-toggle {
554
+ display: inline-flex;
555
+ flex: none;
556
+ width: 32px;
557
+ height: 32px;
558
+ align-items: center;
559
+ justify-content: center;
560
+ padding: 0;
561
+ border: 0;
562
+ border-radius: 999px;
563
+ color: #fff;
564
+ background: var(--sandbox-accent);
565
+ transition: transform 160ms ease, opacity 160ms ease;
566
+ }
567
+
568
+ .sandbox-message-voice-toggle:not(:disabled):active {
569
+ transform: scale(0.92);
570
+ }
571
+
572
+ .sandbox-message-voice-toggle:disabled {
573
+ opacity: 0.45;
574
+ }
575
+
576
+ .sandbox-message-voice-toggle:focus-visible,
577
+ .sandbox-message-voice-wave:focus-visible {
578
+ outline: 2px solid var(--sandbox-accent);
579
+ outline-offset: 2px;
580
+ }
581
+
582
+ .sandbox-message-voice-wave {
583
+ position: relative;
584
+ min-width: 0;
585
+ height: 26px;
586
+ flex: 1;
587
+ border-radius: 4px;
588
+ touch-action: none;
589
+ }
590
+
591
+ .sandbox-message-voice-bars {
592
+ position: absolute;
593
+ inset: 0;
594
+ display: flex;
595
+ align-items: center;
596
+ justify-content: space-between;
597
+ pointer-events: none;
598
+ }
599
+
600
+ .sandbox-message-voice-bars > span {
601
+ width: 3px;
602
+ min-height: 3px;
603
+ border-radius: 999px;
604
+ background: color-mix(in srgb, var(--sandbox-text) 22%, transparent);
605
+ }
606
+
607
+ .sandbox-message-voice-bars.is-played > span {
608
+ background: var(--sandbox-accent);
609
+ }
610
+
611
+ .sandbox-message-voice-time {
612
+ flex: none;
613
+ min-width: 34px;
614
+ color: var(--sandbox-muted);
615
+ font-size: 12px;
616
+ font-variant-numeric: tabular-nums;
617
+ text-align: right;
618
+ white-space: nowrap;
541
619
  }
542
620
 
621
+ .sandbox-message-row.is-outgoing .sandbox-message-voice-toggle {
622
+ color: var(--sandbox-accent);
623
+ background: #fff;
624
+ }
625
+
626
+ .sandbox-message-row.is-outgoing .sandbox-message-voice-toggle:focus-visible,
627
+ .sandbox-message-row.is-outgoing .sandbox-message-voice-wave:focus-visible {
628
+ outline-color: #fff;
629
+ }
630
+
631
+ .sandbox-message-row.is-outgoing .sandbox-message-voice-bars > span {
632
+ background: rgb(255 255 255 / 38%);
633
+ }
634
+
635
+ .sandbox-message-row.is-outgoing .sandbox-message-voice-bars.is-played > span {
636
+ background: #fff;
637
+ }
638
+
639
+ .sandbox-message-row.is-outgoing .sandbox-message-voice-time {
640
+ color: rgb(255 255 255 / 78%);
641
+ }
642
+
643
+ /* 文件卡片:类型色块 + 两行文件名 + 大小与类型,右侧是下载提示。卡片直接占满气泡,不再套一层底色。 */
543
644
  .sandbox-message-file {
544
645
  display: flex;
545
- min-width: 210px;
646
+ width: 248px;
546
647
  max-width: 100%;
547
648
  align-items: center;
548
- gap: 10px;
549
- padding: 9px 10px;
550
- border-radius: 8px;
649
+ gap: 11px;
650
+ margin: -2px -3px;
651
+ padding: 4px 3px;
652
+ border-radius: 10px;
551
653
  color: inherit;
552
- background: rgb(148 163 184 / 14%);
553
654
  text-decoration: none;
655
+ white-space: normal;
656
+ transition: background-color 160ms ease;
657
+ }
658
+
659
+ a.sandbox-message-file:hover {
660
+ background: color-mix(in srgb, var(--sandbox-text) 5%, transparent);
554
661
  }
555
662
 
556
- .sandbox-message-row.is-outgoing .sandbox-message-file {
557
- background: rgb(255 255 255 / 14%);
663
+ a.sandbox-message-file:focus-visible {
664
+ outline: 2px solid var(--sandbox-accent);
665
+ outline-offset: 1px;
558
666
  }
559
667
 
560
- .sandbox-message-file > svg {
668
+ .sandbox-message-file-icon {
669
+ --sandbox-file-color: #64748b;
670
+
671
+ display: inline-flex;
561
672
  flex: none;
673
+ width: 40px;
674
+ height: 40px;
675
+ align-items: center;
676
+ justify-content: center;
677
+ border-radius: 10px;
678
+ color: #fff;
679
+ background: var(--sandbox-file-color);
680
+ }
681
+
682
+ .sandbox-message-file-icon[data-kind="archive"] { --sandbox-file-color: #d97706; }
683
+ .sandbox-message-file-icon[data-kind="audio"] { --sandbox-file-color: #8b5cf6; }
684
+ .sandbox-message-file-icon[data-kind="code"] { --sandbox-file-color: #0f766e; }
685
+ .sandbox-message-file-icon[data-kind="document"] { --sandbox-file-color: #2563eb; }
686
+ .sandbox-message-file-icon[data-kind="image"] { --sandbox-file-color: #16a34a; }
687
+ .sandbox-message-file-icon[data-kind="sheet"] { --sandbox-file-color: #059669; }
688
+ .sandbox-message-file-icon[data-kind="video"] { --sandbox-file-color: #e11d48; }
689
+
690
+ .sandbox-message-file.is-pending .sandbox-message-file-icon {
691
+ opacity: 0.55;
562
692
  }
563
693
 
564
- .sandbox-message-file span {
694
+ .sandbox-message-file-info {
565
695
  display: flex;
566
696
  min-width: 0;
697
+ flex: 1;
567
698
  flex-direction: column;
699
+ gap: 2px;
568
700
  }
569
701
 
570
- .sandbox-message-file strong,
571
- .sandbox-message-file small {
702
+ .sandbox-message-file-info strong {
703
+ display: -webkit-box;
572
704
  overflow: hidden;
573
- text-overflow: ellipsis;
574
- white-space: nowrap;
705
+ font-size: 13px;
706
+ font-weight: 600;
707
+ line-height: 18px;
708
+ overflow-wrap: anywhere;
709
+ -webkit-box-orient: vertical;
710
+ -webkit-line-clamp: 2;
711
+ line-clamp: 2;
575
712
  }
576
713
 
577
- .sandbox-message-file small,
714
+ .sandbox-message-file-info small,
578
715
  .sandbox-message-media-loading {
579
716
  color: var(--sandbox-muted);
580
717
  font-size: 11px;
581
718
  }
582
719
 
583
- .sandbox-message-row.is-outgoing .sandbox-message-file small,
720
+ .sandbox-message-file-info small {
721
+ overflow: hidden;
722
+ line-height: 16px;
723
+ text-overflow: ellipsis;
724
+ white-space: nowrap;
725
+ }
726
+
727
+ .sandbox-message-file-download {
728
+ display: inline-flex;
729
+ flex: none;
730
+ width: 28px;
731
+ height: 28px;
732
+ align-items: center;
733
+ justify-content: center;
734
+ border-radius: 999px;
735
+ color: var(--sandbox-muted);
736
+ background: color-mix(in srgb, var(--sandbox-text) 6%, transparent);
737
+ transition: color 160ms ease, background-color 160ms ease;
738
+ }
739
+
740
+ a.sandbox-message-file:hover .sandbox-message-file-download {
741
+ color: #fff;
742
+ background: var(--sandbox-accent);
743
+ }
744
+
745
+ .sandbox-message-row.is-outgoing a.sandbox-message-file:hover {
746
+ background: rgb(255 255 255 / 12%);
747
+ }
748
+
749
+ .sandbox-message-row.is-outgoing a.sandbox-message-file:focus-visible {
750
+ outline-color: #fff;
751
+ }
752
+
753
+ .sandbox-message-row.is-outgoing .sandbox-message-file-icon {
754
+ box-shadow: 0 0 0 1px rgb(255 255 255 / 28%);
755
+ }
756
+
757
+ .sandbox-message-row.is-outgoing .sandbox-message-file-info small,
584
758
  .sandbox-message-row.is-outgoing .sandbox-message-media-loading {
585
759
  color: rgb(255 255 255 / 72%);
586
760
  }
587
761
 
762
+ .sandbox-message-row.is-outgoing .sandbox-message-file-download {
763
+ color: #fff;
764
+ background: rgb(255 255 255 / 18%);
765
+ }
766
+
767
+ .sandbox-message-row.is-outgoing a.sandbox-message-file:hover .sandbox-message-file-download {
768
+ color: var(--sandbox-accent);
769
+ background: #fff;
770
+ }
771
+
588
772
  .sandbox-message-row.is-quote-target .sandbox-message-bubble::after {
589
773
  position: absolute;
590
774
  inset: 0;
@@ -3,6 +3,8 @@ import { ArrowLeftIcon, ChevronRightIcon, UploadIcon } from 'lucide-react'
3
3
  import { Button } from '@chatluna/ui-kit'
4
4
  import { BUILTIN_AVATARS, type BuiltinAvatar, type BuiltinAvatarKind } from '../../src/builtin-avatar-png'
5
5
  import { useT } from '../i18n'
6
+ import { MEBIBYTE } from '../../src/media-limits'
7
+ import { useWorkspace } from '../workspace/context'
6
8
 
7
9
  function avatarDataUrl(avatar: BuiltinAvatar) {
8
10
  return `data:image/png;base64,${avatar.png}`
@@ -37,6 +39,7 @@ export function AvatarChoices({ kind, onSelect }: {
37
39
  onSelect(avatar: string): void
38
40
  }) {
39
41
  const t = useT()
42
+ const { workspace } = useWorkspace()
40
43
  const [error, setError] = React.useState('')
41
44
  const fileInput = React.useRef<HTMLInputElement>(null)
42
45
 
@@ -45,6 +48,7 @@ export function AvatarChoices({ kind, onSelect }: {
45
48
  event.target.value = ''
46
49
  if (!file) return
47
50
  if (!file.type.startsWith('image/')) return setError(t('sandbox.avatar.notImage'))
51
+ if (file.size > workspace.mediaMaxSize) return setError(t('sandbox.avatar.oversize', { size: workspace.mediaMaxSize / MEBIBYTE }))
48
52
  const reader = new FileReader()
49
53
  reader.addEventListener('load', () => {
50
54
  if (typeof reader.result !== 'string') return
@@ -4,6 +4,7 @@ sandbox.avatar.builtin: "Built-in avatar {id}"
4
4
  sandbox.avatar.change: "Change avatar"
5
5
  sandbox.avatar.description: "Use a built-in avatar or a local image."
6
6
  sandbox.avatar.notImage: "The avatar file is not an image"
7
+ sandbox.avatar.oversize: "The avatar file must be {size} MiB or smaller"
7
8
  sandbox.avatar.readFailed: "Failed to read the avatar image"
8
9
  sandbox.avatar.title: "Choose avatar"
9
10
  sandbox.avatar.upload: "Upload local image"
@@ -53,7 +54,7 @@ sandbox.composer.failed: "Failed to send"
53
54
  sandbox.composer.input: "Message"
54
55
  sandbox.composer.mention: "Mention member"
55
56
  sandbox.composer.noMention: "No matching member"
56
- sandbox.composer.oversize: "Each file must be 10 MB or smaller"
57
+ sandbox.composer.oversize: "Each file must be {size} MiB or smaller"
57
58
  sandbox.composer.placeholder: "Send a message"
58
59
  sandbox.composer.preview: "Preview {name}"
59
60
  sandbox.composer.remove: "Remove {name}"
@@ -85,12 +86,10 @@ sandbox.credential.createdAt: "Created {time}"
85
86
  sandbox.credential.disable: "Disable"
86
87
  sandbox.credential.empty: "No test credentials yet"
87
88
  sandbox.credential.enable: "Enable"
88
- sandbox.credential.generate: "Generate a viewable token"
89
89
  sandbox.credential.hint: "One credential works for both MCP clients and HTTP scripts. Created credentials can show their token again and change name and scopes; call records and logs never print the plain token."
90
90
  sandbox.credential.invalid: "A name and at least one scope are required."
91
91
  sandbox.credential.loadFailed: "Failed to load test credentials"
92
92
  sandbox.credential.name: "Name"
93
- sandbox.credential.noPlainToken: "This credential was created without storing the plain token, so it cannot be shown. Regenerating makes it viewable and revokes the old token immediately."
94
93
  sandbox.credential.revoke: "Revoke"
95
94
  sandbox.credential.revokeDescription: "MCP clients and HTTP scripts using this credential lose access immediately. This cannot be undone."
96
95
  sandbox.credential.revokeTitle: "Revoke credential \"{name}\""
@@ -315,10 +314,14 @@ sandbox.group.requestComment: "Join request from OneBot Sandbox"
315
314
  sandbox.kind.bot: "bot"
316
315
  sandbox.kind.group: "group"
317
316
  sandbox.kind.user: "user"
317
+ sandbox.media.downloadFile: "Download {name}"
318
318
  sandbox.media.loading: "Loading media…"
319
+ sandbox.media.pauseVoice: "Pause voice message"
320
+ sandbox.media.playVoice: "Play voice message"
319
321
  sandbox.media.preview: "Image preview"
320
322
  sandbox.media.unavailable: "Media unavailable"
321
323
  sandbox.media.viewImage: "View image"
324
+ sandbox.media.voiceProgress: "Voice message progress"
322
325
  sandbox.member.adminLimit: "Admins cannot manage the owner or other admins"
323
326
  sandbox.member.kick: "Remove from group"
324
327
  sandbox.member.kickNeedAdmin: "Removing members requires admin"
@@ -491,9 +494,12 @@ sandbox.settings.schema.group.endpoint.description: "MCP and HTTP interfaces tha
491
494
  sandbox.settings.schema.group.endpoint.label: "Test endpoints"
492
495
  sandbox.settings.schema.group.endpointListen.description: "Listening and access"
493
496
  sandbox.settings.schema.group.endpointQuota.description: "Call quotas"
497
+ sandbox.settings.schema.group.media.description: "Media files"
494
498
  sandbox.settings.schema.group.sceneMessages.description: "Scene messages"
495
499
  sandbox.settings.schema.group.storage.description: "Where the simulated environment is stored, and retention limits for messages. Limits apply separately to the main environment and each AI test space"
496
500
  sandbox.settings.schema.group.storage.label: "Data storage"
501
+ sandbox.settings.schema.mediaMaxSizeMiB.description: "Shared upload and download limit for images, audio, video, attachments and avatars"
502
+ sandbox.settings.schema.mediaMaxSizeMiB.label: "Maximum file size (MiB)"
497
503
  sandbox.settings.schema.persistenceMode.description: "Database mode persists across restarts; memory mode is cleared when the process exits"
498
504
  sandbox.settings.schema.persistenceMode.label: "Storage mode"
499
505
  sandbox.settings.schema.persistenceMode.option.database.description: "Database"
@@ -620,6 +626,7 @@ sandbox.testCall.transport.mcp: "MCP client"
620
626
  sandbox.testCall.transportLabel: "Transport"
621
627
  sandbox.text.card.description: "Leave empty to clear the card."
622
628
  sandbox.text.card.placeholder: "Group card"
629
+ sandbox.text.card.sandboxDescription: "Sandbox scene editing can change any member's group card regardless of group role. An empty value clears the current card."
623
630
  sandbox.text.card.title: "Edit group card"
624
631
  sandbox.text.name.description: "The new name is visible to every member and bot."
625
632
  sandbox.text.name.placeholder: "Group name"
@@ -4,6 +4,7 @@ sandbox.avatar.builtin: "内置头像 {id}"
4
4
  sandbox.avatar.change: "更换头像"
5
5
  sandbox.avatar.description: "内置头像或本地图片均可作为头像。"
6
6
  sandbox.avatar.notImage: "头像文件不是图片"
7
+ sandbox.avatar.oversize: "头像文件不能超过 {size} MiB"
7
8
  sandbox.avatar.readFailed: "头像图片读取失败"
8
9
  sandbox.avatar.title: "选择头像"
9
10
  sandbox.avatar.upload: "上传本地图片"
@@ -53,7 +54,7 @@ sandbox.composer.failed: "发送失败"
53
54
  sandbox.composer.input: "消息内容"
54
55
  sandbox.composer.mention: "提及成员"
55
56
  sandbox.composer.noMention: "无匹配成员"
56
- sandbox.composer.oversize: "单个文件不能超过 10 MB"
57
+ sandbox.composer.oversize: "单个文件不能超过 {size} MiB"
57
58
  sandbox.composer.placeholder: "发送消息"
58
59
  sandbox.composer.preview: "预览 {name}"
59
60
  sandbox.composer.remove: "移除 {name}"
@@ -85,12 +86,10 @@ sandbox.credential.createdAt: "创建于 {time}"
85
86
  sandbox.credential.disable: "停用"
86
87
  sandbox.credential.empty: "尚未创建测试凭证"
87
88
  sandbox.credential.enable: "启用"
88
- sandbox.credential.generate: "生成可查看的 Token"
89
89
  sandbox.credential.hint: "同一个凭证同时用于 MCP 客户端与 HTTP 脚本。已创建的凭证可再次查看 Token,并修改名称和权限;调用记录和日志不输出明文。"
90
90
  sandbox.credential.invalid: "名称不能为空,且至少选择一项权限。"
91
91
  sandbox.credential.loadFailed: "读取测试凭证失败"
92
92
  sandbox.credential.name: "凭证名称"
93
- sandbox.credential.noPlainToken: "此凭证创建时未保存明文,无法再次查看。重新生成后可查看,旧 Token 立即失效。"
94
93
  sandbox.credential.revoke: "撤销"
95
94
  sandbox.credential.revokeDescription: "撤销后使用该凭证的 MCP 客户端与 HTTP 脚本立即失去访问权限,此操作不可撤销。"
96
95
  sandbox.credential.revokeTitle: "撤销凭证「{name}」"
@@ -315,10 +314,14 @@ sandbox.group.requestComment: "来自 OneBot 沙盒的入群申请"
315
314
  sandbox.kind.bot: "机器人"
316
315
  sandbox.kind.group: "群组"
317
316
  sandbox.kind.user: "用户"
317
+ sandbox.media.downloadFile: "下载 {name}"
318
318
  sandbox.media.loading: "媒体加载中…"
319
+ sandbox.media.pauseVoice: "暂停语音"
320
+ sandbox.media.playVoice: "播放语音"
319
321
  sandbox.media.preview: "图片预览"
320
322
  sandbox.media.unavailable: "媒体不可用"
321
323
  sandbox.media.viewImage: "查看大图"
324
+ sandbox.media.voiceProgress: "语音播放进度"
322
325
  sandbox.member.adminLimit: "管理员不能管理群主或其他管理员"
323
326
  sandbox.member.kick: "踢出群组"
324
327
  sandbox.member.kickNeedAdmin: "踢人需要管理员权限"
@@ -491,9 +494,12 @@ sandbox.settings.schema.group.endpoint.description: "供 AI 客户端操控沙
491
494
  sandbox.settings.schema.group.endpoint.label: "测试端点"
492
495
  sandbox.settings.schema.group.endpointListen.description: "监听与访问"
493
496
  sandbox.settings.schema.group.endpointQuota.description: "调用配额"
497
+ sandbox.settings.schema.group.media.description: "媒体文件"
494
498
  sandbox.settings.schema.group.sceneMessages.description: "场景消息"
495
499
  sandbox.settings.schema.group.storage.description: "模拟环境的保存位置,以及消息的保留上限。上限按主环境与每个 AI 测试空间分别计算"
496
500
  sandbox.settings.schema.group.storage.label: "数据存储"
501
+ sandbox.settings.schema.mediaMaxSizeMiB.description: "图片、音频、视频、附件与头像共用的上传及下载上限"
502
+ sandbox.settings.schema.mediaMaxSizeMiB.label: "单文件大小上限(MiB)"
497
503
  sandbox.settings.schema.persistenceMode.description: "数据库模式在重启后保留;内存模式在进程退出后清空"
498
504
  sandbox.settings.schema.persistenceMode.label: "存储方式"
499
505
  sandbox.settings.schema.persistenceMode.option.database.description: "数据库"
@@ -620,6 +626,7 @@ sandbox.testCall.transport.mcp: "MCP 客户端"
620
626
  sandbox.testCall.transportLabel: "来路"
621
627
  sandbox.text.card.description: "留空即清除当前群名片。"
622
628
  sandbox.text.card.placeholder: "群名片"
629
+ sandbox.text.card.sandboxDescription: "Sandbox 场景编辑,可修改任意群成员的名片,不受群身份限制。留空即清除当前群名片。"
623
630
  sandbox.text.card.title: "修改群名片"
624
631
  sandbox.text.name.description: "新的群名称对全部群成员与机器人可见。"
625
632
  sandbox.text.name.placeholder: "群名称"
@@ -196,16 +196,12 @@ export function TestCredentialManager() {
196
196
  {editing && (
197
197
  <div className="flex flex-col gap-2">
198
198
  <Label>Token</Label>
199
- {editing.token ? (
200
- <div className="flex items-center gap-2">
201
- <code className="min-w-0 flex-1 rounded-md bg-muted px-2.5 py-2 font-mono text-xs break-all">{editing.token}</code>
202
- <Button size="icon-sm" variant="ghost" aria-label={t('sandbox.credential.copy')} onClick={() => void copy(editing.token!)}><CopyIcon /></Button>
203
- </div>
204
- ) : (
205
- <p className="text-xs leading-5 text-muted-foreground">{t('sandbox.credential.noPlainToken')}</p>
206
- )}
199
+ <div className="flex items-center gap-2">
200
+ <code className="min-w-0 flex-1 rounded-md bg-muted px-2.5 py-2 font-mono text-xs break-all">{editing.token}</code>
201
+ <Button size="icon-sm" variant="ghost" aria-label={t('sandbox.credential.copy')} onClick={() => void copy(editing.token)}><CopyIcon /></Button>
202
+ </div>
207
203
  <Button size="sm" variant="outline" className="self-start" disabled={saving} onClick={() => void rotate()}>
208
- {t(editing.token ? 'sandbox.credential.rotate' : 'sandbox.credential.generate')}
204
+ {t('sandbox.credential.rotate')}
209
205
  </Button>
210
206
  <p className="text-[11px] text-muted-foreground">
211
207
  {t('sandbox.credential.createdAt', { time: time(editing.createdAt) })} · {t(editing.enabled ? 'sandbox.env.enabled' : 'sandbox.env.disabled')}
@@ -44,6 +44,8 @@
44
44
  .sandbox-space-card {
45
45
  position: relative;
46
46
  display: grid;
47
+ /* 限制内部列宽,避免长标题的最小内容宽度把底栏操作挤出卡片。 */
48
+ grid-template-columns: minmax(0, 1fr);
47
49
  min-height: 250px;
48
50
  overflow: hidden;
49
51
  border: 1px solid var(--sandbox-border);
@@ -5,7 +5,6 @@ export interface ComposerDraft { tokens: ComposerDraftToken[], tokenIndex: numbe
5
5
  export interface MentionCandidate { id: string, name: string, avatar?: string, kind: 'user' | 'bot', keywords?: string[] }
6
6
 
7
7
  export function createEmptyComposerDraft(): ComposerDraft { return { tokens: [{ type: 'text', text: '' }], tokenIndex: 0, offset: 0 } }
8
- export function draftText(tokens: readonly ComposerDraftToken[]): string { return tokens.map((token) => token.type === 'text' ? token.text : `@${token.name}`).join('') }
9
8
  export function isComposerDraftEmpty(tokens: readonly ComposerDraftToken[]): boolean { return !tokens.some((token) => token.type === 'mention' || !!token.text.trim()) }
10
9
  export function serializeComposerDraft(tokens: readonly ComposerDraftToken[]): string { return tokens.map((token) => token.type === 'mention' ? `<at id="${token.id}"/>` : token.text.replace(/ /g, ' ')).join('').trim() }
11
10
 
@@ -41,27 +41,35 @@ export function closeForwardStack(): ForwardDialogFrame[] {
41
41
  */
42
42
  export async function loadForwardDialogFrame(input: {
43
43
  readonly input: { forwardId?: string, messageId?: string }
44
- readonly load: (input: { forwardId?: string, messageId?: string }) => Promise<SandboxForward>
44
+ readonly load: (input: { forwardId?: string, messageId?: string }) => Promise<SandboxForward | undefined>
45
45
  }): Promise<ForwardDialogFrame | undefined> {
46
- let forward: SandboxForward
46
+ let forward: SandboxForward | undefined
47
47
  try {
48
48
  forward = await input.load(input.input)
49
49
  } catch {
50
50
  return
51
51
  }
52
52
 
53
+ if (!forward) return
54
+ let cancelled = false
53
55
  const nestedEntries = await Promise.all(
54
56
  forward.nodes
55
57
  .map((node) => node.forwardId)
56
58
  .filter((forwardId): forwardId is string => !!forwardId)
57
59
  .map(async (forwardId) => {
58
60
  try {
59
- return [forwardId, await input.load({ forwardId })] as const
61
+ const nested = await input.load({ forwardId })
62
+ if (!nested) {
63
+ cancelled = true
64
+ return
65
+ }
66
+ return [forwardId, nested] as const
60
67
  } catch {
61
68
  return undefined
62
69
  }
63
70
  }),
64
71
  )
72
+ if (cancelled) return
65
73
 
66
74
  return {
67
75
  // 没有可推断的标题时留空,由界面按当前语言显示「合并转发」。
@@ -0,0 +1,72 @@
1
+ /** 语音条与文件卡片的纯逻辑:文件归类、波形采样与时长格式。 */
2
+
3
+ export type FileKind = 'archive' | 'audio' | 'code' | 'document' | 'image' | 'sheet' | 'video' | 'other'
4
+
5
+ const EXTENSION_KINDS: Record<string, FileKind> = {
6
+ '7z': 'archive', bz2: 'archive', gz: 'archive', rar: 'archive', tar: 'archive', tgz: 'archive', xz: 'archive', zip: 'archive', zst: 'archive',
7
+ aac: 'audio', amr: 'audio', flac: 'audio', m4a: 'audio', mp3: 'audio', ogg: 'audio', opus: 'audio', silk: 'audio', wav: 'audio', wma: 'audio',
8
+ avi: 'video', flv: 'video', m4v: 'video', mkv: 'video', mov: 'video', mp4: 'video', webm: 'video', wmv: 'video',
9
+ avif: 'image', bmp: 'image', gif: 'image', heic: 'image', ico: 'image', jpeg: 'image', jpg: 'image', png: 'image', svg: 'image', webp: 'image',
10
+ csv: 'sheet', numbers: 'sheet', ods: 'sheet', tsv: 'sheet', xls: 'sheet', xlsx: 'sheet',
11
+ doc: 'document', docx: 'document', epub: 'document', key: 'document', md: 'document', odt: 'document', pages: 'document', pdf: 'document',
12
+ ppt: 'document', pptx: 'document', rtf: 'document', txt: 'document',
13
+ c: 'code', cpp: 'code', css: 'code', go: 'code', h: 'code', html: 'code', java: 'code', js: 'code', json: 'code', jsx: 'code', kt: 'code',
14
+ mjs: 'code', php: 'code', py: 'code', rb: 'code', rs: 'code', sh: 'code', sql: 'code', ts: 'code', tsx: 'code', xml: 'code', yaml: 'code', yml: 'code',
15
+ }
16
+
17
+ /** 不含点的小写扩展名;没有扩展名、以点开头的隐藏文件名或过长的尾段返回空串。 */
18
+ export function getFileExtension(name: string): string {
19
+ const index = name.lastIndexOf('.')
20
+ if (index <= 0 || index === name.length - 1) return ''
21
+ const extension = name.slice(index + 1).toLowerCase()
22
+ return /^[a-z0-9]{1,8}$/.test(extension) ? extension : ''
23
+ }
24
+
25
+ /** 扩展名优先,认不出时退回 MIME 主类型;`application/octet-stream` 之类归为 other。 */
26
+ export function getFileKind(name: string, mimeType: string): FileKind {
27
+ const byExtension = EXTENSION_KINDS[getFileExtension(name)]
28
+ if (byExtension) return byExtension
29
+ const major = mimeType.split('/')[0]
30
+ if (major === 'audio' || major === 'video' || major === 'image') return major
31
+ if (major === 'text') return 'document'
32
+ return 'other'
33
+ }
34
+
35
+ export const WAVEFORM_BARS = 32
36
+ /** 静音段也保留一截竖条,语音条不会出现空洞。 */
37
+ const MIN_BAR = 0.16
38
+
39
+ /** 按段取均方根并归一化到 [MIN_BAR, 1]。 */
40
+ export function computeWaveformPeaks(samples: ArrayLike<number>, bars = WAVEFORM_BARS): number[] {
41
+ const size = Math.floor(samples.length / bars)
42
+ if (size < 1) return fallbackWaveformPeaks('', bars)
43
+ const levels: number[] = []
44
+ for (let bar = 0; bar < bars; bar++) {
45
+ let sum = 0
46
+ for (let index = bar * size; index < (bar + 1) * size; index++) sum += samples[index]! * samples[index]!
47
+ levels.push(Math.sqrt(sum / size))
48
+ }
49
+ const max = Math.max(...levels)
50
+ if (!(max > 0)) return levels.map(() => MIN_BAR)
51
+ return levels.map((level) => MIN_BAR + (1 - MIN_BAR) * (level / max))
52
+ }
53
+
54
+ /** 解码失败时按媒体 ID 生成稳定的起伏,同一条语音每次渲染形状一致。 */
55
+ export function fallbackWaveformPeaks(seed: string, bars = WAVEFORM_BARS): number[] {
56
+ let state = 2166136261
57
+ for (let index = 0; index < seed.length; index++) state = Math.imul(state ^ seed.charCodeAt(index), 16777619)
58
+ return Array.from({ length: bars }, (_, bar) => {
59
+ state = Math.imul(state ^ (state >>> 15), 2246822507) >>> 0
60
+ const noise = (state % 1000) / 1000
61
+ // 两端收窄、中段饱满,接近人声的包络。
62
+ const envelope = Math.sin(Math.PI * (bar + 0.5) / bars)
63
+ return MIN_BAR + (1 - MIN_BAR) * Math.min(1, 0.25 + 0.75 * envelope * (0.45 + 0.55 * noise))
64
+ })
65
+ }
66
+
67
+ /** `m:ss`;时长未知时返回 `-:--`。 */
68
+ export function formatPlaybackTime(seconds: number): string {
69
+ if (!Number.isFinite(seconds) || seconds < 0) return '-:--'
70
+ const total = Math.floor(seconds)
71
+ return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, '0')}`
72
+ }
@@ -1,21 +1,16 @@
1
1
  import type { SandboxMessage } from '../../src/types'
2
2
 
3
- export function isImageOnlyMessage(message: SandboxMessage | undefined) {
4
- const media = message?.media
5
- return !!message
6
- && media?.length === 1
7
- && media[0].type === 'image'
8
- && message.content === `[图片] ${media[0].name}`
9
- }
3
+ // 分组只读取呈现字段,等待气泡无需伪造消息 ID 或写入历史。
4
+ type MessageClusterItem = Pick<SandboxMessage, 'authorId' | 'conversationId' | 'event'>
10
5
 
11
- function getDirection(message: SandboxMessage | undefined, currentOperatorId: string | undefined) {
6
+ function getDirection(message: MessageClusterItem | undefined, currentOperatorId: string | undefined) {
12
7
  if (!message) return
13
8
  return message.authorId === currentOperatorId ? 'outgoing' : 'incoming'
14
9
  }
15
10
 
16
11
  function isSameClusterSender(
17
- left: SandboxMessage | undefined,
18
- right: SandboxMessage | undefined,
12
+ left: MessageClusterItem | undefined,
13
+ right: MessageClusterItem | undefined,
19
14
  currentOperatorId: string | undefined,
20
15
  ) {
21
16
  return !!left
@@ -30,23 +25,8 @@ function isSameClusterSender(
30
25
  && getDirection(left, currentOperatorId) === getDirection(right, currentOperatorId)
31
26
  }
32
27
 
33
- function getClusterBubbleMessage(
34
- messages: SandboxMessage[],
35
- index: number,
36
- step: 1 | -1,
37
- currentOperatorId: string | undefined,
38
- ) {
39
- const message = messages[index]
40
- if (!message) return
41
- for (let cursor = index + step; cursor >= 0 && cursor < messages.length; cursor += step) {
42
- const candidate = messages[cursor]
43
- if (!isSameClusterSender(message, candidate, currentOperatorId)) return
44
- if (!isImageOnlyMessage(candidate)) return candidate
45
- }
46
- }
47
-
48
28
  export function isMergedMessage(
49
- messages: SandboxMessage[],
29
+ messages: MessageClusterItem[],
50
30
  index: number,
51
31
  currentOperatorId: string | undefined,
52
32
  ) {
@@ -54,13 +34,13 @@ export function isMergedMessage(
54
34
  }
55
35
 
56
36
  export function getMessageClusterClass(
57
- messages: SandboxMessage[],
37
+ messages: MessageClusterItem[],
58
38
  index: number,
59
39
  currentOperatorId: string | undefined,
60
40
  ) {
61
41
  if (!messages[index]) return ''
62
- const hasPrevious = !!getClusterBubbleMessage(messages, index, -1, currentOperatorId)
63
- const hasNext = !!getClusterBubbleMessage(messages, index, 1, currentOperatorId)
42
+ const hasPrevious = isMergedMessage(messages, index, currentOperatorId)
43
+ const hasNext = isMergedMessage(messages, index + 1, currentOperatorId)
64
44
  if (hasPrevious && hasNext) return 'is-cluster-middle'
65
45
  if (hasNext) return 'is-cluster-first'
66
46
  if (hasPrevious) return 'is-cluster-last'
@@ -42,7 +42,7 @@ interface SandboxContextValue {
42
42
  export interface SandboxDialogs {
43
43
  openEntity(mode: 'edit' | 'delete', target: { type: 'user' | 'bot' | 'group', id: string }): void
44
44
  openRemark(targetId: string): void
45
- openGroupAction(mode: 'card' | 'name' | 'title', targetId: string, groupId?: string): void
45
+ openGroupAction(mode: 'card' | 'sandbox-card' | 'name' | 'title', targetId: string, groupId?: string): void
46
46
  openConversationRename(conversationId: string): void
47
47
  openProfile(participantId: string, anchor?: { x: number, y: number }): void
48
48
  openGroupProfile(groupId: string, anchor?: { x: number, y: number }): void