hydro-ai-helper 2.0.3 → 2.0.4

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.
@@ -97,6 +97,32 @@ export function useTeachingSummary(domainId: string, contestId: string): UseTeac
97
97
  };
98
98
  }, [stopPolling]);
99
99
 
100
+ // startPolling must be declared before fetchSummary to avoid TDZ
101
+ // (fetchSummary's dependency array evaluates startPolling immediately)
102
+ const startPolling = useCallback(() => {
103
+ stopPolling();
104
+ pollTimerRef.current = setInterval(async () => {
105
+ try {
106
+ const url = buildUrl(domainId, `/${contestId}`);
107
+ const res = await fetch(url, {
108
+ credentials: 'include',
109
+ headers: { 'X-Requested-With': 'XMLHttpRequest' },
110
+ });
111
+ if (!res.ok) return;
112
+ const data = await res.json();
113
+ const fetched: TeachingSummary | null = data.summary ?? null;
114
+ if (fetched) {
115
+ setSummary(fetched);
116
+ if (fetched.status === 'completed' || fetched.status === 'failed') {
117
+ stopPolling();
118
+ }
119
+ }
120
+ } catch {
121
+ // ignore transient poll errors
122
+ }
123
+ }, POLL_INTERVAL_MS);
124
+ }, [domainId, contestId, stopPolling]);
125
+
100
126
  const fetchSummary = useCallback(async () => {
101
127
  setLoading(true);
102
128
  setError(null);
@@ -133,30 +159,6 @@ export function useTeachingSummary(domainId: string, contestId: string): UseTeac
133
159
  }
134
160
  }, [domainId, contestId, startPolling]);
135
161
 
136
- const startPolling = useCallback(() => {
137
- stopPolling();
138
- pollTimerRef.current = setInterval(async () => {
139
- try {
140
- const url = buildUrl(domainId, `/${contestId}`);
141
- const res = await fetch(url, {
142
- credentials: 'include',
143
- headers: { 'X-Requested-With': 'XMLHttpRequest' },
144
- });
145
- if (!res.ok) return;
146
- const data = await res.json();
147
- const fetched: TeachingSummary | null = data.summary ?? null;
148
- if (fetched) {
149
- setSummary(fetched);
150
- if (fetched.status === 'completed' || fetched.status === 'failed') {
151
- stopPolling();
152
- }
153
- }
154
- } catch {
155
- // ignore transient poll errors
156
- }
157
- }, POLL_INTERVAL_MS);
158
- }, [domainId, contestId, stopPolling]);
159
-
160
162
  const generate = useCallback(async (teachingFocus?: string, regenerate?: boolean) => {
161
163
  setLoading(true);
162
164
  setError(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hydro-ai-helper",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "HydroOJ AI Learning Assistant - 一个教学优先的 AI 辅助学习插件",
5
5
  "main": "dist/index.js",
6
6
  "author": "Alture",
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "@types/highlight.js": "^9.12.4",
33
33
  "@types/markdown-it": "^14.1.2",
34
- "axios": "^1.13.5",
34
+ "axios": "^1.15.0",
35
35
  "chart.js": "^4.5.1",
36
36
  "dompurify": "^3.3.2",
37
37
  "highlight.js": "^11.11.1",