2fd4bd123d
- Restore {plugins: [...], total: N} for /plugins and /plugins/active-manifests
(flat array broke frontend PluginRegistry → no menu items → empty UI)
- Restore {count: N} for /notifications/unread-count
(scalar broke frontend notification badge)
- Fix ai_ui_control: on_install → on_activate for WS manager registration
(WS 403 on every reconnect after container restart)
- Fix double /api/v1 prefix in useAIContext.ts and SuggestionBadge.tsx
- Add first_name, last_name, avatar_url to User model + migration 0032
- Extend UserUpdate schema with profile + password change fields
- Extend user_service.update_user with profile fields + password change
- Extend frontend UserResponse/UserUpdate types
25 lines
873 B
TypeScript
25 lines
873 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
import { useLocation } from 'react-router-dom';
|
|
import { apiClient } from '@/api/client';
|
|
|
|
export function useAIContext(entityType?: string, entityId?: string, entityData?: any) {
|
|
const location = useLocation();
|
|
const debounceRef = useRef<ReturnType<typeof setTimeout>>();
|
|
|
|
useEffect(() => {
|
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
debounceRef.current = setTimeout(() => {
|
|
apiClient.post('/ai-proactive/context', {
|
|
page: location.pathname,
|
|
entity_type: entityType,
|
|
entity_id: entityId,
|
|
entity_data: entityData,
|
|
}).catch(() => {}); // Silent fail, don't bother user
|
|
}, 500); // Debounce 500ms
|
|
|
|
return () => {
|
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
};
|
|
}, [location.pathname, entityType, entityId, entityData]);
|
|
}
|