Skip to content

Commit

Permalink
feat: init the chrom extension
Browse files Browse the repository at this point in the history
xingwanying committed Jul 17, 2024
1 parent b6a1ca0 commit 728ce29
Showing 24 changed files with 12,205 additions and 2 deletions.
3 changes: 3 additions & 0 deletions extension/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions extension/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
22 changes: 22 additions & 0 deletions extension/export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// create out directory for static Chrome Extension

const fs = require('fs');
const glob = require('glob');

const files = glob.sync('out/**/*.html');
files.forEach((file) => {
const content = fs.readFileSync(file, 'utf-8');
const modifiedContent = content.replace(/\/_next/g, './next');
fs.writeFileSync(file, modifiedContent, 'utf-8');
});

const sourcePath = 'out/_next';
const destinationPath = 'out/next';

fs.rename(sourcePath, destinationPath, (err) => {
if (err) {
console.error('Rename failed:', err);
} else {
console.log('Rename successfully.');
}
});
17 changes: 17 additions & 0 deletions extension/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
output: 'export',

// Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
// trailingSlash: true,

// Optional: Prevent automatic `/me` -> `/me/`, instead preserve `href`
// skipTrailingSlashRedirect: true,

// Optional: Change the output directory `out` -> `dist`
// distDir: 'dist',
}

module.exports = nextConfig
40 changes: 40 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "extension",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "npm run prep",
"prep": "next build && node export.js",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"autoprefixer": "^10.4.19",
"css-loader": "^7.1.2",
"mini-css-extract-plugin": "^2.9.0",
"next": "14.2.5",
"next-compose-plugins": "^2.2.1",
"petercat-lui": "^0.0.24",
"postcss-loader": "^8.1.1",
"react": "^18",
"react-dom": "^18",
"style-loader": "^4.0.0"
},
"devDependencies": {
"@types/chrome": "^0.0.268",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.5",
"next-transpile-modules": "^10.0.1",
"postcss": "^8",
"tailwindcss": "^3.4.6",
"ts-loader": "^9.5.1",
"typescript": "^5",
"webpack": "^5.93.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
}
}
6 changes: 6 additions & 0 deletions extension/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
3 changes: 3 additions & 0 deletions extension/public/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chrome.sidePanel
.setPanelBehavior({ openPanelOnActionClick: true })
.catch((error) => console.error(error));
Binary file added extension/public/icons/logo-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/public/icons/logo-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/public/icons/logo-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/public/icons/logo-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions extension/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"manifest_version": 3,
"name": "PeterCat",
"short_name": "petercat",
"version": "0.0.1",
"description": "petercat, your github Q&A assitant",
"icons": {
"16": "/icons/logo-16.png",
"32": "/icons/logo-32.png",
"48": "/icons/logo-48.png",
"192": "/icons/logo-192.png"
},
"background": {
"service_worker": "background.js"
},
"action": {
"default_title": "点击打开侧边栏"
},
"side_panel": {
"default_path": "index.html"
},
"permissions": ["sidePanel"]
}
Binary file added extension/src/app/favicon.ico
Binary file not shown.
33 changes: 33 additions & 0 deletions extension/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}

@layer utilities {
.text-balance {
text-wrap: balance;
}
}
19 changes: 19 additions & 0 deletions extension/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Metadata } from 'next';
import './globals.css';

export const metadata: Metadata = {
title: 'PeterCat',
description: 'Create your own Q&A bot',
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="zh-CN">
<body>{children}</body>
</html>
);
}
18 changes: 18 additions & 0 deletions extension/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use client';

export default function Home() {
return (
<main
style={{
width: '100vw',
height: '100vh',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: '64px',
}}
>
<h1>PeterCat</h1>
</main>
);
}
14 changes: 14 additions & 0 deletions extension/src/components/ChatPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client';
import { Chat } from 'petercat-lui';
import React from 'react';
const ChatPanel = () => {
return (
<Chat
apiDomain="https://api.petercat.chat"
apiUrl="/api/chat/stream_qa"
token="594dc633-acf6-4fed-a52d-c5852c6f4694"
/>
);
};

export default ChatPanel;
20 changes: 20 additions & 0 deletions extension/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Config } from "tailwindcss";

const config: Config = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
backgroundImage: {
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
"gradient-conic":
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
},
},
},
plugins: [],
};
export default config;
27 changes: 27 additions & 0 deletions extension/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"outDir": "./dist",
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
24 changes: 24 additions & 0 deletions extension/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const path = require('path');

module.exports = {
entry: {
background: './src/background/background.ts',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
mode: "production",
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
};
11,859 changes: 11,859 additions & 0 deletions extension/yarn.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions lui/src/Chat/index.tsx
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import type {
} from '@ant-design/pro-chat';
import { ProChat } from '@ant-design/pro-chat';
import { Markdown } from '@ant-design/pro-editor';

import { isEmpty, map } from 'lodash';
import React, {
ReactNode,
@@ -16,6 +15,7 @@ import React, {
useState,
type FC,
} from 'react';
import useSWR from 'swr';
import StopBtn from '../StopBtn';
import ThoughtChain from '../ThoughtChain';
import SignatureIcon from '../icons/SignatureIcon';
@@ -26,7 +26,6 @@ import { convertChunkToJson, handleStream } from '../utils';
import InputArea from './inputArea/InputArea';
import Actions from './inputArea/actions';

import useSWR from 'swr';
import '../style/global.css';

export interface BotInfo {
4 changes: 4 additions & 0 deletions lui/src/style/global.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

.leftMessageContent .ant-pro-chat-list-item-message-content{
padding: 8px 16px 8px 16px;
gap: 0px;

0 comments on commit 728ce29

Please sign in to comment.