Skip to content

Commit 48ed0e9

Browse files
committed
setup for fixing images and gptr_api_url for npm package
1 parent eefa4cc commit 48ed0e9

9 files changed

+32
-66
lines changed

frontend/nextjs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GPT Researcher UI
22

3-
A React component library for integrating the GPT Researcher interface into your React applications.
3+
A React component library for integrating the GPT Researcher interface into your React applications. Take it for a test ride with the [GPTR React Starter Template](https://github.com/elishakay/gpt-researcher-react), or simply:
44

55
## Installation
66

frontend/nextjs/helpers/getHost.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ interface GetHostParams {
55
export const getHost = ({ purpose }: GetHostParams = {}): string => {
66
if (typeof window !== 'undefined') {
77
let { host } = window.location;
8-
if (process.env.NEXT_PUBLIC_GPTR_API_URL) {
9-
return process.env.NEXT_PUBLIC_GPTR_API_URL;
8+
if (process.env.REACT_APP_GPTR_API_URL || process.env.NEXT_PUBLIC_GPTR_API_URL) {
9+
return process.env.REACT_APP_GPTR_API_URL || process.env.NEXT_PUBLIC_GPTR_API_URL;
1010
} else if (purpose === 'langgraph-gui') {
1111
return host.includes('localhost') ? 'http%3A%2F%2F127.0.0.1%3A8123' : `https://${host}`;
1212
} else {

frontend/nextjs/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
{
22
"name": "gpt-researcher-ui",
33
"description": "GPT Researcher frontend as a React component",
4-
"version": "0.1.59",
4+
"version": "0.1.62",
55
"main": "dist/index.js",
66
"module": "dist/index.esm.js",
77
"types": "dist/index.d.ts",
88
"files": [
99
"dist",
1010
"styles/*",
1111
"app/globals.css",
12-
"components/Settings/App.css",
13-
"public/*",
14-
"src/utils/injectFavicons.ts"
12+
"components/Settings/App.css"
1513
],
1614
"private": false,
1715
"scripts": {

frontend/nextjs/rollup.config.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import json from '@rollup/plugin-json';
77
import postcss from 'rollup-plugin-postcss';
88
import tailwindcss from 'tailwindcss';
99
import autoprefixer from 'autoprefixer';
10+
import imageTransformPlugin from './src/utils/imageTransformPlugin';
1011

1112
const removeUseClientPlugin = {
1213
name: 'remove-use-client',
@@ -41,11 +42,7 @@ export default {
4142
}),
4243
json(), // Add this plugin to handle JSON files
4344
removeUseClientPlugin,
44-
// alias({
45-
// entries: [
46-
// { find: '@', replacement: path.resolve(__dirname, 'src') }
47-
// ]
48-
// }),
45+
imageTransformPlugin(),
4946
resolve({
5047
extensions: ['.js', '.jsx', '.ts', '.tsx'],
5148
browser: true, // Ensures it only includes browser-compatible modules

frontend/nextjs/src/GPTResearcher.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface GPTResearcherProps {
2424
}
2525

2626
export const GPTResearcher = ({
27-
apiUrl = process.env.NEXT_PUBLIC_GPTR_API_URL || 'http://localhost:8000',
27+
apiUrl = process.env.REACT_PUBLIC_GPTR_API_URL || process.env.NEXT_PUBLIC_GPTR_API_URL || 'http://localhost:8000',
2828
apiKey = '',
2929
defaultPrompt = '',
3030
onResultsChange,
@@ -51,6 +51,14 @@ export const GPTResearcher = ({
5151
const [showScrollButton, setShowScrollButton] = useState(false);
5252
const mainContentRef = useRef<HTMLDivElement>(null);
5353

54+
useEffect(() => {
55+
if (apiUrl) {
56+
// Update both environment variables when apiUrl prop changes
57+
process.env.REACT_APP_GPTR_API_URL = apiUrl;
58+
process.env.NEXT_PUBLIC_GPTR_API_URL = apiUrl;
59+
}
60+
}, [apiUrl]);
61+
5462
// Update callback when results change
5563
useEffect(() => {
5664
if (onResultsChange && orderedData.length > 0) {

frontend/nextjs/src/components/GptResearcher.jsx

-42
This file was deleted.

frontend/nextjs/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// src/index.ts
22
import { GPTResearcher } from './GPTResearcher';
3-
export { injectFavicons } from './utils/injectFavicons';
43

54
export { GPTResearcher };
65
export type { GPTResearcherProps } from './GPTResearcher';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// rollup-image-transform-plugin.js
2+
export default function imageTransformPlugin() {
3+
return {
4+
name: 'image-transform',
5+
transform(code) {
6+
// Replace all relative image paths with absolute URLs
7+
return code.replace(
8+
/'img\/([^']+)'/g,
9+
"'https://gptr.app/img/$1'"
10+
).replace(
11+
/"img\/([^"]+)"/g,
12+
'"https://gptr.app/img/$1"'
13+
);
14+
}
15+
};
16+
}

frontend/nextjs/src/utils/injectFavicons.ts

-10
This file was deleted.

0 commit comments

Comments
 (0)