refactor: different Jan builds should have different Cortex server port (#4699)

* refactor: different Jan instances should have different Cortex server port configurations

* chore: update workflow to use env input

* chore: update env for cortex port setting
This commit is contained in:
Louis 2025-02-20 15:53:16 +07:00 committed by GitHub
parent eba6884abb
commit badc632ee4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 45 additions and 22 deletions

View File

@ -18,6 +18,7 @@ jobs:
public_provider: github public_provider: github
new_version: ${{ needs.get-update-version.outputs.new_version }} new_version: ${{ needs.get-update-version.outputs.new_version }}
beta: true beta: true
cortex_api_port: "39271"
build-windows-x64: build-windows-x64:
uses: ./.github/workflows/template-build-windows-x64.yml uses: ./.github/workflows/template-build-windows-x64.yml
@ -28,6 +29,7 @@ jobs:
public_provider: github public_provider: github
new_version: ${{ needs.get-update-version.outputs.new_version }} new_version: ${{ needs.get-update-version.outputs.new_version }}
beta: true beta: true
cortex_api_port: "39271"
build-linux-x64: build-linux-x64:
uses: ./.github/workflows/template-build-linux-x64.yml uses: ./.github/workflows/template-build-linux-x64.yml
@ -38,6 +40,7 @@ jobs:
public_provider: github public_provider: github
new_version: ${{ needs.get-update-version.outputs.new_version }} new_version: ${{ needs.get-update-version.outputs.new_version }}
beta: true beta: true
cortex_api_port: "39271"
sync-temp-to-latest: sync-temp-to-latest:
needs: [build-macos, build-windows-x64, build-linux-x64] needs: [build-macos, build-windows-x64, build-linux-x64]

View File

@ -55,6 +55,7 @@ jobs:
ref: ${{ needs.set-public-provider.outputs.ref }} ref: ${{ needs.set-public-provider.outputs.ref }}
public_provider: ${{ needs.set-public-provider.outputs.public_provider }} public_provider: ${{ needs.set-public-provider.outputs.public_provider }}
new_version: ${{ needs.get-update-version.outputs.new_version }} new_version: ${{ needs.get-update-version.outputs.new_version }}
cortex_api_port: "39261"
build-windows-x64: build-windows-x64:
uses: ./.github/workflows/template-build-windows-x64.yml uses: ./.github/workflows/template-build-windows-x64.yml
@ -64,6 +65,7 @@ jobs:
ref: ${{ needs.set-public-provider.outputs.ref }} ref: ${{ needs.set-public-provider.outputs.ref }}
public_provider: ${{ needs.set-public-provider.outputs.public_provider }} public_provider: ${{ needs.set-public-provider.outputs.public_provider }}
new_version: ${{ needs.get-update-version.outputs.new_version }} new_version: ${{ needs.get-update-version.outputs.new_version }}
cortex_api_port: "39261"
build-linux-x64: build-linux-x64:
@ -74,6 +76,7 @@ jobs:
ref: ${{ needs.set-public-provider.outputs.ref }} ref: ${{ needs.set-public-provider.outputs.ref }}
public_provider: ${{ needs.set-public-provider.outputs.public_provider }} public_provider: ${{ needs.set-public-provider.outputs.public_provider }}
new_version: ${{ needs.get-update-version.outputs.new_version }} new_version: ${{ needs.get-update-version.outputs.new_version }}
cortex_api_port: "39261"
sync-temp-to-latest: sync-temp-to-latest:
needs: [set-public-provider, build-windows-x64, build-linux-x64, build-macos] needs: [set-public-provider, build-windows-x64, build-linux-x64, build-macos]

View File

@ -23,6 +23,10 @@ on:
required: false required: false
type: boolean type: boolean
default: false default: false
cortex_api_port:
required: false
type: string
default: null
secrets: secrets:
DELTA_AWS_S3_BUCKET_NAME: DELTA_AWS_S3_BUCKET_NAME:
required: false required: false
@ -115,6 +119,7 @@ jobs:
AWS_MAX_ATTEMPTS: '5' AWS_MAX_ATTEMPTS: '5'
POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }} POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}
POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }} POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }}
CORTEX_API_PORT: ${{ inputs.cortex_api_port }}
- name: Build and publish app to github - name: Build and publish app to github
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && inputs.public_provider == 'github' && inputs.beta == false if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && inputs.public_provider == 'github' && inputs.beta == false

View File

@ -23,6 +23,10 @@ on:
required: false required: false
type: boolean type: boolean
default: false default: false
cortex_api_port:
required: false
type: string
default: null
secrets: secrets:
DELTA_AWS_S3_BUCKET_NAME: DELTA_AWS_S3_BUCKET_NAME:
required: false required: false
@ -154,6 +158,7 @@ jobs:
AWS_MAX_ATTEMPTS: '5' AWS_MAX_ATTEMPTS: '5'
POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }} POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}
POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }} POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }}
CORTEX_API_PORT: ${{ inputs.cortex_api_port }}
- name: Build and publish app to github - name: Build and publish app to github
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && inputs.public_provider == 'github' && inputs.beta == false if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && inputs.public_provider == 'github' && inputs.beta == false

View File

@ -23,6 +23,10 @@ on:
required: false required: false
type: boolean type: boolean
default: false default: false
cortex_api_port:
required: false
type: string
default: null
secrets: secrets:
DELTA_AWS_S3_BUCKET_NAME: DELTA_AWS_S3_BUCKET_NAME:
required: false required: false
@ -153,6 +157,7 @@ jobs:
AWS_MAX_ATTEMPTS: '5' AWS_MAX_ATTEMPTS: '5'
POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }} POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}
POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }} POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }}
CORTEX_API_PORT: ${{ inputs.cortex_api_port }}
- name: Build app and publish app to github - name: Build app and publish app to github
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && inputs.public_provider == 'github' && inputs.beta == false if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && inputs.public_provider == 'github' && inputs.beta == false

View File

@ -26,6 +26,9 @@ export default defineConfig([
resolve: { resolve: {
extensions: ['.js', '.ts'], extensions: ['.js', '.ts'],
}, },
define: {
CORTEX_API_URL: JSON.stringify(`http://127.0.0.1:${process.env.CORTEX_API_PORT ?? "39291"}`),
},
platform: 'node', platform: 'node',
}, },
]) ])

View File

@ -1,2 +1,3 @@
declare const NODE: string declare const NODE: string
declare const VERSION: string declare const VERSION: string
declare const CORTEX_API_URL: string

View File

@ -28,7 +28,7 @@ export class Retrieval {
this.timeWeightedVectorStore = new MemoryVectorStore( this.timeWeightedVectorStore = new MemoryVectorStore(
new OpenAIEmbeddings( new OpenAIEmbeddings(
{ openAIApiKey: 'cortex-embedding' }, { openAIApiKey: 'cortex-embedding' },
{ basePath: 'http://127.0.0.1:39291/v1' } { basePath: `${CORTEX_API_URL}/v1` }
) )
) )
this.timeWeightedretriever = new TimeWeightedVectorStoreRetriever({ this.timeWeightedretriever = new TimeWeightedVectorStoreRetriever({
@ -51,7 +51,7 @@ export class Retrieval {
this.embeddingModel = new OpenAIEmbeddings( this.embeddingModel = new OpenAIEmbeddings(
{ openAIApiKey: 'cortex-embedding', model }, { openAIApiKey: 'cortex-embedding', model },
// TODO: Raw settings // TODO: Raw settings
{ basePath: 'http://127.0.0.1:39291/v1' } { basePath: `${CORTEX_API_URL}/v1` }
) )
// update time-weighted embedding model // update time-weighted embedding model

View File

@ -8,7 +8,6 @@ export default defineConfig({
}, },
platform: 'browser', platform: 'browser',
define: { define: {
API_URL: JSON.stringify('http://127.0.0.1:39291'), API_URL: JSON.stringify(`http://127.0.0.1:${process.env.CORTEX_API_PORT ?? "39291"}`),
SOCKET_URL: JSON.stringify('ws://127.0.0.1:39291'),
}, },
}) })

View File

@ -1,5 +1,4 @@
declare const API_URL: string declare const API_URL: string
declare const SOCKET_URL: string
interface Core { interface Core {
api: APIFunctions api: APIFunctions

View File

@ -11,8 +11,7 @@ export default defineConfig([
}, },
define: { define: {
NODE: JSON.stringify(`${pkgJson.name}/${pkgJson.node}`), NODE: JSON.stringify(`${pkgJson.name}/${pkgJson.node}`),
API_URL: JSON.stringify('http://127.0.0.1:39291'), API_URL: JSON.stringify(`http://127.0.0.1:${process.env.CORTEX_API_PORT ?? "39291"}`),
SOCKET_URL: JSON.stringify('ws://127.0.0.1:39291'),
PLATFORM: JSON.stringify(process.platform), PLATFORM: JSON.stringify(process.platform),
CORTEX_ENGINE_VERSION: JSON.stringify('v0.1.49'), CORTEX_ENGINE_VERSION: JSON.stringify('v0.1.49'),
DEFAULT_REMOTE_ENGINES: JSON.stringify(engines), DEFAULT_REMOTE_ENGINES: JSON.stringify(engines),

View File

@ -1,7 +1,6 @@
declare const API_URL: string declare const API_URL: string
declare const CORTEX_ENGINE_VERSION: string declare const CORTEX_ENGINE_VERSION: string
declare const PLATFORM: string declare const PLATFORM: string
declare const SOCKET_URL: string
declare const NODE: string declare const NODE: string
declare const DEFAULT_REQUEST_PAYLOAD_TRANSFORM: string declare const DEFAULT_REQUEST_PAYLOAD_TRANSFORM: string
declare const DEFAULT_RESPONSE_BODY_TRANSFORM: string declare const DEFAULT_RESPONSE_BODY_TRANSFORM: string

View File

@ -10,8 +10,7 @@ export default defineConfig([
}, },
define: { define: {
NODE: JSON.stringify(`${pkgJson.name}/${pkgJson.node}`), NODE: JSON.stringify(`${pkgJson.name}/${pkgJson.node}`),
API_URL: JSON.stringify('http://127.0.0.1:39291'), API_URL: JSON.stringify(`http://127.0.0.1:${process.env.CORTEX_API_PORT ?? "39291"}`),
SOCKET_URL: JSON.stringify('ws://127.0.0.1:39291'),
}, },
}, },
]) ])

View File

@ -1,5 +1,4 @@
declare const API_URL: string declare const API_URL: string
declare const SOCKET_URL: string
declare const NODE: string declare const NODE: string
interface Core { interface Core {

View File

@ -122,8 +122,8 @@ export default defineConfig([
]), ]),
NODE: JSON.stringify(`${packageJson.name}/${packageJson.node}`), NODE: JSON.stringify(`${packageJson.name}/${packageJson.node}`),
SETTINGS: JSON.stringify(defaultSettingJson), SETTINGS: JSON.stringify(defaultSettingJson),
CORTEX_API_URL: JSON.stringify('http://127.0.0.1:39291'), CORTEX_API_URL: JSON.stringify(`http://127.0.0.1:${process.env.CORTEX_API_PORT ?? "39291"}`),
CORTEX_SOCKET_URL: JSON.stringify('ws://127.0.0.1:39291'), CORTEX_SOCKET_URL: JSON.stringify(`ws://127.0.0.1:${process.env.CORTEX_API_PORT ?? "39291"}`),
CORTEX_ENGINE_VERSION: JSON.stringify('v0.1.49'), CORTEX_ENGINE_VERSION: JSON.stringify('v0.1.49'),
}, },
}, },
@ -139,6 +139,9 @@ export default defineConfig([
resolve: { resolve: {
extensions: ['.js', '.ts', '.json'], extensions: ['.js', '.ts', '.json'],
}, },
define: {
CORTEX_API_URL: JSON.stringify(`http://127.0.0.1:${process.env.CORTEX_API_PORT ?? "39291"}`),
},
platform: 'node', platform: 'node',
}, },
]) ])

View File

@ -3,13 +3,11 @@ import {
appResourcePath, appResourcePath,
getJanDataFolderPath, getJanDataFolderPath,
log, log,
SystemInformation,
} from '@janhq/core/node' } from '@janhq/core/node'
import { ProcessWatchdog } from './watchdog' import { ProcessWatchdog } from './watchdog'
import { readdir, symlink } from 'fs/promises'
// The HOST address to use for the Nitro subprocess // The HOST address to use for the Nitro subprocess
const LOCAL_PORT = '39291' const LOCAL_PORT = CORTEX_API_URL.split(":").pop() ?? "39291"
let watchdog: ProcessWatchdog | undefined = undefined let watchdog: ProcessWatchdog | undefined = undefined
/** /**

View File

@ -11,8 +11,7 @@ export default defineConfig({
platform: 'browser', platform: 'browser',
define: { define: {
SETTINGS: JSON.stringify(settingJson), SETTINGS: JSON.stringify(settingJson),
API_URL: JSON.stringify('http://127.0.0.1:39291'), API_URL: JSON.stringify(`http://127.0.0.1:${process.env.CORTEX_API_PORT ?? "39291"}`),
SOCKET_URL: JSON.stringify('ws://127.0.0.1:39291'),
DEFAULT_MODEL_SOURCES: JSON.stringify(modelSources), DEFAULT_MODEL_SOURCES: JSON.stringify(modelSources),
}, },
}) })

View File

@ -1,6 +1,5 @@
declare const NODE: string declare const NODE: string
declare const API_URL: string declare const API_URL: string
declare const SOCKET_URL: string
declare const SETTINGS: SettingComponentProps[] declare const SETTINGS: SettingComponentProps[]
declare const DEFAULT_MODEL_SOURCES: any declare const DEFAULT_MODEL_SOURCES: any

1
server/global.d.ts vendored Normal file
View File

@ -0,0 +1 @@
declare const CORTEX_API_URL: string

View File

@ -98,7 +98,7 @@ export const startServer = async (configs?: ServerConfig): Promise<boolean> => {
}) })
server.register(require('@fastify/http-proxy'), { server.register(require('@fastify/http-proxy'), {
upstream: 'http://127.0.0.1:39291/v1', upstream: `${CORTEX_API_URL}/v1`,
prefix: configs?.prefix ?? '/v1', prefix: configs?.prefix ?? '/v1',
http2: false, http2: false,
}) })

View File

@ -14,5 +14,8 @@ export default defineConfig([
}, },
external: ['@fastify/swagger-ui'], external: ['@fastify/swagger-ui'],
platform: 'node', platform: 'node',
define: {
CORTEX_API_URL: JSON.stringify(`http://127.0.0.1:${process.env.CORTEX_API_PORT ?? "39291"}`),
}
}, },
]) ])

View File

@ -35,7 +35,8 @@ const nextConfig = {
POSTHOG_HOST: JSON.stringify(process.env.POSTHOG_HOST), POSTHOG_HOST: JSON.stringify(process.env.POSTHOG_HOST),
ANALYTICS_HOST: JSON.stringify(process.env.ANALYTICS_HOST), ANALYTICS_HOST: JSON.stringify(process.env.ANALYTICS_HOST),
API_BASE_URL: JSON.stringify( API_BASE_URL: JSON.stringify(
process.env.API_BASE_URL ?? 'http://127.0.0.1:39291' process.env.API_BASE_URL ??
`http://127.0.0.1:${process.env.CORTEX_API_PORT ?? '39291'}`
), ),
isMac: process.platform === 'darwin', isMac: process.platform === 'darwin',
isWindows: process.platform === 'win32', isWindows: process.platform === 'win32',

View File

@ -290,7 +290,7 @@ const HubScreen = () => {
)} )}
{hubBannerOption === 'upload' && ( {hubBannerOption === 'upload' && (
<div <div
className={`m-2 flex h-[172px] w-full cursor-pointer items-center justify-center rounded-md border`} className={`mx-2 mb-2 flex h-[172px] cursor-pointer items-center justify-center rounded-md border`}
onClick={() => { onClick={() => {
imageInputRef.current?.click() imageInputRef.current?.click()
}} }}