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<> $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 = () =>
;\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

Hello world

;\n}\n'); + expect(messagesFor(literal, 'i18next/no-literal-string')).toHaveLength(1); + + const labels = lintStdin( + path, + 'export function Probe() {\n return