mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-18 15:48:04 +02:00
[Haik]: ckpt (shld have fixed tool mcp discovery in prod - but untested) (Added browser control animations) (Made browser top input function as search) (swapped run.sh to not open up site locally in addition to the electron app)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { getWebview, type BrowserWebview } from './browserRegistry';
|
||||
import { dashboardWs } from './ws/WebSocketManager';
|
||||
import { resolveInput } from './resolveUrl';
|
||||
|
||||
let initialized = false;
|
||||
|
||||
@@ -61,9 +62,14 @@ async function handleGetText(wv: BrowserWebview): Promise<Record<string, any>> {
|
||||
}
|
||||
|
||||
async function handleNavigate(wv: BrowserWebview, params: Record<string, any>): Promise<Record<string, any>> {
|
||||
const url = params.url as string;
|
||||
if (!url) return { error: 'url parameter is required' };
|
||||
await wv.loadURL(url);
|
||||
const raw = params.url as string;
|
||||
if (!raw) return { error: 'url parameter is required' };
|
||||
const url = resolveInput(raw);
|
||||
try {
|
||||
await wv.loadURL(url);
|
||||
} catch (err: any) {
|
||||
if (!err?.message?.includes('ERR_ABORTED')) throw err;
|
||||
}
|
||||
return { text: `Navigated to ${url}`, url };
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Resolves raw URL-bar input into a navigable URL.
|
||||
*
|
||||
* Priority:
|
||||
* 1. Already has a scheme (http://, https://, file://, etc.) → pass through
|
||||
* 2. Starts with / or ~ → file path, prefix with file://
|
||||
* 3. localhost (with optional port/path) → http://
|
||||
* 4. IP address (with optional port/path) → http://
|
||||
* 5. No spaces + contains a dot followed by a 2+ char TLD → domain, prefix https://
|
||||
* 6. Everything else → Google search
|
||||
*/
|
||||
export function resolveInput(input: string): string {
|
||||
const trimmed = input.trim();
|
||||
if (!trimmed) return trimmed;
|
||||
|
||||
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//i.test(trimmed)) return trimmed;
|
||||
if (/^[~/]/.test(trimmed)) return `file://${trimmed}`;
|
||||
if (/^localhost(:\d+)?(\/.*)?$/i.test(trimmed)) return `http://${trimmed}`;
|
||||
if (/^\d{1,3}(\.\d{1,3}){3}(:\d+)?(\/.*)?$/.test(trimmed)) return `http://${trimmed}`;
|
||||
if (!/\s/.test(trimmed) && /\.[a-zA-Z]{2,}/.test(trimmed)) return `https://${trimmed}`;
|
||||
|
||||
return `https://www.google.com/search?q=${encodeURIComponent(trimmed)}`;
|
||||
}
|
||||
|
||||
export function isGoogleSearch(url: string): boolean {
|
||||
return url.startsWith('https://www.google.com/search');
|
||||
}
|
||||
@@ -43,6 +43,7 @@ export interface DashboardLayoutState {
|
||||
cards: Record<string, CardPosition>;
|
||||
viewCards: Record<string, ViewCardPosition>;
|
||||
browserCards: Record<string, BrowserCardPosition>;
|
||||
glowingBrowserCards: Record<string, string>;
|
||||
persistedExpandedSessionIds: string[];
|
||||
loading: boolean;
|
||||
initialized: boolean;
|
||||
@@ -52,6 +53,7 @@ const initialState: DashboardLayoutState = {
|
||||
cards: {},
|
||||
viewCards: {},
|
||||
browserCards: {},
|
||||
glowingBrowserCards: {},
|
||||
persistedExpandedSessionIds: [],
|
||||
loading: false,
|
||||
initialized: false,
|
||||
@@ -384,10 +386,32 @@ const dashboardLayoutSlice = createSlice({
|
||||
}
|
||||
},
|
||||
|
||||
setGlowingBrowserCards(
|
||||
state,
|
||||
action: PayloadAction<{ browserIds: string[]; sessionId: string }>
|
||||
) {
|
||||
const { browserIds, sessionId } = action.payload;
|
||||
for (const id of browserIds) {
|
||||
state.glowingBrowserCards[id] = sessionId;
|
||||
}
|
||||
},
|
||||
|
||||
clearGlowingBrowserCards(state, action: PayloadAction<string>) {
|
||||
const sessionId = action.payload;
|
||||
for (const [browserId, sid] of Object.entries(state.glowingBrowserCards)) {
|
||||
if (sid === sessionId) delete state.glowingBrowserCards[browserId];
|
||||
}
|
||||
},
|
||||
|
||||
clearAllGlowingBrowserCards(state) {
|
||||
state.glowingBrowserCards = {};
|
||||
},
|
||||
|
||||
resetLayout(state) {
|
||||
state.cards = {};
|
||||
state.viewCards = {};
|
||||
state.browserCards = {};
|
||||
state.glowingBrowserCards = {};
|
||||
state.persistedExpandedSessionIds = [];
|
||||
state.initialized = false;
|
||||
},
|
||||
@@ -438,6 +462,9 @@ export const {
|
||||
removeBrowserCard,
|
||||
updateBrowserCardUrl,
|
||||
moveCards,
|
||||
setGlowingBrowserCards,
|
||||
clearGlowingBrowserCards,
|
||||
clearAllGlowingBrowserCards,
|
||||
resetLayout,
|
||||
} = dashboardLayoutSlice.actions;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user