Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prompt broken after action #77

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/electron/future/apps.ts
@@ -0,0 +1,4 @@
// Cache for apps that are opened
import type { BrowserWindow } from "electron";

export const apps: Record<string, BrowserWindow | null> = {};
44 changes: 12 additions & 32 deletions src/electron/future/ipc/sdk.ts
Expand Up @@ -10,6 +10,7 @@ import { execa } from "execa";
import { buildKey } from "#/build-key";
import { ID } from "#/enums";
import type { VectorStoreDocument } from "#/types/vector-store";
import { apps } from "@/apps";
import { userStore } from "@/stores";
import {
getCaptainData,
Expand Down Expand Up @@ -220,28 +221,15 @@ export const functions: FunctionTree = {
},
};

export function handleCaptainAction(message: {
action: string;
payload: VectorStoreDocument["payload"];
}) {
switch (message.action) {
case "function": {
try {
const { id: functionPath, parameters } = message.payload;
const function_ = getProperty(functions, functionPath);
if (typeof function_ === "function") {
function_(parameters ?? {});
}
} catch (error) {
console.log(error);
}

break;
}

default: {
break;
export function handleCaptainAction(payload: VectorStoreDocument["payload"]) {
try {
const { id: functionPath, parameters } = payload;
const function_ = getProperty(functions, functionPath);
if (typeof function_ === "function") {
function_(parameters ?? {});
}
} catch (error) {
console.log(error);
}
}

Expand All @@ -251,17 +239,9 @@ ipcMain.on(
console.log(message);
switch (message.action) {
case "function": {
try {
const { id: functionPath, parameters } = message.payload as {
id: string;
parameters: Record<string, unknown>;
};
const function_ = getProperty(functions, functionPath);
if (typeof function_ === "function") {
function_(parameters);
}
} catch (error) {
console.log(error);
handleCaptainAction(message.payload as VectorStoreDocument["payload"]);
if (apps.prompt) {
apps.prompt.blur();
}

break;
Expand Down
7 changes: 2 additions & 5 deletions src/electron/future/main.ts
Expand Up @@ -3,7 +3,6 @@ import fsp from "node:fs/promises";
import path from "path";
import url from "url";

import { HuggingFaceTransformersEmbeddings } from "@langchain/community/embeddings/hf_transformers";
import { env } from "@xenova/transformers";
import type { BrowserWindowConstructorOptions } from "electron";
import { app, ipcMain, BrowserWindow, Menu, protocol, screen, globalShortcut } from "electron";
Expand All @@ -18,12 +17,13 @@ import { buildKey } from "#/build-key";
import { LOCAL_PROTOCOL, VECTOR_STORE_COLLECTION } from "#/constants";
import { DownloadState, ID } from "#/enums";
import { isProduction } from "#/flags";
import { apps } from "@/apps";
import { CustomHuggingFaceTransformersEmbeddings } from "@/langchain/custom-hugging-face-transformers-embeddings";
import { VectorStore } from "@/services/vector-store";
import { isCoreApp, isCoreView } from "@/utils/core";
import { createWindow } from "@/utils/create-window";
import { loadURL } from "@/utils/load-window";
import { getCaptainData, getCaptainDownloads, getDirectory } from "@/utils/path-helpers";
import { CustomHuggingFaceTransformersEmbeddings } from "@/langchain/custom-hugging-face-transformers-embeddings";

/**
* Creates and displays the installer window with predefined dimensions.
Expand Down Expand Up @@ -322,9 +322,6 @@ async function populateVectorStoreFromDocuments() {
return vectorStore.upsert(VECTOR_STORE_COLLECTION, documents);
}

// Cache for apps that are opened
const apps: Record<string, BrowserWindow | null> = {};

async function runStartup(withDashboard?: boolean) {
env.localModelPath = getCaptainDownloads("llm/embeddings");
env.allowRemoteModels = false;
Expand Down