wave-code 0.12.1 → 0.12.2

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 (42) hide show
  1. package/dist/components/App.d.ts +1 -0
  2. package/dist/components/App.d.ts.map +1 -1
  3. package/dist/components/App.js +5 -2
  4. package/dist/components/BackgroundTaskManager.d.ts.map +1 -1
  5. package/dist/components/BackgroundTaskManager.js +2 -1
  6. package/dist/components/BangDisplay.d.ts.map +1 -1
  7. package/dist/components/BangDisplay.js +2 -14
  8. package/dist/components/ChatInterface.d.ts.map +1 -1
  9. package/dist/components/ChatInterface.js +17 -27
  10. package/dist/components/ConfirmationDetails.d.ts +0 -1
  11. package/dist/components/ConfirmationDetails.d.ts.map +1 -1
  12. package/dist/components/ConfirmationDetails.js +4 -12
  13. package/dist/components/ConfirmationSelector.d.ts +0 -1
  14. package/dist/components/ConfirmationSelector.d.ts.map +1 -1
  15. package/dist/components/ConfirmationSelector.js +4 -12
  16. package/dist/components/MessageList.d.ts +1 -2
  17. package/dist/components/MessageList.d.ts.map +1 -1
  18. package/dist/components/MessageList.js +4 -14
  19. package/dist/components/RewindCommand.d.ts.map +1 -1
  20. package/dist/components/RewindCommand.js +2 -4
  21. package/dist/components/ToolDisplay.d.ts.map +1 -1
  22. package/dist/components/ToolDisplay.js +2 -5
  23. package/dist/contexts/useChat.d.ts.map +1 -1
  24. package/dist/contexts/useChat.js +26 -11
  25. package/dist/utils/logger.d.ts.map +1 -1
  26. package/dist/utils/logger.js +3 -6
  27. package/dist/utils/throttle.d.ts +15 -0
  28. package/dist/utils/throttle.d.ts.map +1 -0
  29. package/dist/utils/throttle.js +55 -0
  30. package/package.json +2 -2
  31. package/src/components/App.tsx +6 -2
  32. package/src/components/BackgroundTaskManager.tsx +3 -6
  33. package/src/components/BangDisplay.tsx +4 -22
  34. package/src/components/ChatInterface.tsx +18 -33
  35. package/src/components/ConfirmationDetails.tsx +2 -15
  36. package/src/components/ConfirmationSelector.tsx +3 -15
  37. package/src/components/MessageList.tsx +3 -16
  38. package/src/components/RewindCommand.tsx +3 -5
  39. package/src/components/ToolDisplay.tsx +2 -5
  40. package/src/contexts/useChat.tsx +33 -10
  41. package/src/utils/logger.ts +3 -7
  42. package/src/utils/throttle.ts +75 -0
@@ -0,0 +1,75 @@
1
+ export interface ThrottleOptions {
2
+ leading?: boolean;
3
+ trailing?: boolean;
4
+ }
5
+
6
+ export interface ThrottledFunction<T extends (...args: unknown[]) => void> {
7
+ (...args: Parameters<T>): void;
8
+ cancel: () => void;
9
+ flush: () => void;
10
+ }
11
+
12
+ /**
13
+ * Creates a throttled function that only invokes `func` at most once per
14
+ * every `wait` milliseconds.
15
+ */
16
+ export function throttle<T extends (...args: unknown[]) => void>(
17
+ func: T,
18
+ wait: number,
19
+ options: ThrottleOptions = { leading: true, trailing: true },
20
+ ): ThrottledFunction<T> {
21
+ let timeoutId: NodeJS.Timeout | null = null;
22
+ let lastArgs: Parameters<T> | null = null;
23
+ let lastCallTime = 0;
24
+
25
+ const invokeFunc = () => {
26
+ if (lastArgs) {
27
+ func(...lastArgs);
28
+ lastCallTime = Date.now();
29
+ lastArgs = null;
30
+ }
31
+ };
32
+
33
+ const throttled = (...args: Parameters<T>) => {
34
+ const now = Date.now();
35
+ const remaining = wait - (now - lastCallTime);
36
+
37
+ lastArgs = args;
38
+
39
+ if (remaining <= 0 || remaining > wait) {
40
+ if (timeoutId) {
41
+ clearTimeout(timeoutId);
42
+ timeoutId = null;
43
+ }
44
+ if (options.leading !== false || lastCallTime !== 0) {
45
+ invokeFunc();
46
+ } else {
47
+ lastCallTime = now;
48
+ }
49
+ } else if (!timeoutId && options.trailing !== false) {
50
+ timeoutId = setTimeout(() => {
51
+ timeoutId = null;
52
+ invokeFunc();
53
+ }, remaining);
54
+ }
55
+ };
56
+
57
+ throttled.cancel = () => {
58
+ if (timeoutId) {
59
+ clearTimeout(timeoutId);
60
+ timeoutId = null;
61
+ }
62
+ lastArgs = null;
63
+ lastCallTime = 0;
64
+ };
65
+
66
+ throttled.flush = () => {
67
+ if (timeoutId) {
68
+ clearTimeout(timeoutId);
69
+ timeoutId = null;
70
+ }
71
+ invokeFunc();
72
+ };
73
+
74
+ return throttled as ThrottledFunction<T>;
75
+ }