Package net.stoerr.chatgpt.codevengine
Class AbstractPluginAction
- java.lang.Object
-
- jakarta.servlet.GenericServlet
-
- jakarta.servlet.http.HttpServlet
-
- net.stoerr.chatgpt.codevengine.AbstractPluginAction
-
- All Implemented Interfaces:
jakarta.servlet.Servlet
,jakarta.servlet.ServletConfig
,Serializable
- Direct Known Subclasses:
ExecuteExternalAction
,ExecuteOpenAIToolCallAction
,GrepAction
,ListFilesAction
,ReadFileAction
,ReplaceAction
,ReplaceRegexAction
,UrlAction
,WriteFileAction
public abstract class AbstractPluginAction extends jakarta.servlet.http.HttpServlet
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Pattern
BINARY_FILES_PATTERN
A pattern for filenames of binary files where grep would not work.protected static Map<Path,net.stoerr.chatgpt.codevengine.AbstractPluginAction.GitIgnoreRules>
gitIgnoreRules
protected com.google.gson.Gson
gson
-
Constructor Summary
Constructors Constructor Description AbstractPluginAction()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected String
abbreviate(String s, int max)
protected static Stream<Path>
findMatchingFiles(boolean suppressMessage, jakarta.servlet.http.HttpServletResponse response, Path path, Pattern filePathPattern, Pattern grepPattern, boolean recursive, boolean listDirectories)
protected String
getBodyParameter(jakarta.servlet.http.HttpServletResponse response, String json, String parameterName, boolean mandatory)
Returns a parameter encoded in JSON the request body; returns "" if that parameter isn't there.protected String
getMandatoryQueryParam(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String name)
protected Path
getPath(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean mustExist, boolean usedefault)
Returns the path parameter from the request, checks if it is within the current directory.protected String
getQueryParam(jakarta.servlet.http.HttpServletRequest request, String name)
protected static String
getSimilarFilesMessage(jakarta.servlet.http.HttpServletResponse response, Path path, String filename, boolean listDirectories)
abstract String
getUrl()
The URL it is deployed at, e.g.protected static boolean
gitIgnored(Path path)
protected static boolean
isIgnored(Path path)
protected boolean
isNotEmpty(String s)
abstract String
openApiDescription()
The OpenAPI description for this operation.protected static ExecutionAbortedException
sendError(jakarta.servlet.http.HttpServletResponse response, int statusCode, String error)
Logs an error and sends it to ChatGPT, always throwsExecutionAbortedException
.-
Methods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
-
-
-
-
Field Detail
-
BINARY_FILES_PATTERN
public static final Pattern BINARY_FILES_PATTERN
A pattern for filenames of binary files where grep would not work.
-
gson
protected final transient com.google.gson.Gson gson
-
-
Method Detail
-
sendError
protected static ExecutionAbortedException sendError(jakarta.servlet.http.HttpServletResponse response, int statusCode, String error) throws ExecutionAbortedException
Logs an error and sends it to ChatGPT, always throwsExecutionAbortedException
. Use with patternthrow sendError(...)
to let compiler know that.- Throws:
ExecutionAbortedException
-
findMatchingFiles
protected static Stream<Path> findMatchingFiles(boolean suppressMessage, jakarta.servlet.http.HttpServletResponse response, Path path, Pattern filePathPattern, Pattern grepPattern, boolean recursive, boolean listDirectories)
-
isIgnored
protected static boolean isIgnored(Path path)
-
getUrl
public abstract String getUrl()
The URL it is deployed at, e.g. /listFiles.
-
openApiDescription
public abstract String openApiDescription()
The OpenAPI description for this operation.
-
getQueryParam
protected String getQueryParam(jakarta.servlet.http.HttpServletRequest request, String name)
-
getMandatoryQueryParam
protected String getMandatoryQueryParam(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String name)
-
getPath
protected Path getPath(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean mustExist, boolean usedefault)
Returns the path parameter from the request, checks if it is within the current directory.
-
getSimilarFilesMessage
protected static String getSimilarFilesMessage(jakarta.servlet.http.HttpServletResponse response, Path path, String filename, boolean listDirectories)
-
getBodyParameter
@Nullable protected String getBodyParameter(jakarta.servlet.http.HttpServletResponse response, String json, String parameterName, boolean mandatory)
Returns a parameter encoded in JSON the request body; returns "" if that parameter isn't there.
-
isNotEmpty
protected boolean isNotEmpty(String s)
-
gitIgnored
protected static boolean gitIgnored(Path path)
-
-