|
1 | 1 | import "@/index.css" |
2 | | -import { ErrorBoundary, Show, Suspense, lazy, type JSX, type ParentProps } from "solid-js" |
3 | | -import { Router, Route, Navigate } from "@solidjs/router" |
4 | | -import { MetaProvider } from "@solidjs/meta" |
5 | | -import { Font } from "@opencode-ai/ui/font" |
6 | | -import { MarkedProvider } from "@opencode-ai/ui/context/marked" |
7 | | -import { DiffComponentProvider } from "@opencode-ai/ui/context/diff" |
8 | | -import { CodeComponentProvider } from "@opencode-ai/ui/context/code" |
| 2 | +import { Code } from "@opencode-ai/ui/code" |
9 | 3 | import { I18nProvider } from "@opencode-ai/ui/context" |
| 4 | +import { CodeComponentProvider } from "@opencode-ai/ui/context/code" |
| 5 | +import { DialogProvider } from "@opencode-ai/ui/context/dialog" |
| 6 | +import { DiffComponentProvider } from "@opencode-ai/ui/context/diff" |
| 7 | +import { MarkedProvider } from "@opencode-ai/ui/context/marked" |
10 | 8 | import { Diff } from "@opencode-ai/ui/diff" |
11 | | -import { Code } from "@opencode-ai/ui/code" |
| 9 | +import { Font } from "@opencode-ai/ui/font" |
12 | 10 | import { ThemeProvider } from "@opencode-ai/ui/theme" |
| 11 | +import { MetaProvider } from "@solidjs/meta" |
| 12 | +import { Navigate, Route, Router } from "@solidjs/router" |
| 13 | +import { ErrorBoundary, type JSX, lazy, type ParentProps, Show, Suspense } from "solid-js" |
| 14 | +import { CommandProvider } from "@/context/command" |
| 15 | +import { CommentsProvider } from "@/context/comments" |
| 16 | +import { FileProvider } from "@/context/file" |
| 17 | +import { GlobalSDKProvider } from "@/context/global-sdk" |
13 | 18 | import { GlobalSyncProvider } from "@/context/global-sync" |
14 | | -import { PermissionProvider } from "@/context/permission" |
| 19 | +import { HighlightsProvider } from "@/context/highlights" |
| 20 | +import { LanguageProvider, useLanguage } from "@/context/language" |
15 | 21 | import { LayoutProvider } from "@/context/layout" |
16 | | -import { GlobalSDKProvider } from "@/context/global-sdk" |
17 | | -import { normalizeServerUrl, ServerProvider, useServer } from "@/context/server" |
18 | | -import { SettingsProvider } from "@/context/settings" |
19 | | -import { TerminalProvider } from "@/context/terminal" |
20 | | -import { PromptProvider } from "@/context/prompt" |
21 | | -import { FileProvider } from "@/context/file" |
22 | | -import { CommentsProvider } from "@/context/comments" |
23 | | -import { NotificationProvider } from "@/context/notification" |
24 | 22 | import { ModelsProvider } from "@/context/models" |
25 | | -import { DialogProvider } from "@opencode-ai/ui/context/dialog" |
26 | | -import { CommandProvider } from "@/context/command" |
27 | | -import { LanguageProvider, useLanguage } from "@/context/language" |
| 23 | +import { NotificationProvider } from "@/context/notification" |
| 24 | +import { PermissionProvider } from "@/context/permission" |
28 | 25 | import { usePlatform } from "@/context/platform" |
29 | | -import { HighlightsProvider } from "@/context/highlights" |
30 | | -import Layout from "@/pages/layout" |
| 26 | +import { PromptProvider } from "@/context/prompt" |
| 27 | +import { type ServerConnection, ServerProvider, useServer } from "@/context/server" |
| 28 | +import { SettingsProvider } from "@/context/settings" |
| 29 | +import { TerminalProvider } from "@/context/terminal" |
31 | 30 | import DirectoryLayout from "@/pages/directory-layout" |
| 31 | +import Layout from "@/pages/layout" |
32 | 32 | import { ErrorPage } from "./pages/error" |
| 33 | + |
33 | 34 | const Home = lazy(() => import("@/pages/home")) |
34 | 35 | const Session = lazy(() => import("@/pages/session")) |
35 | 36 | const Loading = () => <div class="size-full" /> |
@@ -57,7 +58,11 @@ function UiI18nBridge(props: ParentProps) { |
57 | 58 |
|
58 | 59 | declare global { |
59 | 60 | interface Window { |
60 | | - __OPENCODE__?: { updaterEnabled?: boolean; serverPassword?: string; deepLinks?: string[]; wsl?: boolean } |
| 61 | + __OPENCODE__?: { |
| 62 | + updaterEnabled?: boolean |
| 63 | + deepLinks?: string[] |
| 64 | + wsl?: boolean |
| 65 | + } |
61 | 66 | } |
62 | 67 | } |
63 | 68 |
|
@@ -107,30 +112,6 @@ function RouterRoot(props: ParentProps<{ appChildren?: JSX.Element }>) { |
107 | 112 | ) |
108 | 113 | } |
109 | 114 |
|
110 | | -const getStoredDefaultServerUrl = (platform: ReturnType<typeof usePlatform>) => { |
111 | | - if (platform.platform !== "web") return |
112 | | - const result = platform.getDefaultServerUrl?.() |
113 | | - if (result instanceof Promise) return |
114 | | - if (!result) return |
115 | | - return normalizeServerUrl(result) |
116 | | -} |
117 | | - |
118 | | -const resolveDefaultServerUrl = (props: { |
119 | | - defaultUrl?: string |
120 | | - storedDefaultServerUrl?: string |
121 | | - hostname: string |
122 | | - origin: string |
123 | | - isDev: boolean |
124 | | - devHost?: string |
125 | | - devPort?: string |
126 | | -}) => { |
127 | | - if (props.defaultUrl) return props.defaultUrl |
128 | | - if (props.storedDefaultServerUrl) return props.storedDefaultServerUrl |
129 | | - if (props.hostname.includes("opencode.ai")) return "http://localhost:4096" |
130 | | - if (props.isDev) return `http://${props.devHost ?? "localhost"}:${props.devPort ?? "4096"}` |
131 | | - return props.origin |
132 | | -} |
133 | | - |
134 | 115 | export function AppBaseProviders(props: ParentProps) { |
135 | 116 | return ( |
136 | 117 | <MetaProvider> |
@@ -157,27 +138,19 @@ export function AppBaseProviders(props: ParentProps) { |
157 | 138 | function ServerKey(props: ParentProps) { |
158 | 139 | const server = useServer() |
159 | 140 | return ( |
160 | | - <Show when={server.url} keyed> |
| 141 | + <Show when={server.key} keyed> |
161 | 142 | {props.children} |
162 | 143 | </Show> |
163 | 144 | ) |
164 | 145 | } |
165 | 146 |
|
166 | | -export function AppInterface(props: { defaultUrl?: string; children?: JSX.Element; isSidecar?: boolean }) { |
167 | | - const platform = usePlatform() |
168 | | - const storedDefaultServerUrl = getStoredDefaultServerUrl(platform) |
169 | | - const defaultServerUrl = resolveDefaultServerUrl({ |
170 | | - defaultUrl: props.defaultUrl, |
171 | | - storedDefaultServerUrl, |
172 | | - hostname: location.hostname, |
173 | | - origin: window.location.origin, |
174 | | - isDev: import.meta.env.DEV, |
175 | | - devHost: import.meta.env.VITE_OPENCODE_SERVER_HOST, |
176 | | - devPort: import.meta.env.VITE_OPENCODE_SERVER_PORT, |
177 | | - }) |
178 | | - |
| 147 | +export function AppInterface(props: { |
| 148 | + children?: JSX.Element |
| 149 | + defaultServer: ServerConnection.Key |
| 150 | + servers?: Array<ServerConnection.Any> |
| 151 | +}) { |
179 | 152 | return ( |
180 | | - <ServerProvider defaultUrl={defaultServerUrl} isSidecar={props.isSidecar}> |
| 153 | + <ServerProvider defaultServer={props.defaultServer} servers={props.servers}> |
181 | 154 | <ServerKey> |
182 | 155 | <GlobalSDKProvider> |
183 | 156 | <GlobalSyncProvider> |
|