Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Add library build mode and component barrel exports (#54)

Graham Neubig22b7d6e842de
diff --git a/AGENTS.md b/AGENTS.md
index 0d02d7316a..424a51c5d9 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -61,8 +61,8 @@
- OpenHands Cloud sandbox development note: do **not** reuse the sandbox's existing agent-server for this frontend. Current agent-server releases use a shared `openhands` tmux socket and default `workspace/conversations`, so a naive second server in the same sandbox can kill the cloud session's tmux state or attach to the same persisted conversations. `npm run dev` is now the recommended local workflow and starts an isolated local agent-server for the checkout by overriding `TMUX_TMPDIR`, `OH_CONVERSATIONS_PATH`, `OH_BASH_EVENTS_DIR`, and `OH_VSCODE_PORT` under `.openhands-dev/`; use `npm run dev:frontend` only when intentionally pointing at a separately managed backend, or `npm run dev:mock` for mock mode.
- A successful end-to-end live run in this environment required a real LLM config (`LLM_MODEL` + `LLM_API_KEY`). The default `litellm_proxy/...` model with no `llm_api_key` failed at runtime with a `litellm.AuthenticationError`.
-- Git provider token persistence note: this direct-agent-server frontend now persists `Settings > Git` provider tokens locally in browser storage instead of posting to an app-backend secrets route. `src/api/secrets-service.ts` writes the token payload to localStorage, mirrors provider hosts into `provider_tokens_set` through `SettingsService.saveSettings()`, and `use-delete-git-providers` clears that local state.
+- Git provider token persistence note: this direct-agent-server frontend now persists `Settings > Git` provider tokens locally in browser storage instead of posting to an app-backend secrets route. `src/api/secrets-service.ts` writes the token payload to localStorage, mirrors provider hosts into `provider_tokens_set` through `SettingsService.saveSettings()`, and `use-delete-git-providers` clears that local state.
- README expectation: keep the first section as a concrete, chronological from-scratch quickstart for running this frontend against a real `openhands-agent-server` (clone, install backend, optional `.env`, run `npm run dev`).
- Keep README user-focused and move contributor/developer-specific workflows (Cloud sandbox debugging, `dev:safe`, mock mode, detailed env vars/build-test notes) into `DEVELOPMENT.md`.
@@ -76,7 +76,6 @@
- GitHub PR-review automation should stay aligned with the current OpenHands repo conventions: keep the review workflow at `.github/workflows/pr-review-by-openhands.yml`, keep the companion `.github/workflows/pr-review-evaluation.yml`, auto-run on newly opened non-draft PRs and `ready_for_review` events from established contributors, still support the `review-this` label / `openhands-agent` / `all-hands-bot` reviewer triggers, use the OpenHands app LLM proxy defaults, and use the dual-trigger pattern (`pull_request` for same-repo PRs, `pull_request_target` for forks) so workflow changes can self-verify without widening fork secret exposure.
- The repo now includes `.agents/skills/custom-codereview-guide.md`, adapted from `OpenHands/software-agent-sdk`, to force PR reviews to always leave either an APPROVE or COMMENT review instead of silently finishing with no review object.
-
- HeroUI v3 migration notes:
- The repo now uses `@heroui/[email protected]` plus `@heroui/[email protected]`.
- `src/tailwind.css` should import `@heroui/styles`; the old `hero.ts` Tailwind plugin file was removed and should not be reintroduced.
@@ -86,3 +85,8 @@
- Route decoupling note: `src/components/` should stay free of direct `react-router` imports. Route state now flows through `src/context/navigation-context.tsx`, the standalone app bridges router state with `src/routes/react-router-navigation-provider.tsx`, and link-like UI should use `src/components/shared/navigation-link.tsx`.
- Test helper note: `test-utils.tsx` now wraps renders with a default `NavigationProvider` (`currentPath: "/"`, `conversationId: "test-conversation-id"`). Navigation-sensitive tests can override that via `renderWithProviders(..., { navigation: { ... } })`.
+- Library packaging notes:
+ - Public npm entrypoints now come from `src/index.ts` β†’ `src/lib/index.ts`, with domain barrels under `src/components/{conversation,terminal,browser,files,settings,sidebar}/index.ts`.
+ - `npm run build` remains the standalone app build (`react-router build`), while `npm run build:lib` runs `vite build` in library mode plus `tsc -p tsconfig.lib.json` to emit `.d.ts` files into `dist/`.
+ - The library build relies on `vite.config.ts` with `BUILD_LIB=true`, preserved modules in `dist/`, and package `exports` entries that map root/subpaths to `dist/**/*.js` plus matching declaration files.
+ - Declaration emit needs `src/library-env.d.ts` and the narrowed `tsconfig.lib.json`; broad `src/**/*.tsx` declaration builds pulled in route-only files and missed `?react`/window globals.
diff --git a/__tests__/fixtures/library-consumer-smoke.tsx b/__tests__/fixtures/library-consumer-smoke.tsx
new file mode 100644
index 0000000000..a368c2f6b9
--- /dev/null
+++ b/__tests__/fixtures/library-consumer-smoke.tsx
@@ -0,0 +1,23 @@
+import {
+ AgentServerUIProviders,
+ BrowserPanel,
+ ConversationView,
+ SettingsPanel,
+ TerminalPanel,
+} from "@openhands/agent-server-gui";
+import { LLMSettings } from "@openhands/agent-server-gui/settings";
+import { Sidebar } from "@openhands/agent-server-gui/sidebar";
+
+export function SmokeImportConsumer() {
+ return (
+ <AgentServerUIProviders>
+ <ConversationView />
+ <BrowserPanel />
+ <TerminalPanel />
+ <SettingsPanel navigationItems={[]}>
+ <LLMSettings />
+ </SettingsPanel>
+ <Sidebar />
+ </AgentServerUIProviders>
+ );
+}
diff --git a/__tests__/library-entrypoints.test.ts b/__tests__/library-entrypoints.test.ts
new file mode 100644
index 0000000000..1f0f8200b4
--- /dev/null
+++ b/__tests__/library-entrypoints.test.ts
@@ -0,0 +1,39 @@
+import * as publicApi from "../src/index";
+import * as browserApi from "../src/components/browser/index";
+import * as conversationApi from "../src/components/conversation/index";
+import * as filesApi from "../src/components/files/index";
+import * as settingsApi from "../src/components/settings/index";
+import * as sidebarApi from "../src/components/sidebar/index";
+import * as terminalApi from "../src/components/terminal/index";
+import { describe, expect, it } from "vitest";
+
+describe("library public entrypoints", () => {
+ it("re-exports the primary library surface from the root entry", () => {
+ expect(publicApi.ConversationView).toBeTypeOf("function");
+ expect(publicApi.ChatPanel).toBeTypeOf("function");
+ expect(publicApi.TerminalPanel).toBeTypeOf("function");
+ expect(publicApi.BrowserPanel).toBeTypeOf("function");
+ expect(publicApi.FileExplorer).toBeTypeOf("function");
+ expect(publicApi.SettingsPanel).toBeTypeOf("function");
+ expect(publicApi.LLMSettings).toBeTypeOf("function");
+ expect(publicApi.Sidebar).toBeTypeOf("function");
+ expect(publicApi.ConversationPanel).toBeTypeOf("function");
+ expect(publicApi.AgentServerUIProviders).toBeTypeOf("function");
+ });
+
+ it("keeps each component-domain barrel importable", () => {
+ expect(conversationApi.ConversationView).toBeTypeOf("function");
+ expect(conversationApi.ChatPanel).toBeTypeOf("function");
+ expect(browserApi.BrowserPanel).toBeTypeOf("function");
+ expect(terminalApi.TerminalPanel).toBeTypeOf("function");
+ expect(filesApi.FileExplorer).toBeTypeOf("function");
+ expect(settingsApi.SettingsPanel).toBeTypeOf("function");
+ expect(settingsApi.AppSettings).toBeTypeOf("function");
+ expect(settingsApi.GitSettings).toBeTypeOf("function");
+ expect(settingsApi.LLMSettings).toBeTypeOf("function");
+ expect(settingsApi.MCPSettings).toBeTypeOf("function");
+ expect(settingsApi.SecretsSettings).toBeTypeOf("function");
+ expect(sidebarApi.Sidebar).toBeTypeOf("function");
+ expect(sidebarApi.ConversationPanel).toBeTypeOf("function");
+ });
+});
diff --git a/__tests__/package-library.test.ts b/__tests__/package-library.test.ts
new file mode 100644
index 0000000000..b175416215
--- /dev/null
+++ b/__tests__/package-library.test.ts
@@ -0,0 +1,45 @@
+// @vitest-environment node
+import { readFileSync } from "node:fs";
+import { resolve } from "node:path";
+import { describe, expect, it } from "vitest";
+
+const packageJson = JSON.parse(
+ readFileSync(resolve(__dirname, "../package.json"), "utf8"),
+) as {
+ name: string;
+ main: string;
+ module: string;
+ types: string;
+ exports: Record<string, unknown>;
+};
+
+describe("package library metadata", () => {
+ it("publishes the agent-server-gui package entrypoints", () => {
+ expect(packageJson.name).toBe("@openhands/agent-server-gui");
+ expect(packageJson.main).toBe("./dist/index.cjs");
+ expect(packageJson.module).toBe("./dist/index.js");
+ expect(packageJson.types).toBe("./dist/index.d.ts");
+ expect(packageJson.exports).toMatchObject({
+ ".": {
+ types: "./dist/index.d.ts",
+ import: "./dist/index.js",
+ require: "./dist/index.cjs",
+ },
+ "./conversation": {
+ types: "./dist/components/conversation/index.d.ts",
+ import: "./dist/components/conversation/index.js",
+ require: "./dist/components/conversation/index.cjs",
+ },
+ "./settings": {
+ types: "./dist/components/settings/index.d.ts",
+ import: "./dist/components/settings/index.js",
+ require: "./dist/components/settings/index.cjs",
+ },
+ "./terminal": {
+ types: "./dist/components/terminal/index.d.ts",
+ import: "./dist/components/terminal/index.js",
+ require: "./dist/components/terminal/index.cjs",
+ },
+ });
+ });
+});
diff --git a/__tests__/vite-config.test.ts b/__tests__/vite-config.test.ts
index a7702db43d..864b8eff72 100644
--- a/__tests__/vite-config.test.ts
+++ b/__tests__/vite-config.test.ts
@@ -1,6 +1,10 @@
// @vitest-environment node
import viteConfig from "../vite.config";
-import { describe, expect, it } from "vitest";
+import { afterEach, describe, expect, it } from "vitest";
+
+afterEach(() => {
+ delete process.env.BUILD_LIB;
+});
describe("vite optimizeDeps", () => {
it("prebundles core client entry dependencies", async () => {
@@ -17,3 +21,34 @@ describe("vite optimizeDeps", () => {
);
});
});
+
+describe("vite library build", () => {
+ it("configures a dual-format preserved-module library build", async () => {
+ process.env.BUILD_LIB = "true";
+
+ const config = await viteConfig({ mode: "production", command: "build" });
+
+ expect((config as { copyPublicDir?: boolean }).copyPublicDir).toBe(false);
+ expect(config.build?.lib).toMatchObject({
+ formats: ["es"],
+ });
+ expect(config.build?.rollupOptions?.external).toEqual(
+ expect.arrayContaining(["react", "react-dom", "react-router"]),
+ );
+ expect(config.build?.rollupOptions?.output).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({
+ format: "es",
+ preserveModules: true,
+ preserveModulesRoot: "src",
+ }),
+ expect.objectContaining({
+ format: "cjs",
+ preserveModules: true,
+ preserveModulesRoot: "src",
+ exports: "named",
+ }),
+ ]),
+ );
+ });
+});
diff --git a/package-lock.json b/package-lock.json
index 24fa1898ad..782c6c2294 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,11 +1,11 @@
{
- "name": "openhands-frontend",
+ "name": "@openhands/agent-server-gui",
"version": "1.6.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
- "name": "openhands-frontend",
+ "name": "@openhands/agent-server-gui",
"version": "1.6.0",
"license": "MIT",
"dependencies": {
@@ -93,7 +93,8 @@
},
"engines": {
"node": ">=22.12.0"
- }
+ },
+ "private": false
},
"node_modules/@adobe/css-tools": {
"version": "4.4.4",
diff --git a/package.json b/package.json
index 6b6853b84e..45dd536f2c 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,8 @@
{
- "name": "openhands-frontend",
+ "name": "@openhands/agent-server-gui",
"version": "1.6.0",
"license": "MIT",
- "private": true,
+ "private": false,
"type": "module",
"engines": {
"node": ">=22.12.0"
@@ -56,7 +56,7 @@
"dev:frontend": "npm run make-i18n && cross-env VITE_MOCK_API=false react-router dev",
"dev:mock": "npm run make-i18n && cross-env VITE_MOCK_API=true VITE_MOCK_SAAS=false react-router dev",
"dev:mock:saas": "npm run make-i18n && cross-env VITE_MOCK_API=true VITE_MOCK_SAAS=true react-router dev",
- "build": "npm run make-i18n && react-router build",
+ "build": "npm run build:app",
"build:mock": "npm run make-i18n && cross-env VITE_MOCK_API=true VITE_MOCK_SAAS=false react-router build",
"start": "npx sirv-cli build/ --single",
"test": "npm run make-i18n && vitest run",
@@ -71,7 +71,9 @@
"prepare": "cd .. && husky frontend/.husky",
"typecheck": "react-router typegen && tsc",
"typecheck:staged": "react-router typegen && npx tsc --noEmit --skipLibCheck",
- "check-translation-completeness": "node scripts/check-translation-completeness.cjs"
+ "check-translation-completeness": "node scripts/check-translation-completeness.cjs",
+ "build:app": "npm run make-i18n && react-router build",
+ "build:lib": "npm run make-i18n && react-router typegen && cross-env BUILD_LIB=true vite build && tsc -p tsconfig.lib.json"
},
"lint-staged": {
"src/**/*.{ts,tsx,js}": [
@@ -136,5 +138,54 @@
},
"overrides": {
"dompurify": "3.3.2"
+ },
+ "main": "./dist/index.cjs",
+ "module": "./dist/index.js",
+ "types": "./dist/index.d.ts",
+ "files": [
+ "dist"
+ ],
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "import": "./dist/index.js",
+ "require": "./dist/index.cjs"
+ },
+ "./browser": {
+ "types": "./dist/components/browser/index.d.ts",
+ "import": "./dist/components/browser/index.js",
+ "require": "./dist/components/browser/index.cjs"
+ },
+ "./conversation": {
+ "types": "./dist/components/conversation/index.d.ts",
+ "import": "./dist/components/conversation/index.js",
+ "require": "./dist/components/conversation/index.cjs"
+ },
+ "./files": {
+ "types": "./dist/components/files/index.d.ts",
+ "import": "./dist/components/files/index.js",
+ "require": "./dist/components/files/index.cjs"
+ },
+ "./settings": {
+ "types": "./dist/components/settings/index.d.ts",
+ "import": "./dist/components/settings/index.js",
+ "require": "./dist/components/settings/index.cjs"
+ },
+ "./sidebar": {
+ "types": "./dist/components/sidebar/index.d.ts",
+ "import": "./dist/components/sidebar/index.js",
+ "require": "./dist/components/sidebar/index.cjs"
+ },
+ "./terminal": {
+ "types": "./dist/components/terminal/index.d.ts",
+ "import": "./dist/components/terminal/index.js",
+ "require": "./dist/components/terminal/index.cjs"
+ },
+ "./package.json": "./package.json"
+ },
+ "peerDependencies": {
+ "react": "19.2.5",
+ "react-dom": "19.2.5",
+ "react-router": "7.14.1"
}
}
diff --git a/src/components/browser/index.ts b/src/components/browser/index.ts
new file mode 100644
index 0000000000..221de2ec80
--- /dev/null
+++ b/src/components/browser/index.ts
@@ -0,0 +1,3 @@
+export { BrowserPanel } from "../features/browser/browser";
+export { BrowserSnapshot } from "../features/browser/browser-snapshot";
+export { EmptyBrowserMessage } from "../features/browser/empty-browser-message";
diff --git a/src/components/conversation/index.ts b/src/components/conversation/index.ts
new file mode 100644
index 0000000000..95a35e29ed
--- /dev/null
+++ b/src/components/conversation/index.ts
@@ -0,0 +1,9 @@
+export { ConversationView } from "../../routes/conversation";
+export { ChatInterface as ChatPanel } from "../features/chat/chat-interface";
+export { ConversationLoading } from "../features/conversation/conversation-loading";
+export { ConversationMain } from "../features/conversation/conversation-main/conversation-main";
+export { ChatInterfaceWrapper } from "../features/conversation/conversation-main/chat-interface-wrapper";
+export { ConversationName } from "../features/conversation/conversation-name";
+export { ConversationNameWithStatus } from "../features/conversation/conversation-name-with-status";
+export { ConversationTabs } from "../features/conversation/conversation-tabs/conversation-tabs";
+export { MetricsModal } from "../features/conversation/metrics-modal/metrics-modal";
diff --git a/src/components/files/index.ts b/src/components/files/index.ts
new file mode 100644
index 0000000000..707ae95846
--- /dev/null
+++ b/src/components/files/index.ts
@@ -0,0 +1,5 @@
+export { FileItem } from "../features/files/file-item";
+export {
+ FileList,
+ FileList as FileExplorer,
+} from "../features/files/file-list";
diff --git a/src/components/settings/index.ts b/src/components/settings/index.ts
new file mode 100644
index 0000000000..28a4b82828
--- /dev/null
+++ b/src/components/settings/index.ts
@@ -0,0 +1,10 @@
+export * from "../features/settings";
+export { AppSettingsScreen as AppSettings } from "../../routes/app-settings";
+export { GitSettingsScreen as GitSettings } from "../../routes/git-settings";
+export { LlmSettingsScreen as LLMSettings } from "../../routes/llm-settings";
+export { MCPSettingsScreen as MCPSettings } from "../../routes/mcp-settings";
+export { SecretsSettingsScreen as SecretsSettings } from "../../routes/secrets-settings";
+export {
+ SettingsLayout,
+ SettingsLayout as SettingsPanel,
+} from "../features/settings/settings-layout";
diff --git a/src/components/sidebar/index.ts b/src/components/sidebar/index.ts
new file mode 100644
index 0000000000..3878fa7a17
--- /dev/null
+++ b/src/components/sidebar/index.ts
@@ -0,0 +1,6 @@
+export { Sidebar } from "../features/sidebar/sidebar";
+export { Avatar } from "../features/sidebar/avatar";
+export { UserActions } from "../features/sidebar/user-actions";
+export { UserAvatar } from "../features/sidebar/user-avatar";
+export { ConversationPanel } from "../features/conversation-panel/conversation-panel";
+export { ConversationPanelWrapper } from "../features/conversation-panel/conversation-panel-wrapper";
diff --git a/src/components/terminal/index.ts b/src/components/terminal/index.ts
new file mode 100644
index 0000000000..8f9fd860ea
--- /dev/null
+++ b/src/components/terminal/index.ts
@@ -0,0 +1 @@
+export { default as TerminalPanel } from "../features/terminal/terminal";
diff --git a/src/index.ts b/src/index.ts
index 8d99c61c00..8cd5167d1c 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,20 +1 @@
-export {
- AgentServerUIProviders,
- DEFAULT_AGENT_SERVER_ANALYTICS,
- type AgentServerUIAnalyticsConfig,
- type AgentServerUIProvidersProps,
-} from "./components/providers";
-export {
- createAgentServerQueryClient,
- getDefaultQueryClient,
- getQueryClient,
- queryClient,
- setQueryClient,
-} from "./query-client-config";
-export {
- AvailableLanguages,
- createAgentServerI18n,
- getDefaultI18n,
- getI18n,
- setI18n,
-} from "./i18n";
+export * from "./lib";
diff --git a/src/lib/index.ts b/src/lib/index.ts
new file mode 100644
index 0000000000..ff2a909811
--- /dev/null
+++ b/src/lib/index.ts
@@ -0,0 +1,26 @@
+export * from "../components/browser";
+export * from "../components/conversation";
+export * from "../components/files";
+export * from "../components/settings";
+export * from "../components/sidebar";
+export * from "../components/terminal";
+export {
+ AgentServerUIProviders,
+ DEFAULT_AGENT_SERVER_ANALYTICS,
+ type AgentServerUIAnalyticsConfig,
+ type AgentServerUIProvidersProps,
+} from "../components/providers";
+export {
+ createAgentServerQueryClient,
+ getDefaultQueryClient,
+ getQueryClient,
+ queryClient,
+ setQueryClient,
+} from "../query-client-config";
+export {
+ AvailableLanguages,
+ createAgentServerI18n,
+ getDefaultI18n,
+ getI18n,
+ setI18n,
+} from "../i18n";
diff --git a/src/library-env.d.ts b/src/library-env.d.ts
new file mode 100644
index 0000000000..c076513083
--- /dev/null
+++ b/src/library-env.d.ts
@@ -0,0 +1,33 @@
+/// <reference types="vite/client" />
+/// <reference types="vite-plugin-svgr/client" />
+
+interface Window {
+ __APP_MODE__?: "saas" | "oss";
+ __GITHUB_CLIENT_ID__?: string | null;
+ posthog?: {
+ capture: (event: string, properties?: Record<string, unknown>) => void;
+ };
+ Reo?: {
+ init: (config: { clientID: string }) => void;
+ identify: (identity: {
+ username: string;
+ type: "github" | "email";
+ other_identities?: Array<{
+ username: string;
+ type: "github" | "email";
+ }>;
+ firstname?: string;
+ lastname?: string;
+ company?: string;
+ }) => void;
+ };
+ grecaptcha?: {
+ enterprise: {
+ ready: (callback: () => void) => void;
+ execute: (
+ siteKey: string,
+ options: { action: string },
+ ) => Promise<string>;
+ };
+ };
+}
diff --git a/src/routes/app-settings.tsx b/src/routes/app-settings.tsx
index 43753fbec7..ab620a9dc4 100644
--- a/src/routes/app-settings.tsx
+++ b/src/routes/app-settings.tsx
@@ -31,7 +31,7 @@ export const clientLoader = createPermissionGuard(
"manage_application_settings",
);
-function AppSettingsScreen() {
+export function AppSettingsScreen() {
const posthog = usePostHog();
const { t } = useTranslation();
diff --git a/src/routes/conversation.tsx b/src/routes/conversation.tsx
index 27fbdff054..a0539cf5e8 100644
--- a/src/routes/conversation.tsx
+++ b/src/routes/conversation.tsx
@@ -117,8 +117,8 @@ function AppContent() {
);
}
-function App() {
+export function ConversationView() {
return <AppContent />;
}
-export default App;
+export default ConversationView;
diff --git a/src/routes/git-settings.tsx b/src/routes/git-settings.tsx
index 3b4ae9d944..b62b4b77a5 100644
--- a/src/routes/git-settings.tsx
+++ b/src/routes/git-settings.tsx
@@ -25,7 +25,7 @@ import { Provider, ProviderToken } from "#/types/settings";
export const clientLoader = createPermissionGuard("manage_integrations");
-function GitSettingsScreen() {
+export function GitSettingsScreen() {
const { t } = useTranslation();
const { mutate: saveGitProviders, isPending } = useAddGitProviders();
@@ -94,30 +94,42 @@ function GitSettingsScreen() {
return;
}
- const githubToken =
- (formData.get("github-token-input")?.toString() || "").trim();
- const gitlabToken =
- (formData.get("gitlab-token-input")?.toString() || "").trim();
- const bitbucketToken =
- (formData.get("bitbucket-token-input")?.toString() || "").trim();
- const bitbucketDCToken =
- (formData.get("bitbucket-dc-token-input")?.toString() || "").trim();
- const azureDevOpsToken =
- (formData.get("azure-devops-token-input")?.toString() || "").trim();
- const forgejoToken =
- (formData.get("forgejo-token-input")?.toString() || "").trim();
- const githubHost =
- (formData.get("github-host-input")?.toString() || "").trim();
- const gitlabHost =
- (formData.get("gitlab-host-input")?.toString() || "").trim();
- const bitbucketHost =
- (formData.get("bitbucket-host-input")?.toString() || "").trim();
- const bitbucketDCHost =
- (formData.get("bitbucket-dc-host-input")?.toString() || "").trim();
- const azureDevOpsHost =
- (formData.get("azure-devops-host-input")?.toString() || "").trim();
- const forgejoHost =
- (formData.get("forgejo-host-input")?.toString() || "").trim();
+ const githubToken = (
+ formData.get("github-token-input")?.toString() || ""
+ ).trim();
+ const gitlabToken = (
+ formData.get("gitlab-token-input")?.toString() || ""
+ ).trim();
+ const bitbucketToken = (
+ formData.get("bitbucket-token-input")?.toString() || ""
+ ).trim();
+ const bitbucketDCToken = (
+ formData.get("bitbucket-dc-token-input")?.toString() || ""
+ ).trim();
+ const azureDevOpsToken = (
+ formData.get("azure-devops-token-input")?.toString() || ""
+ ).trim();
+ const forgejoToken = (
+ formData.get("forgejo-token-input")?.toString() || ""
+ ).trim();
+ const githubHost = (
+ formData.get("github-host-input")?.toString() || ""
+ ).trim();
+ const gitlabHost = (
+ formData.get("gitlab-host-input")?.toString() || ""
+ ).trim();
+ const bitbucketHost = (
+ formData.get("bitbucket-host-input")?.toString() || ""
+ ).trim();
+ const bitbucketDCHost = (
+ formData.get("bitbucket-dc-host-input")?.toString() || ""
+ ).trim();
+ const azureDevOpsHost = (
+ formData.get("azure-devops-host-input")?.toString() || ""
+ ).trim();
+ const forgejoHost = (
+ formData.get("forgejo-host-input")?.toString() || ""
+ ).trim();
const providerTokens: Partial<Record<Provider, ProviderToken>> = {
github: { token: githubToken, host: githubHost },
diff --git a/src/routes/mcp-settings.tsx b/src/routes/mcp-settings.tsx
index 6fcebfcb42..7c5bc403c4 100644
--- a/src/routes/mcp-settings.tsx
+++ b/src/routes/mcp-settings.tsx
@@ -43,7 +43,7 @@ interface MCPServerConfig {
env?: Record<string, string>;
}
-function MCPSettingsScreen() {
+export function MCPSettingsScreen() {
const { t } = useTranslation();
const { data: settings, isLoading } = useSettings();
const { data: config } = useConfig();
diff --git a/src/routes/secrets-settings.tsx b/src/routes/secrets-settings.tsx
index e9490ca64c..c9272a7e20 100644
--- a/src/routes/secrets-settings.tsx
+++ b/src/routes/secrets-settings.tsx
@@ -16,7 +16,7 @@ import { LoadingSpinner } from "#/components/shared/loading-spinner";
export const clientLoader = createPermissionGuard("manage_secrets");
-function SecretsSettingsScreen() {
+export function SecretsSettingsScreen() {
const queryClient = useQueryClient();
const { t } = useTranslation();
const tableContainerRef = useRef<HTMLDivElement>(null);
diff --git a/src/stores/metrics-store.ts b/src/stores/metrics-store.ts
index 82060e28c4..32682b2db0 100644
--- a/src/stores/metrics-store.ts
+++ b/src/stores/metrics-store.ts
@@ -1,6 +1,6 @@
import { create } from "zustand";
-interface MetricsState {
+export interface MetricsState {
cost: number | null;
max_budget_per_task: number | null;
usage: {
@@ -13,7 +13,7 @@ interface MetricsState {
} | null;
}
-interface MetricsStore extends MetricsState {
+export interface MetricsStore extends MetricsState {
setMetrics: (metrics: MetricsState) => void;
}
diff --git a/tsconfig.json b/tsconfig.json
index 7a94a12427..2d3af9f2bf 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -6,23 +6,14 @@
"**/.server/**/*.tsx",
"**/.client/**/*.ts",
"**/.client/**/*.tsx",
- ".react-router/types/**/*",
+ ".react-router/types/**/*"
],
+ "exclude": ["__tests__/fixtures/**/*"],
"compilerOptions": {
- "lib": [
- "dom",
- "dom.iterable",
- "es2022"
- ],
+ "lib": ["dom", "dom.iterable", "es2022"],
"target": "es2022",
- "types": [
- "@react-router/node",
- "vite/client",
- ],
- "rootDirs": [
- ".",
- "./.react-router/types"
- ],
+ "types": ["@react-router/node", "vite/client"],
+ "rootDirs": [".", "./.react-router/types"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
@@ -38,9 +29,7 @@
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
- "#/*": [
- "./src/*"
- ]
+ "#/*": ["./src/*"]
},
// Vite takes care of building everything, not tsc.
"noEmit": true
diff --git a/tsconfig.lib.json b/tsconfig.lib.json
new file mode 100644
index 0000000000..19d9b5b4ca
--- /dev/null
+++ b/tsconfig.lib.json
@@ -0,0 +1,35 @@
+{
+ "extends": "./tsconfig.json",
+ "include": [
+ "src/index.ts",
+ "src/**/*.d.ts",
+ "src/lib/**/*.ts",
+ "src/lib/**/*.tsx",
+ "src/components/**/*.ts",
+ "src/components/**/*.tsx",
+ "src/query-client-config.ts",
+ "src/i18n/**/*.ts",
+ "src/i18n/**/*.tsx",
+ "src/routes/conversation.tsx",
+ "src/routes/app-settings.tsx",
+ "src/routes/git-settings.tsx",
+ "src/routes/llm-settings.tsx",
+ "src/routes/mcp-settings.tsx",
+ "src/routes/secrets-settings.tsx"
+ ],
+ "exclude": ["src/**/*.test.ts", "src/**/*.test.tsx"],
+ "compilerOptions": {
+ "noEmit": false,
+ "declaration": true,
+ "emitDeclarationOnly": true,
+ "declarationMap": false,
+ "outDir": "dist",
+ "rootDir": "src",
+ "types": [
+ "@react-router/node",
+ "vite/client",
+ "vite-plugin-svgr/client",
+ "node"
+ ]
+ }
+}
diff --git a/vite.config.ts b/vite.config.ts
index 91d5e4c5c6..e269b5dfeb 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,5 +1,6 @@
/// <reference types="vitest" />
/// <reference types="vite-plugin-svgr/client" />
+import { fileURLToPath } from "node:url";
import { defineConfig, loadEnv } from "vite";
import viteTsconfigPaths from "vite-tsconfig-paths";
import svgr from "vite-plugin-svgr";
@@ -7,6 +8,15 @@ import { reactRouter } from "@react-router/dev/vite";
import { configDefaults } from "vitest/config";
import tailwindcss from "@tailwindcss/vite";
+const LIB_ENTRY = fileURLToPath(new URL("./src/index.ts", import.meta.url));
+const LIB_EXTERNALS = [
+ "react",
+ "react-dom",
+ "react/jsx-runtime",
+ "react/jsx-dev-runtime",
+ "react-router",
+];
+
export default defineConfig(({ mode }) => {
const {
VITE_BACKEND_HOST = "127.0.0.1:8000",
@@ -15,6 +25,7 @@ export default defineConfig(({ mode }) => {
VITE_INSECURE_SKIP_VERIFY = "false",
} = loadEnv(mode, process.cwd());
+ const isLibraryBuild = process.env.BUILD_LIB === "true";
const USE_TLS = VITE_USE_TLS === "true";
const INSECURE_SKIP_VERIFY = VITE_INSECURE_SKIP_VERIFY === "true";
const PROTOCOL = USE_TLS ? "https" : "http";
@@ -26,11 +37,45 @@ export default defineConfig(({ mode }) => {
return {
plugins: [
- !process.env.VITEST && reactRouter(),
+ !process.env.VITEST && !isLibraryBuild && reactRouter(),
viteTsconfigPaths(),
svgr(),
tailwindcss(),
],
+ build: isLibraryBuild
+ ? {
+ outDir: "dist",
+ emptyOutDir: true,
+ sourcemap: true,
+ lib: {
+ entry: LIB_ENTRY,
+ formats: ["es"],
+ },
+ rollupOptions: {
+ external: LIB_EXTERNALS,
+ output: [
+ {
+ format: "es",
+ preserveModules: true,
+ preserveModulesRoot: "src",
+ entryFileNames: "[name].js",
+ chunkFileNames: "chunks/[name]-[hash].js",
+ assetFileNames: "assets/[name]-[hash][extname]",
+ },
+ {
+ format: "cjs",
+ preserveModules: true,
+ preserveModulesRoot: "src",
+ entryFileNames: "[name].cjs",
+ chunkFileNames: "chunks/[name]-[hash].cjs",
+ assetFileNames: "assets/[name]-[hash][extname]",
+ exports: "named",
+ },
+ ],
+ },
+ }
+ : undefined,
+ copyPublicDir: !isLibraryBuild,
optimizeDeps: {
include: [
// Pre-bundle client entry dependencies so the first page load does not 504
@@ -63,7 +108,7 @@ export default defineConfig(({ mode }) => {
"react-icons/lu",
"react-icons/di",
"react-icons/io5",
- "react-icons/io", // Added to prevent runtime optimization
+ "react-icons/io",
"@monaco-editor/react",
"react-textarea-autosize",
"react-markdown",