@mingxy/ocosay 1.1.32 → 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.
@@ -1,17 +1,26 @@
1
1
  export type ToastType = 'success' | 'error' | 'warning' | 'info';
2
+ export interface ShowToastOptions {
3
+ title?: string;
4
+ message: string;
5
+ variant?: ToastType;
6
+ duration?: number;
7
+ }
2
8
  export declare class NotificationService {
3
9
  private constructor();
4
10
  static getInstance(): NotificationService;
5
11
  initialize(tuiInstance: any): void;
6
12
  isReady(): boolean;
13
+ showToast(options: ShowToastOptions): void;
7
14
  showToast(message: string, type?: ToastType): void;
8
- success(message: string): void;
9
- error(message: string): void;
10
- warning(message: string): void;
11
- info(message: string): void;
15
+ success(message: string, duration?: number): void;
16
+ error(message: string, duration?: number): void;
17
+ warning(message: string, duration?: number): void;
18
+ info(message: string, duration?: number): void;
19
+ showSpinnerToast(title: string, message: string, duration?: number): Promise<void>;
12
20
  private getTitleForType;
13
21
  private fallbackLog;
14
22
  }
23
+ export declare function showToast(options: ShowToastOptions): void;
15
24
  export declare function showToast(message: string, type?: ToastType): void;
16
25
  export declare function initializeNotificationService(tuiInstance: any): void;
17
26
  //# sourceMappingURL=notification-service.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { logger } from '../utils/logger.js';
2
+ const SISYPHUS_SPINNER = ['·', '•', '●', '○', '◌', '◦', ' '];
2
3
  let instance;
3
4
  let tui = null;
4
5
  let initialized = false;
@@ -20,15 +21,30 @@ export class NotificationService {
20
21
  isReady() {
21
22
  return initialized && tui !== null;
22
23
  }
23
- showToast(message, type = 'info') {
24
- const title = this.getTitleForType(type);
24
+ showToast(options, type) {
25
+ let title;
26
+ let message;
27
+ let variant;
28
+ let duration;
29
+ if (typeof options === 'string') {
30
+ message = options;
31
+ variant = type || 'info';
32
+ title = this.getTitleForType(variant);
33
+ duration = variant === 'error' ? 8000 : 5000;
34
+ }
35
+ else {
36
+ message = options.message;
37
+ variant = options.variant || 'info';
38
+ title = options.title || this.getTitleForType(variant);
39
+ duration = options.duration || (variant === 'error' ? 8000 : 5000);
40
+ }
25
41
  if (tui?.showToast) {
26
42
  try {
27
43
  tui.showToast({
28
44
  title,
29
45
  message,
30
- variant: type,
31
- duration: type === 'error' ? 8000 : 5000
46
+ variant,
47
+ duration
32
48
  });
33
49
  return;
34
50
  }
@@ -36,12 +52,46 @@ export class NotificationService {
36
52
  logger.warn({ err }, 'tui.showToast failed');
37
53
  }
38
54
  }
39
- this.fallbackLog(type, title, message);
55
+ this.fallbackLog(variant, title, message);
56
+ }
57
+ success(message, duration) {
58
+ this.showToast({ message, variant: 'success', duration });
59
+ }
60
+ error(message, duration) {
61
+ this.showToast({ message, variant: 'error', duration: duration || 8000 });
62
+ }
63
+ warning(message, duration) {
64
+ this.showToast({ message, variant: 'warning', duration });
65
+ }
66
+ info(message, duration) {
67
+ this.showToast({ message, variant: 'info', duration });
68
+ }
69
+ async showSpinnerToast(title, message, duration = 2000) {
70
+ const frameInterval = 100;
71
+ const totalFrames = Math.ceil(duration / frameInterval);
72
+ for (let i = 0; i < totalFrames; i++) {
73
+ const spinner = SISYPHUS_SPINNER[i % SISYPHUS_SPINNER.length];
74
+ const toastDuration = Math.min(frameInterval + 50, duration - i * frameInterval);
75
+ if (toastDuration <= 0)
76
+ break;
77
+ if (tui?.showToast) {
78
+ try {
79
+ await tui.showToast({
80
+ title: `${spinner} ${title}`,
81
+ message,
82
+ variant: 'info',
83
+ duration: toastDuration
84
+ });
85
+ }
86
+ catch (err) {
87
+ logger.warn({ err }, 'tui.showSpinnerToast failed');
88
+ }
89
+ }
90
+ if (i < totalFrames - 1) {
91
+ await new Promise((resolve) => setTimeout(resolve, frameInterval));
92
+ }
93
+ }
40
94
  }
41
- success(message) { this.showToast(message, 'success'); }
42
- error(message) { this.showToast(message, 'error'); }
43
- warning(message) { this.showToast(message, 'warning'); }
44
- info(message) { this.showToast(message, 'info'); }
45
95
  getTitleForType(type) {
46
96
  const titles = {
47
97
  success: 'Success',
@@ -65,8 +115,8 @@ export class NotificationService {
65
115
  }
66
116
  }
67
117
  }
68
- export function showToast(message, type = 'info') {
69
- NotificationService.getInstance().showToast(message, type);
118
+ export function showToast(options, type) {
119
+ NotificationService.getInstance().showToast(options, type);
70
120
  }
71
121
  export function initializeNotificationService(tuiInstance) {
72
122
  NotificationService.getInstance().initialize(tuiInstance);
@@ -5,9 +5,8 @@ export interface speakerServiceOptions {
5
5
  defaultVoice?: string;
6
6
  }
7
7
  export declare class SpeakerService {
8
- private options;
9
8
  private speaker;
10
- constructor(options?: speakerServiceOptions);
9
+ constructor(_options?: speakerServiceOptions);
11
10
  speak(text: string, options?: SpeakOptions & {
12
11
  provider?: string;
13
12
  }): Promise<void>;
@@ -1,10 +1,8 @@
1
1
  import { getDefaultSpeaker, speak as coreSpeak, stop as coreStop, pause as corePause, resume as coreResume, listVoices as coreListVoices } from '../core/speaker';
2
2
  import { logger } from '../utils/logger';
3
3
  export class SpeakerService {
4
- options;
5
4
  speaker;
6
- constructor(options = {}) {
7
- this.options = options;
5
+ constructor(_options = {}) {
8
6
  this.speaker = getDefaultSpeaker();
9
7
  }
10
8
  async speak(text, options) {
@@ -117,7 +117,7 @@ export class StreamingService extends EventEmitter {
117
117
  }
118
118
  // 初始化播放器
119
119
  const player = this.initPlayer();
120
- player.start();
120
+ await player.start();
121
121
  this._isActive = true;
122
122
  this._bytesWritten = 0;
123
123
  // 调用 Provider 的流式合成
@@ -149,7 +149,7 @@ export class StreamingService extends EventEmitter {
149
149
  }
150
150
  else if (Buffer.isBuffer(result.audioData)) {
151
151
  // 非流式数据:直接写入
152
- player.write(result.audioData);
152
+ await player.write(result.audioData);
153
153
  player.end();
154
154
  }
155
155
  }
@@ -166,7 +166,7 @@ export class StreamingService extends EventEmitter {
166
166
  }
167
167
  if (value) {
168
168
  const chunk = Buffer.isBuffer(value) ? value : Buffer.from(value);
169
- player.write(chunk);
169
+ await player.write(chunk);
170
170
  }
171
171
  }
172
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/ocosay",
3
- "version": "1.1.32",
3
+ "version": "1.2.0",
4
4
  "description": "OpenCode TTS 播放插件 - 支持豆包模式边接收边朗读",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.js",