Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions emain/emain-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ ipcMain.on("get-data-dir", (event) => {
ipcMain.on("get-config-dir", (event) => {
event.returnValue = getWaveConfigDir();
});
ipcMain.on("get-home-dir", (event) => {
event.returnValue = app.getPath("home");
});

/**
* Gets the value of the XDG_CURRENT_DESKTOP environment variable. If ORIGINAL_XDG_CURRENT_DESKTOP is set, it will be returned instead.
Expand Down
1 change: 1 addition & 0 deletions emain/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contextBridge.exposeInMainWorld("api", {
getHostName: () => ipcRenderer.sendSync("get-host-name"),
getDataDir: () => ipcRenderer.sendSync("get-data-dir"),
getConfigDir: () => ipcRenderer.sendSync("get-config-dir"),
getHomeDir: () => ipcRenderer.sendSync("get-home-dir"),
getAboutModalDetails: () => ipcRenderer.sendSync("get-about-modal-details"),
getDocsiteUrl: () => ipcRenderer.sendSync("get-docsite-url"),
getWebviewPreload: () => ipcRenderer.sendSync("get-webview-preload"),
Expand Down
31 changes: 27 additions & 4 deletions frontend/app/view/codeeditor/schemaendpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,34 @@ type EndpointInfo = {
schema: object;
};

function prependWildcard(path: string): string {
return path.startsWith("/") ? `*${path}` : `*/${path}`;
}

function convertToTildePath(absolutePath: string): string {
const homeDir = getApi().getHomeDir();
if (absolutePath.startsWith(homeDir)) {
return "~" + absolutePath.slice(homeDir.length);
}
return absolutePath;
}

function makeConfigPathMatches(suffix: string): Array<string> {
const configPath = `${getApi().getConfigDir()}${suffix}`;
const tildePath = convertToTildePath(configPath);
const paths = [configPath, prependWildcard(configPath)];
if (tildePath !== configPath) {
paths.push(tildePath);
paths.push(prependWildcard(tildePath));
}
return paths;
}

const allFilepaths: Map<string, Array<string>> = new Map();
allFilepaths.set(`${getWebServerEndpoint()}/schema/settings.json`, [`${getApi().getConfigDir()}/settings.json`]);
allFilepaths.set(`${getWebServerEndpoint()}/schema/connections.json`, [`${getApi().getConfigDir()}/connections.json`]);
allFilepaths.set(`${getWebServerEndpoint()}/schema/aipresets.json`, [`${getApi().getConfigDir()}/presets/ai.json`]);
allFilepaths.set(`${getWebServerEndpoint()}/schema/widgets.json`, [`${getApi().getConfigDir()}/widgets.json`]);
allFilepaths.set(`${getWebServerEndpoint()}/schema/settings.json`, makeConfigPathMatches("/settings.json"));
allFilepaths.set(`${getWebServerEndpoint()}/schema/connections.json`, makeConfigPathMatches("/connections.json"));
allFilepaths.set(`${getWebServerEndpoint()}/schema/aipresets.json`, makeConfigPathMatches("/presets/ai.json"));
allFilepaths.set(`${getWebServerEndpoint()}/schema/widgets.json`, makeConfigPathMatches("/widgets.json"));

async function getSchemaEndpointInfo(endpoint: string): Promise<EndpointInfo> {
let schema: Object;
Expand Down
1 change: 1 addition & 0 deletions frontend/types/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ declare global {
getHostName: () => string; // get-host-name
getDataDir: () => string; // get-data-dir
getConfigDir: () => string; // get-config-dir
getHomeDir: () => string; // get-home-dir
getWebviewPreload: () => string; // get-webview-preload
getAboutModalDetails: () => AboutModalDetails; // get-about-modal-details
getDocsiteUrl: () => string; // get-docsite-url
Expand Down
20 changes: 16 additions & 4 deletions pkg/aiusechat/openai/openai-convertmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package openai
import (
"bytes"
"context"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -58,6 +60,16 @@ func extractXmlAttribute(tag, attrName string) (string, bool) {
return value, true
}

// generateDeterministicSuffix creates an 8-character hash from input strings
func generateDeterministicSuffix(inputs ...string) string {
hasher := sha256.New()
for _, input := range inputs {
hasher.Write([]byte(input))
}
hash := hasher.Sum(nil)
return hex.EncodeToString(hash)[:8]
}

// ---------- OpenAI Request Types ----------

type StreamOptionsType struct {
Expand Down Expand Up @@ -388,8 +400,8 @@ func convertFileAIMessagePart(part uctypes.AIMessagePart) (*OpenAIMessageContent
encodedFileName := strings.ReplaceAll(fileName, `"`, "&quot;")
quotedFileName := strconv.Quote(encodedFileName)

randomSuffix := uuid.New().String()[0:8]
formattedText := fmt.Sprintf("<AttachedTextFile_%s file_name=%s>\n%s\n</AttachedTextFile_%s>", randomSuffix, quotedFileName, textContent, randomSuffix)
deterministicSuffix := generateDeterministicSuffix(textContent, fileName)
formattedText := fmt.Sprintf("<AttachedTextFile_%s file_name=%s>\n%s\n</AttachedTextFile_%s>", deterministicSuffix, quotedFileName, textContent, deterministicSuffix)

return &OpenAIMessageContent{
Type: "input_text",
Expand All @@ -412,8 +424,8 @@ func convertFileAIMessagePart(part uctypes.AIMessagePart) (*OpenAIMessageContent
encodedDirName := strings.ReplaceAll(directoryName, `"`, "&quot;")
quotedDirName := strconv.Quote(encodedDirName)

randomSuffix := uuid.New().String()[0:8]
formattedText := fmt.Sprintf("<AttachedDirectoryListing_%s directory_name=%s>\n%s\n</AttachedDirectoryListing_%s>", randomSuffix, quotedDirName, jsonContent, randomSuffix)
deterministicSuffix := generateDeterministicSuffix(jsonContent, directoryName)
formattedText := fmt.Sprintf("<AttachedDirectoryListing_%s directory_name=%s>\n%s\n</AttachedDirectoryListing_%s>", deterministicSuffix, quotedDirName, jsonContent, deterministicSuffix)

return &OpenAIMessageContent{
Type: "input_text",
Expand Down
Loading