Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

📦 feat: Scaffold the @librechat/chat Package (#16964)

Marco Berettac00c776e0e6a
diff --git a/.github/workflows/codegraph-e2e-votes.yml b/.github/workflows/codegraph-e2e-votes.yml
index 251c7a9a71..0c44824cb4 100644
--- a/.github/workflows/codegraph-e2e-votes.yml
+++ b/.github/workflows/codegraph-e2e-votes.yml
@@ -66,6 +66,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
packages/data-schemas/node_modules
packages/api/node_modules
@@ -125,7 +126,7 @@ jobs:
uses: actions/cache@v5
with:
path: client/dist
- key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
+ key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/chat/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
- name: Build client app
if: steps.cache-client-app.outputs.cache-hit != 'true'
diff --git a/.github/workflows/docker-smoke.yml b/.github/workflows/docker-smoke.yml
index 5da967f90e..811d500a13 100644
--- a/.github/workflows/docker-smoke.yml
+++ b/.github/workflows/docker-smoke.yml
@@ -16,6 +16,7 @@ on:
- 'skill/**'
- 'packages/api/**'
- 'packages/client/**'
+ - 'packages/chat/**'
- 'packages/data-provider/**'
- 'packages/data-schemas/**'
- '!**.md'
diff --git a/.github/workflows/frontend-review.yml b/.github/workflows/frontend-review.yml
index f6b88df7a0..fba49e174c 100644
--- a/.github/workflows/frontend-review.yml
+++ b/.github/workflows/frontend-review.yml
@@ -6,6 +6,7 @@ on:
- 'e2e/client-build.test.mjs'
- 'client/**'
- 'packages/client/**'
+ - 'packages/chat/**'
- 'packages/data-provider/**'
- 'package.json'
- 'package-lock.json'
@@ -20,6 +21,7 @@ on:
- 'e2e/client-build.test.mjs'
- 'client/**'
- 'packages/client/**'
+ - 'packages/chat/**'
- 'packages/data-provider/**'
- 'package.json'
- 'package-lock.json'
@@ -179,6 +181,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
key: node-modules-frontend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
@@ -208,6 +211,11 @@ jobs:
if: steps.cache-client-package.outputs.cache-hit != 'true'
run: npm run build:client-package
+ # About a second, so it is not cached. Nothing downstream consumes the output yet; the step
+ # proves the package's tsdown build, declarations and exports on every frontend run.
+ - name: Build chat package
+ run: npm run build:chat
+
- name: Upload data-provider build
uses: actions/upload-artifact@v6
with:
@@ -243,6 +251,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
key: node-modules-frontend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
@@ -266,6 +275,50 @@ jobs:
run: npm run typecheck
working-directory: client
+ test-packages-chat:
+ name: 'Tests: @librechat/chat'
+ needs: build
+ if: ${{ !cancelled() && needs.build.result == 'success' }}
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
+ - uses: actions/checkout@v5
+
+ - name: Use Node.js 24.16.0
+ uses: actions/setup-node@v5
+ with:
+ node-version: '24.16.0'
+
+ - name: Restore node_modules cache
+ id: cache-node-modules
+ uses: actions/cache@v5
+ with:
+ path: |
+ node_modules
+ client/node_modules
+ packages/client/node_modules
+ packages/chat/node_modules
+ packages/data-provider/node_modules
+ key: node-modules-frontend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
+
+ - name: Install dependencies
+ if: steps.cache-node-modules.outputs.cache-hit != 'true'
+ run: npm ci
+
+ - name: Download data-provider build
+ uses: actions/download-artifact@v7
+ with:
+ name: build-data-provider
+ path: packages/data-provider/dist
+
+ - name: Type check
+ run: npm run typecheck
+ working-directory: packages/chat
+
+ - name: Run unit tests
+ run: npm run test:ci
+ working-directory: packages/chat
+
test-packages-client:
name: 'Tests: @librechat/client'
needs: [build, codegraph_select]
@@ -290,6 +343,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
key: node-modules-frontend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
@@ -372,6 +426,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
key: node-modules-frontend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
@@ -448,6 +503,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
key: node-modules-frontend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
diff --git a/.github/workflows/frontend-windows-nightly.yml b/.github/workflows/frontend-windows-nightly.yml
index 28c1ea4605..a8ad82a87c 100644
--- a/.github/workflows/frontend-windows-nightly.yml
+++ b/.github/workflows/frontend-windows-nightly.yml
@@ -45,6 +45,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
key: node-modules-frontend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
@@ -115,6 +116,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
key: node-modules-frontend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
diff --git a/.github/workflows/playwright-bombadil.yml b/.github/workflows/playwright-bombadil.yml
index 0f37ff1b11..9354eedc18 100644
--- a/.github/workflows/playwright-bombadil.yml
+++ b/.github/workflows/playwright-bombadil.yml
@@ -54,6 +54,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
packages/data-schemas/node_modules
packages/api/node_modules
@@ -113,7 +114,7 @@ jobs:
uses: actions/cache@v4
with:
path: client/dist
- key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
+ key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/chat/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
- name: Build client app
if: steps.cache-client-app.outputs.cache-hit != 'true'
diff --git a/.github/workflows/playwright-mock.yml b/.github/workflows/playwright-mock.yml
index 6f740ca27d..bf8d7e431f 100644
--- a/.github/workflows/playwright-mock.yml
+++ b/.github/workflows/playwright-mock.yml
@@ -211,6 +211,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
packages/data-schemas/node_modules
packages/api/node_modules
@@ -268,12 +269,16 @@ jobs:
if: steps.cache-client-package.outputs.cache-hit != 'true'
run: npm run build:client-package
+ # About a second, so it is not cached; the chat-package scenarios load the built entries.
+ - name: Build chat package
+ run: npm run build:chat
+
- name: Restore client app build cache
id: cache-client-app
uses: actions/cache@v5
with:
path: client/dist
- key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
+ key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/chat/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
- name: Build client app
if: steps.cache-client-app.outputs.cache-hit != 'true'
@@ -462,6 +467,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
packages/data-schemas/node_modules
packages/api/node_modules
@@ -608,6 +614,7 @@ jobs:
node_modules
client/node_modules
packages/client/node_modules
+ packages/chat/node_modules
packages/data-provider/node_modules
packages/data-schemas/node_modules
packages/api/node_modules
diff --git a/.github/workflows/promote-main.yml b/.github/workflows/promote-main.yml
index 311828b220..00cffc8022 100644
--- a/.github/workflows/promote-main.yml
+++ b/.github/workflows/promote-main.yml
@@ -70,7 +70,7 @@ jobs:
'frontend-review.yml': (59789527, {
'Build packages', 'Client build recovery regression',
'TypeScript type checks (client)', 'Vite build verification',
- 'Tests: @librechat/client',
+ 'Tests: @librechat/client', 'Tests: @librechat/chat',
*[f'Tests: Ubuntu (shard {n}/2)' for n in range(1, 3)],
}),
}
diff --git a/.github/workflows/static-checks.yml b/.github/workflows/static-checks.yml
index 98d6f1c5e2..079535c486 100644
--- a/.github/workflows/static-checks.yml
+++ b/.github/workflows/static-checks.yml
@@ -77,6 +77,7 @@ jobs:
- '**/eslint-suppressions.json'
- 'client/src/**'
- 'packages/client/src/**'
+ - 'packages/chat/src/**'
# The bundle the rules resolve primitives through is named by the
# library's manifest, produced by its build config and shaped by
# its compiler options.
@@ -102,6 +103,7 @@ jobs:
css_colors:
- 'client/src/**/*.css'
- 'packages/client/src/**/*.css'
+ - 'packages/chat/src/**/*.css'
- 'packages/client/src/theme/allowlist.md'
# The scanner parses with postcss: an upgrade changes what it reads.
- 'package.json'
@@ -122,6 +124,7 @@ jobs:
- 'api/**'
- 'client/src/**'
- 'packages/client/**'
+ - 'packages/chat/src/**'
- 'packages/data-provider/src/**'
- 'packages/data-schemas/src/**'
- '.github/workflows/static-checks.yml'
@@ -135,6 +138,7 @@ jobs:
- 'client/**'
- 'packages/api/**'
- 'packages/client/**'
+ - 'packages/chat/**'
# Every workspace manifest the JSON validation step covers, plus
# the ones whose dependencies feed the unused-package calculation
# through api/package.json's @librechat/data-schemas entry.
@@ -429,7 +433,7 @@ jobs:
if: always() && steps.paths.outputs.unused_packages == 'true'
continue-on-error: true
run: |
- for FILE in package.json client/package.json api/package.json packages/api/package.json packages/client/package.json packages/data-provider/package.json packages/data-schemas/package.json; do
+ for FILE in package.json client/package.json api/package.json packages/api/package.json packages/client/package.json packages/chat/package.json packages/data-provider/package.json packages/data-schemas/package.json; do
if [[ -f "$FILE" ]]; then
jq empty "$FILE" || (echo "::error title=Invalid JSON::$FILE is invalid" && exit 1)
fi
@@ -661,12 +665,28 @@ jobs:
cd ..
fi
+ - name: Run depcheck for packages/chat/package.json
+ if: always() && steps.paths.outputs.unused_packages == 'true'
+ id: check-chat
+ continue-on-error: true
+ run: |
+ if [[ -f "packages/chat/package.json" ]]; then
+ cd packages/chat
+ UNUSED=$(depcheck --json | jq -r '.dependencies | join("\n")' || echo "")
+ # Exclude dependencies the package's own scripts invoke
+ UNUSED=$(comm -23 <(echo "$UNUSED" | sort) <(jq -r '.scripts // {} | .[]' package.json | tr ' ' '\n' | sort -u) || echo "")
+ echo "CHAT_UNUSED<<EOF" >> $GITHUB_ENV
+ echo "$UNUSED" >> $GITHUB_ENV
+ echo "EOF" >> $GITHUB_ENV
+ cd ../..
+ fi
+
- name: Fail workflow if unused dependencies found
id: unused_packages
if: >
always() &&
steps.paths.outputs.unused_packages == 'true' &&
- (env.ROOT_UNUSED != '' || env.CLIENT_UNUSED != '' || env.API_UNUSED != '')
+ (env.ROOT_UNUSED != '' || env.CLIENT_UNUSED != '' || env.API_UNUSED != '' || env.CHAT_UNUSED != '')
continue-on-error: true
run: exit 1
@@ -703,6 +723,7 @@ jobs:
CHECK_ROOT_OUTCOME: ${{ steps.check-root.outcome }}
CHECK_CLIENT_OUTCOME: ${{ steps.check-client.outcome }}
CHECK_API_OUTCOME: ${{ steps.check-api.outcome }}
+ CHECK_CHAT_OUTCOME: ${{ steps.check-chat.outcome }}
UNUSED_PACKAGES_OUTCOME: ${{ steps.unused_packages.outcome }}
run: |
failures=()
@@ -743,12 +764,14 @@ jobs:
record_failure "Root depcheck" "$CHECK_ROOT_OUTCOME"
record_failure "Client depcheck" "$CHECK_CLIENT_OUTCOME"
record_failure "API depcheck" "$CHECK_API_OUTCOME"
+ record_failure "Chat depcheck" "$CHECK_CHAT_OUTCOME"
record_failure "Unused NPM packages" "$UNUSED_PACKAGES_OUTCOME"
if [[ "$UNUSED_PACKAGES_OUTCOME" == "failure" ]]; then
[[ -n "$ROOT_UNUSED" ]] && printf 'Root unused dependencies:\n%s\n' "$ROOT_UNUSED"
[[ -n "$CLIENT_UNUSED" ]] && printf 'Client unused dependencies:\n%s\n' "$CLIENT_UNUSED"
[[ -n "$API_UNUSED" ]] && printf 'API unused dependencies:\n%s\n' "$API_UNUSED"
+ [[ -n "$CHAT_UNUSED" ]] && printf 'Chat unused dependencies:\n%s\n' "$CHAT_UNUSED"
fi
if [[ ${#failures[@]} -eq 0 ]]; then
diff --git a/AGENTS.md b/AGENTS.md
index 6a486ba134..ff82d6ea82 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -3,7 +3,8 @@
`AGENTS.md` is the repository's contributor guidance. Backend code lives in `packages/api`
(TypeScript) and `packages/data-schemas` (database methods); `api` is legacy Express wiring.
Shared API types and services live in `packages/data-provider`, and the React app lives in
-`client` with shared primitives in `packages/client`.
+`client` with shared primitives in `packages/client`. Chat state, transport and message components
+are moving into `packages/chat` (`@librechat/chat`), which never imports the app.
## Branching and pull requests
@@ -60,7 +61,7 @@ reads and reuse loaded request data. Run `npm run lighthouse` before completion:
the CI lane adds 250 ms per Mongo query and checks the visible conversation's LCP.
See [budgets, reproduction and failure diagnosis](e2e/lighthouse/README.md).
-A green build is not a typecheck: `packages/api`, `packages/client` and `packages/data-schemas` build
+A green build is not a typecheck: `packages/api`, `packages/client`, `packages/chat` and `packages/data-schemas` build
with `tsdown`, which emits without checking types. Run `npx tsc --noEmit` in the workspace you
changed. `packages/client` excludes `*.spec.ts(x)` and `*.test.ts(x)` from typechecking entirely.
`npm run sort-imports` with no arguments rewrites every source root — pass the paths you touched.
diff --git a/Dockerfile b/Dockerfile
index d89e6c60f5..cd7aca075a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -32,6 +32,7 @@ COPY --chown=node:node client/package.json ./client/package.json
COPY --chown=node:node packages/data-provider/package.json ./packages/data-provider/package.json
COPY --chown=node:node packages/data-schemas/package.json ./packages/data-schemas/package.json
COPY --chown=node:node packages/api/package.json ./packages/api/package.json
+COPY --chown=node:node packages/chat/package.json ./packages/chat/package.json
RUN \
# Allow mounting of these files, which have no default
diff --git a/Dockerfile.multi b/Dockerfile.multi
index 2e83773454..3c99f25cef 100644
--- a/Dockerfile.multi
+++ b/Dockerfile.multi
@@ -30,6 +30,7 @@ COPY packages/data-provider/package*.json ./packages/data-provider/
COPY packages/api/package*.json ./packages/api/
COPY packages/data-schemas/package*.json ./packages/data-schemas/
COPY packages/client/package*.json ./packages/client/
+COPY packages/chat/package*.json ./packages/chat/
COPY client/package*.json ./client/
COPY api/package*.json ./api/
@@ -78,6 +79,13 @@ COPY packages/client ./
COPY --from=data-provider-build /app/packages/data-provider/dist /app/packages/data-provider/dist
RUN npm run build
+# Build `chat` package
+FROM base AS chat-package-build
+WORKDIR /app/packages/chat
+COPY packages/chat ./
+COPY --from=data-provider-build /app/packages/data-provider/dist /app/packages/data-provider/dist
+RUN npm run build
+
# Client build
FROM base AS client-build
WORKDIR /app/client
@@ -87,6 +95,9 @@ COPY --from=client-package-build /app/packages/client/dist /app/packages/client/
COPY --from=client-package-build /app/packages/client/src /app/packages/client/src
COPY --from=client-package-build /app/packages/client/tailwind.preset.cjs /app/packages/client/tailwind.preset.cjs
COPY --from=client-package-build /app/packages/client/tailwind.compat.cjs /app/packages/client/tailwind.compat.cjs
+# The client's Tailwind content scans the chat sources, and the app resolves the package's dist.
+COPY --from=chat-package-build /app/packages/chat/dist /app/packages/chat/dist
+COPY --from=chat-package-build /app/packages/chat/src /app/packages/chat/src
ARG VITE_MCP_SANDBOX_URL=
ARG NODE_MAX_OLD_SPACE_SIZE
ENV NODE_OPTIONS="--max-old-space-size=${NODE_MAX_OLD_SPACE_SIZE}"
diff --git a/client/tailwind.config.cjs b/client/tailwind.config.cjs
index c2671416bc..e58bd5a2a4 100644
--- a/client/tailwind.config.cjs
+++ b/client/tailwind.config.cjs
@@ -10,6 +10,7 @@ module.exports = {
'./src/**/*.{js,jsx,ts,tsx}',
// Include component library files
'../packages/client/src/**/*.{js,jsx,ts,tsx}',
+ '../packages/chat/src/**/*.{js,jsx,ts,tsx}',
],
// darkMode: 'class',
darkMode: ['class'],
diff --git a/config/circular-deps.mjs b/config/circular-deps.mjs
index bd8bf80569..a91c073357 100644
--- a/config/circular-deps.mjs
+++ b/config/circular-deps.mjs
@@ -53,6 +53,19 @@ const targets = [
internal: ['~'],
minModules: 100,
},
+ {
+ name: '@librechat/chat',
+ dir: 'packages/chat',
+ entries: ['src/index.ts', 'src/react.ts', 'src/components.ts'],
+ /** A self-import through the package name crosses an entry; resolve it so the scan sees it. */
+ alias: {
+ '@librechat/chat/components': 'src/components.ts',
+ '@librechat/chat/react': 'src/react.ts',
+ '@librechat/chat': 'src/index.ts',
+ },
+ internal: ['@librechat/chat'],
+ minModules: 3,
+ },
{
name: 'api server',
dir: 'api',
diff --git a/config/packages.js b/config/packages.js
index e2a3b06b06..083a1a65c0 100644
--- a/config/packages.js
+++ b/config/packages.js
@@ -13,6 +13,7 @@ const directories = [
path.resolve(rootDir, 'packages', 'data-provider'),
path.resolve(rootDir, 'packages', 'data-schemas'),
path.resolve(rootDir, 'packages', 'api'),
+ path.resolve(rootDir, 'packages', 'chat'),
path.resolve(rootDir, 'client'),
path.resolve(rootDir, 'api'),
];
diff --git a/e2e/specs/mock/scenarios/chat-package.spec.ts b/e2e/specs/mock/scenarios/chat-package.spec.ts
new file mode 100644
index 0000000000..004d800ab0
--- /dev/null
+++ b/e2e/specs/mock/scenarios/chat-package.spec.ts
@@ -0,0 +1,213 @@
+import { existsSync } from 'node:fs';
+import { resolve } from 'node:path';
+import { expect, test } from '@playwright/test';
+import {
+ run,
+ repoRoot,
+ lintStdin,
+ messagesFor,
+ inOneProject,
+ designRuleSeverities,
+} from './lint.helpers';
+
+/**
+ * `@librechat/chat` is the package the chat hooks and components move into. Its
+ * boundaries are what make it reusable: the core runs without a UI framework, and
+ * nothing in the package reaches back into the app. These scenarios ask the real
+ * flat config and the real build whether that holds, before any code has moved in.
+ */
+
+const UI_MODULES = [
+ 'react',
+ 'react-dom',
+ 'jotai',
+ 'recoil',
+ '@tanstack/react-query',
+ '@librechat/client',
+];
+
+const restricted = (relativePath: string, source: string): string[] =>
+ messagesFor(lintStdin(relativePath, source), 'no-restricted-imports');
+
+/** `import()` and `require()` are not static imports; their own rule reports them. */
+const restrictedLoad = (relativePath: string, specifier: string): string[] =>
+ messagesFor(
+ lintStdin(
+ relativePath,
+ [
+ `export const load = () => import('${specifier}');`,
+ `export const sync = () => require('${specifier}');`,
+ `export const template = () => import(\`${specifier}\`);`,
+ `export const templateSync = () => require(\`${specifier}\`);`,
+ '',
+ ].join('\n'),
+ ),
+ 'no-restricted-syntax',
+ );
+
+test.describe('the @librechat/chat package boundary', () => {
+ test.beforeEach(() => inOneProject());
+
+ test('the chat core rejects a UI framework import @scenario:the-chat-core-rejects-a-ui-framework-import', () => {
+ test.setTimeout(120_000);
+ const source = "import { useState } from 'react';\nexport const probe = useState;\n";
+
+ const core = restricted('packages/chat/src/core/probe.ts', source);
+ expect(core.join('\n')).toContain("'react' import is restricted");
+ expect(restricted('packages/chat/src/index.ts', source)).toHaveLength(1);
+ expect(restricted('packages/chat/src/core/Probe.tsx', source)).toHaveLength(1);
+ const jsx = lintStdin(
+ 'packages/chat/src/core/Probe.tsx',
+ 'export const Probe = () => <div />;\n',
+ );
+ expect(messagesFor(jsx, 'no-restricted-syntax')).toHaveLength(1);
+ for (const entry of ['../../react', '../../components']) {
+ const nested = `import * as entry from '${entry}';\nexport const probe = entry;\n`;
+ expect(restricted('packages/chat/src/core/streaming/probe.ts', nested), entry).toHaveLength(
+ 1,
+ );
+ }
+ expect(
+ restricted(
+ 'packages/chat/src/core/probe.ts',
+ "import { atom } from 'jotai';\nexport const a = atom;\n",
+ ),
+ ).toHaveLength(1);
+
+ for (const specifier of [
+ 'react',
+ 'react/jsx-runtime',
+ 'jotai',
+ '@librechat/client',
+ '../components',
+ '../react',
+ '../react.js',
+ '../components.mjs',
+ ]) {
+ expect(restrictedLoad('packages/chat/src/core/probe.ts', specifier), specifier).toHaveLength(
+ 4,
+ );
+ }
+ expect(restrictedLoad('packages/chat/src/core/probe.ts', 'librechat-data-provider')).toEqual(
+ [],
+ );
+
+ expect(restricted('packages/chat/src/react/probe.ts', source)).toEqual([]);
+ expect(restrictedLoad('packages/chat/src/react/probe.ts', 'react')).toEqual([]);
+ });
+
+ test('the chat package rejects an import from the app @scenario:the-chat-package-rejects-an-import-from-the-app', () => {
+ test.setTimeout(120_000);
+ const probes = [
+ "import store from '~/store';\nexport const s = store;\n",
+ "import { useAuthContext } from '../../../../client/src/hooks';\nexport const h = useAuthContext;\n",
+ "import { useRecoilValue } from 'recoil';\nexport const r = useRecoilValue;\n",
+ "export { showFilesDialogAtom } from '@librechat/frontend/src/store/filesDialog';\n",
+ "export * from '@librechat/chat/components';\n",
+ ];
+ for (const path of [
+ 'packages/chat/src/react/probe.ts',
+ 'packages/chat/src/components/probe.tsx',
+ ]) {
+ for (const source of probes) {
+ expect(restricted(path, source), `${path}\n${source}`).toHaveLength(1);
+ }
+ for (const specifier of [
+ '~/store',
+ '../../../../client/src/hooks',
+ 'recoil',
+ '@librechat/frontend/src/store/filesDialog',
+ '@librechat/chat/components',
+ ]) {
+ expect(restrictedLoad(path, specifier), `${path}\n${specifier}`).toHaveLength(4);
+ }
+ }
+ });
+
+ test('chat components reject literal copy @scenario:chat-components-reject-literal-copy', () => {
+ test.setTimeout(120_000);
+ const path = 'packages/chat/src/components/Probe.tsx';
+ const literal = lintStdin(path, 'export function Probe() {\n return <p>Hello world</p>;\n}\n');
+ expect(messagesFor(literal, 'i18next/no-literal-string')).toHaveLength(1);
+
+ const labels = lintStdin(
+ path,
+ 'export function Probe() {\n return <button title="Stop generating" aria-label={`Stop generating`} />;\n}\n',
+ );
+ expect(messagesFor(labels, 'no-restricted-syntax')).toHaveLength(2);
+ const props = lintStdin(
+ path,
+ 'export function Probe() {\n return <img alt="" className="size-4" role="presentation" />;\n}\n',
+ );
+ expect(messagesFor(props, 'no-restricted-syntax')).toEqual([]);
+
+ const localized = lintStdin(
+ path,
+ 'export function Probe({ label }: { label: string }) {\n return <p>{label}</p>;\n}\n',
+ );
+ expect(messagesFor(localized, 'i18next/no-literal-string')).toEqual([]);
+ });
+
+ test('the design rules police the chat components @scenario:the-design-rules-police-the-chat-components', () => {
+ test.setTimeout(120_000);
+ const path = 'packages/chat/src/components/Probe.tsx';
+ const severities = designRuleSeverities([path])[path];
+ for (const rule of [
+ 'shadcn/no-restyle',
+ 'shadcn/no-raw-colors',
+ 'shadcn/no-arbitrary-values',
+ 'shadcn/no-inline-styles',
+ 'shadcn/require-static-classes',
+ 'shadcn/no-unknown-classes',
+ ]) {
+ expect(severities[rule], rule).toBe(2);
+ }
+
+ const messages = lintStdin(
+ path,
+ 'export function Probe() {\n return <p className="bg-red-500">x</p>;\n}\n',
+ );
+ expect(messagesFor(messages, 'shadcn/no-raw-colors').length).toBeGreaterThan(0);
+ });
+});
+
+test.describe('the built @librechat/chat package', () => {
+ test.beforeEach(() => inOneProject());
+
+ test('the chat core loads without React, Jotai or Recoil @scenario:the-chat-core-loads-without-react-jotai-or-recoil', () => {
+ test.setTimeout(120_000);
+ const dist = resolve(repoRoot, 'packages/chat/dist');
+ expect(existsSync(dist), 'packages/chat/dist is missing: run npm run build').toBe(true);
+
+ /** Every UI module fails to resolve in this process, so loading the core
+ * succeeds only when nothing it reaches imports one. */
+ const probe = `
+ const Module = require('node:module');
+ const blocked = new Set(${JSON.stringify(UI_MODULES)});
+ const resolveFilename = Module._resolveFilename;
+ Module._resolveFilename = function (request, ...rest) {
+ if (blocked.has(request)) throw new Error('the core reached ' + request);
+ return resolveFilename.call(this, request, ...rest);
+ };
+ const core = require('@librechat/chat');
+ const answer = {
+ contentTypesText: core.ContentTypes.TEXT,
+ toUIMessage: typeof core.toUIMessage,
+ react: require.resolve('@librechat/chat/react'),
+ components: require.resolve('@librechat/chat/components'),
+ };
+ import('@librechat/chat').then((esm) => {
+ answer.esmToUIMessage = typeof esm.toUIMessage;
+ process.stdout.write(JSON.stringify(answer));
+ });
+ `;
+ const loaded = run(process.execPath, ['-e', probe]);
+ expect(loaded.status, loaded.output).toBe(0);
+ const answer = JSON.parse(loaded.stdout) as Record<string, string>;
+ expect(answer.contentTypesText).toBe('text');
+ expect(answer.toUIMessage).toBe('function');
+ expect(answer.esmToUIMessage).toBe('function');
+ expect(answer.react).toBe(resolve(dist, 'react.cjs'));
+ expect(answer.components).toBe(resolve(dist, 'components.cjs'));
+ });
+});
diff --git a/e2e/specs/mock/scenarios/css-color-triplets.spec.ts b/e2e/specs/mock/scenarios/css-color-triplets.spec.ts
index b75f951965..3f3f324a8f 100644
--- a/e2e/specs/mock/scenarios/css-color-triplets.spec.ts
+++ b/e2e/specs/mock/scenarios/css-color-triplets.spec.ts
@@ -20,6 +20,7 @@ function scanStylesheet(css: string): { status: number; output: string } {
mkdirSync(join(root, 'scripts'));
mkdirSync(join(root, 'client/src'), { recursive: true });
mkdirSync(join(root, 'packages/client/src'), { recursive: true });
+ mkdirSync(join(root, 'packages/chat/src'), { recursive: true });
copyFileSync(resolve(repoRoot, 'scripts/css-colors.mts'), join(root, 'scripts/css-colors.mts'));
symlinkSync(resolve(repoRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
writeFileSync(join(root, STYLESHEET), css);
diff --git a/e2e/specs/mock/scenarios/suppression-baseline.spec.ts b/e2e/specs/mock/scenarios/suppression-baseline.spec.ts
index 5f1b0e629a..d28c0f5faa 100644
--- a/e2e/specs/mock/scenarios/suppression-baseline.spec.ts
+++ b/e2e/specs/mock/scenarios/suppression-baseline.spec.ts
@@ -1125,6 +1125,8 @@ function syntheticRoot(): string {
write('client/src/Other.tsx', 'export default () => <div className="bg-surface-primary" />;\n');
write('client/src/components/ui/Thing.tsx', 'export const Thing = () => null;\n');
write('packages/client/src/Primitive.tsx', 'export const Primitive = () => null;\n');
+ /** The third root `lint:design:record` names; ESLint fails on a root that matches nothing. */
+ write('packages/chat/src/index.ts', 'export {};\n');
/** A spec beside each of them, under both metadata roots. The real roots are
* full of these — every primitive in `packages/client/src/components` has
* one — and the flat config turns every design rule off inside them, so what
diff --git a/eslint.config.mjs b/eslint.config.mjs
index ee1e7adee5..8ddf00ad8c 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -42,6 +42,99 @@ const tenantModelRestrictions = [
},
];
+/** `@librechat/chat` is consumed by the app, never the reverse: nothing in it reaches into `client/src`. */
+const chatPackageRestrictions = [
+ {
+ group: [
+ '~/*',
+ '**/client/src',
+ '**/client/src/**',
+ '@librechat/frontend',
+ '@librechat/frontend/*',
+ ],
+ message: '@librechat/chat cannot import the app; take what it needs from the host instead.',
+ },
+ {
+ group: ['recoil'],
+ message:
+ '@librechat/chat holds no Recoil state; per-pane run state is Jotai in the React binding.',
+ },
+ {
+ group: ['@librechat/chat', '@librechat/chat/*'],
+ message: '@librechat/chat imports its own modules by relative path, not through its entries.',
+ },
+];
+
+/**
+ * `no-restricted-imports` reads only static imports, so the same boundaries are restated for
+ * `import()` and `require()` of a literal specifier. Each pattern is an esquery regex body, which
+ * cannot hold a slash, so `\x2F` stands for one.
+ */
+const restrictedLoads = (pattern, message) => ({
+ selector: [
+ `ImportExpression[source.value=/${pattern}/]`,
+ `ImportExpression[source.quasis.0.value.cooked=/${pattern}/]`,
+ `CallExpression[callee.name='require'][arguments.0.value=/${pattern}/]`,
+ `CallExpression[callee.name='require'][arguments.0.quasis.0.value.cooked=/${pattern}/]`,
+ ].join(', '),
+ message,
+});
+
+const chatPackageLoads = [
+ restrictedLoads(
+ '^~\\x2F|^@librechat\\x2Ffrontend(\\x2F|$)|(^|\\x2F)client\\x2Fsrc(\\x2F|$)',
+ chatPackageRestrictions[0].message,
+ ),
+ restrictedLoads('^recoil(\\x2F|$)', chatPackageRestrictions[1].message),
+ restrictedLoads('^@librechat\\x2Fchat(\\x2F|$)', chatPackageRestrictions[2].message),
+];
+
+/** Attributes a person reads or hears; a literal in one ships untranslated copy. */
+const chatLiteralAttributeNames =
+ '/^(title|alt|placeholder|label|aria-label|aria-description|aria-placeholder|aria-roledescription|aria-valuetext)$/';
+const chatLiteralAttributes = {
+ selector: [
+ `JSXAttribute[name.name=${chatLiteralAttributeNames}][value.type='Literal'][value.value=/[A-Za-z]/]`,
+ `JSXAttribute[name.name=${chatLiteralAttributeNames}] > JSXExpressionContainer > Literal[value=/[A-Za-z]/]`,
+ `JSXAttribute[name.name=${chatLiteralAttributeNames}] > JSXExpressionContainer > TemplateLiteral[expressions.length=0][quasis.0.value.cooked=/[A-Za-z]/]`,
+ ].join(', '),
+ message: 'Localize user-facing attribute text with useLocalize().',
+};
+
+/** The core entry runs without a UI framework, so a non-React host or a worker can drive a chat. */
+const chatCoreRestrictions = [
+ ...chatPackageRestrictions,
+ {
+ group: [
+ 'react',
+ 'react-dom',
+ 'react-dom/*',
+ 'jotai',
+ 'jotai/*',
+ '@tanstack/*',
+ '@librechat/client',
+ ],
+ message:
+ 'The @librechat/chat core has no UI dependency; React and Jotai belong in the /react entry.',
+ },
+ {
+ group: ['**/components', '**/components/**', '**/components.*', '../**/react.*', './react.*'],
+ message: 'The core cannot import the /react or /components entries; they build on the core.',
+ },
+];
+
+const chatCoreLoads = [
+ ...chatPackageLoads,
+ restrictedLoads(
+ '^(react|react-dom|jotai|@librechat\\x2Fclient)(\\x2F|$)|^@tanstack\\x2F',
+ chatCoreRestrictions[chatPackageRestrictions.length].message,
+ ),
+ restrictedLoads(
+ '(^|\\x2F)components(\\.[cm]?[jt]sx?)?(\\x2F|$)|^\\.\\.?\\x2F(.*\\x2F)?react(\\.[cm]?[jt]sx?)?(\\x2F|$)',
+ chatCoreRestrictions[chatPackageRestrictions.length + 1].message,
+ ),
+];
+
export default [
{
ignores: [
@@ -54,6 +147,7 @@ export default [
'packages/api/test_bundle/**/*',
'api/demo/**/*',
'packages/client/dist/**/*',
+ 'packages/chat/dist/**/*',
'packages/data-provider/types/**/*',
'packages/data-provider/dist/**/*',
'packages/data-provider/test_bundle/**/*',
@@ -199,7 +293,11 @@ export default [
// The client's entry points and helpers are `.jsx`/`.js` — App.jsx among them — so the globs
// name those extensions too: the rules have to see them.
{
- files: ['client/src/**/*.{ts,tsx,js,jsx}', 'packages/client/src/**/*.{ts,tsx,js,jsx}'],
+ files: [
+ 'client/src/**/*.{ts,tsx,js,jsx}',
+ 'packages/client/src/**/*.{ts,tsx,js,jsx}',
+ 'packages/chat/src/**/*.{ts,tsx,js,jsx}',
+ ],
plugins: { shadcn, design },
settings: {
shadcn: {
@@ -341,6 +439,8 @@ export default [
'client/src/**/__tests__/**/*.{ts,tsx,js,jsx}',
'packages/client/src/**/*.{spec,test}.{ts,tsx,js,jsx}',
'packages/client/src/**/__tests__/**/*.{ts,tsx,js,jsx}',
+ 'packages/chat/src/**/*.{spec,test}.{ts,tsx,js,jsx}',
+ 'packages/chat/src/**/__tests__/**/*.{ts,tsx,js,jsx}',
],
rules: {
'design/disabled-recipe': 'off',
@@ -606,4 +706,43 @@ export default [
],
},
},
+ {
+ files: ['packages/chat/src/**/*.{ts,tsx,js,jsx}'],
+ rules: {
+ 'no-restricted-imports': ['error', { patterns: chatPackageRestrictions }],
+ 'no-restricted-syntax': ['error', ...chatPackageLoads],
+ },
+ },
+ {
+ // The app's literal-copy rule skips `packages/**`; chat components render visible text, so it
+ // reaches them. Specs assert rendered strings and stay exempt, as they are in the app.
+ files: ['packages/chat/src/**/*.{tsx,jsx}'],
+ ignores: ['**/*.{spec,test}.{tsx,jsx}', '**/__tests__/**'],
+ rules: {
+ 'i18next/no-literal-string': [
+ 'error',
+ {
+ mode: 'jsx-text-only',
+ 'should-validate-template': true,
+ },
+ ],
+ 'no-restricted-syntax': ['error', ...chatPackageLoads, chatLiteralAttributes],
+ },
+ },
+ {
+ files: ['packages/chat/src/index.ts', 'packages/chat/src/core/**/*.{ts,tsx,js,jsx}'],
+ ignores: ['**/*.{spec,test}.{ts,tsx,js,jsx}'],
+ rules: {
+ 'no-restricted-imports': ['error', { patterns: chatCoreRestrictions }],
+ 'no-restricted-syntax': [
+ 'error',
+ ...chatCoreLoads,
+ {
+ selector: 'JSXElement, JSXFragment',
+ message:
+ 'The @librechat/chat core has no UI dependency; JSX compiles to react/jsx-runtime.',
+ },
+ ],
+ },
+ },
];
diff --git a/package-lock.json b/package-lock.json
index 666d5b90ab..19a4f002a8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9843,6 +9843,10 @@
"resolved": "api",
"link": true
},
+ "node_modules/@librechat/chat": {
+ "resolved": "packages/chat",
+ "link": true
+ },
"node_modules/@librechat/client": {
"resolved": "packages/client",
"link": true
@@ -14919,6 +14923,92 @@
"node": "^20.19.0 || >=22.12.0"
}
},
+ "node_modules/@rolldown/binding-wasm32-wasi": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.1.5.tgz",
+ "integrity": "sha512-VbQGPX2b4r48TAMIM2cjgluIM1HYutm4pcTEJsle7iEP7sB1dFqtPLBVbdLAZCxy1txCcPxf4QFf4v8uvltPqA==",
+ "cpu": [
+ "wasm32"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@emnapi/core": "1.11.1",
+ "@emnapi/runtime": "1.11.1",
+ "@napi-rs/wasm-runtime": "^1.1.6"
+ },
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "node_modules/@rolldown/binding-wasm32-wasi/node_modules/@emnapi/core": {
+ "version": "1.11.1",
+ "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.11.1.tgz",
+ "integrity": "sha512-RSvbQmHzdKzNsLYa/wHrbc3KN4sYLKAdPZxqiM2HATqv/SBk2/ENSHpvXGaLOMcsAyz0poEGqkmmKYG3OWiJEQ==",
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@emnapi/wasi-threads": "1.2.2",
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@rolldown/binding-wasm32-wasi/node_modules/@emnapi/runtime": {
+ "version": "1.11.1",
+ "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.1.tgz",
+ "integrity": "sha512-vgj7R3y3Wgx24IQaGPA/R6YFXLHVMOZ0uVEyIQPaWs+rd1AzfEMXlAC22FYwO1XkKR6NPsq7mUandH8oIRdZFw==",
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@rolldown/binding-wasm32-wasi/node_modules/@emnapi/wasi-threads": {
+ "version": "1.2.2",
+ "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.2.tgz",
+ "integrity": "sha512-c95qOXkHdydNKhscBTebqEC1CVAZpyqOfVfBzQ1qgzyl3gfeldUjIggDbIZgDKsHLgnsM+igH7TJ/eAasaVuMA==",
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@rolldown/binding-wasm32-wasi/node_modules/@napi-rs/wasm-runtime": {
+ "version": "1.2.5",
+ "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.5.tgz",
+ "integrity": "sha512-HshSvXzmBxNzqejd3k/KemgQ3hdREUYFRRrgxOZ+gPljDIsO2SDZrVZMd4Z/HsxudQbE62OVyVFE8z9BCurfjA==",
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@tybys/wasm-util": "^0.10.3"
+ },
+ "engines": {
+ "node": "^20.19.0 || ^22.13.0 || >=23.5.0"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/Brooooooklyn"
+ },
+ "peerDependencies": {
+ "@emnapi/core": "^1.7.1 || ^2.0.0-alpha.4",
+ "@emnapi/runtime": "^1.7.1 || ^2.0.0-alpha.4"
+ }
+ },
+ "node_modules/@rolldown/binding-wasm32-wasi/node_modules/@tybys/wasm-util": {
+ "version": "0.10.4",
+ "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.4.tgz",
+ "integrity": "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==",
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
"node_modules/@rolldown/binding-win32-arm64-msvc": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.6.tgz",
@@ -41450,6 +41540,569 @@
}
}
},
+ "packages/chat": {
+ "name": "@librechat/chat",
+ "version": "0.1.0",
+ "devDependencies": {
+ "@babel/preset-env": "^7.29.5",
+ "@babel/preset-react": "^7.22.15",
+ "@babel/preset-typescript": "^7.21.0",
+ "@types/jest": "^29.5.2",
+ "babel-plugin-replace-ts-export-assignment": "^0.0.2",
+ "jest": "^30.2.0",
+ "librechat-data-provider": "*",
+ "rimraf": "^6.1.3",
+ "tsdown": "0.22.2",
+ "typescript": "^5.9.3"
+ },
+ "peerDependencies": {
+ "librechat-data-provider": "*"
+ }
+ },
+ "packages/chat/node_modules/@babel/generator": {
+ "version": "8.0.0-rc.6",
+ "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-8.0.0-rc.6.tgz",
+ "integrity": "sha512-6mIzgVK8DgEzvIapoQwhXTMnnkuE4STQmVv9H03i/tZ2ml8oev3TRvZJgTenK2Bsq0YWNtzOrFdTyNzCMFtjJQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@babel/parser": "^8.0.0-rc.6",
+ "@babel/types": "^8.0.0-rc.6",
+ "@jridgewell/gen-mapping": "^0.3.12",
+ "@jridgewell/trace-mapping": "^0.3.28",
+ "@types/jsesc": "^2.5.0",
+ "jsesc": "^3.0.2"
+ },
+ "engines": {
+ "node": "^22.18.0 || >=24.11.0"
+ }
+ },
+ "packages/chat/node_modules/@babel/helper-string-parser": {
+ "version": "8.0.6",
+ "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-8.0.6.tgz",
+ "integrity": "sha512-+6HYEBnsDRZHJtUTAEfMQd0zMDqdFHS7C+5vAsEZqBUr3vEMWOWlHJ0Jz1gS8jJIlCvLsuA6ivmeoqzH936YcA==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": "^22.18.0 || >=24.11.0"
+ }
+ },
+ "packages/chat/node_modules/@babel/helper-validator-identifier": {
+ "version": "8.0.0-rc.6",
+ "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-8.0.0-rc.6.tgz",
+ "integrity": "sha512-nVJ+1JcCgntv8d78rRo++o2wuODT0Irknx2BF8Np4Ft2CRgjLqIs4qzSZ8b66yGbBdMWGmZBO9WEZv1hhNiSpg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": "^22.18.0 || >=24.11.0"
+ }
+ },
+ "packages/chat/node_modules/@babel/parser": {
+ "version": "8.0.0-rc.6",
+ "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-8.0.0-rc.6.tgz",
+ "integrity": "sha512-rOS8IpdO7mQELkTPlCsTgPejO0bFuZdEDCGQJouYbYf9e1FLTym7Fei2pEjq8q7MWbX0ravcd7QQYKs1TxOuog==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@babel/types": "^8.0.0-rc.6"
+ },
+ "bin": {
+ "parser": "bin/babel-parser.js"
+ },
+ "engines": {
+ "node": "^22.18.0 || >=24.11.0"
+ }
+ },
+ "packages/chat/node_modules/@babel/types": {
+ "version": "8.0.6",
+ "resolved": "https://registry.npmjs.org/@babel/types/-/types-8.0.6.tgz",
+ "integrity": "sha512-c+xgSWboV2pdwXP67BUWDVRHi2BO5Q3KwxyFVs7taVTY+fsK47/L51ZXQoV9rozHJDNHvJ4v4WEsI/IlxV2l2A==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@babel/helper-string-parser": "^8.0.6",
+ "@babel/helper-validator-identifier": "^8.0.6"
+ },
+ "engines": {
+ "node": "^22.18.0 || >=24.11.0"
+ }
+ },
+ "packages/chat/node_modules/@babel/types/node_modules/@babel/helper-validator-identifier": {
+ "version": "8.0.6",
+ "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-8.0.6.tgz",
+ "integrity": "sha512-HYx0YmuchRxRSpnjvcNffnPS8DCauKNmnumIuHG3jnQAVewRA7kfJGwF13ayEpSZs7s4R/oBH4eppuXcAQd5JQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": "^22.18.0 || >=24.11.0"
+ }
+ },
+ "packages/chat/node_modules/@oxc-project/types": {
+ "version": "0.139.0",
+ "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.139.0.tgz",
+ "integrity": "sha512-r9gHphtCs+1M7J0pw6Sn/hh/Wpa/iQrOOkrNAlVLF/gHq+/CJmHIWKKUUhdWjcD6CIa8idarspCsASiXCXvFUw==",
+ "dev": true,
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/Boshen"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-android-arm64": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.1.5.tgz",
+ "integrity": "sha512-lZg8fqIv2v7FF237bwMgzGZEJvGL79/s5knJ/i6FmsGF4XXlzccZ4jb+TrFIxtSSxFtIpdsgrPZeMk1I9AFcyQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-darwin-arm64": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.1.5.tgz",
+ "integrity": "sha512-51Bnx9pNiMRKSUNtBfySkNJ9vMU9Hh3I1ozDd6gyPPYzaXCfnptUcEZxXGYFn+ul2dtcMUiqGR1Yai2K10uoTw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-darwin-x64": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.1.5.tgz",
+ "integrity": "sha512-Tm+gbfC0aHu1tBA/JvKQh32S0K6YgCHkiAF4/W6xX0K0RmNuc94VeK419dJoE65R5aRxmo+noZQSWrAMF6yb6g==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-freebsd-x64": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.1.5.tgz",
+ "integrity": "sha512-JMzDKCCXq93YccG5gz3hvOs1oXRKAf0XYpfOS88e+wZrC8Iugj6j68867vrYZkvpDDpKn/KoKORThmchMpF6TA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-linux-arm-gnueabihf": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.1.5.tgz",
+ "integrity": "sha512-uML21j2K5TfPGutKxub+M+nLjZIrWjXQ5Grx4lCe/nimTj9B4L63zHpjXLl4y0L3mcm2htEQIb06oCG/szerNw==",
+ "cpu": [
+ "arm"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-linux-arm64-gnu": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.1.5.tgz",
+ "integrity": "sha512-navSiuTMogvnQoZoM/v+l3ZWo50/NTwSHSzheABx/RCnmUPaKwq9qSo4Br2OYRs21+Fz8uFqITZM3H4opOB0/Q==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "libc": [
+ "glibc"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-linux-arm64-musl": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.1.5.tgz",
+ "integrity": "sha512-lAryqH7IteztmCXQXk0etKj4wBQ7Gx5S6LjKhsgp9zb8I5bsuvU/2llH1hDQcjsFeqIsovMVN339/8pUDDBXxA==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "libc": [
+ "musl"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-linux-ppc64-gnu": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.1.5.tgz",
+ "integrity": "sha512-fsK/sNBnxzBlL4O1JNrZakVQxPspqpED5dLtNsZS9oOKmtSpdNIzxH2kkol5HYTWJN47sE20ztMJPxfZ89qGOg==",
+ "cpu": [
+ "ppc64"
+ ],
+ "dev": true,
+ "libc": [
+ "glibc"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-linux-s390x-gnu": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.1.5.tgz",
+ "integrity": "sha512-gLYb4BIadlfTOYT5gO503n8zQjXflgzpD0FcyKh0Mzx3rqCZKnHoJWV9xe1KXUJ5lx2JfcSHr/mhzS0PC/McAA==",
+ "cpu": [
+ "s390x"
+ ],
+ "dev": true,
+ "libc": [
+ "glibc"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-linux-x64-gnu": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.1.5.tgz",
+ "integrity": "sha512-FjcpEKUyJygHgs1o50VYNvkt5+7Le/VEdYt0AkRpkL33MnyQfwr8l5mXwMmfmTbyMPr5vJLC+8/Gd9gXnwU1QQ==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "libc": [
+ "glibc"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-linux-x64-musl": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.1.5.tgz",
+ "integrity": "sha512-Me+PfPI2TMeOQk0gYWfLQZtTktrmzbr8cDboqX83XKc7UrgAi55gF+2dUkWdxd19n55Essp2yeca+O9N5rBxHg==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "libc": [
+ "musl"
+ ],
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-openharmony-arm64": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.1.5.tgz",
+ "integrity": "sha512-yc5WrLzXks6zCQfn9Oxr8pORKyl/pF+QjHmW/Qx3qu0oyrrNC+y2JLTU1E2rcWYAmzlnqngWXHQjy51VzW70Vw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "openharmony"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-win32-arm64-msvc": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.1.5.tgz",
+ "integrity": "sha512-gHv82k63z4qpV5+Q1y/12KrK0ltWBukVDI8nZcbT7Tt/ZlOIVwppazneq0F93oDxTo3IgAMEDIoQh3E2n6mVsw==",
+ "cpu": [
+ "arm64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/@rolldown/binding-win32-x64-msvc": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.1.5.tgz",
+ "integrity": "sha512-tTZuDBPw85tEN5PQi1pnEBzDy0Z49HtScLAbD5t6hyeU92A95pRWaSMw1GZZi/RwgSgUIl0xrSlXIT/9QzvYSA==",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ }
+ },
+ "packages/chat/node_modules/get-tsconfig": {
+ "version": "5.0.0-beta.5",
+ "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-5.0.0-beta.5.tgz",
+ "integrity": "sha512-/6gFNr0N04nob252sTQxyFLi3eKFRqIg1I87YcqAMT1i6SQrSF6KujUEQrtrjMV0H/eejTCltLdDSTEMzHbnsQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "resolve-pkg-maps": "^1.0.0"
+ },
+ "engines": {
+ "node": ">=20.20.0"
+ },
+ "funding": {
+ "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1"
+ }
+ },
+ "packages/chat/node_modules/picomatch": {
+ "version": "4.0.7",
+ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz",
+ "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/jonschlinkert"
+ }
+ },
+ "packages/chat/node_modules/rimraf": {
+ "version": "6.1.3",
+ "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-6.1.3.tgz",
+ "integrity": "sha512-LKg+Cr2ZF61fkcaK1UdkH2yEBBKnYjTyWzTJT6KNPcSPaiT7HSdhtMXQuN5wkTX0Xu72KQ1l8S42rlmexS2hSA==",
+ "dev": true,
+ "license": "BlueOak-1.0.0",
+ "dependencies": {
+ "glob": "^13.0.3",
+ "package-json-from-dist": "^1.0.1"
+ },
+ "bin": {
+ "rimraf": "dist/esm/bin.mjs"
+ },
+ "engines": {
+ "node": "20 || >=22"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/isaacs"
+ }
+ },
+ "packages/chat/node_modules/rolldown": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.1.5.tgz",
+ "integrity": "sha512-t9z29cJjXf/vxQ8dyhCSpt6H6aSwHTk8cT5I3iy6SMXuFpk5mB6PL6XfC8PCwrPTx93udwKUm9HRteAlTGBLiA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@oxc-project/types": "=0.139.0",
+ "@rolldown/pluginutils": "^1.0.0"
+ },
+ "bin": {
+ "rolldown": "bin/cli.mjs"
+ },
+ "engines": {
+ "node": "^20.19.0 || >=22.12.0"
+ },
+ "optionalDependencies": {
+ "@rolldown/binding-android-arm64": "1.1.5",
+ "@rolldown/binding-darwin-arm64": "1.1.5",
+ "@rolldown/binding-darwin-x64": "1.1.5",
+ "@rolldown/binding-freebsd-x64": "1.1.5",
+ "@rolldown/binding-linux-arm-gnueabihf": "1.1.5",
+ "@rolldown/binding-linux-arm64-gnu": "1.1.5",
+ "@rolldown/binding-linux-arm64-musl": "1.1.5",
+ "@rolldown/binding-linux-ppc64-gnu": "1.1.5",
+ "@rolldown/binding-linux-s390x-gnu": "1.1.5",
+ "@rolldown/binding-linux-x64-gnu": "1.1.5",
+ "@rolldown/binding-linux-x64-musl": "1.1.5",
+ "@rolldown/binding-openharmony-arm64": "1.1.5",
+ "@rolldown/binding-wasm32-wasi": "1.1.5",
+ "@rolldown/binding-win32-arm64-msvc": "1.1.5",
+ "@rolldown/binding-win32-x64-msvc": "1.1.5"
+ }
+ },
+ "packages/chat/node_modules/tsdown": {
+ "version": "0.22.2",
+ "resolved": "https://registry.npmjs.org/tsdown/-/tsdown-0.22.2.tgz",
+ "integrity": "sha512-VX9gsyKXsTnBZjnIM4jsHl9aRv+GfgkE/k1hQslilaBfZMlaw3JuGR+6yhiU0QxWBtOCDnTjwOSoXzgB7Rr50g==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "ansis": "^4.3.1",
+ "cac": "^7.0.0",
+ "defu": "^6.1.7",
+ "empathic": "^2.0.1",
+ "hookable": "^6.1.1",
+ "import-without-cache": "^0.4.0",
+ "obug": "^2.1.1",
+ "picomatch": "^4.0.4",
+ "rolldown": "~1.1.0",
+ "rolldown-plugin-dts": "^0.25.2",
+ "semver": "^7.8.1",
+ "tinyexec": "^1.2.4",
+ "tinyglobby": "^0.2.17",
+ "tree-kill": "^1.2.2",
+ "unconfig-core": "^7.5.0"
+ },
+ "bin": {
+ "tsdown": "dist/run.mjs"
+ },
+ "engines": {
+ "node": "^22.18.0 || >=24.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/sxzz"
+ },
+ "peerDependencies": {
+ "@arethetypeswrong/core": "^0.18.1",
+ "@tsdown/css": "0.22.2",
+ "@tsdown/exe": "0.22.2",
+ "@vitejs/devtools": "*",
+ "publint": "^0.3.8",
+ "tsx": "*",
+ "typescript": "^5.0.0 || ^6.0.0",
+ "unplugin-unused": "^0.5.0",
+ "unrun": "*"
+ },
+ "peerDependenciesMeta": {
+ "@arethetypeswrong/core": {
+ "optional": true
+ },
+ "@tsdown/css": {
+ "optional": true
+ },
+ "@tsdown/exe": {
+ "optional": true
+ },
+ "@vitejs/devtools": {
+ "optional": true
+ },
+ "publint": {
+ "optional": true
+ },
+ "tsx": {
+ "optional": true
+ },
+ "typescript": {
+ "optional": true
+ },
+ "unplugin-unused": {
+ "optional": true
+ },
+ "unrun": {
+ "optional": true
+ }
+ }
+ },
+ "packages/chat/node_modules/tsdown/node_modules/rolldown-plugin-dts": {
+ "version": "0.25.2",
+ "resolved": "https://registry.npmjs.org/rolldown-plugin-dts/-/rolldown-plugin-dts-0.25.2.tgz",
+ "integrity": "sha512-nMhN/R+vmR8GM45ZW1FWMSjRTSDDn/6w4GTf8RNrEFCBdl8B1kySWrU1ixPtbwzXoRlcO+R/S88VgXuJQwfdDg==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@babel/generator": "8.0.0-rc.6",
+ "@babel/helper-validator-identifier": "8.0.0-rc.6",
+ "@babel/parser": "8.0.0-rc.6",
+ "ast-kit": "^3.0.0-beta.1",
+ "birpc": "^4.0.0",
+ "dts-resolver": "^3.0.0",
+ "get-tsconfig": "5.0.0-beta.5",
+ "obug": "^2.1.1"
+ },
+ "engines": {
+ "node": "^22.18.0 || >=24.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/sxzz"
+ },
+ "peerDependencies": {
+ "@ts-macro/tsc": "^0.3.6",
+ "@typescript/native-preview": ">=7.0.0-dev.20260325.1",
+ "rolldown": "^1.0.0",
+ "typescript": "^5.0.0 || ^6.0.0",
+ "vue-tsc": "~3.2.0"
+ },
+ "peerDependenciesMeta": {
+ "@ts-macro/tsc": {
+ "optional": true
+ },
+ "@typescript/native-preview": {
+ "optional": true
+ },
+ "typescript": {
+ "optional": true
+ },
+ "vue-tsc": {
+ "optional": true
+ }
+ }
+ },
"packages/client": {
"name": "@librechat/client",
"version": "0.4.82",
diff --git a/package.json b/package.json
index 12cc394b80..4927ac8a5c 100644
--- a/package.json
+++ b/package.json
@@ -59,11 +59,12 @@
"build:data-schemas": "cd packages/data-schemas && npm run build",
"build:client": "cd client && npm run build",
"build:client-package": "cd packages/client && npm run build",
- "build:packages": "npm run build:data-provider && npm run build:data-schemas && npm run build:api && npm run build:client-package",
+ "build:chat": "cd packages/chat && npm run build",
+ "build:packages": "npm run build:data-provider && npm run build:data-schemas && npm run build:api && npm run build:client-package && npm run build:chat",
"build": "npx turbo run build",
"build:safe": "npx turbo run build --no-daemon",
- "frontend": "npm run build:data-provider && npm run build:data-schemas && npm run build:api && npm run build:client-package && cd client && npm run build",
- "frontend:ci": "npm run build:data-provider && npm run build:client-package && cd client && npm run build:ci",
+ "frontend": "npm run build:data-provider && npm run build:data-schemas && npm run build:api && npm run build:client-package && npm run build:chat && cd client && npm run build",
+ "frontend:ci": "npm run build:data-provider && npm run build:client-package && npm run build:chat && cd client && npm run build:ci",
"frontend:dev": "cd client && npm run dev",
"e2e:prepare": "npm run frontend",
"test:client-build": "node --test e2e/client-build.test.mjs",
@@ -107,16 +108,17 @@
"test:packages:api": "cd packages/api && npm run test:ci",
"test:packages:data-provider": "cd packages/data-provider && npm run test:ci",
"test:packages:data-schemas": "cd packages/data-schemas && npm run test:ci",
+ "test:packages:chat": "npm run build:data-provider && cd packages/chat && npm run test:ci",
"test:config": "jest --config config/jest.config.js",
- "test:all": "npm run test:client && npm run test:api && npm run test:packages:api && npm run test:packages:data-provider && npm run test:packages:data-schemas",
- "test:turbo": "turbo run test:ci --concurrency=2 --filter=@librechat/frontend --filter=@librechat/client --filter=@librechat/backend --filter=@librechat/api --filter=librechat-data-provider --filter=@librechat/data-schemas",
+ "test:all": "npm run test:client && npm run test:api && npm run test:packages:api && npm run test:packages:data-provider && npm run test:packages:data-schemas && npm run test:packages:chat",
+ "test:turbo": "turbo run test:ci --concurrency=2 --filter=@librechat/frontend --filter=@librechat/client --filter=@librechat/backend --filter=@librechat/api --filter=librechat-data-provider --filter=@librechat/data-schemas --filter=@librechat/chat",
"e2e:update": "npm run e2e:prepare && playwright test --config=e2e/playwright.config.local.ts --update-snapshots",
"e2e:report": "npx playwright show-report e2e/playwright-report",
"lint:fix": "npm run build:client-package && eslint . --fix --pass-on-unpruned-suppressions",
"lint": "npm run build:client-package && eslint . --pass-on-unpruned-suppressions",
- "lint:design:record": "npm run build:client-package && eslint --no-warn-ignored --suppress-rule shadcn/no-restyle --suppress-rule shadcn/no-raw-colors --suppress-rule shadcn/no-arbitrary-values --suppress-rule shadcn/no-inline-styles --suppress-rule shadcn/require-static-classes --suppress-rule shadcn/no-unknown-classes --suppress-rule design/disabled-recipe client/src packages/client/src",
+ "lint:design:record": "npm run build:client-package && eslint --no-warn-ignored --suppress-rule shadcn/no-restyle --suppress-rule shadcn/no-raw-colors --suppress-rule shadcn/no-arbitrary-values --suppress-rule shadcn/no-inline-styles --suppress-rule shadcn/require-static-classes --suppress-rule shadcn/no-unknown-classes --suppress-rule design/disabled-recipe client/src packages/client/src packages/chat/src",
"lint:design:suppress": "(npm run --silent lint:design:record || node -e \"\") && npm run lint:design:prune",
- "lint:design:prune": "npm run build:client-package && eslint --no-warn-ignored --prune-suppressions client/src packages/client/src",
+ "lint:design:prune": "npm run build:client-package && eslint --no-warn-ignored --prune-suppressions client/src packages/client/src packages/chat/src",
"sort-imports": "node scripts/sort-imports.mts",
"sort-imports:check": "node scripts/sort-imports.mts --check",
"static-checks": "node scripts/static-checks.mts",
@@ -127,10 +129,11 @@
"b:api:dev": "NODE_ENV=production bun run --watch api/server/index.js",
"b:data": "cd packages/data-provider && bun run b:build",
"b:build:client-package": "cd packages/client && bun run b:build",
+ "b:build:chat": "cd packages/chat && bun run b:build",
"b:data-schemas": "cd packages/data-schemas && bun run b:build",
"b:build:api": "cd packages/api && bun run b:build",
"b:build:client": "cd client && bun --bun run b:build",
- "b:client": "bun --bun run b:data && bun --bun run b:data-schemas && bun --bun run b:build:api && bun --bun run b:build:client-package && bun --bun run b:build:client",
+ "b:client": "bun --bun run b:data && bun --bun run b:data-schemas && bun --bun run b:build:api && bun --bun run b:build:client-package && bun --bun run b:build:chat && bun --bun run b:build:client",
"b:client:dev": "cd client && bun run b:dev",
"b:test:client": "cd client && bun run b:test",
"b:test:api": "cd api && bun run b:test",
diff --git a/packages/chat/babel.config.js b/packages/chat/babel.config.js
new file mode 100644
index 0000000000..5970459434
--- /dev/null
+++ b/packages/chat/babel.config.js
@@ -0,0 +1,8 @@
+module.exports = {
+ presets: [
+ ['@babel/preset-env', { targets: { node: 'current' } }],
+ ['@babel/preset-react', { runtime: 'automatic' }],
+ '@babel/preset-typescript',
+ ],
+ plugins: ['babel-plugin-replace-ts-export-assignment'],
+};
diff --git a/packages/chat/jest.config.js b/packages/chat/jest.config.js
new file mode 100644
index 0000000000..3bb01a29a8
--- /dev/null
+++ b/packages/chat/jest.config.js
@@ -0,0 +1,11 @@
+const { maxWorkers } = require('../../config/jest.workers.cjs');
+
+module.exports = {
+ collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!<rootDir>/node_modules/'],
+ coveragePathIgnorePatterns: ['/node_modules/', '/dist/'],
+ coverageReporters: ['text', 'cobertura'],
+ maxWorkers,
+ restoreMocks: true,
+ // The core runs without a DOM; a React spec opts into jsdom with a docblock.
+ testEnvironment: 'node',
+};
diff --git a/packages/chat/package.json b/packages/chat/package.json
new file mode 100644
index 0000000000..db73d16416
--- /dev/null
+++ b/packages/chat/package.json
@@ -0,0 +1,75 @@
+{
+ "name": "@librechat/chat",
+ "version": "0.1.0",
+ "private": true,
+ "description": "Chat state, transport and message components for LibreChat",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/LibreChat-AI/LibreChat"
+ },
+ "sideEffects": false,
+ "main": "dist/index.cjs",
+ "module": "dist/index.mjs",
+ "types": "./dist/index.d.cts",
+ "exports": {
+ ".": {
+ "import": {
+ "types": "./dist/index.d.mts",
+ "default": "./dist/index.mjs"
+ },
+ "require": {
+ "types": "./dist/index.d.cts",
+ "default": "./dist/index.cjs"
+ }
+ },
+ "./react": {
+ "import": {
+ "types": "./dist/react.d.mts",
+ "default": "./dist/react.mjs"
+ },
+ "require": {
+ "types": "./dist/react.d.cts",
+ "default": "./dist/react.cjs"
+ }
+ },
+ "./components": {
+ "import": {
+ "types": "./dist/components.d.mts",
+ "default": "./dist/components.mjs"
+ },
+ "require": {
+ "types": "./dist/components.d.cts",
+ "default": "./dist/components.cjs"
+ }
+ },
+ "./package.json": "./package.json"
+ },
+ "files": [
+ "dist"
+ ],
+ "scripts": {
+ "clean": "rimraf dist",
+ "b:clean": "bun run rimraf dist",
+ "build": "npm run clean && tsdown",
+ "b:build": "bun run b:clean && bun run tsdown",
+ "build:watch": "tsdown --watch",
+ "typecheck": "tsc --noEmit",
+ "test": "jest",
+ "test:ci": "jest --ci"
+ },
+ "peerDependencies": {
+ "librechat-data-provider": "*"
+ },
+ "devDependencies": {
+ "@babel/preset-env": "^7.29.5",
+ "@babel/preset-react": "^7.22.15",
+ "@babel/preset-typescript": "^7.21.0",
+ "@types/jest": "^29.5.2",
+ "babel-plugin-replace-ts-export-assignment": "^0.0.2",
+ "jest": "^30.2.0",
+ "librechat-data-provider": "*",
+ "rimraf": "^6.1.3",
+ "tsdown": "0.22.2",
+ "typescript": "^5.9.3"
+ }
+}
diff --git a/packages/chat/src/__tests__/core.spec.ts b/packages/chat/src/__tests__/core.spec.ts
new file mode 100644
index 0000000000..6b754997d3
--- /dev/null
+++ b/packages/chat/src/__tests__/core.spec.ts
@@ -0,0 +1,47 @@
+const UI_MODULES: string[] = [
+ 'react',
+ 'react-dom',
+ 'jotai',
+ 'recoil',
+ '@tanstack/react-query',
+ '@librechat/client',
+];
+
+beforeAll(() => {
+ for (const name of UI_MODULES) {
+ jest.doMock(
+ name,
+ () => {
+ throw new Error(`the core entry imported ${name}`);
+ },
+ { virtual: true },
+ );
+ }
+});
+
+describe('@librechat/chat core entry', () => {
+ it('runs without a DOM', () => {
+ expect(typeof window).toBe('undefined');
+ expect(typeof document).toBe('undefined');
+ });
+
+ it('loads without React, Jotai, Recoil, React Query or the component library', async () => {
+ const core = await import('../index');
+ expect(core.ContentTypes.TEXT).toBe('text');
+ expect(typeof core.toUIMessage).toBe('function');
+ expect(typeof core.fromUIMessage).toBe('function');
+ expect(typeof core.isUIToolPart).toBe('function');
+ expect(typeof core.isUIDataPart).toBe('function');
+ });
+
+ it('re-exports the data-provider message mapping unchanged', async () => {
+ const core = await import('../index');
+ const provider = await import('librechat-data-provider');
+ expect(core.toUIMessage).toBe(provider.toUIMessage);
+ expect(core.fromUIMessage).toBe(provider.fromUIMessage);
+ });
+
+ it('fails when a UI module is imported, so the guard above is live', async () => {
+ await expect(import('react')).rejects.toThrow('the core entry imported react');
+ });
+});
diff --git a/packages/chat/src/__tests__/jsx.spec.ts b/packages/chat/src/__tests__/jsx.spec.ts
new file mode 100644
index 0000000000..33e3ddf5cc
--- /dev/null
+++ b/packages/chat/src/__tests__/jsx.spec.ts
@@ -0,0 +1,13 @@
+import path from 'node:path';
+import { transformSync } from '@babel/core';
+
+describe('@librechat/chat jest transform', () => {
+ it('compiles TSX to the automatic React runtime', () => {
+ const output = transformSync('export const Probe = (): JSX.Element => <div />;\n', {
+ filename: path.join(__dirname, 'Probe.tsx'),
+ configFile: path.resolve(__dirname, '../../babel.config.js'),
+ });
+ expect(output?.code).toContain('react/jsx-runtime');
+ expect(output?.code).not.toContain('<div');
+ });
+});
diff --git a/packages/chat/src/components.ts b/packages/chat/src/components.ts
new file mode 100644
index 0000000000..8464f3bcb2
--- /dev/null
+++ b/packages/chat/src/components.ts
@@ -0,0 +1,2 @@
+/** Themed message and part components. Populated as the components move in. */
+export {};
diff --git a/packages/chat/src/core/index.ts b/packages/chat/src/core/index.ts
new file mode 100644
index 0000000000..fcb073fefc
--- /dev/null
+++ b/packages/chat/src/core/index.ts
@@ -0,0 +1 @@
+export * from './types';
diff --git a/packages/chat/src/core/types.ts b/packages/chat/src/core/types.ts
new file mode 100644
index 0000000000..885f229f65
--- /dev/null
+++ b/packages/chat/src/core/types.ts
@@ -0,0 +1,363 @@
+import type {
+ TUser,
+ Agents,
+ TModelSpec,
+ RetentionMode,
+ TPayload,
+ TMessage,
+ TEphemeralAgent,
+ ChatEvent,
+ TConversation,
+ TPendingSteer,
+ TAgentQueuedTurnReceipt,
+ TEnqueueAgentQueuedTurnRequest,
+} from 'librechat-data-provider';
+
+export type {
+ TMessage,
+ ChatEvent,
+ UIMessage,
+ UIToolPart,
+ UIDataPart,
+ UITextPart,
+ UIMessagePart,
+ UIReasoningPart,
+ TMessageContentParts,
+} from 'librechat-data-provider';
+export {
+ ContentTypes,
+ toUIMessage,
+ fromUIMessage,
+ isUIToolPart,
+ isUIDataPart,
+} from 'librechat-data-provider';
+
+/**
+ * Where a chat is in its turn. AI SDK: `ChatStatus`.
+ * `submitted` until the first event of the response is applied, `streaming` until the terminal
+ * event, then `ready`, or `error` until the error is cleared.
+ */
+export type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
+
+/**
+ * Whether the chat holds a live stream. Orthogonal to {@link ChatStatus}: a dropped connection
+ * stays `streaming` while it is `reconnecting`, because the server keeps generating.
+ */
+export type ChatConnection = 'idle' | 'live' | 'reconnecting';
+
+/** A value, or a function that produces it on demand. AI SDK: `Resolvable`. */
+export type Resolvable<T> = T | (() => T | Promise<T>);
+
+/** Per-request additions a caller layers over the transport's defaults. AI SDK: `ChatRequestOptions`. */
+export type ChatRequestOptions = {
+ headers?: Record<string, string>;
+ body?: object;
+};
+
+/** What started a stream. AI SDK: `trigger`, plus LibreChat's continue. */
+export type ChatTrigger = 'submit-message' | 'regenerate-message' | 'continue-message';
+
+/** One attached response stream: the events in wire order, ending at the terminal one. */
+export type ChatStream = AsyncIterable<ChatEvent> & {
+ /** The server's id for the generation, when it names one; what a reconnect addresses. */
+ readonly streamId?: string;
+ /**
+ * When the server started this generation. A stream id is reused across a conversation's turns,
+ * so an abort carries this to stop only the generation it means.
+ */
+ readonly generationCreatedAt?: number;
+ /** The generation protocol the server selected for this stream; missing or `1` is legacy. */
+ readonly generationProtocolVersion?: number;
+ /** The start attached to a generation already running for this turn instead of starting one. */
+ readonly resumed?: boolean;
+ close(): void;
+};
+
+/**
+ * How a start ended. `settled`: the turn already reached its terminal state, so there is nothing
+ * to attach to. `replaced`: a newer generation owns the conversation; the caller attaches to it
+ * or reports the conflict.
+ */
+export type ChatSendResult =
+ | { status: 'stream'; stream: ChatStream }
+ | { status: 'settled'; conversationId: string; generationProtocolVersion?: number }
+ | {
+ status: 'replaced';
+ conversationId: string;
+ streamId: string;
+ generationCreatedAt: number;
+ /** Both control outcomes are v2-only; a caller trusts them only when this says `2`. */
+ generationProtocolVersion?: number;
+ };
+
+export type ChatSendRequest = ChatRequestOptions & {
+ trigger: ChatTrigger;
+ chatId: string;
+ messageId?: string;
+ payload: TPayload;
+ abortSignal?: AbortSignal;
+};
+
+export type ChatReconnectRequest = ChatRequestOptions & {
+ chatId: string;
+ streamId?: string;
+ /** Replays the generation so far before live events, for a client that missed them. */
+ resume?: boolean;
+ /** The {@link ChatStream.generationCreatedAt} to reattach to, so a newer run is not attached instead. */
+ generationCreatedAt?: number;
+ abortSignal?: AbortSignal;
+};
+
+export type ChatAbortRequest = {
+ chatId: string;
+ streamId?: string;
+ /** The {@link ChatStream.generationCreatedAt} of the run to stop; a newer run is left running. */
+ generationCreatedAt?: number;
+ endpoint: string;
+ /**
+ * `conversationId:responseMessageId` of a run with no resumable stream (Assistants), which the
+ * endpoint's own abort route addresses instead of a stream id.
+ */
+ abortKey?: string;
+};
+
+/** What the server did with a stop request for a resumable generation. */
+export type ChatStreamAbortResult = {
+ success: boolean;
+ generationProtocolVersion?: number;
+ /** The id of the stream that was stopped. */
+ aborted?: string;
+ streamId?: string;
+ /** The run reached its own terminal state first, so no abort event follows. */
+ settled?: boolean;
+ terminalStatus?: 'complete' | 'error' | 'aborted';
+ /** The run stopped but its terminal state was not saved; the queue must not drain behind it. */
+ persistenceFailed?: boolean;
+ /** Steers the run never injected, handed back so they can be restored. */
+ pendingSteers?: TPendingSteer[];
+ code?: string;
+ error?: string;
+};
+
+/**
+ * An Assistants stop, addressed by `abortKey`. That stream ends without a final event of its own,
+ * so the stop's response carries the terminal conversation and messages; `null` when there was no
+ * run left to stop.
+ */
+export type ChatRunAbortResult = {
+ final: true;
+ conversation: Partial<TConversation>;
+ runMessages: TMessage[];
+} | null;
+
+export type ChatAbortResult = ChatStreamAbortResult | ChatRunAbortResult;
+
+/** Text folded into the running generation at its next injection boundary. */
+export type ChatSteerRequest = {
+ conversationId: string;
+ /** The generation being steered; a steer for a finished generation is refused. */
+ generationCreatedAt?: number;
+ /** Correlates terminal events that can arrive before the steer is acknowledged. */
+ clientSteerId?: string;
+ text: string;
+ files?: TMessage['files'];
+ /** Quoted excerpts sent with the text, merged into the turn at the injection boundary. */
+ quotes?: string[];
+ /** Asks to interrupt the running step instead of waiting for a tool boundary. */
+ preempt?: boolean;
+};
+
+/** The server queued the steer; `settled` and `leftover` mark a receipt replayed after the run ended. */
+export type ChatSteerResult = {
+ generationProtocolVersion?: number;
+ status: 'queued';
+ steerId: string;
+ position: number;
+ conversationId: string;
+ preempt?: boolean;
+ preemptRevision?: number;
+ /** Whether the server kept the quotes; when absent they are restored to the composer. */
+ quotesAccepted?: boolean;
+ settled?: boolean;
+ leftover?: boolean;
+ replayed?: boolean;
+};
+
+/** Identifies a queued steer of one generation. */
+export type ChatSteerTarget = {
+ conversationId: string;
+ steerId: string;
+ generationCreatedAt?: number;
+};
+
+/** `removed: false` means the cancel lost its race with the injection or the run's end. */
+export type ChatCancelSteerResult = { generationProtocolVersion?: number; removed?: boolean };
+
+/** `armed: false` means the steer already injected, was cancelled, or cannot interrupt here. */
+export type ChatArmSteerResult = {
+ generationProtocolVersion?: number;
+ armed?: boolean;
+ code?: string;
+ preemptRevision?: number;
+};
+
+/** The server's view of a conversation's generation, read before reattaching. */
+export type ChatStreamStatus = {
+ generationProtocolVersion?: number;
+ active: boolean;
+ streamId?: string;
+ status?: 'running' | 'complete' | 'error' | 'aborted' | 'requires_action';
+ /** Content generated so far, for a client that reattaches mid-turn. */
+ aggregatedContent?: Array<{ type: string; text?: string }>;
+ createdAt?: number;
+ /** Generation age on the server's clock, so elapsed time survives clock skew. */
+ elapsedMs?: number;
+ resumeState?: Agents.ResumeState;
+ isTemporary?: boolean;
+ /** The pending approval while `status` is `requires_action`. */
+ pendingAction?: Agents.PendingAction;
+ /** Steers a terminal drain parked because no subscriber was live; restored as queued. */
+ unrecoveredSteers?: TPendingSteer[];
+};
+
+/** The agent selection a paused generation resumes with, matching its original request. */
+export type ChatResumeSelection = {
+ conversationId: string;
+ /** The paused generation being resumed. */
+ generationCreatedAt: number;
+ endpoint?: string | null;
+ endpointType?: string | null;
+ agent_id?: string | null;
+ model?: string | null;
+ spec?: string | null;
+ promptPrefix?: string | null;
+ ephemeralAgent?: TEphemeralAgent | null;
+ isTemporary?: boolean;
+};
+
+/** Answers a paused generation: tool approval decisions, or an ask-user reply. */
+export type ChatResumeRequest = ChatResumeSelection & { actionId: string } & (
+ | { decisions: Agents.ToolApprovalResolution[] }
+ | { answer?: string; answers?: Record<string, string> }
+ );
+
+/** The continuation streams over the stream already attached. */
+export type ChatResumeResult = {
+ generationProtocolVersion?: number;
+ streamId: string;
+ conversationId: string;
+ status: 'resuming';
+};
+
+/**
+ * A failed transport request. `code` is `ERR_NETWORK` when the request never got a response, so a
+ * caller can tell an ambiguous failure from a refusal; `response.data` carries the server's reason,
+ * such as `NO_ACTIVE_RUN`, `RUN_PAUSED`, `STEER_UNSUPPORTED` or `RUN_REPLACED`.
+ */
+export type ChatTransportError = Error & {
+ code?: string;
+ response?: { status: number; data: unknown; headers: Record<string, string> };
+};
+
+/**
+ * The wire a chat runs over. AI SDK: `ChatTransport`, with LibreChat's two-step run underneath:
+ * a turn is started by a POST and then attached to, so `reconnectToStream` can reattach to a
+ * generation the server kept running. The steer and queue methods are optional capabilities; a chat
+ * reports them as unsupported when the transport leaves them out.
+ */
+export interface ChatTransport {
+ /** Starts a turn, then attaches to its stream. Rejects with a {@link ChatTransportError}. */
+ sendMessages(request: ChatSendRequest): Promise<ChatSendResult>;
+ /** Attaches to the running generation, or resolves `null` when nothing is running. */
+ reconnectToStream(request: ChatReconnectRequest): Promise<ChatStream | null>;
+ /**
+ * Stops the running generation; its stream then reports the abort, unless the result says it
+ * settled first. A request with `abortKey` resolves to a {@link ChatRunAbortResult}.
+ */
+ abort(request: ChatAbortRequest): Promise<ChatAbortResult>;
+ close?(): void;
+ /** Reads the conversation's generation state; what a reload checks before reattaching. */
+ getStatus?(conversationId: string): Promise<ChatStreamStatus>;
+ /** Resumes a paused generation with approval decisions or an ask-user reply. */
+ resume?(request: ChatResumeRequest): Promise<ChatResumeResult>;
+ /** Folds text into the running generation. */
+ steer?(request: ChatSteerRequest): Promise<ChatSteerResult>;
+ /** Withdraws a steer that has not been injected yet. */
+ cancelSteer?(
+ request: ChatSteerTarget & { clientSteerId?: string },
+ ): Promise<ChatCancelSteerResult>;
+ /** Escalates a queued steer to interrupt the running step. */
+ armSteer?(request: ChatSteerTarget): Promise<ChatArmSteerResult>;
+ listQueued?(
+ conversationId: string,
+ clientRequestIds?: string[],
+ ): Promise<TAgentQueuedTurnReceipt[]>;
+ enqueue?(input: TEnqueueAgentQueuedTurnRequest): Promise<TAgentQueuedTurnReceipt>;
+ cancelQueued?(input: {
+ conversationId: string;
+ queuedTurnId: string;
+ }): Promise<TAgentQueuedTurnReceipt>;
+}
+
+/** Composer action while a run is in flight: fold the text into the run, or queue a new turn. */
+export type DuringRunAction = 'steer' | 'interrupt' | 'queue';
+
+/** App-global preferences the chat reads but does not own. */
+export type ChatHostSettings = {
+ duringRunDefaultAction: DuringRunAction;
+ setDuringRunDefaultAction: (action: DuringRunAction) => void;
+ /** Closes the artifacts panel, called when the active conversation changes. */
+ resetVisibleArtifacts: () => void;
+ /** Whether composer text and attachments are kept as drafts across navigation. */
+ saveDrafts: boolean;
+ /** Whether new turns are sent as a temporary chat that the server does not retain. */
+ isTemporary: boolean;
+ setIsTemporary: (value: boolean | ((previous: boolean) => boolean)) => void;
+};
+
+/** The deployment configuration the chat reads. */
+export type ChatHostConfig = {
+ /** How long the deployment keeps conversations; forced temporary retention hides saving paths. */
+ retentionMode?: RetentionMode;
+ /** Whether replies offer rating feedback. */
+ feedbackEnabled: boolean;
+ /** Whether a running chat can be renamed, because the deployment protects a manual title. */
+ canRenameRunningChat: boolean;
+ /** Model specs the deployment offers, for the presets and token limits a spec carries. */
+ modelSpecs?: TModelSpec[];
+ balanceEnabled: boolean;
+ queuedSendLockTimeoutMs?: number;
+ queuedTurnReconciliationTimeoutMs?: number;
+ steerArmConfirmationTimeoutMs?: number;
+};
+
+export type ChatHostAuth = {
+ headers: Resolvable<Record<string, string>>;
+ /** Resolves a fresh token after a 401, or `undefined` when the session cannot be refreshed. */
+ refreshToken?: () => Promise<string | undefined>;
+ /** Fills user variables such as `{{current_user}}` in a conversation's prompt prefix. */
+ user?: TUser;
+};
+
+export type ChatHostNavigation = {
+ /** Moves the `new` route onto the conversation the server created, without a history entry. */
+ replaceNewConversationUrl(conversationId: string): void;
+ onConversationCreated?(conversation: TConversation): void;
+};
+
+export type ChatNotification = {
+ message: string;
+ status: 'error' | 'info' | 'success';
+};
+
+/**
+ * Everything app-global a chat needs, supplied by the app that hosts it. Nothing in the package
+ * reads the app's stores, startup config or auth context; the host passes them in here.
+ */
+export type ChatHost = {
+ settings: ChatHostSettings;
+ config: ChatHostConfig;
+ auth: ChatHostAuth;
+ navigation: ChatHostNavigation;
+ notify?: (notification: ChatNotification) => void;
+};
diff --git a/packages/chat/src/index.ts b/packages/chat/src/index.ts
new file mode 100644
index 0000000000..4b0e041376
--- /dev/null
+++ b/packages/chat/src/index.ts
@@ -0,0 +1 @@
+export * from './core';
diff --git a/packages/chat/src/react.ts b/packages/chat/src/react.ts
new file mode 100644
index 0000000000..f2ee47cbd7
--- /dev/null
+++ b/packages/chat/src/react.ts
@@ -0,0 +1,2 @@
+/** React bindings for the core `Chat`: providers and `useChat`. Populated as the hooks move in. */
+export {};
diff --git a/packages/chat/tsconfig.json b/packages/chat/tsconfig.json
new file mode 100644
index 0000000000..ff6ee0f3bb
--- /dev/null
+++ b/packages/chat/tsconfig.json
@@ -0,0 +1,24 @@
+{
+ "compilerOptions": {
+ "target": "ES2020",
+ "module": "ESNext",
+ "moduleResolution": "bundler",
+ "jsx": "react-jsx",
+ "jsxImportSource": "react",
+ "declaration": true,
+ "declarationMap": true,
+ "isolatedDeclarations": true,
+ "sourceMap": true,
+ "esModuleInterop": true,
+ "allowSyntheticDefaultImports": true,
+ "strict": true,
+ "skipLibCheck": true,
+ "forceConsistentCasingInFileNames": true,
+ "outDir": "./dist",
+ "rootDir": "./src",
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
+ "types": ["jest"]
+ },
+ "include": ["src/**/*"],
+ "exclude": ["dist", "node_modules"]
+}
diff --git a/packages/chat/tsdown.config.mjs b/packages/chat/tsdown.config.mjs
new file mode 100644
index 0000000000..9c1c1a9bc1
--- /dev/null
+++ b/packages/chat/tsdown.config.mjs
@@ -0,0 +1,25 @@
+import path from 'node:path';
+import { defineConfig } from 'tsdown';
+
+export default defineConfig({
+ entry: {
+ index: 'src/index.ts',
+ react: 'src/react.ts',
+ components: 'src/components.ts',
+ },
+ format: ['esm', 'cjs'],
+ platform: 'browser',
+ dts: { oxc: true },
+ outDir: 'dist',
+ sourcemap: true,
+ checks: { circularDependency: true },
+ // Same as @librechat/client: the package stays CommonJS for its jest and babel configs while
+ // shipping .mjs/.cjs pairs.
+ fixedExtension: true,
+ // Every third-party import is a peer the consuming app provides; only the package's own
+ // relative sources are bundled.
+ deps: {
+ neverBundle: (id) => !id.startsWith('.') && !path.isAbsolute(id),
+ onlyBundle: false,
+ },
+});
diff --git a/scripts/css-colors.mts b/scripts/css-colors.mts
index 6263ef6d90..f7b4619533 100644
--- a/scripts/css-colors.mts
+++ b/scripts/css-colors.mts
@@ -16,7 +16,7 @@ export interface CssColorFinding {
literal: string;
}
-export const CSS_ROOTS = ['client/src', 'packages/client/src'];
+export const CSS_ROOTS = ['client/src', 'packages/client/src', 'packages/chat/src'];
/** Theme token sources (allowlist.md entry 1): their custom property declarations may hold a literal or a channel triplet. */
export const CSS_COLOR_ALLOWED_FILES = [
diff --git a/scripts/sort-imports.mts b/scripts/sort-imports.mts
index a4cb1308f4..f003c88b8d 100644
--- a/scripts/sort-imports.mts
+++ b/scripts/sort-imports.mts
@@ -34,6 +34,7 @@ const SOURCE_ROOTS = [
'packages/data-provider/src',
'packages/data-schemas/src',
'packages/client/src',
+ 'packages/chat/src',
];
const SOURCE_DIRS = SOURCE_ROOTS.map((rel) => resolve(ROOT, rel));
diff --git a/scripts/static-checks.mts b/scripts/static-checks.mts
index 35c0bc2e11..eda1c75c17 100644
--- a/scripts/static-checks.mts
+++ b/scripts/static-checks.mts
@@ -91,6 +91,7 @@ const FILTERS = {
'**/eslint-suppressions.json',
'client/src/**',
'packages/client/src/**',
+ 'packages/chat/src/**',
/** The bundle the rules resolve primitives through is named by the library's
* manifest, produced by its build config and shaped by its compiler
* options. */
@@ -114,8 +115,10 @@ const FILTERS = {
css_colors: [
'client/src/*.css',
'packages/client/src/*.css',
+ 'packages/chat/src/*.css',
'client/src/**/*.css',
'packages/client/src/**/*.css',
+ 'packages/chat/src/**/*.css',
'packages/client/src/theme/allowlist.md',
/** The scanner parses with postcss: an upgrade changes what it reads. */
'package.json',
@@ -132,6 +135,7 @@ const FILTERS = {
'api/**',
'client/src/**',
'packages/client/**',
+ 'packages/chat/src/**',
'packages/data-provider/src/**',
'packages/data-schemas/src/**',
'.github/workflows/static-checks.yml',
@@ -163,6 +167,7 @@ const FILTERS = {
'client/**',
'packages/api/**',
'packages/client/**',
+ 'packages/chat/**',
// Every workspace manifest PACKAGE_JSON_FILES validates, plus the ones
// whose dependencies feed the unused-package calculation through
// api/package.json's @librechat/data-schemas entry.
@@ -193,6 +198,7 @@ const PACKAGE_JSON_FILES = [
'api/package.json',
'packages/api/package.json',
'packages/client/package.json',
+ 'packages/chat/package.json',
'packages/data-provider/package.json',
'packages/data-schemas/package.json',
];
@@ -242,8 +248,8 @@ const DESIGN_METADATA_FILES = [
'packages/client/tsconfig.json',
];
-/** The two trees the design rules police, and what `lint:design:record` records. */
-const DESIGN_ROOTS = ['client/src', 'packages/client/src'];
+/** The trees the design rules police, and what `lint:design:record` records. */
+const DESIGN_ROOTS = ['client/src', 'packages/client/src', 'packages/chat/src'];
/**
* This runner is the gate the record is measured against: `unusedCapacity` and
@@ -302,6 +308,7 @@ const I18N_SOURCE_DIRS = [
'api',
'packages/data-provider/src',
'packages/client',
+ 'packages/chat/src',
'packages/data-schemas/src',
];
@@ -1945,6 +1952,17 @@ const TYPECHECK_PROJECTS = [
],
requires: ['build:data-provider'],
},
+ {
+ project: 'packages/chat/tsconfig.json',
+ paths: [
+ 'packages/data-provider/**',
+ 'packages/chat/**',
+ ...ROOT_MANIFESTS,
+ FRONTEND_REVIEW,
+ '!**.md',
+ ],
+ requires: ['build:data-provider'],
+ },
{
project: 'client/tsconfig.json',
paths: [
@@ -2094,23 +2112,32 @@ async function findUnusedPackages(): Promise<CheckOutcome> {
return { ok: true, skipped: 'depcheck is not installed — npm install -g depcheck' };
}
- const [rootManifest, clientManifest, apiManifest, packagesClientManifest, packagesApiManifest] =
+ const [
+ rootManifest,
+ clientManifest,
+ apiManifest,
+ packagesClientManifest,
+ packagesApiManifest,
+ packagesChatManifest,
+ ] = await Promise.all([
+ readManifest('package.json'),
+ readManifest('client/package.json'),
+ readManifest('api/package.json'),
+ readManifest('packages/client/package.json'),
+ readManifest('packages/api/package.json'),
+ readManifest('packages/chat/package.json'),
+ ]);
+
+ const [rootCode, clientCode, apiCode, packagesClientCode, packagesApiCode, packagesChatCode] =
await Promise.all([
- readManifest('package.json'),
- readManifest('client/package.json'),
- readManifest('api/package.json'),
- readManifest('packages/client/package.json'),
- readManifest('packages/api/package.json'),
+ importedPackages('.'),
+ importedPackages('client'),
+ importedPackages('api'),
+ importedPackages('packages/client'),
+ importedPackages('packages/api'),
+ importedPackages('packages/chat'),
]);
- const [rootCode, clientCode, apiCode, packagesClientCode, packagesApiCode] = await Promise.all([
- importedPackages('.'),
- importedPackages('client'),
- importedPackages('api'),
- importedPackages('packages/client'),
- importedPackages('packages/api'),
- ]);
-
const targets = [
{
name: 'Root',
@@ -2143,6 +2170,12 @@ async function findUnusedPackages(): Promise<CheckOutcome> {
],
ignored: new Set<string>(),
},
+ {
+ name: 'Chat',
+ dir: resolve(ROOT, 'packages/chat'),
+ allowed: [scriptWords(packagesChatManifest), packagesChatCode],
+ ignored: new Set<string>(),
+ },
];
const findings: string[] = [];
diff --git a/turbo.json b/turbo.json
index 9a3ee708a4..52228390a9 100644
--- a/turbo.json
+++ b/turbo.json
@@ -70,6 +70,17 @@
],
"outputs": ["dist/**"],
"env": ["NODE_ENV", "VITE_ENABLE_LOGGER", "VITE_LOGGER_FILTER"]
+ },
+ "@librechat/chat#build": {
+ "dependsOn": ["^build", "librechat-data-provider#build", "@librechat/client#build"],
+ "inputs": [
+ "$TURBO_DEFAULT$",
+ "!**/__tests__/**",
+ "!**/__mocks__/**",
+ "!**/*.test.*",
+ "!**/*.spec.*"
+ ],
+ "outputs": ["dist/**"]
}
}
}