Переглянути джерело

【新增】客户端添加基础样式和布局

- 新增全局样式和变量
- 实现控制面板、设置面板和聊天面板的基本布局
- 添加图标样式和 Markdown 样式
- 增加响应式设计,适配不同屏幕尺寸
PJ568 1 рік тому
батько
коміт
5ac2d27f1f

+ 1 - 1
Cargo.lock

@@ -2433,7 +2433,7 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51"
 
 [[package]]
 name = "yaa"
-version = "2.1.0"
+version = "2.2.0"
 dependencies = [
  "actix-web",
  "anyhow",

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "yaa"
-version = "2.1.0"
+version = "2.2.0"
 edition = "2024"
 
 [dependencies]

+ 15 - 0
client/assets/Byte-Tea.svg

@@ -0,0 +1,15 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
+  <!-- 背景圆 -->
+  <circle cx="50" cy="50" r="45" fill="#2F3E46" />
+  
+  <!-- 茶叶形状 -->
+  <path 
+    d="M50 20q15 0 25 25t-25 25q-15 0-25-25t25-25z" 
+    fill="#7BA06B" 
+    stroke="#FFF" 
+    stroke-width="2"
+  />
+  
+  <!-- 叶柄线条 -->
+  <line x1="50" y1="40" x2="70" y2="90" stroke="#FFF" stroke-width="3" />
+</svg>

+ 22 - 0
client/assets/yaa.svg

@@ -0,0 +1,22 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
+  <!-- 背景圆 -->
+  <circle cx="50" cy="50" r="45" fill="#2F3E46" />
+  
+  <!-- 主体 -->
+  <path 
+    d="m 43 16 c 6 -3 7 11 18 17 2 1 27 -4 15 10 -3 3 10 17 6 21 -4 5 -10 -6 -23 0 -5 3 1 17 -8 18 -7 0 -7 -13 -11 -15 -5 -3 -6 8 -13 4 -5 -3 3 -12 1 -17 C 26 49 13 43 13 39 14 32 31 42 37 36 41 32 37 19 43 16 Z" 
+    fill="#7BA06B" 
+    stroke="#FFF" 
+    stroke-width="2"
+  />
+  
+  <!-- 面部 -->
+  <line x1="35" y1="45" x2="40" y2="50" stroke="#FFF" stroke-width="2" />
+  <line x1="45" y1="35" x2="50" y2="40" stroke="#FFF" stroke-width="2" />
+  <path
+     d="m 54 49 c -1 3 -1 4 -4 4 -3 0 -9 2 -2 -5 6 -6 7 -2 6 1 z"
+     fill="#A1C58A"
+     stroke="#FFF"
+     stroke-width="2"
+ />
+</svg>

+ 61 - 0
client/css/icon.css

@@ -0,0 +1,61 @@
+.yaa-container .icon {
+  background-size: 50%;
+  background-position: center;
+  background-repeat: no-repeat;
+}
+
+.yaa-container .yaa {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100"><!-- 背景圆 --><circle cx="50" cy="50" r="45" fill="%232F3E46" /><!-- 主体 --><path d="m 43 16 c 6 -3 7 11 18 17 2 1 27 -4 15 10 -3 3 10 17 6 21 -4 5 -10 -6 -23 0 -5 3 1 17 -8 18 -7 0 -7 -13 -11 -15 -5 -3 -6 8 -13 4 -5 -3 3 -12 1 -17 C 26 49 13 43 13 39 14 32 31 42 37 36 41 32 37 19 43 16 Z" fill="%237BA06B" stroke="%23FFF" stroke-width="2" /><!-- 面部 --><line x1="35" y1="45" x2="40" y2="50" stroke="%23FFF" stroke-width="2" /><line x1="45" y1="35" x2="50" y2="40" stroke="%23FFF" stroke-width="2" /><path d="m 54 49 c -1 3 -1 4 -4 4 -3 0 -9 2 -2 -5 6 -6 7 -2 6 1 z" fill="%23A1C58A" stroke="%23FFF" stroke-width="2" /></svg>');
+}
+
+.yaa-container .menu {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-menu-2"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 6l16 0" /><path d="M4 12l16 0" /><path d="M4 18l16 0" /></svg>');
+}
+
+.yaa-container .maximize {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-arrows-minimize"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 9l4 0l0 -4" /><path d="M3 3l6 6" /><path d="M5 15l4 0l0 4" /><path d="M3 21l6 -6" /><path d="M19 9l-4 0l0 -4" /><path d="M15 9l6 -6" /><path d="M19 15l-4 0l0 4" /><path d="M15 15l6 6" /></svg>');
+}
+
+.yaa-container.not-max .maximize {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-arrows-maximize"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M16 4l4 0l0 4" /><path d="M14 10l6 -6" /><path d="M8 20l-4 0l0 -4" /><path d="M4 20l6 -6" /><path d="M16 20l4 0l0 -4" /><path d="M14 14l6 6" /><path d="M8 4l-4 0l0 4" /><path d="M4 4l6 6" /></svg>');
+}
+
+.yaa-container .save {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-download"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2" /><path d="M7 11l5 5l5 -5" /><path d="M12 4l0 12" /></svg>');
+}
+
+.yaa-container .add-attachment {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-paperclip"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M15 7l-6.5 6.5a1.5 1.5 0 0 0 3 3l6.5 -6.5a3 3 0 0 0 -6 -6l-6.5 6.5a4.5 4.5 0 0 0 9 9l6.5 -6.5" /></svg>');
+}
+
+.yaa-container .send-message {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-send"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M10 14l11 -11" /><path d="M21 3l-6.5 18a.55 .55 0 0 1 -1 0l-3.5 -7l-7 -3.5a.55 .55 0 0 1 0 -1l18 -6.5" /></svg>');
+}
+
+.yaa-container .reload {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-refresh"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4" /><path d="M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4" /></svg>');
+}
+
+.yaa-container .object.system .avatar {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-automation"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M13 20.693c-.905 .628 -2.36 .292 -2.675 -1.01a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.492 .362 1.716 2.219 .674 3.03" /><path d="M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0" /><path d="M17 22l5 -3l-5 -3z" /></svg>');
+}
+
+.yaa-container .object.user .avatar {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-user"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M8 7a4 4 0 1 0 8 0a4 4 0 0 0 -8 0" /><path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" /></svg>');
+}
+
+.yaa-container .object.assistant .avatar {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-ai"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M8 16v-6a2 2 0 1 1 4 0v6" /><path d="M8 13h4" /><path d="M16 8v8" /></svg>');
+}
+
+.yaa-container .delete {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-trash"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 7l16 0" /><path d="M10 11l0 6" /><path d="M14 11l0 6" /><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12" /><path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3" /></svg>');
+}
+
+.yaa-container .back-bottom {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-arrow-move-down"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 11v10" /><path d="M9 18l3 3l3 -3" /><path d="M12 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" /></svg>');
+}
+
+.yaa-container .save-settings {
+  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-device-floppy"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2" /><path d="M12 14m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" /><path d="M14 4l0 4l-6 0l0 -4" /></svg>');
+}

+ 400 - 0
client/css/main.css

@@ -0,0 +1,400 @@
+/* 全局 */
+* {
+  transition: all 0.2s ease;
+  box-sizing: border-box;
+}
+
+button,
+select,
+input,
+.session-item,
+textarea {
+  background-color: rgba(72, 95, 108, .1);
+  margin: .1rem;
+  padding: .5rem;
+  border: none;
+  outline: none;
+  border-radius: .5rem;
+  cursor: pointer;
+}
+
+input,
+textarea {
+  width: 100%;
+  cursor: initial;
+}
+
+button:hover,
+select:hover,
+.session-item:hover {
+  background-color: rgba(255, 255, 255, .1);
+}
+
+/* 桌面端 */
+@media only screen and (min-height: 760px) and (min-width: 1024px) {
+  .not-max {
+    max-height: 760px !important;
+    max-width: 1024px !important;
+    border-radius: 1rem;
+    border: .1rem solid var(--bg-border-color);
+    box-shadow: 0 0 200px rgba(0, 0, 0, .2);
+  }
+
+  .yaa-container.not-max .ctrl-panel {
+    width: var(--ctrl-panel-width) !important;
+  }
+
+  .yaa-container.not-max .ctrl-panel .session .session-item {
+    flex-direction: row !important;
+  }
+}
+
+/* 定义全局变量 */
+:root {
+  /* 色 */
+  --bg-border-color: #9E9E9E;
+  --bg-color-light: #E6E6E6;
+  --bg-color-dark: #485f6C;
+  --content-border-color: #E0E0E0;
+  --content-color-light: #F5F5F5;
+  --content-color-dark: #618092;
+  --font-color-light: #FAFAFA;
+  --font-color-midium: #CCCCCC;
+  --font-color-dark: #212121;
+  /* 侧栏宽 */
+  --ctrl-panel-width: 15rem;
+  --sett-panel-width: 20rem;
+  /* 标题栏高 */
+  --header-height: 4rem;
+}
+
+/* 背景和主体 */
+:root,
+body {
+  background-color: var(--bg-color-light);
+  color: var(--font-color-dark);
+  font-family: "Open Sans", sans-serif;
+  height: 100%;
+  width: 100%;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  text-align: center;
+  margin: 0;
+}
+
+.yaa-container,
+.not-max {
+  background-color: var(--content-color-light);
+  max-height: 100%;
+  max-width: 100%;
+  height: 100%;
+  width: 100%;
+  display: flex;
+  flex-direction: row;
+  justify-content: space-between;
+  overflow: hidden;
+}
+
+.yaa-container.not-max .ctrl-panel {
+  width: 4rem;
+}
+
+.yaa-container>* {
+  border-right: .1rem solid var(--content-border-color);
+}
+
+.yaa-container>*:last-child {
+  border-right: 0 solid transparent;
+}
+
+/* 栏 */
+.yaa-container .panel {
+  display: flex;
+  flex-direction: column;
+  overflow: hidden;
+  background-color: var(--bg-color-light);
+  color: var(--font-color-dark);
+  height: 100%;
+}
+
+.yaa-container .panel>* {
+  border-bottom: .1rem solid var(--content-border-color);
+}
+
+.yaa-container .panel>*:last-child {
+  border-bottom: 0 solid transparent;
+}
+
+/* 栏为关闭状态 */
+.yaa-container .panel.closed {
+  width: 0rem !important;
+  border: none;
+}
+
+.yaa-container .panel .header {
+  height: var(--header-height);
+  display: flex;
+  justify-content: space-between;
+  text-align: center;
+  align-items: center;
+  font-size: x-large;
+  font-weight: bolder;
+  padding: .5rem;
+}
+
+.yaa-container .panel .buttons {
+  display: flex;
+  gap: 1rem;
+}
+
+.yaa-container .panel .buttons button {
+  display: flex;
+  width: 2rem;
+  height: 2rem;
+  justify-content: center;
+  align-items: center;
+  background-size: 50%;
+  background-position: center;
+  background-repeat: no-repeat;
+}
+
+.yaa-container .panel .list {
+  overflow: hidden;
+  display: flex;
+  flex-direction: column;
+  gap: .5rem;
+  padding: .5rem;
+}
+
+/* 控制面板 */
+.yaa-container .ctrl-panel {
+  width: var(--ctrl-panel-width);
+  background-color: var(--bg-color-dark);
+  color: var(--font-color-light);
+}
+
+.yaa-container .ctrl-panel>* {
+  border-bottom: .1rem solid var(--content-color-dark);
+}
+
+.yaa-container .ctrl-panel .header img {
+  height: 3rem;
+}
+
+.yaa-container .ctrl-panel .header span {
+  overflow: hidden;
+  white-space: nowrap;
+  text-overflow: ellipsis;
+}
+
+.yaa-container .ctrl-panel .header span,
+.yaa-container .ctrl-panel .session {
+  flex: 1;
+}
+
+.yaa-container .ctrl-panel .session {
+  display: flex;
+  flex-direction: column;
+  gap: .5rem;
+  padding: .5rem;
+}
+
+.yaa-container .ctrl-panel .session .session-item {
+  display: flex;
+  flex-direction: row;
+}
+
+.yaa-container.not-max .ctrl-panel .session .session-item {
+  flex-direction: column;
+}
+
+.yaa-container .ctrl-panel .session .session-item .session-info {
+  overflow: hidden;
+  white-space: nowrap;
+  text-overflow: ellipsis;
+  flex: 1;
+  text-align: left;
+}
+
+.yaa-container .ctrl-panel .session .session-item .delete-session-btn {
+  width: 1.5rem;
+  height: 1.5rem;
+  background-color: #FF6B6B;
+}
+
+.yaa-container .ctrl-panel .session .session-item .delete-session-btn:hover {
+  background-color: #FF5252;
+}
+
+.yaa-container .ctrl-panel .session .session-item .session-item-content,
+.yaa-container .ctrl-panel .session .session-item .session-item-time {
+  color: var(--font-color-midium);
+  white-space: nowrap;
+  overflow: hidden;
+  text-overflow: ellipsis;
+}
+
+.yaa-container .ctrl-panel .session .session-item .session-item-content {
+  font-size: medium;
+}
+
+.yaa-container .ctrl-panel .session .session-item .session-item-time {
+  font-size: small;
+}
+
+.yaa-container .ctrl-panel .btn.list {
+  height: 20%;
+  justify-content: space-between;
+}
+
+.yaa-container .ctrl-panel .btn button {
+  color: var(--font-color-light);
+}
+
+/* 设置面板 */
+.yaa-container .sett-panel {
+  width: var(--sett-panel-width);
+  background-color: white;
+  text-align: left;
+}
+
+.yaa-container .sett-panel .header {
+  padding: 1rem;
+}
+
+.yaa-container .sett-panel .header .head-title {
+  font-size: x-large;
+  font-weight: bolder;
+}
+
+.yaa-container .sett-panel .sett-block {
+  overflow-y: scroll;
+  overflow-x: clip;
+  padding: 1rem;
+}
+
+.yaa-container .sett-panel .sett-block>*:first-child {
+  margin-top: 0;
+}
+
+.yaa-container .sett-panel .sett-block>*:last-child {
+  margin-bottom: 0;
+}
+
+/* 交互面板 */
+.yaa-container .chat-panel {
+  flex: 1;
+  justify-content: space-between;
+}
+
+.yaa-container .chat-panel .header {
+  background-color: white;
+  display: flex;
+  text-align: center;
+  align-items: center;
+  font-size: x-large;
+  font-weight: bolder;
+  padding: 1rem;
+}
+
+.yaa-container .chat-panel .header span {
+  flex: 1;
+  overflow: hidden;
+  white-space: nowrap;
+  text-overflow: ellipsis;
+  margin: 1rem;
+}
+
+.yaa-container .chat-panel .content {
+  display: flex;
+  justify-content: center;
+  overflow-x: clip;
+  overflow-y: scroll;
+  flex: 1;
+}
+
+.yaa-container .chat-panel .content .width-768 {
+  padding: 1rem 1rem 0 1rem;
+  max-width: 768px;
+  width: 100%;
+  height: max-content;
+}
+
+.yaa-container .chat-panel .input {
+  display: flex;
+  height: 20%;
+  padding: .5rem;
+  gap: .5rem;
+  justify-content: space-between;
+  background-color: white;
+}
+
+.yaa-container .chat-panel .input textarea {
+  font: inherit;
+  flex: 1;
+  resize: none;
+  overflow: auto;
+}
+
+.yaa-container .chat-panel .input .buttons {
+  display: flex;
+  flex-direction: column-reverse;
+  gap: .5rem;
+}
+
+/* 内容气泡 */
+.yaa-container .chat-panel .content .object {
+  margin-bottom: 1rem;
+  display: flex;
+  gap: 1rem;
+}
+
+.yaa-container .chat-panel .content .object.user {
+  flex-direction: row-reverse;
+}
+
+/* 气泡尖伪元素 */
+/* .yaa-container .chat-panel .content .object.system:before,
+.yaa-container .chat-panel .content .object.assistant:before {
+  content: "";
+  position: relative;
+  max-width: 0;
+  max-height: 0;
+  border-left: 10px solid transparent;
+  border-top: 10px solid transparent;
+  border-right: 10px solid #fff;
+  border-bottom: 10px solid transparent;
+  left: 60px;
+  top: 10px;
+} */
+
+.yaa-container .chat-panel .content .object .avatar {
+  width: 2rem;
+  min-width: 2rem;
+  height: 2rem;
+  background-size: cover;
+  background-color: #FAFDFF;
+  border-radius: 50%;
+  box-shadow: 0 0 200px rgba(0, 0, 0, .2);
+}
+
+.yaa-container .chat-panel .content .object .bubble {
+  text-align: left;
+  overflow: hidden;
+  border-radius: 0 1rem 1rem 1rem;
+  padding: 1rem;
+  word-wrap: break-word;
+  word-break: normal;
+  background-color: #FAFDFF;
+  box-shadow: 0 0 200px rgba(0, 0, 0, .2);
+}
+
+.yaa-container .chat-panel .content .object.user .bubble {
+  border-radius: 1rem 0 1rem 1rem;
+}
+
+.yaa-container .chat-panel .content .object.system .avatar,
+.yaa-container .chat-panel .content .object.system .bubble {
+  background-color: #FFFAFA;
+}

+ 118 - 0
client/css/markdown.css

@@ -0,0 +1,118 @@
+/* Markdown 主要内容 */
+.yaa-container .chat-panel .content .object .bubble>*:first-child {
+  margin-top: 0;
+}
+
+.yaa-container .chat-panel .content .object .bubble>*:last-child {
+  margin-bottom: 0;
+}
+
+.yaa-container img,
+.yaa-container video,
+.yaa-container iframe,
+.yaa-container object,
+.yaa-container embed,
+.yaa-container svg,
+.yaa-container canvas,
+.yaa-container audio {
+  max-width: 100%;
+}
+
+/* Markdown 样式 */
+.yaa-container a {
+  transition:
+    color .2s,
+    background-color .2s;
+}
+
+.yaa-container a:hover {
+  background-color: rgba(255, 255, 255, .1);
+}
+
+.yaa-container ul,
+.yaa-container ol {
+  padding-left: 2rem;
+}
+
+.yaa-container pre {
+  background-color: rgba(72, 95, 108, .1);
+  padding: .4rem;
+  border-radius: .5rem;
+  overflow-y: scroll;
+}
+
+.yaa-container code {
+  font-family: "cousine nerd font mono", monospace;
+  background-color: rgba(72, 95, 108, .1);
+  font-size: small;
+  padding: .2rem;
+  border-radius: .2rem;
+}
+
+.yaa-container pre code {
+  background-color: unset;
+  font-size: unset;
+  padding: unset;
+  border-radius: unset;
+}
+
+.yaa-container blockquote {
+  border-radius: .5rem;
+  background-color: rgba(72, 95, 108, .1);
+  font-size: small;
+  padding: .4rem;
+  margin: .5rem 2rem;
+  border-left: 5px solid rgba(0, 0, 0, 0.1);
+}
+
+.yaa-container blockquote>*:first-child {
+  margin-top: 0;
+}
+
+.yaa-container blockquote>*:last-child {
+  margin-bottom: 0;
+}
+
+.yaa-container details {
+  border: 1px solid rgba(0, 0, 0, 0.1);
+  border-radius: .1rem;
+}
+
+.yaa-container summary {
+  font-size: small;
+  cursor: pointer;
+  background-color: rgba(72, 95, 108, .1);
+  padding: .4rem;
+  font-weight: bold;
+}
+
+.yaa-container details a {
+  margin-left: -2rem;
+}
+
+.yaa-container table {
+  border-spacing: 0;
+  border-radius: .1rem;
+  width: 100%;
+  border-collapse: separate;
+  border: .1rem solid rgba(72, 95, 108, .1);
+}
+
+.yaa-container table td,
+.yaa-container table th {
+  border-right: .1rem solid rgba(72, 95, 108, .1);
+}
+
+.yaa-container table td,
+.yaa-container table th {
+  border-top: .1rem solid rgba(72, 95, 108, .1);
+}
+
+.yaa-container table td:last-child,
+.yaa-container th:last-child {
+  border-right-color: transparent;
+}
+
+.yaa-container table thead tr:first-child>* {
+  border-top: .1rem solid transparent;
+}

Різницю між файлами не показано, бо вона завелика
+ 113 - 0
client/index.html


+ 393 - 0
client/js/main.js

@@ -0,0 +1,393 @@
+(function () {
+  var current_session_id = null;
+  var current_config = null;
+  var yaa_api = 'http://127.0.0.1:12345';
+  var yaa_api_key = '';
+  var yaa_character = "你是一个叫 yaa 的智能体。";
+  var all_session_data = [];
+
+  // 载入所有会话数据
+  function load_all_session_data() {
+    try {
+      const saved = localStorage.getItem('all_session_data');
+      all_session_data = saved ? JSON.parse(saved) : [];
+    } catch (error) {
+      error('载入所有会话数据时出错:', error);
+    }
+  }
+
+  // 保存所有会话数据
+  function save_all_session_data() {
+    try {
+      localStorage.setItem('all_session_data', JSON.stringify(all_session_data));
+    } catch (error) {
+      error('保存所有会话数据时出错:', error);
+    }
+  }
+
+  // 载入设置数据
+  function load_config_data() {
+    try {
+      const savedConfig = localStorage.getItem('config_data');
+      current_config = savedConfig ? JSON.parse(savedConfig) : null;
+
+      const yaaApi = localStorage.getItem('yaa_api');
+      if (yaaApi) {
+        yaa_api = yaaApi;
+      }
+
+      const yaaApiKey = localStorage.getItem('yaa_api_key');
+      if (yaaApiKey) {
+        yaa_api_key = yaaApiKey;
+      }
+
+      const yaaCharacter = localStorage.getItem('yaa_character');
+      if (yaaCharacter) {
+        yaa_character = yaaCharacter;
+      }
+    } catch (error) {
+      error('载入所有会话数据时出错:', error);
+    }
+  }
+
+  // 保存设置数据
+  function save_config_data() {
+    try {
+      localStorage.setItem('config_data', JSON.stringify(current_config));
+      localStorage.setItem('yaa_api', yaa_api);
+      localStorage.setItem('yaa_api_key', yaa_api_key);
+      localStorage.setItem('yaa_character', yaa_character);
+    } catch (error) {
+      error('保存设置数据时出错:', error);
+    }
+  }
+
+  // 生成会话数据
+  function new_session_data(content, title = '', character = yaa_character) {
+    return {
+      'id': Date.now().toString(),
+      'title': title,
+      'startTime': new Date().toISOString(),
+      'character': character,
+      'status': "in-progress",
+      'messages': [
+        {
+          'role': 'user',
+          'content': content
+        }
+      ]
+    }
+  }
+
+  // 取现有会话数据
+  function get_session_data(session_id) {
+    return all_session_data.find(session => session.id === session_id);
+  }
+
+  // 生成配置数据
+  function new_config_data(api_url = 'https://api.deepseek.com', api_key, model_name = 'deepseek-chat') {
+    return {
+      'llm_api': {
+        'provider': {
+          'api_url': api_url,
+          'api_key': api_key,
+          'model_name': model_name
+        }
+      }
+    }
+  }
+
+  // 添加新会话到会话列表
+  function push_session(session_data = null, content = null) {
+    if (session_data == null) {
+      if (content == null) {
+        error('添加新会话到会话列表时未指定消息内容');
+        return;
+      }
+      session_data = new_session_data(content = content);
+    }
+    all_session_data.push(session_data);
+  }
+
+  // 添加新消息到会话
+  function push_message(role, content, session_id = null) {
+    if (session_id == null) {
+      if (current_session_id == null) {
+        error('添加新消息到会话时未指定会话数据 ID');
+        return;
+      }
+      session_id = current_session_id;
+    }
+    if (all_session_data.find(session => session.id === session_id)) {
+      all_session_data.find(session => session.id === session_id).messages.push({
+        'role': role,
+        'content': content
+      });
+    } else {
+      error('添加新消息到会话时未找到会话数据 ID');
+      return;
+    }
+  }
+
+  // 删除会话
+  function delete_session(session_id) {
+    if (session_id == null) {
+      error('删除会话时未指定会话数据 ID');
+      return;
+    }
+    if (all_session_data.find(session => session.id === session_id)) {
+      all_session_data = all_session_data.filter(session => session.id !== session_id);
+      save_all_session_data();
+    } else {
+      error('删除会话时会话数据 ID 不存在');
+    }
+    if (current_session_id == session_id) {
+      view_delete_messages();
+    }
+  }
+
+  // 删除显示会话列表中的会话
+  function view_delete_session(sessionDelBtn) {
+    sessionDelBtn.parentElement.remove();
+  }
+
+  // 删除显示的消息记录
+  function view_delete_messages() {
+    current_session_id = null;
+    const chatContent = document.querySelector('.yaa-container .chat-panel .content .width-768');
+    chatContent.innerHTML = '';
+  }
+
+  // 显示新会话
+  function view_new_session() {
+    view_delete_messages();
+  }
+
+  // 显示指定会话
+  function view_switch_session(session_id) {
+    if (!session_id) {
+      error('显示指定会话时未指定会话数据 ID');
+      return;
+    }
+    if (all_session_data.find(session => session.id === session_id)) {
+      const chatContent = document.querySelector('.yaa-container .chat-panel .content .width-768');
+      chatContent.innerHTML = '';
+      const session = all_session_data.find(session => session.id === session_id);
+      for (let i = 0; i < session.messages.length; i++) {
+        const role = session.messages[i].role;
+        const content = session.messages[i].content;
+        var marked_content = '';
+        if (role == 'user') {
+          marked_content = content;
+        } else {
+          marked_content = marked.parse(content);
+        }
+        view_push_message(role, marked_content);
+      }
+      current_session_id = session_id;
+    } else {
+      error('显示指定会话时会话数据 ID 不存在');
+      return;
+    }
+  }
+
+  // 显示会话到列表
+  function view_push_session(session_id, title = '', start_time, content) {
+    const sessionList = document.querySelector('.yaa-container .ctrl-panel .session.list');
+    const sessionDiv = document.createElement('div');
+    sessionDiv.className = `session-item`;
+    sessionDiv.innerHTML = `
+      <div class="session-info">
+        <strong>${title}</strong>
+        <div class="session-item-content">${content}</div>
+        <div class="session-item-time">${start_time}</div>
+      </div>
+      <button data-id="${session_id}" class="delete-session-btn delete icon"></button>
+    `;
+    sessionList.appendChild(sessionDiv);
+  }
+
+  // 显示新消息,如果离底部很近(10px),触发回到底部
+  function view_push_message(role, marked_content, model_name = '') {
+    const chatContent = document.querySelector('.yaa-container .chat-panel .content .width-768');
+    const messageDiv = document.createElement('div');
+    messageDiv.className = `object ${role}`;
+    messageDiv.innerHTML = `
+      <div class="avatar" title="${model_name}"></div>
+      <div class="bubble">
+        ${marked_content}
+      </div>
+    `;
+    messageDiv.querySelector('.avatar').classList.add(role);
+    messageDiv.querySelector('.bubble').classList.add(role);
+    chatContent.appendChild(messageDiv);
+
+    // const distanceFromBottom = chatContent.scrollHeight - chatContent.scrollTop - chatContent.clientHeight;
+    // if (distanceFromBottom <= 10) {
+    //   to_bottom();
+    // }
+  }
+
+  // 最大化
+  function toggle_maximize() {
+    const yaaContainer = document.querySelector('.yaa-container');
+    yaaContainer.classList.toggle('not-max');
+  }
+
+  // 切换控制面板显示状态
+  function toggle_ctrl_panel() {
+    const controlPanel = document.querySelector('.yaa-container .ctrl-panel');
+    const settingsPanel = document.querySelector('.yaa-container .sett-panel');
+    if (!settingsPanel.classList.contains('closed')) {
+      settingsPanel.classList.toggle('closed');
+    }
+    controlPanel.classList.toggle('closed');
+  }
+
+  // 切换设置面板显示状态
+  function toggle_sett_panel() {
+    const settingsPanel = document.querySelector('.yaa-container .sett-panel');
+    settingsPanel.classList.toggle('closed');
+  }
+
+  // 回到最底
+  function to_bottom() {
+    const chatContent = document.querySelector('.yaa-container .chat-panel .content');
+    chatContent.scrollTo({
+      top: chatContent.scrollHeight,
+      behavior: 'smooth'
+    })
+  }
+
+  // 按下保存设置按钮
+  function toggle_save_settings() {
+    const settingsPanel = document.querySelector('.yaa-container .sett-panel');
+    if (settingsPanel.classList.contains('closed')) {
+      console.warn('保存设置按钮在面板关闭时被按下')
+      return;
+    }
+    // 获取设置面板输入值
+    const yaaApiInput = document.querySelector('.yaa-api').value;
+    const yaaApiKeyInput = document.querySelector('.yaa-api-key').value;
+    const yaaCharacterInput = document.querySelector('.yaa-character').value;
+    const llmApiUrl = document.querySelector('.api-url').value;
+    const llmApiKey = document.querySelector('.api-key').value;
+    const model = document.querySelector('.model-name').value;
+
+    // 应用新配置
+    current_config = new_config_data(llmApiUrl, llmApiKey, model);
+    yaa_api = yaaApiInput;
+    yaa_api_key = yaaApiKeyInput;
+    yaa_character = yaaCharacterInput;
+
+    // 保存配置到本地存储
+    save_config_data();
+  }
+
+  // 重载
+  function reload_all() {
+    var userConfirmed = confirm('确认要重载?');
+    if (userConfirmed) {
+      location.reload();
+    }
+  }
+
+  // 发送消息
+  async function send_message_and_deal_with_api() {
+    const input = document.querySelector('.yaa-container .chat-panel .input textarea');
+    if (input.value.trim() === '') {
+      return;
+    }
+    var session_id = null;
+    if (current_session_id == null) {
+      const session_data = new_session_data(content = input.value, title = input.value);
+      current_session_id = session_data.id;
+      session_id = session_data.id;
+      push_session(session_data);
+      view_push_session(session_id = session_data.id, session_data.title, session_data.startTime, input.value);
+    } else {
+      session_id = current_session_id;
+    }
+    try {
+      const response = await fetch(yaa_api, {
+        method: 'POST',
+        headers: { 'Authorzation': 'YAA-API-KEY ' + yaa_api_key, 'Content-Type': 'application/json' },
+        body: JSON.stringify(get_session_data(session_id))
+      });
+      const data = await response.json();
+      for (var i = 0; i < data.messages.length; ++i) {
+        const role = data.messages[i].role;
+        const content = data.messages[i].content;
+        push_message(role, content);
+        if (session_id == current_session_id) {
+          view_push_message(role, marked.parse(content));
+        }
+      }
+    } catch (e) {
+      error('解析消息时出错:' + e);
+    }
+    save_all_session_data()
+  }
+
+  // 错误信息处理
+  function error(e) {
+    console.error('客户端错误:' + e);
+    view_push_message('system', '客户端错误:' + e);
+  }
+
+  // 初始化
+  function initialize() {
+    load_config_data();
+    load_all_session_data();
+  }
+
+  // 点击事件委托
+  document.addEventListener('click', function (event) {
+    const imgOrSvg = event.target.closest('.yaa-container .chat-panel .content .object .bubble img, .yaa-container .chat-panel .content .object .bubble svg');
+    const sessionDelBtn = event.target.closest('.yaa-container .ctrl-panel .session.list .session-item .delete-session-btn');
+    const sessionItem = event.target.closest('.yaa-container .ctrl-panel .session.list .session-item');
+    if (imgOrSvg) {
+      const url = imgOrSvg.getAttribute('src') || imgOrSvg.getAttribute('xlink:href');
+      if (url) {
+        window.open(url, '_blank');
+        event.preventDefault();
+        return;
+      } else {
+        const newWindow = window.open('', '_blank');
+        newWindow.document.body.innerHTML = imgOrSvg.outerHTML;
+        newWindow.document.close();
+        event.preventDefault();
+        return;
+      }
+    } else if (sessionDelBtn) {
+      const session_id = sessionDelBtn.getAttribute('data-id');
+      if (confirm('确认要删除会话?')) {
+        delete_session(session_id);
+        view_delete_session(sessionDelBtn);
+      }
+    } else if (sessionItem) {
+      const session_id = sessionItem.querySelector('.delete-session-btn').getAttribute('data-id');
+      view_switch_session(session_id);
+    } else if (event.target.closest('.yaa-container .chat-panel .header .maximize')) {
+      toggle_maximize();
+    } else if (event.target.closest('.yaa-container .chat-panel .header .menu, .yaa-container .yaa')) {
+      toggle_ctrl_panel();
+    } else if (event.target.closest('.yaa-container .chat-panel .header .reload')) {
+      reload_all();
+    } else if (event.target.closest('.yaa-container .chat-panel .input .back-bottom')) {
+      to_bottom();
+    } else if (event.target.closest('.yaa-container .ctrl-panel .btn-new')) {
+      view_new_session();
+    } else if (event.target.closest('.yaa-container .ctrl-panel .btn-settings')) {
+      toggle_sett_panel();
+    } else if (event.target.closest('.yaa-container .ctrl-panel .btn-about')) {
+      window.open('https://github.com/Byte-tea/yaa', '_blank');
+    } else if (event.target.closest('.yaa-container .chat-panel .input .send-message')) {
+      send_message_and_deal_with_api();
+    } else if (event.target.closest('.yaa-container .sett-panel .header .save-settings')) {
+      toggle_save_settings();
+    }
+  });
+  // 网页加载完毕后触发初始化
+  window.addEventListener('DOMContentLoaded', () => initialize());
+})();

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
client/js/marked.min.js


Деякі файли не було показано, через те що забагато файлів було змінено