@opentiny/next 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/README.md +14 -13
  2. package/client.js +299 -297
  3. package/package.json +3 -3
  4. package/server.d.ts +2 -6
  5. package/server.js +189 -185
package/README.md CHANGED
@@ -234,6 +234,9 @@ const app = express();
234
234
  // 启用跨域资源共享
235
235
  app.use(cors());
236
236
 
237
+ // 获取代理背后真实的 IP 地址
238
+ app.set('trust proxy', 1);
239
+
237
240
  // 配置 session 中间件,支持会话管理
238
241
  app.use(
239
242
  session({
@@ -246,9 +249,10 @@ app.use(
246
249
 
247
250
  // 获取所有客户端的 sessionId
248
251
  app.get('/list', async (req: Request, res: Response) => {
249
- const sessions: Record<string, string> = {};
252
+ const sessions: Record<string, object> = {};
250
253
  for (const sessionId in clients) {
251
- sessions[sessionId] = clients[sessionId].user.userId as string;
254
+ const { user, device, type } = clients[sessionId];
255
+ sessions[sessionId] = { user, device, type };
252
256
  }
253
257
  res.json(sessions);
254
258
  });
@@ -258,7 +262,6 @@ app.use(auth({ secret: process.env.SECRET_KEY as string }));
258
262
 
259
263
  // MCP inspector url http://localhost:5173/agent/inspector?sessionId=
260
264
  app.get('/inspector', async (req: Request, res: Response) => {
261
- console.log('AI Agent inspector auth:', req.user?.userId);
262
265
  try {
263
266
  await handleSseInspector(req, res, '/agent/messages');
264
267
  } catch (error) {
@@ -268,7 +271,6 @@ app.get('/inspector', async (req: Request, res: Response) => {
268
271
 
269
272
  // SSE 端点,支持 inspector 和 proxy 两种模式,inspector url http://localhost:8001/sse?sessionId=
270
273
  app.get('/sse', async (req: Request, res: Response) => {
271
- console.log('AI Agent sse auth:', req.user?.userId);
272
274
  try {
273
275
  if (req.query.sessionId) {
274
276
  await handleSseInspector(req, res, '/messages');
@@ -282,7 +284,6 @@ app.get('/sse', async (req: Request, res: Response) => {
282
284
 
283
285
  // 消息转发端点,根据 sessionId 找到对应 transport 处理消息
284
286
  app.post('/messages', async (req: Request, res: Response) => {
285
- console.log('AI Agent messages auth:', req.user?.userId);
286
287
  try {
287
288
  await handleSseMessage(req, res);
288
289
  } catch (error) {
@@ -327,6 +328,9 @@ const app = express();
327
328
  // 启用跨域资源共享
328
329
  app.use(cors());
329
330
 
331
+ // 获取代理背后真实的 IP 地址
332
+ app.set('trust proxy', 1);
333
+
330
334
  // 配置 session 中间件,支持会话管理
331
335
  app.use(
332
336
  session({
@@ -339,9 +343,10 @@ app.use(
339
343
 
340
344
  // 获取所有客户端的 sessionId
341
345
  app.get('/list', async (req: Request, res: Response) => {
342
- const sessions: Record<string, string> = {};
346
+ const sessions: Record<string, object> = {};
343
347
  for (const sessionId in clients) {
344
- sessions[sessionId] = clients[sessionId].user.userId as string;
348
+ const { user, device, type } = clients[sessionId];
349
+ sessions[sessionId] = { user, device, type };
345
350
  }
346
351
  res.json(sessions);
347
352
  });
@@ -353,7 +358,6 @@ app.use(auth({ secret: process.env.SECRET_KEY as string }));
353
358
  // 可以使用 MCP inspector 连接调试,方式与 SSE 连接相同,如下:
354
359
  // http://localhost:8001/mcp?sessionId= 或 http://localhost:5173/agent/mcp?sessionId=
355
360
  app.all('/mcp', express.json(), async (req: Request, res: Response) => {
356
- console.log('AI Agent mcp auth:', req.user?.userId);
357
361
  try {
358
362
  if (req.query.sessionId) {
359
363
  await handleStreamInspector(req, res);
@@ -394,18 +398,15 @@ import dotenv from 'dotenv';
394
398
  import path from 'path';
395
399
 
396
400
  // Vite 配置文件
397
- export default defineConfig(({ mode }) => {
401
+ export default defineConfig(() => {
398
402
  // 加载 .env 文件中的环境变量
399
403
  dotenv.config({ path: '.env' });
400
404
 
401
- const isProduction = mode === 'production';
402
-
403
405
  return {
404
406
  // 注入环境变量到前端代码
405
407
  define: {
406
408
  'process.env': {
407
- USER_TOKEN: process.env.USER_TOKEN,
408
- ADMIN_TOKEN: process.env.ADMIN_TOKEN
409
+ USER_TOKEN: process.env.USER_TOKEN
409
410
  }
410
411
  },
411
412
  plugins: [vue()],