Support exclude paths in manual context management (#774)
This commit is contained in:
@@ -15,7 +15,12 @@ export function useContextPaths() {
|
||||
} = useQuery<ContextPathResults, Error>({
|
||||
queryKey: ["context-paths", appId],
|
||||
queryFn: async () => {
|
||||
if (!appId) return { contextPaths: [], smartContextAutoIncludes: [] };
|
||||
if (!appId)
|
||||
return {
|
||||
contextPaths: [],
|
||||
smartContextAutoIncludes: [],
|
||||
excludePaths: [],
|
||||
};
|
||||
const ipcClient = IpcClient.getInstance();
|
||||
return ipcClient.getChatContextResults({ appId });
|
||||
},
|
||||
@@ -25,9 +30,17 @@ export function useContextPaths() {
|
||||
const updateContextPathsMutation = useMutation<
|
||||
unknown,
|
||||
Error,
|
||||
{ contextPaths: GlobPath[]; smartContextAutoIncludes?: GlobPath[] }
|
||||
{
|
||||
contextPaths: GlobPath[];
|
||||
smartContextAutoIncludes?: GlobPath[];
|
||||
excludePaths?: GlobPath[];
|
||||
}
|
||||
>({
|
||||
mutationFn: async ({ contextPaths, smartContextAutoIncludes }) => {
|
||||
mutationFn: async ({
|
||||
contextPaths,
|
||||
smartContextAutoIncludes,
|
||||
excludePaths,
|
||||
}) => {
|
||||
if (!appId) throw new Error("No app selected");
|
||||
const ipcClient = IpcClient.getInstance();
|
||||
return ipcClient.setChatContext({
|
||||
@@ -35,6 +48,7 @@ export function useContextPaths() {
|
||||
chatContext: {
|
||||
contextPaths,
|
||||
smartContextAutoIncludes: smartContextAutoIncludes || [],
|
||||
excludePaths: excludePaths || [],
|
||||
},
|
||||
});
|
||||
},
|
||||
@@ -46,28 +60,63 @@ export function useContextPaths() {
|
||||
const updateContextPaths = async (paths: GlobPath[]) => {
|
||||
const currentAutoIncludes =
|
||||
contextPathsData?.smartContextAutoIncludes || [];
|
||||
const currentExcludePaths = contextPathsData?.excludePaths || [];
|
||||
return updateContextPathsMutation.mutateAsync({
|
||||
contextPaths: paths,
|
||||
smartContextAutoIncludes: currentAutoIncludes.map(({ globPath }) => ({
|
||||
globPath,
|
||||
})),
|
||||
smartContextAutoIncludes: currentAutoIncludes.map(
|
||||
({ globPath }: { globPath: string }) => ({
|
||||
globPath,
|
||||
}),
|
||||
),
|
||||
excludePaths: currentExcludePaths.map(
|
||||
({ globPath }: { globPath: string }) => ({
|
||||
globPath,
|
||||
}),
|
||||
),
|
||||
});
|
||||
};
|
||||
|
||||
const updateSmartContextAutoIncludes = async (paths: GlobPath[]) => {
|
||||
const currentContextPaths = contextPathsData?.contextPaths || [];
|
||||
const currentExcludePaths = contextPathsData?.excludePaths || [];
|
||||
return updateContextPathsMutation.mutateAsync({
|
||||
contextPaths: currentContextPaths.map(({ globPath }) => ({ globPath })),
|
||||
contextPaths: currentContextPaths.map(
|
||||
({ globPath }: { globPath: string }) => ({ globPath }),
|
||||
),
|
||||
smartContextAutoIncludes: paths,
|
||||
excludePaths: currentExcludePaths.map(
|
||||
({ globPath }: { globPath: string }) => ({
|
||||
globPath,
|
||||
}),
|
||||
),
|
||||
});
|
||||
};
|
||||
|
||||
const updateExcludePaths = async (paths: GlobPath[]) => {
|
||||
const currentContextPaths = contextPathsData?.contextPaths || [];
|
||||
const currentAutoIncludes =
|
||||
contextPathsData?.smartContextAutoIncludes || [];
|
||||
return updateContextPathsMutation.mutateAsync({
|
||||
contextPaths: currentContextPaths.map(
|
||||
({ globPath }: { globPath: string }) => ({ globPath }),
|
||||
),
|
||||
smartContextAutoIncludes: currentAutoIncludes.map(
|
||||
({ globPath }: { globPath: string }) => ({
|
||||
globPath,
|
||||
}),
|
||||
),
|
||||
excludePaths: paths,
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
contextPaths: contextPathsData?.contextPaths || [],
|
||||
smartContextAutoIncludes: contextPathsData?.smartContextAutoIncludes || [],
|
||||
excludePaths: contextPathsData?.excludePaths || [],
|
||||
isLoading,
|
||||
error,
|
||||
updateContextPaths,
|
||||
updateSmartContextAutoIncludes,
|
||||
updateExcludePaths,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user