From 23a48738a38fbe6fa0730487267a9e480fcfeb87 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Mon, 19 May 2025 17:05:29 -0700 Subject: [PATCH] Fixed reset of job desc. to remove agent Fixed craco for streamingresponse --- frontend/craco.config.js | 33 +++++++++++++++++++----- frontend/package.json | 2 +- frontend/src/Global.tsx | 4 ++- frontend/src/NewApp/BackstoryApp.tsx | 2 +- frontend/src/Pages/ResumeBuilderPage.tsx | 12 ++++++--- src/server.py | 9 +++++-- src/utils/context.py | 4 +++ 7 files changed, 51 insertions(+), 15 deletions(-) diff --git a/frontend/craco.config.js b/frontend/craco.config.js index ce4b802..4d75f10 100644 --- a/frontend/craco.config.js +++ b/frontend/craco.config.js @@ -2,18 +2,37 @@ module.exports = { devServer: { server: { type: 'https', - // You can also specify custom certificates if needed: // options: { // cert: '/path/to/cert.pem', // key: '/path/to/key.pem', // } }, - proxy: { - '/api': { - target: 'https://backstory:8911', // Replace with your FastAPI server URL - changeOrigin: true, - secure: false, // Set to true if your FastAPI server uses HTTPS - }, + setupMiddlewares: (middlewares, devServer) => { + const { createProxyMiddleware } = require('http-proxy-middleware'); + + if (!devServer) { + throw new Error('webpack-dev-server is not defined'); + } + + devServer.app.use('/api', createProxyMiddleware({ + target: 'https://backstory:8911', + changeOrigin: true, + secure: false, + buffer: false, + proxyTimeout: 3600000, + onProxyRes: function(proxyRes, req, res) { + // Remove any header that might cause buffering + proxyRes.headers['transfer-encoding'] = 'chunked'; + delete proxyRes.headers['content-length']; + + // Set proper streaming headers + proxyRes.headers['cache-control'] = 'no-cache'; + proxyRes.headers['content-type'] = 'text/event-stream'; + proxyRes.headers['connection'] = 'keep-alive'; + }, + })); + + return middlewares; } }, webpack: { diff --git a/frontend/package.json b/frontend/package.json index a7ec2eb..aecdb10 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -41,7 +41,7 @@ "web-vitals": "^2.1.4" }, "scripts": { - "start": "HTTPS=true WDS_SOCKET_HOST=backstory-beta.ketrenos.com WDS_SOCKET_PORT=443 craco start", + "start": "WDS_SOCKET_HOST=backstory-beta.ketrenos.com WDS_SOCKET_PORT=443 craco start", "build": "craco build", "test": "craco test" }, diff --git a/frontend/src/Global.tsx b/frontend/src/Global.tsx index af984fe..dc7faa4 100644 --- a/frontend/src/Global.tsx +++ b/frontend/src/Global.tsx @@ -1,5 +1,7 @@ const getConnectionBase = (loc: any): string => { - if (!loc.host.match(/.*battle-linux.*/)) { + if (!loc.host.match(/.*battle-linux.*/) + // && !loc.host.match(/.*backstory-beta.*/) + ) { return loc.protocol + "//" + loc.host; } else { return loc.protocol + "//battle-linux.ketrenos.com:8912"; diff --git a/frontend/src/NewApp/BackstoryApp.tsx b/frontend/src/NewApp/BackstoryApp.tsx index c8bfc66..42eb6c9 100644 --- a/frontend/src/NewApp/BackstoryApp.tsx +++ b/frontend/src/NewApp/BackstoryApp.tsx @@ -249,7 +249,7 @@ const BackstoryApp = () => { } }; fetchSession(); - }, []); + }, [cookieSessionId, setSnack, storeInCookie, urlSessionId]); const copyLink = () => { const link = `${window.location.origin}${window.location.pathname}?id=${sessionId}`; diff --git a/frontend/src/Pages/ResumeBuilderPage.tsx b/frontend/src/Pages/ResumeBuilderPage.tsx index 04d9d17..f801b64 100644 --- a/frontend/src/Pages/ResumeBuilderPage.tsx +++ b/frontend/src/Pages/ResumeBuilderPage.tsx @@ -152,15 +152,21 @@ const ResumeBuilderPage: React.FC = (props: BackstoryPagePro const jobResponse = useCallback(async (message: BackstoryMessage) => { if (message.actions && message.actions.includes("job_description")) { - await jobConversationRef.current.fetchHistory(); + if (jobConversationRef.current) { + await jobConversationRef.current.fetchHistory(); + } } if (message.actions && message.actions.includes("resume_generated")) { - await resumeConversationRef.current.fetchHistory(); + if (resumeConversationRef.current) { + await resumeConversationRef.current.fetchHistory(); + } setHasResume(true); setActiveTab(1); // Switch to Resume tab } if (message.actions && message.actions.includes("facts_checked")) { - await factsConversationRef.current.fetchHistory(); + if (factsConversationRef.current) { + await factsConversationRef.current.fetchHistory(); + } setHasFacts(true); } }, [setHasFacts, setHasResume, setActiveTab]); diff --git a/src/server.py b/src/server.py index b1c1cc6..3bd42bf 100644 --- a/src/server.py +++ b/src/server.py @@ -261,9 +261,11 @@ class WebServer: ) if self.ssl_enabled: - allow_origins = ["https://battle-linux.ketrenos.com:3000"] + allow_origins = ["https://battle-linux.ketrenos.com:3000", + "https://backstory-beta.ketrenos.com"] else: - allow_origins = ["http://battle-linux.ketrenos.com:3000"] + allow_origins = ["http://battle-linux.ketrenos.com:3000", + "http://backstory-beta.ketrenos.com"] logger.info(f"Allowed origins: {allow_origins}") @@ -470,6 +472,9 @@ class WebServer: ) continue logger.info(f"Resetting {reset_operation} for {mode}") + if mode != "chat": + logger.info(f"Removing agent {tmp.agent_type} from {context_id}") + context.remove_agent(tmp) tmp.conversation.reset() response["history"] = [] response["context_used"] = agent.context_tokens diff --git a/src/utils/context.py b/src/utils/context.py index eb43139..4c47168 100644 --- a/src/utils/context.py +++ b/src/utils/context.py @@ -140,6 +140,10 @@ class Context(BaseModel): ) self.agents.append(agent) + def remove_agent(self, agent: AnyAgent) -> None: + """Remove an Agent from the context based on its agent_type.""" + self.agents = [a for a in self.agents if a.agent_type != agent.agent_type] + def get_agent(self, agent_type: str) -> Agent | None: """Return the Agent with the given agent_type, or None if not found.""" for agent in self.agents: