- Add intelligent-router.sh hook for automatic agent routing - Add AUTO-TRIGGER-SUMMARY.md documentation - Add FINAL-INTEGRATION-SUMMARY.md documentation - Complete Prometheus integration (6 commands + 4 tools) - Complete Dexto integration (12 commands + 5 tools) - Enhanced Ralph with access to all agents - Fix /clawd command (removed disable-model-invocation) - Update hooks.json to v5 with intelligent routing - 291 total skills now available - All 21 commands with automatic routing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
86 lines
2.9 KiB
TypeScript
86 lines
2.9 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { client } from '@/lib/client.js';
|
|
import { queryKeys } from '@/lib/queryKeys.js';
|
|
|
|
export function useSessions(enabled: boolean = true) {
|
|
return useQuery({
|
|
queryKey: queryKeys.sessions.all,
|
|
queryFn: async () => {
|
|
const response = await client.api.sessions.$get();
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to fetch sessions: ${response.status}`);
|
|
}
|
|
const data = await response.json();
|
|
return data.sessions;
|
|
},
|
|
enabled,
|
|
staleTime: 30 * 1000, // 30 seconds - sessions can be created frequently
|
|
});
|
|
}
|
|
|
|
// Create a new session
|
|
export function useCreateSession() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ sessionId }: { sessionId?: string }) => {
|
|
const response = await client.api.sessions.$post({
|
|
json: { sessionId: sessionId?.trim() || undefined },
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to create session: ${response.status}`);
|
|
}
|
|
const data = await response.json();
|
|
return data.session;
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.sessions.all });
|
|
},
|
|
});
|
|
}
|
|
|
|
// Delete a session
|
|
export function useDeleteSession() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ sessionId }: { sessionId: string }) => {
|
|
const response = await client.api.sessions[':sessionId'].$delete({
|
|
param: { sessionId },
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to delete session: ${response.status}`);
|
|
}
|
|
},
|
|
onSuccess: () => {
|
|
// Invalidate sessions list to refresh after deletion
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.sessions.all });
|
|
},
|
|
});
|
|
}
|
|
|
|
// Rename a session (update title)
|
|
export function useRenameSession() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ sessionId, title }: { sessionId: string; title: string }) => {
|
|
const response = await client.api.sessions[':sessionId'].$patch({
|
|
param: { sessionId },
|
|
json: { title },
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error('Failed to rename session');
|
|
}
|
|
const data = await response.json();
|
|
return data.session;
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.sessions.all });
|
|
},
|
|
});
|
|
}
|
|
|
|
// Export inferred types for components to use
|
|
export type Session = NonNullable<ReturnType<typeof useSessions>['data']>[number];
|