session-viewer-plugin 0.1.0

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.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # session-viewer-plugin
2
+
3
+ 会话指标查看插件:提供可嵌入 Vue3 + Element Plus 宿主应用(如 tnnotix)的视图组件库,搭配一个独立伴生服务(HTTP + CORS)提供数据。
4
+
5
+ - **本地会话**:扫描本机会话快照 JSON,按会话卡片、月度分组、收藏筛选浏览,并提供步骤时间线 / Token / 工具调用等图表的详情页。
6
+ - **云端数据**:管理 AGC(华为云存储)桶内文件,支持按前缀浏览、下载、重命名、删除,并可在线配置凭证与连通性测试。
7
+
8
+ ## 架构
9
+
10
+ ```
11
+ 宿主应用(任意 Vue3+EP) 伴生服务(本插件 bin)
12
+ ┌────────────────────┐ HTTP/CORS ┌──────────────────────┐
13
+ │ SessionViewer │ ────────────▶ │ GET /api/sessions │──▶ 本机会话快照目录
14
+ │ SessionDetail │ │ GET /api/cloud/* │──▶ AGC 云存储
15
+ │ CloudFileList │ │ ... │──▶ 运行时配置(data 目录)
16
+ └────────────────────┘ └──────────────────────┘
17
+ ```
18
+
19
+ 宿主只负责渲染,服务独立进程运行(同机部署即可,前端经 `baseUrl` 直连或反向代理)。
20
+
21
+ ## 快速开始(伴生服务)
22
+
23
+ ```bash
24
+ npm i session-viewer-plugin
25
+ npx session-viewer-plugin # 默认 http://127.0.0.1:3001
26
+ ```
27
+
28
+ ### 环境变量
29
+
30
+ | 变量 | 默认值 | 说明 |
31
+ | --- | --- | --- |
32
+ | `PORT` | `3001` | 监听端口 |
33
+ | `HOST` | `127.0.0.1` | 绑定地址;容器部署需设 `0.0.0.0` |
34
+ | `LOG_DIR` | 内置目录集 | 覆盖扫描目录(单目录;容器部署时配合卷挂载使用) |
35
+ | `AGC_CREDENTIALS_FILE` | - | AGC 凭证 JSON 文件路径(优先级最高) |
36
+ | `AGC_CREDENTIALS_JSON` | - | AGC 凭证内联 JSON 字符串 |
37
+
38
+ ### AGC 凭证
39
+
40
+ 固定通过项目文件配置,按优先级:**环境变量 > 包内默认文件**。
41
+
42
+ - 包内默认文件:`server/src/assets/agc-apiclient.json`(构建时随包发布到 `server/dist/assets/`),仓库内维护。
43
+ - 环境变量覆盖:`AGC_CREDENTIALS_FILE`(凭证文件路径)或 `AGC_CREDENTIALS_JSON`(内联 JSON)。
44
+ - 必填字段:`client_id`、`client_secret`、`project_id`、`bucket_name`;`region` 缺省为 `CN`。
45
+
46
+ ## 宿主应用集成(Vue3 + Element Plus)
47
+
48
+ ```bash
49
+ npm i session-viewer-plugin element-plus @element-plus/icons-vue
50
+ ```
51
+
52
+ ```js
53
+ import { createApp } from 'vue'
54
+ import ElementPlus from 'element-plus'
55
+ import 'element-plus/dist/index.css'
56
+ import 'session-viewer-plugin/ui.css'
57
+ import { SessionViewer, CloudFileList, API_BASE_KEY } from 'session-viewer-plugin/ui'
58
+
59
+ const app = createApp({
60
+ components: { SessionViewer, CloudFileList },
61
+ template: `
62
+ <SessionViewer base-url="http://127.0.0.1:3001" @select-session="onSelect" />
63
+ `,
64
+ })
65
+ app.use(ElementPlus) // 需注册 v-loading 指令
66
+ app.provide(API_BASE_KEY, 'http://127.0.0.1:3001') // 或统一注入基址,组件可不传 prop
67
+ app.mount('#app')
68
+ ```
69
+
70
+ ### 导出内容
71
+
72
+ | 导出 | 说明 |
73
+ | --- | --- |
74
+ | `SessionViewer` | 会话列表页(含侧栏分组/收藏/搜索),`@select-session` 返回会话 id |
75
+ | `SessionDetail` | 会话详情页,props:`sessionId`(必填)、`baseUrl`;插槽 `#header-actions` |
76
+ | `CloudFileList` | 云端文件管理页 |
77
+ | `API_BASE_KEY` / `setApiBase` / `getApiBase` / `useApiBase` | API 基址管理;组件 prop `baseUrl` 优先于 provide 注入 |
78
+
79
+ 宿主要求:Vue ≥ 3.4、Element Plus ≥ 2.4(需 `app.use(ElementPlus)` 或至少注册 `v-loading` 指令)。
80
+
81
+ ## Docker 部署
82
+
83
+ ```bash
84
+ npm run build:server
85
+ docker build -t session-viewer-plugin .
86
+ docker run -d -p 3001:3001 session-viewer-plugin
87
+ ```
88
+
89
+ ## 开发
90
+
91
+ 仓库为前后端双包结构:
92
+
93
+ ```bash
94
+ npm run setup # 安装 server + frontend 依赖
95
+ npm run dev # 同时启动后端(:3001)与前端开发壳(:5173)
96
+ npm run build # 构建 server/dist 与 frontend/dist-ui
97
+ ```
98
+
99
+ - 后端:Express 5 + TypeScript(`server/`)。
100
+ - 前端:Vue 3 + Vite + Element Plus(显式导入);`frontend/src/plugin-entry.js` 为库入口,独立开发壳为 `frontend/src/main.js`。
101
+ - 发布产物:`server/dist`(伴生服务)+ `frontend/dist-ui`(组件库)。