File tree 8 files changed +36
-20
lines changed
8 files changed +36
-20
lines changed Original file line number Diff line number Diff line change 1
- # When adding additional environment variables, the schema in "/src/env.js"
2
- # should be updated accordingly.
3
-
4
- # Prisma, ref: https://www.prisma.io/docs/reference/database-reference/connection-urls#env
5
- # 可前可后,服务端应设置公网地址
1
+ # #######################################
2
+ # =
6
3
DATABASE_URL =
7
4
# DATABASE_URL=
8
5
6
+ NEXT_PUBLIC_SOCKET_URL =
7
+ # NEXT_PUBLIC_SOCKET_URL=
8
+
9
+ NEXT_PUBLIC_BACKEND_URL =
10
+ # NEXT_PUBLIC_BACKEND_URL=
11
+
12
+ PROXY =
13
+ # PROXY=
14
+ # #######################################
15
+
16
+
9
17
# nginx 打过来,本地和网址一样
10
18
NEXT_PUBLIC_APP_URL =
19
+
11
20
# 可前可后,服务端应设置公网地址
12
- NEXT_PUBLIC_SOCKET_URL =
21
+
13
22
# 可前可后,服务端应设置公网地址
14
- NEXT_PUBLIC_BACKEND_URL =
15
23
16
24
# Next Auth
17
25
# You can generate a new secret on the command line with:
@@ -58,3 +66,4 @@ DASHSCOPE_API_KEY=
58
66
VERCEL_GITHUB_COMMIT_SHA =
59
67
NEXT_PUBLIC_PINO_LOGFLARE_API_KEY =
60
68
NEXT_PUBLIC_PINO_LOGFLARE_SOURCE_TOKEN =
69
+
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " cs-magic" ,
3
- "version" : " V0.7.177 (α)" ,
3
+ "version" : " V0.7.178 (α)" ,
4
4
"repository" :
" [email protected] :MarkShawn2020/p01.git" ,
5
5
"author" :
" markshawn2020 <[email protected] >" ,
6
6
"license" : " MIT" ,
20
20
},
21
21
"devDependencies" : {
22
22
"@types/jest" : " ^29.5.12" ,
23
+ "dotenv" : " ^16.4.5" ,
23
24
"jest" : " ^29.7.0" ,
24
25
"pino-pretty" : " ^11.0.0" ,
25
26
"ts-jest" : " ^29.1.2" ,
Original file line number Diff line number Diff line change
1
+ import { env } from "../common-env"
1
2
import { createHttpInstance } from "./core"
2
3
3
- // 因为这个api主要用于客户端使用,但是环境变量的读取需要用fs,所以就单独拆一下
4
- const baseURL = process . env . NEXT_PUBLIC_BACKEND_URL
5
- if ( ! baseURL ) throw new Error ( "no NEXT_PUBLIC_BACKEND_URL env" )
6
-
7
4
export const backendApi = createHttpInstance ( {
8
- baseURL,
5
+ baseURL : env . NEXT_PUBLIC_BACKEND_URL ,
9
6
} )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Path } from "../../common-path"
3
3
import { getEnv } from "../index"
4
4
5
5
/**
6
+ * @deprecated 不建议使用,推荐在package.json 里使用 source .env
6
7
* 加载并返回环境变量
7
8
* 返回的原因是因为不能在 browser 端使用
8
9
*/
Original file line number Diff line number Diff line change @@ -5,13 +5,17 @@ import { HttpsProxyAgent } from "https-proxy-agent"
5
5
import OpenAI from "openai/index"
6
6
import { v4 } from "uuid"
7
7
import { env } from "../common-env"
8
+ import { logEnv } from "../common-env/utils/log-env"
8
9
import { callLlm } from "./call-llm"
9
10
import { model2provider } from "./model2provider"
10
11
import { ICallLlmOptions , ICallLlmResponse } from "./schema/llm"
11
12
12
13
export const safeCallLLM = async (
13
14
options : ICallLlmOptions ,
14
15
) : Promise < ICallLlmResponse > => {
16
+ logEnv ( "api_key" )
17
+ console . log ( { env } )
18
+
15
19
const llmModelType = options . model
16
20
const llmProviderType = model2provider ( llmModelType )
17
21
Original file line number Diff line number Diff line change 6
6
"scripts" : {
7
7
"build" : " tsc" ,
8
8
"start" : " node dist/server.js" ,
9
- "dev-watch" : " tsx watch src/server.ts" ,
9
+ "dev-watch" : " tsx atch src/server.ts" ,
10
10
"dev" : " tsx src/server.ts"
11
11
},
12
12
"dependencies" : {
15
15
"@cs-magic/wechaty" : " 0.1.0" ,
16
16
"@fastify/websocket" : " ^10.0.1" ,
17
17
"@types/lodash" : " ^4.14.202" ,
18
+ "dotenv" : " ^16.4.5" ,
18
19
"fastify" : " ^4.26.2" ,
19
20
"fastify-websocket" : " ^4.3.0" ,
20
21
"lodash" : " ^4.17.21"
21
22
},
22
23
"devDependencies" : {
24
+ "@types/dotenv" : " ^8.2.0" ,
23
25
"@types/ws" : " ^8.5.10" ,
24
26
"typescript" : " ^5.4.5"
25
27
}
Original file line number Diff line number Diff line change 1
- // load for api and so on
2
1
import { genId } from "@cs-magic/common/utils/gen-id"
3
2
import { logger } from "@cs-magic/log/logger"
4
3
import { createWechatyBot } from "@cs-magic/wechaty/create-wechaty-bot"
5
4
import fw from "@fastify/websocket"
5
+ import dotenv from "dotenv"
6
+
6
7
import Fastify from "fastify"
7
8
import remove from "lodash/remove"
8
- import * as process from "process"
9
- import { loadEnv } from "../../../packages/common-env/utils/load-env"
9
+ import { Path } from "../../../packages/common-path"
10
10
import { IContext } from "./schema/context"
11
11
import { handleMessage } from "./utils/handle-message"
12
12
import { syncClients } from "./utils/sync-clients"
13
13
import { transferMessage } from "./utils/transfer-message"
14
14
15
- loadEnv ( )
15
+ dotenv . config ( { path : Path . envFile } )
16
16
17
17
logger . info ( "fastify initializing..." )
18
18
const fastify = Fastify ( {
Original file line number Diff line number Diff line change 1
1
import { logger } from "@cs-magic/log/logger"
2
+ import dotenv from "dotenv"
2
3
import qrcodeTerminal from "qrcode-terminal"
3
4
import { type Wechaty , WechatyBuilder } from "wechaty"
4
5
import { PuppetPadlocal } from "wechaty-puppet-padlocal"
5
- import { loadEnv } from "../../packages/common-env/utils/load -env"
6
+ import { env } from "../../packages/common-env"
6
7
import { logEnv } from "../../packages/common-env/utils/log-env"
8
+ import { Path } from "../../packages/common-path"
7
9
import { handleMessage } from "./handle-messages/handle-message"
8
10
import { SenderQueue } from "./handle-messages/sender-queue"
9
11
import { initBotStaticContext } from "./utils/bot-context"
10
12
import { getBotWxid } from "./utils/bot-wxid"
11
13
12
- const env = loadEnv ( )
14
+ dotenv . config ( { path : Path . envFile } )
13
15
logEnv ( "wechaty" )
14
16
15
17
export const createWechatyBot = ( { name } : { name ?: string } ) => {
You can’t perform that action at this time.
0 commit comments