Documentation ¶
Index ¶
- func AppendCorsRoute(r *router.Router, method string, route string, ...)
- func EnsureDir(dirPath string) (string, error)
- func ExecuteCommand(rawCommand string) (*exec.Cmd, error)
- func GetAndCheckInput(args []string, openEditor bool) string
- func GetApiAccessType() (string, error)
- func GetDefaultAddNoNewLineToChatAnswerSetting() bool
- func GetEnvFilePath() (string, error)
- func GetInput(args []string, openEditor bool) (string, error)
- func GetOperatingSystemName() string
- func GetShellName() string
- func GetSystemFilePath() (string, error)
- func GetSystemPrompt() (string, bool, error)
- func GetUISettingsFilePath() (string, error)
- func IsTruthy(val string) bool
- func OpenSQLConnection(connectionStr string) (*sql.DB, string, error)
- func RemoveMarkdownCode(str string) string
- func SendHttpError(ctx *fasthttp.RequestCtx, err error)
- func SetupCorsHeaders(ctx *fasthttp.RequestCtx)
- func TryGetBestOpenEditorCommand(filePath string) (string, []string)
- func TryGetExecutablePath(command string) string
- func TryOpen(resource string) error
- func WriteStringToStdOut(str string, withNewline bool)
- func WriteToStdOut(data []byte, withNewline bool)
- type OAuth2TokenResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendCorsRoute ¶ added in v0.7.0
func AppendCorsRoute(r *router.Router, method string, route string, handler egoTypes.FHRequestHandler, noOptionsRoute bool)
AppendRoute adds a route with CORS headers.
func EnsureDir ¶ added in v0.7.0
EnsureDir checks if a directory exists at the given path. If it doesn't exist, it creates a directory with the given path. The function returns the directory path and an error, if any.
func ExecuteCommand ¶
ExecuteCommand creates a new exec.Cmd instance and starts a new process with the provided raw command using the shell specified by GetShellName(). The command output is printed to stdout and stderr, and the command is run with os.Stdin. It returns the cmd object and an error if one occurs.
func GetAndCheckInput ¶
GetAndCheckInput retrieves user input from the command line using the GetInput function and panics if an error occurs. It trims the whitespace from the input and panics if the input is empty.
func GetApiAccessType ¶ added in v0.7.0
GetApiAccessType returns the type of API access to be used. It checks if OpenAI API Key is provided in environment variable OPENAI_API_KEY, if not, it checks if Chat API Client ID is provided in environment variable CHAT_API_CLIENT_ID. If Chat API Client ID is provided, it further checks if Chat API URL and Key are provided. If Chat API URL and Key are provided, it returns "proxy_api_key". If Chat API URL and Key are not provided, it gets the access token using GetAccessToken and returns "proxy_oauth2". If none of the above are provided, it returns an empty string and no error.
func GetDefaultAddNoNewLineToChatAnswerSetting ¶ added in v0.10.0
func GetDefaultAddNoNewLineToChatAnswerSetting() bool
GetDefaultAddNoNewLineToChatAnswerSetting gets the default value for the setting, NOT adding a new line to each answer of a chat to STDOUT
func GetEnvFilePath ¶ added in v0.2.0
GetEnvFilePath returns the path to the .env file located in the user's home directory. If an error occurs while getting the user's home directory, it returns an empty string and the error.
func GetInput ¶
GetInput function retrieves user input from the command-line arguments, standard input, or an editor
func GetOperatingSystemName ¶
func GetOperatingSystemName() string
GetOperatingSystemName function returns the name of the operating system running the program
func GetShellName ¶
func GetShellName() string
GetShellName function returns the name of the shell running the program
func GetSystemFilePath ¶ added in v0.4.0
GetSystemFilePath function returns the path of the .system file used by the program
func GetSystemPrompt ¶ added in v0.4.0
GetSystemPrompt returns the system prompt message, a boolean value indicating whether the prompt message is custom, and an error if there is any.
func GetUISettingsFilePath ¶ added in v0.7.0
GetUISettingsFilePath returns the file path for the UI settings file and an error if there is any.
func IsTruthy ¶ added in v0.10.0
IsTruthy checks if a string value is a "truthy" value like: "true", "t", "1", "y", "yes", "yeah", "✅", "👍"
func OpenSQLConnection ¶ added in v0.3.0
OpenSQLConnection opens a connection to a SQL database and returns the database object, the display name of the database provider, and an error, if any.
func RemoveMarkdownCode ¶ added in v0.1.1
RemoveMarkdownCode removes the beginning and ending backticks from the given string.
func SendHttpError ¶ added in v0.7.0
func SendHttpError(ctx *fasthttp.RequestCtx, err error)
SendHttpError sends an HTTP 500 error with the given error message.
func SetupCorsHeaders ¶ added in v0.7.0
func SetupCorsHeaders(ctx *fasthttp.RequestCtx)
SetupCorsHeaders sets the necessary headers to enable CORS on an HTTP response.
func TryGetBestOpenEditorCommand ¶
TryGetBestOpenEditorCommand tries to find and return the best command to open a file for editing with the given file path. It returns the command and its arguments as a slice of strings. If no suitable editor is found, it returns an empty string and an empty slice.
func TryGetExecutablePath ¶
TryGetExecutablePath tries to find and return the path of the given command executable file. It returns the path as a string. If the executable file is not found, it returns an empty string.
func TryOpen ¶ added in v0.5.0
TryOpen opens the given resource using the appropriate command based on the OS. It returns an error if the command failed to execute.
func WriteStringToStdOut ¶ added in v0.9.0
func WriteToStdOut ¶ added in v0.9.0
Types ¶
type OAuth2TokenResponse ¶
type OAuth2TokenResponse struct { AccessToken string `json:"access_token"` ExpiresIn int `json:"expires_in"` TokenType string `json:"token_type"` }
func GetAccessToken ¶
func GetAccessToken() (OAuth2TokenResponse, error)
GetAccessToken retrieves an OAuth2TokenResponse struct, which contains an access token and other authentication details, from an API endpoint. If the response status code is 200, it attempts to parse the response body as JSON and returns the tokenResponse struct. Otherwise, it returns an error containing the response error message.