-
Notifications
You must be signed in to change notification settings - Fork 108
feat(ai): AI gateway integration with custom provider support #1072
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
Open
ddecrulle
wants to merge
5
commits into
main
Choose a base branch
from
ia-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule api
updated
10 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Commands | ||
|
|
||
| All commands use **Yarn** (not npm). | ||
|
|
||
| ```bash | ||
| yarn dev # Start dev server (processes env YAML first via scripts/unyamlify-env-local.ts) | ||
| yarn build # Type-check (tsc) then build for production | ||
| yarn test # Run all tests once (Vitest, non-watch) | ||
| yarn format # Format all .ts/.tsx/.json/.md files with Prettier | ||
| yarn format:check # Check formatting without writing | ||
| yarn storybook # Launch Storybook on port 6006 | ||
| ``` | ||
|
|
||
| **Run a single test file:** | ||
|
|
||
| ```bash | ||
| yarn vitest run src/core/usecases/launcher/decoupledLogic/computeHelmValues.test.ts | ||
| ``` | ||
|
|
||
| **Run tests matching a name pattern:** | ||
|
|
||
| ```bash | ||
| yarn vitest run --reporter=verbose -t "pattern" | ||
| ``` | ||
|
|
||
| Pre-commit hooks run `eslint --fix` and `prettier --write` via lint-staged. | ||
|
|
||
| ## Architecture | ||
|
|
||
| Onyxia Web is a React SPA — a data science platform portal for launching Kubernetes services (Helm charts), browsing catalogs, managing S3 files, managing Vault secrets, and querying data via DuckDB. It is deployed as static files served by nginx. | ||
|
|
||
| ### Core principles | ||
|
|
||
| - **React is only for rendering.** Business logic is React-agnostic and lives in `src/core/`. The `src/ui/` layer is strictly for React components and hooks. | ||
| - **Unidirectional dependencies.** `src/core/` never imports from `src/ui/`, not even for types. | ||
| - **Reactive over promise-based.** Thunks update observable state; the UI reacts to state changes. Prefer dispatching actions and reading state over returning values from thunks. | ||
| - **Constants outside Redux state.** Values that don't change are not stored in state — they are retrieved from thunks when needed, to avoid unnecessary re-renders. | ||
|
|
||
| ### `src/core/` — Business logic | ||
|
|
||
| Follows a clean-architecture / ports-and-adapters pattern using the `clean-architecture` npm package (a Redux-like store without Redux). | ||
|
|
||
| - **`ports/`** — TypeScript interfaces defining contracts for external dependencies (`OnyxiaApi`, `Oidc`, `S3Client`, `SecretsManager`, `SqlOlap`). | ||
| - **`adapters/`** — Concrete implementations: `onyxiaApi/` (axios-based HTTP), `oidc/` (oidc-spa), `s3Client/` (AWS SDK v3), `secretManager/` (Vault), `sqlOlap/` (DuckDB WASM). Each adapter has a mock counterpart for dev/testing. | ||
| - **`usecases/`** — One folder per feature (20+ total: `catalog`, `launcher`, `serviceManagement`, `fileExplorer`, `secretExplorer`, `dataExplorer`, etc.). Each usecase follows the pattern: | ||
| - `state.ts` — state shape + `createUsecaseActions` (slice-like) | ||
| - `thunks.ts` — async side effects, accesses adapters via `createUsecaseContextApi` | ||
| - `selectors.ts` — memoized state derivations | ||
| - `index.ts` — re-exports all three | ||
| - **`bootstrap.ts`** — Wires adapters together and creates the core store. | ||
| - **`index.ts`** — Exports `useCoreState`, `getCore`, `createReactApi` bindings consumed by `src/ui/`. | ||
|
|
||
| **Complex use-cases** (especially `launcher/`) have a `decoupledLogic/` subfolder with pure functions and no framework dependencies — this is where most unit tests live. | ||
|
|
||
| ### `src/ui/` — React layer | ||
|
|
||
| - **`App/`** — Root layout: Header, LeftBar, Main, Footer. `App.tsx` triggers core bootstrap; `Main.tsx` is the route-based page switcher. | ||
| - **`pages/`** — One folder per route/page. Each page exports `routeDefs` (via `type-route`'s `defineRoute`) and `routeGroup`. All are merged in `pages/index.ts`. | ||
| - **`routes.tsx`** — Router instantiation. Navigation uses `routes.catalog(...).push()` or `session.push()`. | ||
| - **`i18n/`** — i18nifty setup. Translation keys are declared at the component level via `declareComponentKeys`, collected into a `ComponentKey` union in `i18n/types.ts`. Nine languages: en, fr, zh-CN, no, fi, nl, it, es, de. | ||
| - **`theme/`** — onyxia-ui theme setup (palette, fonts, favicon). | ||
| - **`shared/`** — Reusable components (CommandBar, CodeBlock, SettingField, etc.). | ||
|
|
||
| ### Key patterns | ||
|
|
||
| **Consuming core state in React:** | ||
|
|
||
| ```ts | ||
| import { useCoreState, getCore } from "core"; | ||
| const helmReleases = useCoreState(state => state.serviceManagement.helmReleases); | ||
| await getCore().dispatch(usecases.serviceManagement.thunks.initialize()); | ||
| ``` | ||
|
|
||
| **Styling — tss-react** (not plain CSS modules): | ||
|
|
||
| ```ts | ||
| import { tss } from "tss"; | ||
| const useStyles = tss.withName({ MyComponent }).create(({ theme }) => ({ ... })); | ||
| const { classes, cx } = useStyles(); | ||
| ``` | ||
|
|
||
| **Absolute imports** — `tsconfig.json` sets `baseUrl: "src"`, so use `import { foo } from "core/usecases/catalog"` (not relative paths). | ||
|
|
||
| **Environment variables** — All env vars are centrally parsed and validated in `src/env.ts`. The `index.html` is an EJS template processed by `vite-envs` at build time. | ||
|
|
||
| **Authentication** — OIDC init (`oidc-spa`) happens before React renders, in `main.tsx`. Use the `Oidc` port interface, not the adapter directly. | ||
|
|
||
| **Plugin system** — `src/pluginSystem.ts` exposes `window.onyxia` after boot and fires an `"onyxiaready"` `CustomEvent`, allowing external JS to interact with core state, routes, theme, and i18n. | ||
|
|
||
| **Keycloak theme** — `src/keycloak-theme/` is a Keycloakify login theme that shares env and i18n infrastructure with the main app. Build with `yarn build-keycloak-theme`. | ||
|
|
||
| ## Key libraries | ||
|
|
||
| | Library | Role | | ||
| | -------------------- | ------------------------------------------------------------ | | ||
| | `onyxia-ui` | In-house design system on top of MUI v6 | | ||
| | `type-route` | Strongly-typed client-side router | | ||
| | `i18nifty` | Component-level i18n | | ||
| | `clean-architecture` | Redux-like store (ports/usecases pattern) | | ||
| | `oidc-spa` | OIDC/OAuth2 authentication | | ||
| | `keycloakify` | Keycloak login theme from React components | | ||
| | `tss-react` | CSS-in-JS bound to onyxia-ui theme | | ||
| | `vite-envs` | Env var injection into EJS `index.html` at build time | | ||
| | DuckDB WASM | In-browser SQL OLAP queries (`dataExplorer`, `sqlOlapShell`) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from "./openWebUi"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import type { Ai } from "core/ports/Ai"; | ||
|
|
||
| export function createAi(params: { id: string; name: string; webUiUrl: string }): Ai { | ||
| const { id, name, webUiUrl } = params; | ||
|
|
||
| return { | ||
| id, | ||
| name, | ||
| webUiUrl, | ||
| apiBase: `${webUiUrl}/api`, | ||
| getToken: async () => ({ status: "success" as const, token: "mock-ai-token" }), | ||
| listModels: async () => [ | ||
| { id: "llama3.2", name: "Llama 3.2" }, | ||
| { id: "mistral-7b", name: "Mistral 7B" }, | ||
| { id: "codestral", name: "Codestral" } | ||
| ] | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import type { Ai, GetTokenResult } from "core/ports/Ai"; | ||
| import { oidcTokenExchange, OidcTokenExchangeError } from "core/tools/oidcTokenExchange"; | ||
| import { z } from "zod"; | ||
|
|
||
| export function createAi(params: { | ||
| id: string; | ||
| name: string; | ||
| webUiUrl: string; | ||
| oauthProvider: string; | ||
| getOidcAccessToken: () => Promise<string>; | ||
| }): Ai { | ||
| const { id, name, webUiUrl, oauthProvider, getOidcAccessToken } = params; | ||
|
|
||
| const apiBase = `${webUiUrl}/api`; | ||
|
|
||
| return { | ||
| id, | ||
| name, | ||
| webUiUrl, | ||
| apiBase, | ||
| getToken: async (): Promise<GetTokenResult> => { | ||
| const oidcAccessToken = await getOidcAccessToken(); | ||
|
|
||
| return oidcTokenExchange({ | ||
| tokenExchangeEndpoint: `${webUiUrl}/api/v1/auths/oauth/${oauthProvider}/token/exchange`, | ||
| oidcAccessToken | ||
| }) | ||
| .then(token => ({ status: "success" as const, token })) | ||
| .catch((error: unknown) => { | ||
| if (error instanceof OidcTokenExchangeError && error.status === 403) { | ||
| return { status: "no-account" as const }; | ||
| } | ||
| return { status: "error" as const }; | ||
| }); | ||
| }, | ||
| listModels: async (token: string) => { | ||
| const response = await fetch(`${apiBase}/models`, { | ||
| headers: { Authorization: `Bearer ${token}` } | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`Failed to list models (${response.status})`); | ||
| } | ||
|
|
||
| const { data } = z | ||
| .object({ data: z.array(z.object({ id: z.string(), name: z.string() })) }) | ||
| .parse(await response.json()); | ||
|
|
||
| return data.map(({ id, name }) => ({ id, name })); | ||
| } | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| export type Ai = { | ||
| id: string; | ||
| name: string; | ||
| webUiUrl: string; | ||
| apiBase: string; | ||
| getToken: () => Promise<GetTokenResult>; | ||
| listModels: (token: string) => Promise<{ id: string; name: string }[]>; | ||
| }; | ||
|
|
||
| export type GetTokenResult = | ||
| | { status: "success"; token: string } | ||
| | { status: "no-account" } | ||
| | { status: "error" }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalize
webUiUrlbefore composingapiBase.If
webUiUrlends with/, this produces a double slash (...//api), which can break strict gateways/proxies.Suggested change
export function createAi(params: { id: string; name: string; webUiUrl: string }): Ai { const { id, name, webUiUrl } = params; + const normalizedWebUiUrl = webUiUrl.replace(/\/+$/, ""); return { id, name, webUiUrl, - apiBase: `${webUiUrl}/api`, + apiBase: `${normalizedWebUiUrl}/api`, getToken: async () => ({ status: "success" as const, token: "mock-ai-token" }), listModels: async () => [📝 Committable suggestion
🤖 Prompt for AI Agents