@opentiny/genui-sdk-vue 1.2.1 → 1.3.0-alpha.3

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 (36) hide show
  1. package/README.md +10 -2
  2. package/dist/ConfigProvider-BzxW9L3f.js +95 -0
  3. package/dist/ConfigProvider-BzxW9L3f.js.map +1 -0
  4. package/dist/GenuiRenderer-B9wcUl25.js +15164 -0
  5. package/dist/GenuiRenderer-B9wcUl25.js.map +1 -0
  6. package/dist/___vite-browser-external_commonjs-proxy-4gYZYw55.js +1 -0
  7. package/dist/___vite-browser-external_commonjs-proxy-4gYZYw55.js.map +1 -0
  8. package/dist/chat.d.ts +82 -2410
  9. package/dist/chat.js +18 -19
  10. package/dist/chat.js.map +1 -0
  11. package/dist/chat.types-BRLoMarP.js +1792 -0
  12. package/dist/chat.types-BRLoMarP.js.map +1 -0
  13. package/dist/config-provider.d.ts +9 -0
  14. package/dist/config-provider.js +6 -1
  15. package/dist/config-provider.js.map +1 -0
  16. package/dist/index.d.ts +89 -2407
  17. package/dist/index.js +28 -26
  18. package/dist/index.js.map +1 -0
  19. package/dist/{injection-tokens-D8CFCpjy.js → injection-tokens-CuDQs1ne.js} +49 -49
  20. package/dist/injection-tokens-CuDQs1ne.js.map +1 -0
  21. package/dist/legacy-chat.d.ts +1277 -0
  22. package/dist/legacy-chat.js +67 -0
  23. package/dist/legacy-chat.js.map +1 -0
  24. package/dist/legacy-renderer.d.ts +59 -0
  25. package/dist/legacy-renderer.js +41 -0
  26. package/dist/legacy-renderer.js.map +1 -0
  27. package/dist/renderer.d.ts +6 -2031
  28. package/dist/renderer.js +2 -1
  29. package/dist/renderer.js.map +1 -0
  30. package/dist/transform-jsx.d.ts +3 -1
  31. package/dist/transform-jsx.js +1 -0
  32. package/dist/transform-jsx.js.map +1 -0
  33. package/package.json +30 -33
  34. package/dist/ConfigProvider-BaJsiFgd.js +0 -86
  35. package/dist/SchemaCardRenderer-Bjn61C0M.js +0 -13440
  36. package/dist/chat.types-Cqd67Yp-.js +0 -1753
@@ -1,1753 +0,0 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(`.attachments-renderer[data-v-63821ae8]{display:flex;gap:8px;flex-wrap:wrap;margin-top:8px}.image-thumbnail[data-v-63821ae8]{position:relative;width:50px;height:50px;cursor:pointer;flex-shrink:0}.image-thumbnail .image-wrapper[data-v-63821ae8]{width:100%;height:100%;border-radius:6px;overflow:hidden;position:relative}.image-thumbnail img[data-v-63821ae8]{width:100%;height:100%;object-fit:cover;display:block}.image-thumbnail .delete-btn[data-v-63821ae8]{position:absolute;top:-8px;right:-8px;border-radius:50%;border:none;display:flex;align-items:center;justify-content:center;cursor:pointer;transition:all .2s;padding:0;background-color:transparent}.image-thumbnail .delete-btn .delete-btn-icon[data-v-63821ae8]{width:14px;height:14px}.image-thumbnail .hover-overlay[data-v-63821ae8]{position:absolute;top:0;left:0;right:0;bottom:0;background-color:#00000080;border-radius:8px;display:flex;align-items:center;justify-content:center;opacity:0;visibility:hidden;transition:opacity .2s,visibility .2s}.image-thumbnail .hover-overlay .preview-text[data-v-63821ae8]{color:#fff;font-size:12px;font-weight:500}.image-thumbnail:hover .hover-overlay[data-v-63821ae8]{opacity:1;visibility:visible}.file-item[data-v-63821ae8]{padding:8px 12px;background-color:#f5f5f5;border-radius:4px;display:inline-flex;align-items:center}.file-item .file-name[data-v-63821ae8]{font-size:14px;color:#333;word-break:break-all}.fullscreen-overlay[data-v-63821ae8]{position:fixed;top:0;left:0;right:0;bottom:0;background-color:#000c;display:flex;align-items:center;justify-content:center;z-index:9999;cursor:pointer;padding:20px}.fullscreen-overlay img[data-v-63821ae8]{max-width:90%;max-height:90%;object-fit:contain;cursor:default;border-radius:8px}.fullscreen-fade-enter-active[data-v-63821ae8]{transition:opacity .3s ease}.fullscreen-fade-leave-active[data-v-63821ae8]{transition:opacity .25s ease}.fullscreen-fade-enter-from[data-v-63821ae8],.fullscreen-fade-leave-to[data-v-63821ae8]{opacity:0}.image-scale-enter-active[data-v-63821ae8]{transition:transform .4s cubic-bezier(.34,1.56,.64,1),opacity .4s ease}.image-scale-leave-active[data-v-63821ae8]{transition:transform .3s cubic-bezier(.55,.055,.675,.19),opacity .3s ease}.image-scale-enter-from[data-v-63821ae8]{transform:scale(.2);opacity:0}.image-scale-leave-to[data-v-63821ae8]{transform:scale(.9);opacity:0}.template-data-renderer[data-v-e158cad0]{display:inline;word-break:break-word}.text-item[data-v-e158cad0]{display:inline}.template-item[data-v-e158cad0]{position:relative;display:inline}.template-item .template-text[data-v-e158cad0]{display:inline;cursor:pointer;color:#1476ff;background-color:#1476ff1a;padding:2px 4px;border-radius:4px}.image-preview[data-v-e158cad0]{max-width:200px;cursor:pointer}.image-preview .image-preview-img[data-v-e158cad0]{width:100%;height:100%;object-fit:contain}.fullscreen-overlay[data-v-e158cad0]{position:fixed;top:0;left:0;right:0;bottom:0;background-color:#000c;display:flex;align-items:center;justify-content:center;z-index:9999;cursor:pointer;padding:20px}.fullscreen-overlay img[data-v-e158cad0]{max-width:90%;max-height:90%;object-fit:contain;cursor:default;border-radius:8px}.fullscreen-fade-enter-active[data-v-e158cad0]{transition:opacity .3s ease}.fullscreen-fade-leave-active[data-v-e158cad0]{transition:opacity .25s ease}.fullscreen-fade-enter-from[data-v-e158cad0],.fullscreen-fade-leave-to[data-v-e158cad0]{opacity:0}.image-scale-enter-active[data-v-e158cad0]{transition:transform .4s cubic-bezier(.34,1.56,.64,1),opacity .4s ease}.image-scale-leave-active[data-v-e158cad0]{transition:transform .3s cubic-bezier(.55,.055,.675,.19),opacity .3s ease}.image-scale-enter-from[data-v-e158cad0]{transform:scale(.2);opacity:0}.image-scale-leave-to[data-v-e158cad0]{transform:scale(.9);opacity:0}.tr-bubble__reasoning[data-v-1ffff0cd]:not(:last-child){margin-top:8px}.header[data-v-1ffff0cd]{font-size:16px;line-height:1.5;color:var(--tr-text-secondary);display:flex;align-items:center;gap:8px;cursor:pointer}.header[data-v-1ffff0cd]:hover{color:var(--tr-text-primary);fill:var(--tr-text-primary)}.header .icon-and-text[data-v-1ffff0cd]{display:flex;align-items:center;gap:8px}.header .expand-icon.-rotate-90[data-v-1ffff0cd]{transform:rotate(-90deg)}@keyframes thinking-pulse-1ffff0cd{20%{opacity:1}50%{opacity:.5}80%{opacity:1}}.thinking[data-v-1ffff0cd]{animation:thinking-pulse-1ffff0cd 1.5s infinite linear}.detail[data-v-1ffff0cd]{color:var(--tr-text-secondary);margin-block:8px;display:flex;gap:8px;align-items:center;font-size:14px}.detail .detail-content[data-v-1ffff0cd]{max-height:300px;overflow-y:auto}.detail .detail-content[data-v-1ffff0cd]>*:first-child{margin-top:0}.detail .detail-content[data-v-1ffff0cd]>*:last-child{margin-bottom:0}.detail .side-border[data-v-1ffff0cd]{width:16px;flex-shrink:0;align-self:stretch;display:flex;flex-direction:column;align-items:center}.detail .side-border .dot-wrapper[data-v-1ffff0cd]{width:4px;height:16px;display:flex;align-items:center;flex-shrink:0}.detail .side-border .dot[data-v-1ffff0cd]{width:4px;height:4px;border-radius:50%;background-color:var(--tr-text-primary)}.detail .side-border .border-line[data-v-1ffff0cd]{flex:1;width:1.5px;background-color:#c2c2c2;border-radius:1px}.tr-bubble__step-tool[data-v-e45d630e]{font-size:14px;line-height:24px;padding:12px;color:var(--tr-text-secondary);background-color:var(--tr-container-bg-default-2);border-radius:12px}.tr-bubble__step-tool .tr-bubble__step-tool-header[data-v-e45d630e]{display:flex;align-items:center;justify-content:space-between;gap:8px}.tr-bubble__step-tool .tr-bubble__step-tool-left[data-v-e45d630e]{display:flex;align-items:center;gap:8px}.tr-bubble__step-tool .tr-bubble__step-tool-left .tr-bubble__step-tool-icon[data-v-e45d630e]{font-size:20px;flex-shrink:0}.tr-bubble__step-tool .tr-bubble__step-tool-left .tr-bubble__step-tool-icon.icon-running[data-v-e45d630e]{color:#898989;animation:spin 1s linear infinite}.tr-bubble__step-tool .tr-bubble__step-tool-left .tr-bubble__step-tool-icon.icon-success[data-v-e45d630e]{color:#898989}.tr-bubble__step-tool .tr-bubble__step-tool-left .tr-bubble__step-tool-icon.icon-failed[data-v-e45d630e],.tr-bubble__step-tool .tr-bubble__step-tool-left .tr-bubble__step-tool-icon.icon-cancelled[data-v-e45d630e]{color:var(--tr-color-error)}.tr-bubble__step-tool .tr-bubble__step-tool-left .tr-bubble__step-tool-title[data-v-e45d630e]{word-break:break-word}.tr-bubble__step-tool .tr-bubble__step-tool-left .tr-bubble__step-tool-name[data-v-e45d630e]{color:var(--tr-text-primary);font-weight:600}.tr-bubble__step-tool .tr-bubble__step-tool-expand[data-v-e45d630e]{display:flex;align-items:center;justify-content:center;cursor:pointer;flex-shrink:0}.tr-bubble__step-tool .tr-bubble__step-tool-expand .expand-icon[data-v-e45d630e]{font-size:16px}.tr-bubble__step-tool .tr-bubble__step-tool-expand .expand-icon.-rotate-90[data-v-e45d630e]{transform:rotate(-90deg)}.tr-bubble__step-tool .tr-bubble__step-tool-hr[data-v-e45d630e]{margin:12px 0;color:#dbdbdb}.tr-bubble__step-tool .tr-bubble__step-tool-params-content[data-v-e45d630e]{white-space:pre-wrap;word-break:break-word;font-family:monospace}._key_1ej6o_2{color:var(--tr-bubble-tool-key-color)}._number_1ej6o_6{color:var(--tr-bubble-tool-number-color)}._string_1ej6o_10{color:var(--tr-bubble-tool-string-color)}._boolean_1ej6o_14{color:var(--tr-bubble-tool-boolean-color)}._null_1ej6o_18{color:var(--tr-bubble-tool-null-color)}.loading-wrapper[data-v-e1124fd9]{width:fit-content;max-width:100%;overflow:hidden;direction:rtl}.loading-container[type=loading-text][data-v-e1124fd9]{margin:10px 0;color:#666;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;direction:ltr;display:inline-block}@supports ((background-clip: text)){.loading-container[type=loading-text][data-v-e1124fd9]{background:linear-gradient(90deg,#666,#666 45%,#999,#999,#666 60%,#666);background-size:200% 100%;-webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;animation:text-shimmer-e1124fd9 6s linear infinite}}@keyframes text-shimmer-e1124fd9{0%{background-position:200% 0}to{background-position:-200% 0}}.tg-playground-error-card[data-v-a0f77c05]{margin:8px 0;padding:16px 24px;border-radius:24px;background-color:var(--tv-color-error-bg-light);font-family:SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:var(--tr-bubble-text-font-size);line-height:var(--tr-bubble-text-line-height);overflow:hidden;color:var(--tr-text-primary)}.card-header[data-v-a0f77c05]{display:flex;position:relative;align-items:center;font-weight:500;gap:8px}.icon-error[data-v-a0f77c05]{width:18px;height:18px;fill:var(--tv-color-error-icon);transform:translateY(-1px)}.icon-right[data-v-a0f77c05]{width:16px;height:16px;position:absolute;fill:var(--tr-text-primary);right:0;top:50%;transform:translateY(-50%) rotate(0);cursor:pointer;transition:transform .2s ease-out}.icon-right.expanded[data-v-a0f77c05]{transform:translateY(-50%) rotate(90deg)}.card-title[data-v-a0f77c05]{white-space:nowrap}.card-body[data-v-a0f77c05]{margin:8px 0 0;background-color:var(--tr-bubble-content-bg);padding:8px 10px;border-radius:6px;max-height:60vh;overflow-x:auto;white-space:pre-wrap;word-break:break-all}.card-body.collapsed[data-v-a0f77c05]{height:0;padding:0;margin-top:0;overflow:hidden}.tg-chat-container[data-v-c5592237]{--ti-gen-chat-container-bg-color: #f0f0f0;--thinking-display: initial;--sender-bg: url("data:image/svg+xml,%3csvg%20viewBox='0%200%201244%20186'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='1244.000000'%20height='186.000000'%20fill='none'%3e%3cdefs%3e%3cclipPath%20id='clipPath_0'%3e%3crect%20width='1083.000122'%20height='276.998108'%20x='81.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20/%3e%3c/clipPath%3e%3cradialGradient%20id='paint_radial_0'%20cx='0'%20cy='0'%20r='1'%20gradientUnits='userSpaceOnUse'%20gradientTransform='matrix(-229.7,0,0,-152.751,410.969,285.331)'%3e%3cstop%20stop-color='rgb(255,239,248)'%20offset='0'%20stop-opacity='1'%20/%3e%3cstop%20stop-color='rgb(255,239,248)'%20offset='1'%20stop-opacity='0'%20/%3e%3c/radialGradient%3e%3cradialGradient%20id='paint_radial_1'%20cx='0'%20cy='0'%20r='1'%20gradientUnits='userSpaceOnUse'%20gradientTransform='matrix(372.771,0,0,193.995,774,236.999)'%3e%3cstop%20stop-color='rgb(230,240,255)'%20offset='0'%20stop-opacity='1'%20/%3e%3cstop%20stop-color='rgb(230,240,255)'%20offset='1'%20stop-opacity='0'%20/%3e%3c/radialGradient%3e%3c/defs%3e%3crect%20id='亮色背景'%20width='1244.000000'%20height='186.000000'%20x='0.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3cg%20id='对话框背景%201'%20clip-path='url(%23clipPath_0)'%20customFrame='url(%23clipPath_0)'%3e%3crect%20id='对话框背景%201'%20width='1083.000122'%20height='276.998108'%20x='81.000000'%20y='0.000000'%20/%3e%3crect%20id='容器%202'%20width='1083.000122'%20height='276.998108'%20x='81.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3crect%20id='show_mask_2'%20width='460.000000'%20height='305.501465'%20x='180.969238'%20y='132.583984'%20rx='152.750717'%20fill='url(%23paint_radial_0)'%20/%3e%3crect%20id='show_mask_1'%20width='912.000000'%20height='474.000000'%20x='318.000000'%20y='0.000000'%20rx='237.000000'%20fill='url(%23paint_radial_1)'%20/%3e%3c/g%3e%3c/svg%3e") no-repeat center;--sender-border-color: #e5e5e5;--generating-bg-before: linear-gradient(90deg, #fff, #a2c7f4);--generating-bg-after: #fff;box-sizing:border-box;height:100%;color:var(--tr-text-primary);background-color:var(--ti-gen-chat-container-bg-color);position:relative;display:flex;flex-direction:column;overflow:auto}.tg-chat-container.dark[data-v-c5592237]{--ti-gen-chat-container-bg-color: #191919;--sender-bg: url("data:image/svg+xml,%3csvg%20viewBox='0%200%201244%20186'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='1244.000000'%20height='186.000000'%20fill='none'%3e%3cmask%20id='mask_3'%20width='528.384094'%20height='282.593811'%20x='111.420166'%20y='110.491211'%20maskUnits='userSpaceOnUse'%3e%3cg%20filter='url(%23pixso_custom_mask_type_outline)'%3e%3crect%20id='蒙版'%20width='528.384094'%20height='282.593811'%20x='111.420166'%20y='110.491211'%20rx='141.296906'%20fill='rgb(255,255,255)'%20/%3e%3c/g%3e%3c/mask%3e%3cmask%20id='mask_2'%20width='1047.578979'%20height='560.273071'%20x='276.827148'%20y='-104.525391'%20maskUnits='userSpaceOnUse'%3e%3cg%20filter='url(%23pixso_custom_mask_type_outline)'%3e%3crect%20id='蒙版'%20width='1047.578979'%20height='560.273071'%20x='276.827148'%20y='-104.525391'%20rx='235.379578'%20fill='rgb(255,255,255)'%20/%3e%3c/g%3e%3c/mask%3e%3cmask%20id='mask_1'%20width='639.804199'%20height='342.184357'%20x='374.463623'%20y='-30.191406'%20maskUnits='userSpaceOnUse'%3e%3cg%20filter='url(%23pixso_custom_mask_type_outline)'%3e%3crect%20id='蒙版'%20width='639.804199'%20height='342.184357'%20x='374.463623'%20y='-30.191406'%20rx='171.092178'%20fill='rgb(255,255,255)'%20/%3e%3c/g%3e%3c/mask%3e%3cmask%20id='mask_0'%20width='1244.000000'%20height='360.000000'%20x='0.000000'%20y='38.000000'%20maskUnits='userSpaceOnUse'%3e%3cg%20filter='url(%23pixso_custom_mask_type_alpha)'%3e%3cellipse%20id='椭圆形'%20rx='622.000000'%20ry='180.000000'%20cx='622'%20cy='218'%20fill='url(%23paint_radial_2)'%20/%3e%3cellipse%20id='椭圆形'%20rx='621.500000'%20ry='179.500000'%20cx='622'%20cy='218'%20stroke='rgb(151,151,151)'%20stroke-opacity='0'%20stroke-width='1'%20/%3e%3c/g%3e%3c/mask%3e%3cdefs%3e%3cclipPath%20id='clipPath_1'%3e%3crect%20width='1244.000000'%20height='148.000000'%20x='0.000000'%20y='38.000000'%20fill='rgb(255,255,255)'%20/%3e%3c/clipPath%3e%3cradialGradient%20id='paint_radial_2'%20cx='0'%20cy='0'%20r='1'%20gradientUnits='userSpaceOnUse'%20gradientTransform='matrix(689.165,0,0,158.722,622,218)'%3e%3cstop%20stop-color='rgb(0,0,0)'%20offset='0'%20stop-opacity='1'%20/%3e%3cstop%20stop-color='rgb(68.3036,68.2353,68.2353)'%20offset='0.309297144'%20stop-opacity='1'%20/%3e%3cstop%20stop-color='rgb(0,0,0)'%20offset='1'%20stop-opacity='0'%20/%3e%3c/radialGradient%3e%3cfilter%20id='pixso_custom_mask_type_alpha'%3e%3cfeColorMatrix%20type='matrix'%20values='0%200%200%200%201%200%200%200%200%201%200%200%200%200%201%200%200%200%201%200%20'%20/%3e%3c/filter%3e%3cradialGradient%20id='paint_radial_3'%20cx='0'%20cy='0'%20r='1'%20gradientUnits='userSpaceOnUse'%20gradientTransform='matrix(319.485,0,0,171.092,694.366,140.901)'%3e%3cstop%20stop-color='rgb(144.576,104.098,32.8582)'%20offset='0'%20stop-opacity='1'%20/%3e%3cstop%20stop-color='rgb(129.777,92.7956,27.1351)'%20offset='1'%20stop-opacity='0'%20/%3e%3c/radialGradient%3e%3cfilter%20id='pixso_custom_mask_type_outline'%3e%3cfeColorMatrix%20type='matrix'%20values='0%200%200%200%201%200%200%200%200%201%200%200%200%200%201%200%200%200%201%200%20'%20/%3e%3c/filter%3e%3cradialGradient%20id='paint_radial_4'%20cx='0'%20cy='0'%20r='1'%20gradientUnits='userSpaceOnUse'%20gradientTransform='matrix(652.421,0,0,349.387,800.617,175.611)'%3e%3cstop%20stop-color='rgb(18.6076,39.3967,70.5804)'%20offset='0'%20stop-opacity='1'%20/%3e%3cstop%20stop-color='rgb(22.209,47.0218,84.2411)'%20offset='1'%20stop-opacity='0'%20/%3e%3c/radialGradient%3e%3cradialGradient%20id='paint_radial_5'%20cx='0'%20cy='0'%20r='1'%20gradientUnits='userSpaceOnUse'%20gradientTransform='matrix(263.848,0,0,141.297,375.612,251.788)'%3e%3cstop%20stop-color='rgb(75.1339,33.8103,57.0548)'%20offset='0'%20stop-opacity='1'%20/%3e%3cstop%20stop-color='rgb(75.1339,33.4688,56.9054)'%20offset='1'%20stop-opacity='0'%20/%3e%3c/radialGradient%3e%3c/defs%3e%3crect%20id='暗色背景'%20width='1244.000000'%20height='186.000000'%20x='0.000000'%20y='0.000000'%20fill='rgb(25,25,25)'%20fill-opacity='0'%20/%3e%3cg%20id='组合%205542'%3e%3cg%20id='容器%204'%20clip-path='url(%23clipPath_1)'%20customFrame='url(%23clipPath_1)'%3e%3crect%20id='容器%204'%20width='1244.000000'%20height='148.000000'%20x='0.000000'%20y='38.000000'%20fill='rgb(25,25,25)'%20fill-opacity='0'%20/%3e%3cg%20id='椭圆形%204'%20mask='url(%23mask_0)'%3e%3cg%20id='BLUE备份%202'%20opacity='0.100000001'%20showMaskRef='url(%23show_mask_0)'%20mask='url(%23mask_1)'%3e%3crect%20id='show_mask_0'%20width='639.804199'%20height='342.184357'%20x='374.463623'%20y='-30.191406'%20rx='171.092178'%20fill='url(%23paint_radial_3)'%20/%3e%3c/g%3e%3cg%20id='BLUE备份%203'%20showMaskRef='url(%23show_mask_1)'%20mask='url(%23mask_2)'%3e%3crect%20id='show_mask_1'%20width='1047.578979'%20height='560.273071'%20x='276.827148'%20y='-104.525391'%20rx='235.379578'%20fill='url(%23paint_radial_4)'%20/%3e%3c/g%3e%3cg%20id='BLUE备份%204'%20showMaskRef='url(%23show_mask_2)'%20mask='url(%23mask_3)'%3e%3crect%20id='show_mask_2'%20width='528.384094'%20height='282.593811'%20x='111.420166'%20y='110.491211'%20rx='141.296906'%20fill='url(%23paint_radial_5)'%20/%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e") no-repeat center;--sender-border-color: #333;--generating-bg-before: linear-gradient(90deg, #262626, #808080);--generating-bg-after: #191919}.is-loading-in-top[data-v-c5592237]{margin-top:-48px}.messages-container[data-v-c5592237]{flex:1;overflow:auto;word-break:break-word}[data-v-c5592237] .tr-bubble__loading{margin-top:8px}[data-v-c5592237] .tr-bubble.placement-start .tr-bubble__content{padding:0;background:transparent;border-radius:0;box-shadow:none}[data-v-c5592237] .tr-bubble[data-role=assistant] .tr-bubble__content-items>[type]:not([type=""]):not([type=schema-card]):not([type=loading-text]){display:var(--thinking-display, initial)}[data-v-c5592237] .tr-bubble__step-tool+.tr-bubble__step-tool{margin-top:16px}[data-v-c5592237] .tr-bubble.placement-end{width:100%}[data-v-c5592237] .tr-bubble__content-wrapper{max-width:calc(100% - var(--ti-gen-chat-avatar-and-gap-width, 56px) * 2)}[data-v-c5592237] .tr-bubble__content-wrapper .tr-bubble__content{max-width:100%}[data-v-c5592237] .tr-bubble__content-wrapper .tr-bubble__content-items{overflow-x:auto}.sender-container[data-v-c5592237]{position:relative;flex-shrink:0;padding:16px 0;background:var(--sender-bg)}.sender-container .attachments-container[data-v-c5592237]{padding:0 20px}.scroll-to-bottom-button[data-v-c5592237]{position:absolute;left:50%;transform:translate(-50%);top:-35px;width:40px;height:40px;background-color:var(--generating-bg-after);border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;border:1px solid var(--sender-border-color);z-index:1000}.scroll-to-bottom-button>svg[data-v-c5592237]{width:20px;height:20px}.scroll-to-bottom-button[data-v-c5592237]:hover{box-shadow:0 10px 20px #0000001a,0 0 1px #00000026}.scroll-to-bottom-button.is-generating[data-v-c5592237]{border:none;background-color:transparent}.scroll-to-bottom-button.is-generating[data-v-c5592237]:before{content:"";position:absolute;top:-2px;left:-2px;right:-2px;bottom:-2px;width:calc(100% + 4px);height:calc(100% + 4px);border-radius:50%;background:var(--generating-bg-before);z-index:0;animation:rotate-border-c5592237 2s linear infinite}.scroll-to-bottom-button.is-generating[data-v-c5592237]:after{content:"";position:absolute;top:0;left:0;width:100%;height:100%;border-radius:50%;background-color:var(--generating-bg-after);z-index:1}.scroll-to-bottom-button.is-generating>svg[data-v-c5592237]{z-index:2}.footer-text[data-v-c5592237]{font-size:12px;color:#999;text-align:center;margin-top:16px}[data-v-c5592237] .schema-render-container{min-width:min(calc(var(--messages-container-width) - 250px),400px)}@keyframes rotate-border-c5592237{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.tiny-sender[data-v-c5592237]{width:80%;margin:0 auto}`)),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
- import { ref as I, onMounted as ve, onUnmounted as nt, h as se, nextTick as at, defineComponent as Q, computed as D, createElementBlock as E, openBlock as x, createVNode as F, Fragment as ie, renderList as fe, createElementVNode as _, withModifiers as ot, unref as M, toDisplayString as L, Transition as ce, withCtx as W, createCommentVNode as K, withDirectives as Ae, normalizeClass as V, vShow as De, useCssModule as rt, createBlock as $e, resolveDynamicComponent as lt, createTextVNode as it, onBeforeUnmount as Oe, reactive as de, toRaw as Z, isRef as Be, isReactive as ct, watch as ue, inject as ut, provide as dt, normalizeStyle as Re, renderSlot as mt, createSlots as pt } from "vue";
3
- import "@opentiny/tiny-robot/dist/style.css";
4
- import { BubbleMarkdownContentRenderer as Ne, TrBubbleProvider as gt, TrBubbleList as ht, TrSender as ft } from "@opentiny/tiny-robot";
5
- import { BaseModelProvider as vt, STATUS as H, GeneratingStatus as oe, AIClient as yt } from "@opentiny/tiny-robot-kit";
6
- import { IconFileRemove as _t, IconArrowDown as ye, IconLoading as wt, IconPlugin as ke, IconError as Ct, IconCancelled as bt, IconUser as Mt, IconAi as St } from "@opentiny/tiny-robot-svgs";
7
- import { TinyNotify as xe, TinyPopover as Rt } from "@opentiny/vue";
8
- import { u as $, _ as ee, b as kt, C as xt } from "./injection-tokens-D8CFCpjy.js";
9
- import { a as Ee, y as Te, G as Et, c as Tt } from "./SchemaCardRenderer-Bjn61C0M.js";
10
- import { iconChevronRight as It, iconOperationfaild as Ft } from "@opentiny/vue-icon";
11
- import { v4 as At } from "uuid";
12
- const Dt = (t) => t.map((s) => ({
13
- name: s.name,
14
- description: s.description,
15
- parameters: s.parameters
16
- })), $t = (t) => t.map((s) => {
17
- const { ref: e, ...n } = s;
18
- return n;
19
- }), Ot = async (t) => {
20
- const { url: s, messages: e, model: n, temperature: a, signal: m, customComponents: i, customSnippets: d, customExamples: r, customActions: l, customFetch: o } = t, p = {
21
- customComponents: $t(i),
22
- customSnippets: d,
23
- customExamples: r,
24
- customActions: Dt(l)
25
- }, C = {
26
- tinygenui: JSON.stringify(p)
27
- }, f = {
28
- method: "POST",
29
- headers: {
30
- "Content-Type": "application/json"
31
- },
32
- signal: m,
33
- body: JSON.stringify({
34
- messages: e,
35
- model: n,
36
- temperature: a,
37
- metadata: C
38
- })
39
- }, S = await (o || fetch)(s, f);
40
- if (!S.ok) {
41
- const B = await S.text();
42
- throw new Error(`HTTP error! status: ${S.status}, details: ${B}`);
43
- }
44
- return S;
45
- };
46
- async function Bt(t, s) {
47
- let e = "";
48
- const n = new TextDecoder("utf-8");
49
- for (; ; ) {
50
- const { done: a, value: m } = await t.read();
51
- if (a) break;
52
- for (e += n.decode(m, { stream: !0 }); ; ) {
53
- const i = e.indexOf(`
54
- `);
55
- if (i === -1) break;
56
- const d = e.slice(0, i).trim();
57
- if (e = e.slice(i + 1), !d.startsWith("data:")) continue;
58
- const r = d.slice(5).trim();
59
- if (r === "[DONE]") break;
60
- s(r);
61
- }
62
- }
63
- return !0;
64
- }
65
- class Nt extends vt {
66
- constructor({ getChatOptions: s }) {
67
- super({ provider: "custom" }), this.responseHandlers = [], this.getChatOptions = s;
68
- }
69
- validateRequest(s) {
70
- }
71
- setResponseHandlers(s) {
72
- this.responseHandlers = s;
73
- }
74
- async getData(s) {
75
- var o;
76
- const {
77
- url: e,
78
- model: n,
79
- temperature: a,
80
- customComponents: m,
81
- customSnippets: i,
82
- customExamples: d,
83
- customActions: r,
84
- customFetch: l
85
- } = this.getChatOptions();
86
- return await Ot({
87
- url: e,
88
- messages: s.messages,
89
- model: n,
90
- temperature: a,
91
- signal: (o = s.options) == null ? void 0 : o.signal,
92
- customComponents: m,
93
- customSnippets: i,
94
- customExamples: d,
95
- customActions: r,
96
- customFetch: l
97
- });
98
- }
99
- async chat(s) {
100
- return {};
101
- }
102
- async chatStream(s, e) {
103
- var C;
104
- const { onDone: n, onData: a, onError: m } = e;
105
- let i;
106
- try {
107
- i = await this.getData(s);
108
- } catch (f) {
109
- n({ type: "error", error: f });
110
- return;
111
- }
112
- const r = i.body.getReader(), l = {}, { chatConfig: o } = this.getChatOptions();
113
- l.chatConfig = o;
114
- const p = (C = s.options) == null ? void 0 : C.signal;
115
- p == null || p.addEventListener(
116
- "abort",
117
- () => {
118
- r.cancel(), this.handlerEnd(l);
119
- },
120
- { once: !0 }
121
- ), this.handlerStart(l, e), await Bt(r, (f) => {
122
- this.handlerChunk(f, l);
123
- }), this.handlerEnd(l);
124
- }
125
- handlerChunk(s, e) {
126
- try {
127
- const n = JSON.parse(s);
128
- for (const a of this.responseHandlers)
129
- if (a.match(n, e)) {
130
- if (a.handler(n, e)) break;
131
- } else if (a.notMatchHandler && a.notMatchHandler(n, e))
132
- break;
133
- } catch (n) {
134
- console.error(n);
135
- }
136
- }
137
- handlerStart(s, e) {
138
- for (const n of this.responseHandlers)
139
- n.start && n.start(s, e);
140
- }
141
- handlerEnd(s) {
142
- for (const e of this.responseHandlers)
143
- e.end && e.end(s);
144
- }
145
- }
146
- function Pt(t, s) {
147
- let e = null, n = 0;
148
- return function(...a) {
149
- const m = Date.now(), i = m - n;
150
- if (i >= s)
151
- e && (clearTimeout(e), e = null), n = m, t.apply(this, a);
152
- else {
153
- e && clearTimeout(e);
154
- const d = s - i;
155
- e = setTimeout(() => {
156
- n = Date.now(), e = null, t.apply(this, a);
157
- }, d);
158
- }
159
- };
160
- }
161
- const Lt = (t) => {
162
- const s = I(!1), e = I(!1);
163
- let n = null;
164
- const a = () => {
165
- t.value && (s.value = t.value.scrollTop + t.value.clientHeight + 130 >= t.value.scrollHeight);
166
- }, m = () => {
167
- t.value && at(() => {
168
- var l;
169
- (l = t.value) == null || l.scrollTo({
170
- top: t.value.scrollHeight,
171
- behavior: "smooth"
172
- });
173
- });
174
- }, i = (l = 10, o = 150) => {
175
- if (!t.value) return;
176
- let p = 0, C = 0, f = 0;
177
- const A = () => {
178
- if (!t.value) return;
179
- const S = t.value.scrollHeight, B = t.value.scrollTop, O = t.value.clientHeight, z = B + O + 10 >= S;
180
- S !== C ? (C = S, f = 0, p = 0) : f++, !z && ((f >= 2 || p >= 2) && m(), !z && p < l && (p++, setTimeout(() => {
181
- requestAnimationFrame(() => {
182
- A();
183
- });
184
- }, o)));
185
- };
186
- setTimeout(() => {
187
- A(), a();
188
- }, 50);
189
- }, d = () => {
190
- !s.value || e.value || m();
191
- }, r = () => {
192
- e.value = !0, n && clearTimeout(n), n = setTimeout(() => {
193
- e.value = !1, n = null;
194
- }, 100);
195
- };
196
- return ve(() => {
197
- a(), t.value && (t.value.addEventListener("scroll", a, { passive: !0 }), t.value.addEventListener("wheel", r, { passive: !0 }), t.value.addEventListener("touchmove", r, { passive: !0 }));
198
- }), nt(() => {
199
- t.value && (t.value.removeEventListener("scroll", a), t.value.removeEventListener("wheel", r), t.value.removeEventListener("touchmove", r));
200
- }), {
201
- scrollToBottom: m,
202
- scrollToBottomWithRetry: i,
203
- autoScrollToBottom: d,
204
- isLastMessageInBottom: s,
205
- updateIsLastMessageInBottom: a
206
- };
207
- }, he = (t) => {
208
- if (t)
209
- return typeof t == "function" && !("__name" in t || "setup" in t || "render" in t) ? t : (s) => se(t, s);
210
- }, Ut = {
211
- // 图片格式
212
- jpg: "image/jpeg",
213
- jpeg: "image/jpeg",
214
- png: "image/png",
215
- gif: "image/gif",
216
- webp: "image/webp",
217
- bmp: "image/bmp",
218
- heic: "image/heic",
219
- tiff: "image/tiff",
220
- // 文档格式
221
- pdf: "application/pdf",
222
- doc: "application/msword",
223
- docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
224
- xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
225
- txt: "text/plain",
226
- md: "text/markdown",
227
- csv: "text/csv",
228
- json: "application/json",
229
- epub: "application/epub+zip",
230
- mobi: "application/x-mobipocket-ebook"
231
- }, _e = [
232
- "image/jpeg",
233
- "image/png",
234
- "image/gif",
235
- "image/webp",
236
- "image/bmp",
237
- "image/heic",
238
- "image/tiff"
239
- ];
240
- function Ht(t, s) {
241
- const { t: e } = $(), n = s * 1024 * 1024;
242
- if (t.size > n)
243
- throw new Error(e("fileUpload.error.fileSizeExceeded", {
244
- maxSizeMB: s,
245
- currentSizeMB: (t.size / 1024 / 1024).toFixed(2)
246
- }));
247
- }
248
- function zt(t, s) {
249
- var i, d, r;
250
- const { t: e } = $();
251
- if (!s)
252
- return { valid: !1, error: e("fileUpload.error.unsupportedModel") };
253
- const n = ((i = t.name.split(".").pop()) == null ? void 0 : i.toLowerCase()) || "";
254
- if (!((d = s.supportImage) != null && d.supportedFileTypes.includes(n)))
255
- return {
256
- valid: !1,
257
- error: e("fileUpload.error.unsupportedFormat", { extension: n })
258
- };
259
- const a = ((r = s.supportImage) == null ? void 0 : r.maxImageSize) || 0, m = a * 1024 * 1024;
260
- return t.size > m ? {
261
- valid: !1,
262
- error: e("fileUpload.error.sizeLimitExceeded", { maxSize: a })
263
- } : { valid: !0 };
264
- }
265
- function qt(t) {
266
- return _e.includes(t) ? "image" : "document";
267
- }
268
- const Jt = async (t, s) => {
269
- var a;
270
- const { t: e } = $();
271
- if (!s)
272
- throw new Error(e("fileUpload.error.unsupportedModel"));
273
- if ((a = s.supportImage) != null && a.maxFilesPerRequest && t.length > s.supportImage.maxFilesPerRequest)
274
- throw new Error(e("fileUpload.error.maxFilesExceeded", { maxFiles: s.supportImage.maxFilesPerRequest }));
275
- return await Promise.all(t.map((m) => Gt(m, s)));
276
- }, Gt = async (t, s) => {
277
- var i;
278
- const { t: e } = $(), n = qt(t.type), a = zt(t, s);
279
- if (!a.valid)
280
- throw new Error(a.error);
281
- const m = ((i = s.supportImage) == null ? void 0 : i.maxImageSize) || 0;
282
- if (Ht(t, m), n === "image")
283
- return {
284
- type: "image",
285
- image: t.base64,
286
- filename: t.name
287
- };
288
- if (n === "document")
289
- return {
290
- type: "file",
291
- mediaType: t.type,
292
- data: t.base64,
293
- filename: t.name
294
- };
295
- throw new Error(e("fileUpload.error.unsupportedFileType", { fileCategory: n }));
296
- }, jt = (t) => new Promise((s, e) => {
297
- const n = new FileReader();
298
- n.readAsDataURL(t), n.onload = () => {
299
- const a = {
300
- name: t.name,
301
- type: t.type,
302
- size: t.size,
303
- lastModified: t.lastModified,
304
- base64: n.result
305
- };
306
- s(a);
307
- }, n.onerror = (a) => e(a);
308
- }), Wt = () => {
309
- const { t } = $(), s = I([]), e = I([]);
310
- return {
311
- attachments: s,
312
- templateData: e,
313
- processAttachments: async (d, r) => {
314
- let l = [];
315
- if (d.length === 0)
316
- return { apiContent: l };
317
- try {
318
- return l = await Jt(d, r), {
319
- apiContent: l
320
- };
321
- } catch (o) {
322
- return xe({
323
- type: "error",
324
- title: t("fileUpload.error.processFailed"),
325
- message: o instanceof Error ? o.message : t("fileUpload.error.unknownError"),
326
- position: "top-right"
327
- }), null;
328
- }
329
- },
330
- clearAttachments: () => {
331
- s.value = [];
332
- },
333
- handleFilesSelected: async (d, r) => {
334
- if (!(!d || d.length === 0)) {
335
- e.value.length || e.value.unshift({
336
- type: "text",
337
- content: r
338
- });
339
- for (const l of d) {
340
- e.value.push({
341
- type: "template",
342
- content: l.name || ""
343
- });
344
- try {
345
- if (s.value.find((p) => p.name === l.name))
346
- continue;
347
- const o = await jt(l);
348
- s.value.push(o);
349
- } catch (o) {
350
- xe({
351
- type: "error",
352
- title: t("fileUpload.error.validationFailed"),
353
- message: o instanceof Error ? o.message : t("fileUpload.error.unknownError"),
354
- position: "top-right"
355
- });
356
- }
357
- }
358
- }
359
- },
360
- handleTemplateEdit: (d, r) => {
361
- const l = d.value, o = new Set(
362
- s.value.map((f) => f.name).filter((f) => !!f)
363
- ), p = l.filter((f) => {
364
- if (f.type === "template") {
365
- const A = f.content;
366
- return A && o.has(A);
367
- }
368
- return !0;
369
- }), C = new Set(
370
- p.filter((f) => f.type === "template" && f.content).map((f) => f.content)
371
- );
372
- for (let f = s.value.length - 1; f >= 0; f--) {
373
- const S = s.value[f].name;
374
- S && !C.has(S) && s.value.splice(f, 1);
375
- }
376
- return p;
377
- }
378
- };
379
- }, Kt = { class: "attachments-renderer" }, Vt = ["onClick"], Zt = { class: "image-wrapper" }, Yt = ["src", "alt"], Xt = ["onClick"], Qt = { class: "file-name" }, es = ["src", "alt"], ts = /* @__PURE__ */ Q({
380
- __name: "AttachmentsRenderer",
381
- props: {
382
- attachments: {}
383
- },
384
- emits: ["remove"],
385
- setup(t, { emit: s }) {
386
- const e = t, n = s, a = I(null), m = (p) => _e.includes(p.type), i = D(() => e.attachments.filter((p) => m(p))), d = D(() => e.attachments.filter((p) => !m(p))), r = (p) => {
387
- n("remove", p);
388
- }, l = (p) => {
389
- a.value = p, document.body.style.overflow = "hidden";
390
- }, o = () => {
391
- a.value = null, document.body.style.overflow = "";
392
- };
393
- return (p, C) => (x(), E("div", Kt, [
394
- (x(!0), E(ie, null, fe(i.value, (f, A) => (x(), E("div", {
395
- key: f.name,
396
- class: "image-thumbnail",
397
- onClick: (S) => l(f)
398
- }, [
399
- _("div", Zt, [
400
- _("img", {
401
- src: f.base64,
402
- alt: f.name
403
- }, null, 8, Yt)
404
- ]),
405
- _("button", {
406
- class: "delete-btn",
407
- onClick: ot((S) => r(f), ["stop"]),
408
- type: "button"
409
- }, [
410
- F(M(_t), { class: "delete-btn-icon" })
411
- ], 8, Xt),
412
- C[0] || (C[0] = _("div", { class: "hover-overlay" }, [
413
- _("span", { class: "preview-text" }, "预览")
414
- ], -1))
415
- ], 8, Vt))), 128)),
416
- (x(!0), E(ie, null, fe(d.value, (f) => (x(), E("div", {
417
- key: f.name,
418
- class: "file-item"
419
- }, [
420
- _("span", Qt, L(f.name), 1)
421
- ]))), 128)),
422
- F(ce, { name: "fullscreen-fade" }, {
423
- default: W(() => [
424
- a.value ? (x(), E("div", {
425
- key: 0,
426
- class: "fullscreen-overlay",
427
- onClick: o
428
- }, [
429
- F(ce, { name: "image-scale" }, {
430
- default: W(() => [
431
- a.value ? (x(), E("img", {
432
- key: 0,
433
- src: a.value.base64,
434
- alt: a.value.name
435
- }, null, 8, es)) : K("", !0)
436
- ]),
437
- _: 1
438
- })
439
- ])) : K("", !0)
440
- ]),
441
- _: 1
442
- })
443
- ]));
444
- }
445
- }), ss = /* @__PURE__ */ ee(ts, [["__scopeId", "data-v-63821ae8"]]), ns = { class: "template-data-renderer" }, as = {
446
- key: 0,
447
- class: "text-item"
448
- }, os = {
449
- key: 1,
450
- class: "template-item"
451
- }, rs = ["onClick"], ls = {
452
- key: 0,
453
- class: "image-preview"
454
- }, is = ["src", "alt", "onClick"], cs = ["src", "alt"], us = /* @__PURE__ */ Q({
455
- __name: "TemplateDataRenderer",
456
- props: {
457
- templateData: { default: () => [] },
458
- attachments: { default: () => [] }
459
- },
460
- setup(t) {
461
- const s = t, e = I(null), n = (l) => {
462
- if (l.type !== "template" || !l.content)
463
- return !1;
464
- const o = s.attachments.find((p) => p.name === l.content);
465
- return o ? _e.includes(o.type) : !1;
466
- }, a = (l) => {
467
- if (l.type !== "template" || !l.content)
468
- return "";
469
- const o = s.attachments.find((p) => p.name === l.content);
470
- return (o == null ? void 0 : o.base64) || "";
471
- }, m = (l) => {
472
- if (!(l.type !== "template" || !l.content))
473
- return s.attachments.find((o) => o.name === l.content);
474
- }, i = (l) => {
475
- const o = m(l);
476
- o && d(o);
477
- }, d = (l) => {
478
- e.value = l, document.body.style.overflow = "hidden";
479
- }, r = () => {
480
- e.value = null, document.body.style.overflow = "";
481
- };
482
- return (l, o) => (x(), E("div", ns, [
483
- (x(!0), E(ie, null, fe(t.templateData, (p, C) => (x(), E(ie, { key: C }, [
484
- p.type === "text" ? (x(), E("span", as, L(p.content), 1)) : p.type === "template" ? (x(), E("span", os, [
485
- F(M(Rt), {
486
- width: "200",
487
- trigger: "hover",
488
- content: p.content,
489
- placement: "top"
490
- }, {
491
- reference: W(() => [
492
- _("span", {
493
- class: "template-text",
494
- onClick: (f) => i(p)
495
- }, L(p.content), 9, rs)
496
- ]),
497
- default: W(() => [
498
- n(p) ? (x(), E("div", ls, [
499
- _("img", {
500
- class: "image-preview-img",
501
- src: a(p),
502
- alt: p.content,
503
- onClick: (f) => i(p)
504
- }, null, 8, is)
505
- ])) : K("", !0)
506
- ]),
507
- _: 2
508
- }, 1032, ["content"])
509
- ])) : K("", !0)
510
- ], 64))), 128)),
511
- F(ce, { name: "fullscreen-fade" }, {
512
- default: W(() => [
513
- e.value ? (x(), E("div", {
514
- key: 0,
515
- class: "fullscreen-overlay",
516
- onClick: r
517
- }, [
518
- F(ce, { name: "image-scale" }, {
519
- default: W(() => [
520
- e.value ? (x(), E("img", {
521
- key: 0,
522
- src: e.value.base64,
523
- alt: e.value.name
524
- }, null, 8, cs)) : K("", !0)
525
- ]),
526
- _: 1
527
- })
528
- ])) : K("", !0)
529
- ]),
530
- _: 1
531
- })
532
- ]));
533
- }
534
- }), ds = /* @__PURE__ */ ee(us, [["__scopeId", "data-v-e158cad0"]]), ms = {
535
- class: "tr-bubble__reasoning",
536
- "data-type": "reasoning"
537
- }, ps = { class: "title" }, gs = { class: "detail" }, hs = /* @__PURE__ */ Q({
538
- __name: "ReasoningRenderer",
539
- props: {
540
- content: {},
541
- thinking: { type: Boolean }
542
- },
543
- setup(t) {
544
- const s = t, e = I(!1), { t: n } = $(), a = () => {
545
- e.value = !e.value;
546
- }, m = new Ne({
547
- defaultAttrs: { class: "markdown-content" },
548
- mdConfig: { html: !0 }
549
- }), i = (d) => m.render({ content: d.content });
550
- return (d, r) => (x(), E("div", ms, [
551
- _("div", {
552
- class: "header",
553
- onClick: a
554
- }, [
555
- _("div", {
556
- class: V(["icon-and-text", { thinking: s.thinking }])
557
- }, [
558
- r[0] || (r[0] = _("svg", {
559
- class: "thinking-icon",
560
- width: "1em",
561
- height: "1em",
562
- viewBox: "0 0 24 24",
563
- xmlns: "http://www.w3.org/2000/svg",
564
- fill: "none",
565
- stroke: "currentColor",
566
- "stroke-width": "2",
567
- "stroke-linecap": "round",
568
- "stroke-linejoin": "round"
569
- }, [
570
- _("circle", {
571
- cx: "12",
572
- cy: "12",
573
- r: "1"
574
- }),
575
- _("path", { d: "M20.2 20.2c2.04-2.03.02-7.36-4.5-11.9-4.54-4.52-9.87-6.54-11.9-4.5-2.04 2.03-.02 7.36 4.5 11.9 4.54 4.52 9.87 6.54 11.9 4.5Z" }),
576
- _("path", { d: "M15.7 15.7c4.52-4.54 6.54-9.87 4.5-11.9-2.03-2.04-7.36-.02-11.9 4.5-4.52 4.54-6.54 9.87-4.5 11.9 2.03 2.04 7.36.02 11.9-4.5Z" })
577
- ], -1)),
578
- _("span", ps, L(s.thinking ? M(n)("reasoning.thinking") : M(n)("reasoning.thinkingEnd")), 1)
579
- ], 2),
580
- F(M(ye), {
581
- class: V(["expand-icon", { "-rotate-90": !e.value }])
582
- }, null, 8, ["class"])
583
- ]),
584
- Ae(_("div", gs, [
585
- r[1] || (r[1] = _("div", { class: "side-border" }, [
586
- _("div", { class: "dot-wrapper" }, [
587
- _("div", { class: "dot" })
588
- ]),
589
- _("div", { class: "border-line" })
590
- ], -1)),
591
- F(i, {
592
- content: s.content,
593
- class: "detail-content"
594
- }, null, 8, ["content"])
595
- ], 512), [
596
- [De, e.value]
597
- ])
598
- ]));
599
- }
600
- }), fs = /* @__PURE__ */ ee(hs, [["__scopeId", "data-v-1ffff0cd"]]), vs = { class: "tr-bubble__step-tool" }, ys = { class: "tr-bubble__step-tool-header" }, _s = { class: "tr-bubble__step-tool-left" }, ws = { class: "tr-bubble__step-tool-title" }, Cs = { class: "tr-bubble__step-tool-name" }, bs = { class: "tr-bubble__step-tool-expand" }, Ms = {
601
- key: 0,
602
- class: "tr-bubble__step-tool-params"
603
- }, Ss = ["innerHTML"], Rs = /* @__PURE__ */ Q({
604
- __name: "ToolRenderer",
605
- props: {
606
- name: {},
607
- status: {},
608
- content: {},
609
- formatPretty: { type: Boolean },
610
- defaultOpen: { type: Boolean }
611
- },
612
- setup(t) {
613
- const s = t, { t: e } = $(), n = I(s.defaultOpen ?? !1), a = /* @__PURE__ */ new Map([
614
- ["running", { text: e("toolStatus.running"), icon: wt }],
615
- ["success", { text: e("toolStatus.success"), icon: ke }],
616
- ["failed", { text: e("toolStatus.failed"), icon: Ct }],
617
- ["cancelled", { text: e("toolStatus.cancelled"), icon: bt }]
618
- ]), m = D(() => a.get(s.status) || { text: "", icon: ke }), i = rt(), d = (r) => {
619
- if (!r)
620
- return "";
621
- let l = "";
622
- const o = s.formatPretty ? 2 : 0;
623
- try {
624
- typeof r == "string" ? l = JSON.stringify(JSON.parse(r), null, o) : l = JSON.stringify(r, null, o);
625
- } catch (p) {
626
- console.warn(p);
627
- }
628
- return l = l.replace(
629
- /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g,
630
- (p) => {
631
- let C = "number";
632
- return /^"/.test(p) ? C = /:$/.test(p) ? "key" : "string" : /true|false/.test(p) ? C = "boolean" : /null/.test(p) && (C = "null"), `<span class="${i[C]}">${p}</span>`;
633
- }
634
- ), l;
635
- };
636
- return (r, l) => (x(), E("div", vs, [
637
- _("div", ys, [
638
- _("div", _s, [
639
- (x(), $e(lt(m.value.icon), {
640
- class: V(["tr-bubble__step-tool-icon", `icon-${s.status}`])
641
- }, null, 8, ["class"])),
642
- _("span", ws, [
643
- it(L(m.value.text) + " ", 1),
644
- _("span", Cs, L(s.name), 1)
645
- ])
646
- ]),
647
- _("div", bs, [
648
- F(M(ye), {
649
- class: V(["expand-icon", { "-rotate-90": !n.value }]),
650
- onClick: l[0] || (l[0] = (o) => n.value = !n.value)
651
- }, null, 8, ["class"])
652
- ])
653
- ]),
654
- n.value ? (x(), E("div", Ms, [
655
- l[1] || (l[1] = _("hr", { class: "tr-bubble__step-tool-hr" }, null, -1)),
656
- _("div", {
657
- class: "tr-bubble__step-tool-params-content",
658
- innerHTML: d(s.content)
659
- }, null, 8, Ss)
660
- ])) : K("", !0)
661
- ]));
662
- }
663
- }), ks = "_key_1ej6o_2", xs = "_number_1ej6o_6", Es = "_string_1ej6o_10", Ts = "_boolean_1ej6o_14", Is = {
664
- key: ks,
665
- number: xs,
666
- string: Es,
667
- boolean: Ts,
668
- null: "_null_1ej6o_18"
669
- }, Fs = {
670
- $style: Is
671
- }, As = /* @__PURE__ */ ee(Rs, [["__cssModules", Fs], ["__scopeId", "data-v-e45d630e"]]);
672
- class Ds {
673
- constructor() {
674
- this.events = {}, this.events = /* @__PURE__ */ Object.create(null);
675
- }
676
- /**
677
- * @param {string} eventName - 事件名
678
- * @param {Function} callback - 回调函数
679
- * @param {boolean} [once=false] - 是否只触发一次
680
- */
681
- on(s, e, n = !1) {
682
- if (typeof e != "function")
683
- throw new TypeError("回调必须是函数");
684
- this.events[s] || (this.events[s] = []), this.events[s].push({ callback: e, once: n });
685
- }
686
- /**
687
- * @param {string} eventName - 事件名
688
- * @param {Function} callback - 要移除的回调(必须是注册时的同一个函数引用)
689
- */
690
- off(s, e) {
691
- this.events[s] && (this.events[s] = this.events[s].filter((n) => n.callback !== e), this.events[s].length === 0 && delete this.events[s]);
692
- }
693
- /**
694
- * @param {string} eventName - 事件名
695
- * @param {...any} args - 传递给回调的参数
696
- */
697
- emit(s, ...e) {
698
- if (!this.events[s]) return;
699
- [...this.events[s]].forEach((a, m) => {
700
- const { callback: i, once: d } = a;
701
- i.apply(this, e), d && this.events[s].splice(m, 1);
702
- }), this.events[s].length === 0 && delete this.events[s];
703
- }
704
- /**
705
- * @param {string} eventName - 事件名
706
- * @param {Function} callback - 回调函数
707
- */
708
- once(s, e) {
709
- this.on(s, e, !0);
710
- }
711
- }
712
- const re = new Ds(), $s = {
713
- key: 0,
714
- class: "loading-wrapper"
715
- }, Os = {
716
- class: "loading-container",
717
- type: "loading-text"
718
- }, Bs = /* @__PURE__ */ Q({
719
- __name: "GeneratingComponent",
720
- props: {
721
- emitter: {},
722
- message: {},
723
- showThinkingResult: { type: Boolean }
724
- },
725
- setup(t) {
726
- const s = t, { t: e } = $(), n = I(e("loading.response")), a = /* @__PURE__ */ new Map([
727
- ["running", { textKey: "toolStatus.running" }],
728
- ["success", { textKey: "toolStatus.success" }],
729
- ["failed", { textKey: "toolStatus.failed" }],
730
- ["cancelled", { textKey: "toolStatus.cancelled" }]
731
- ]), m = (i) => {
732
- var r;
733
- if (i.type === "done") {
734
- n.value = "";
735
- return;
736
- }
737
- if (i.type === "schema-card") {
738
- n.value = e("loading.generatingCard");
739
- return;
740
- }
741
- if (s.showThinkingResult) {
742
- n.value = e("loading.response");
743
- return;
744
- }
745
- if (i.type === "tool") {
746
- const { toolCallData: l } = i, o = ((r = a.get(l.status)) == null ? void 0 : r.textKey) || "loading.response";
747
- n.value = `${e(o)} ${l.name}...`;
748
- return;
749
- }
750
- const d = i.chatMessage.messages[i.chatMessage.messages.length - 1];
751
- d && (n.value = `${d.content}...`);
752
- };
753
- return ve(() => {
754
- s.emitter.on("notification", m);
755
- }), Oe(() => {
756
- s.emitter.off("notification", m);
757
- }), (i, d) => n.value ? (x(), E("div", $s, [
758
- _("div", Os, L(n.value), 1)
759
- ])) : K("", !0);
760
- }
761
- }), Ns = /* @__PURE__ */ ee(Bs, [["__scopeId", "data-v-e1124fd9"]]);
762
- function Ps({
763
- chat: t,
764
- saveState: s
765
- }) {
766
- const { t: e } = $();
767
- return {
768
- continueChatAction: {
769
- name: "continueChat",
770
- description: e("continueChat.description"),
771
- execute: (n, a) => {
772
- t({
773
- llmFriendlyMessage: `${n.message},${e("continueChat.messageParam")}${JSON.stringify(a.state || {})}`,
774
- humanFriendlyMessage: n.message,
775
- context: a
776
- });
777
- },
778
- parameters: {
779
- type: "object",
780
- properties: {
781
- message: {
782
- type: "string",
783
- description: e("continueChat.paramDescription")
784
- }
785
- }
786
- }
787
- },
788
- saveStateAction: {
789
- name: "saveState",
790
- description: e("saveState.description"),
791
- execute: (n, a) => {
792
- s(a);
793
- },
794
- parameters: { type: "null" }
795
- }
796
- };
797
- }
798
- const Ls = { class: "tg-playground-error-card" }, Us = { class: "card-title" }, Hs = /* @__PURE__ */ Q({
799
- __name: "ErrorText",
800
- props: {
801
- content: {}
802
- },
803
- setup(t) {
804
- const s = It(), e = Ft(), { t: n } = $(), a = I(!1), m = () => {
805
- a.value = !a.value;
806
- };
807
- return (i, d) => (x(), E("div", Ls, [
808
- _("div", {
809
- class: "card-header",
810
- onClick: m
811
- }, [
812
- F(M(e), { class: "icon-error" }),
813
- _("span", Us, L(M(n)("error.title")), 1),
814
- F(M(s), {
815
- class: V(["icon-right", { expanded: a.value }])
816
- }, null, 8, ["class"])
817
- ]),
818
- _("pre", {
819
- class: V(["card-body", { collapsed: !a.value }])
820
- }, " " + L(t.content) + `
821
- `, 3)
822
- ]));
823
- }
824
- }), zs = /* @__PURE__ */ ee(Hs, [["__scopeId", "data-v-a0f77c05"]]);
825
- function qs(t) {
826
- const s = I(0), e = I(0);
827
- let n = null, a = null;
828
- const m = (r) => {
829
- if (!r) {
830
- s.value = 0, e.value = 0;
831
- return;
832
- }
833
- const l = r.getBoundingClientRect();
834
- s.value = l.width, e.value = l.height;
835
- }, i = (r) => {
836
- a !== null && cancelAnimationFrame(a), a = requestAnimationFrame(() => {
837
- m(r), a = null;
838
- });
839
- }, d = () => {
840
- n && t.value && n.unobserve(t.value), n = null, a !== null && (cancelAnimationFrame(a), a = null);
841
- };
842
- return ve(() => {
843
- typeof ResizeObserver > "u" || !t.value || (n = new ResizeObserver((r) => {
844
- const o = r[0].target;
845
- i(o);
846
- }), n.observe(t.value), m(t.value));
847
- }), Oe(() => {
848
- d();
849
- }), {
850
- width: s,
851
- height: e
852
- };
853
- }
854
- function Pe(t) {
855
- const { t: s } = $(), { client: e, useStreamByDefault: n = !0, errorMessage: a = s("message.requestFailed"), initialMessages: m = [] } = t, i = I([...m]), d = I(""), r = I(n);
856
- let l = null;
857
- const o = de({
858
- status: H.INIT,
859
- errorMsg: null
860
- }), p = (w) => {
861
- var h;
862
- const g = (h = t.events) == null ? void 0 : h.onReceiveData;
863
- let v = !1;
864
- if (g && g(w, i, () => {
865
- v = !0;
866
- }), !v) {
867
- const R = {
868
- role: "assistant",
869
- content: w.choices[0].message.content
870
- };
871
- i.value.push(R);
872
- }
873
- }, C = async (w) => {
874
- const g = await e.chat({
875
- messages: Z(i.value),
876
- options: {
877
- stream: !1,
878
- signal: w.signal
879
- }
880
- });
881
- p(g);
882
- }, f = (w) => {
883
- var h, R;
884
- const g = (h = t.events) == null ? void 0 : h.onReceiveData;
885
- let v = !1;
886
- if (g && g(w, i, () => {
887
- v = !0;
888
- }), !v) {
889
- i.value[i.value.length - 1].role === "user" && i.value.push({ role: "assistant", content: "" });
890
- const J = (R = w.choices) == null ? void 0 : R[0];
891
- J && J.delta.content && (i.value[i.value.length - 1].content += J.delta.content);
892
- }
893
- }, A = async (w) => {
894
- await e.chatStream(
895
- {
896
- messages: Z(i.value),
897
- options: {
898
- stream: !0,
899
- signal: w.signal
900
- }
901
- },
902
- {
903
- onData: (g) => {
904
- o.status = H.STREAMING, f(g);
905
- },
906
- onError: (g) => {
907
- o.status = H.ERROR, o.errorMsg = a, console.error("Stream request error:", g);
908
- },
909
- onDone: (g) => {
910
- var R;
911
- const v = (R = t.events) == null ? void 0 : R.onFinish;
912
- let h = !1;
913
- if (v && v(g, { messages: i, messageState: o }, () => {
914
- h = !0;
915
- }), !h) {
916
- if (g === "aborted" || o.status === H.ABORTED)
917
- return;
918
- o.status = H.FINISHED;
919
- }
920
- }
921
- }
922
- );
923
- }, S = async () => {
924
- o.status = H.PROCESSING, o.errorMsg = null, l = new AbortController();
925
- try {
926
- r.value ? await A(l) : await C(l);
927
- } catch (w) {
928
- o.errorMsg = a, o.status = H.ERROR, console.error("Send message error:", w);
929
- } finally {
930
- l = null;
931
- }
932
- }, B = async (w = d.value, g = !0) => {
933
- if (oe.includes(o.status) || !w || typeof w == "string" && !w.trim() || Array.isArray(w) && w.length === 0)
934
- return;
935
- const v = {
936
- role: "user",
937
- content: w
938
- };
939
- i.value.push(v), g && (d.value = ""), await S();
940
- }, O = async () => {
941
- oe.includes(o.status) || await S();
942
- }, z = () => {
943
- l && (l.abort(), l = null, o.status = H.ABORTED);
944
- }, N = async (w) => {
945
- w === 0 || !i.value[w] || i.value[w].role === "user" || (i.value.splice(w), await S());
946
- }, q = () => {
947
- i.value = [], o.errorMsg = null;
948
- }, Y = (w) => {
949
- Array.isArray(w) ? i.value.push(...w) : i.value.push(w);
950
- };
951
- return {
952
- conversationId: t.conversationId,
953
- messages: i,
954
- messageState: o,
955
- inputMessage: d,
956
- useStream: r,
957
- sendMessage: B,
958
- send: O,
959
- clearMessages: q,
960
- addMessage: Y,
961
- abortRequest: z,
962
- retryRequest: N
963
- };
964
- }
965
- class Js {
966
- constructor(s, e) {
967
- this.messageManagerMap = /* @__PURE__ */ new Map(), this.messageManagerMap = /* @__PURE__ */ new Map(), this.conversationState = s, this.options = e;
968
- }
969
- getMessageManager(s) {
970
- const e = this.messageManagerMap.get(s);
971
- if (e)
972
- return e;
973
- if (!this.conversationState.conversations.find(
974
- (a) => a.id === s
975
- ))
976
- throw new Error(`Conversation not found for id: ${s}`);
977
- return this.setMessageManager(s);
978
- }
979
- setMessageManager(s, e) {
980
- if (this.messageManagerMap.has(s))
981
- return this.messageManagerMap.get(s);
982
- const n = Pe(e ?? { ...this.options, conversationId: s });
983
- return this.messageManagerMap.set(s, n), n;
984
- }
985
- deleteMessageManager(s) {
986
- this.messageManagerMap.delete(s);
987
- }
988
- }
989
- const ae = (t) => Be(t) ? ae(M(t)) : ct(t) ? ae(Z(t)) : Array.isArray(t) ? t.map(ae) : t && typeof t == "object" ? Object.keys(t).reduce((s, e) => (s[e] = ae(t[e]), s), {}) : t;
990
- class Gs {
991
- constructor(s = "genui-ai", e = "conversations", n = "conversations-list") {
992
- this.db = null, this.dbName = s, this.storeName = e, this.dataKey = n;
993
- }
994
- async openDB() {
995
- return this.db ? this.db : new Promise((s, e) => {
996
- const n = indexedDB.open(this.dbName, 1);
997
- n.onerror = () => {
998
- e(new Error("打开 IndexedDB 失败"));
999
- }, n.onsuccess = () => {
1000
- this.db = n.result, s(this.db);
1001
- }, n.onupgradeneeded = (a) => {
1002
- const m = a.target.result;
1003
- m.objectStoreNames.contains(this.storeName) || m.createObjectStore(this.storeName);
1004
- };
1005
- });
1006
- }
1007
- async saveConversations(s) {
1008
- try {
1009
- const a = (await this.openDB()).transaction([this.storeName], "readwrite").objectStore(this.storeName), m = ae(s);
1010
- return new Promise((i, d) => {
1011
- const r = a.put(m, this.dataKey);
1012
- r.onsuccess = () => i(), r.onerror = () => {
1013
- console.error("保存会话失败:", r.error), d(r.error);
1014
- };
1015
- });
1016
- } catch (e) {
1017
- throw console.error("保存会话失败:", e), e;
1018
- }
1019
- }
1020
- async loadConversations() {
1021
- try {
1022
- const n = (await this.openDB()).transaction([this.storeName], "readonly").objectStore(this.storeName);
1023
- return new Promise((a, m) => {
1024
- const i = n.get(this.dataKey);
1025
- i.onsuccess = () => {
1026
- const d = i.result;
1027
- if (!d) {
1028
- a([]);
1029
- return;
1030
- }
1031
- let r = [];
1032
- if (typeof d == "string")
1033
- try {
1034
- r = JSON.parse(d);
1035
- } catch (l) {
1036
- console.error("解析会话数据失败:", l), a([]);
1037
- return;
1038
- }
1039
- else
1040
- r = Array.isArray(d) ? d : [];
1041
- a(r);
1042
- }, i.onerror = () => {
1043
- console.error("加载会话失败:", i.error), m(i.error);
1044
- };
1045
- });
1046
- } catch (s) {
1047
- return console.error("加载会话失败:", s), [];
1048
- }
1049
- }
1050
- }
1051
- function js() {
1052
- return Date.now().toString(36) + Math.random().toString(36).substring(2, 9);
1053
- }
1054
- function Ws(t) {
1055
- const { t: s } = $(), {
1056
- client: e,
1057
- storage: n = new Gs(),
1058
- autoSave: a = !0,
1059
- allowEmpty: m = !1,
1060
- useStreamByDefault: i = !0,
1061
- errorMessage: d,
1062
- events: r
1063
- } = t, l = d || s("message.requestFailed"), o = de({
1064
- conversations: [],
1065
- currentId: null,
1066
- loading: !1
1067
- });
1068
- let p = !1;
1069
- const C = new Js(o, {
1070
- client: e,
1071
- useStreamByDefault: i,
1072
- conversationId: "",
1073
- errorMessage: l,
1074
- initialMessages: [],
1075
- events: {
1076
- onReceiveData: r == null ? void 0 : r.onReceiveData,
1077
- onFinish: r == null ? void 0 : r.onFinish
1078
- }
1079
- }), f = D(() => o.currentId ? C.getMessageManager(o.currentId) : Pe({
1080
- client: e,
1081
- useStreamByDefault: i,
1082
- conversationId: "",
1083
- errorMessage: l,
1084
- initialMessages: [],
1085
- events: {
1086
- onReceiveData: r == null ? void 0 : r.onReceiveData,
1087
- onFinish: r == null ? void 0 : r.onFinish
1088
- }
1089
- }));
1090
- ue(
1091
- () => f.value,
1092
- () => {
1093
- C.messageManagerMap.forEach((g) => {
1094
- const v = g.messages.value;
1095
- if (o.currentId && v.length > 0) {
1096
- const h = o.conversations.findIndex((R) => R.id === g.conversationId);
1097
- h !== -1 && (o.conversations[h].messages = [...v], o.conversations[h].updatedAt = Date.now(), a && N());
1098
- }
1099
- });
1100
- },
1101
- { deep: !0 }
1102
- );
1103
- const A = (g, v = {}) => {
1104
- const h = g || s("conversation.newConversation");
1105
- if (!m && f.value.messages.value.length === 0 && o.currentId)
1106
- return o.currentId;
1107
- const R = js(), J = {
1108
- id: R,
1109
- title: h,
1110
- createdAt: Date.now(),
1111
- updatedAt: Date.now(),
1112
- messages: [],
1113
- metadata: v
1114
- };
1115
- return o.conversations.unshift(J), C.setMessageManager(R, { ...t, conversationId: R }), S(R), a && N(), R;
1116
- }, S = (g) => {
1117
- const v = o.conversations.find((h) => h.id === g);
1118
- v && (o.currentId = g, C.setMessageManager(g, { ...t, initialMessages: v.messages, conversationId: g }));
1119
- }, B = (g) => {
1120
- const v = o.conversations.findIndex((h) => h.id === g);
1121
- v !== -1 && (C.deleteMessageManager(g), o.conversations.splice(v, 1), o.currentId === g && (o.conversations.length > 0 ? S(o.conversations[0].id) : o.currentId = null), a && N());
1122
- }, O = (g, v) => {
1123
- const h = o.conversations.find((R) => R.id === g);
1124
- h && (h.title = v, h.updatedAt = Date.now(), a && N());
1125
- }, z = (g, v) => {
1126
- const h = o.conversations.find((R) => R.id === g);
1127
- h && (h.metadata = { ...h.metadata, ...v }, h.updatedAt = Date.now(), a && N());
1128
- }, N = async () => {
1129
- try {
1130
- await n.saveConversations(o.conversations);
1131
- } catch (g) {
1132
- console.error("保存会话失败:", g);
1133
- }
1134
- }, q = async () => {
1135
- o.loading = !0;
1136
- try {
1137
- const g = await n.loadConversations();
1138
- o.conversations = g, g.length > 0 && !o.currentId && S(g[0].id), !p && (r != null && r.onLoaded) && (p = !0, r.onLoaded(g));
1139
- } catch (g) {
1140
- console.error("加载会话失败:", g);
1141
- } finally {
1142
- o.loading = !1;
1143
- }
1144
- }, Y = async (g) => {
1145
- const v = o.conversations.find((h) => h.id === g);
1146
- if (!v || v.messages.length < 2)
1147
- return (v == null ? void 0 : v.title) || s("conversation.newConversation");
1148
- try {
1149
- const h = {
1150
- role: "system",
1151
- content: "请根据以下对话内容,生成一个简短的标题(不超过20个字符)。只需要返回标题文本,不需要任何解释或额外内容。"
1152
- }, R = v.messages.slice(0, Math.min(4, v.messages.length)), G = (await e.chat({
1153
- messages: [h, ...R],
1154
- options: {
1155
- stream: !1,
1156
- max_tokens: 30
1157
- }
1158
- })).choices[0].message.content.trim();
1159
- return O(g, G), G;
1160
- } catch (h) {
1161
- return console.error("生成标题失败:", h), v.title;
1162
- }
1163
- }, w = () => o.currentId && o.conversations.find((g) => g.id === o.currentId) || null;
1164
- return q(), {
1165
- state: o,
1166
- messageManager: f,
1167
- createConversation: A,
1168
- switchConversation: S,
1169
- deleteConversation: B,
1170
- updateTitle: O,
1171
- updateMetadata: z,
1172
- saveConversations: N,
1173
- loadConversations: q,
1174
- generateTitle: Y,
1175
- getCurrentConversation: w
1176
- };
1177
- }
1178
- class Ks {
1179
- constructor() {
1180
- this.thinkStartFlag = "<think>", this.thinkEndFlag = "</think>", this.startRegex = new RegExp(`${this.thinkStartFlag}`), this.endRegex = new RegExp(`${this.thinkEndFlag}`), this.partialStartRegex = new RegExp(`${Ee(this.thinkStartFlag)}$`), this.partialEndRegex = new RegExp(`${Ee(this.thinkEndFlag)}$`);
1181
- }
1182
- get regExpMap() {
1183
- return {
1184
- start: {
1185
- full: this.startRegex,
1186
- partial: this.partialStartRegex
1187
- },
1188
- end: {
1189
- full: this.endRegex,
1190
- partial: this.partialEndRegex
1191
- }
1192
- };
1193
- }
1194
- }
1195
- const j = (t) => {
1196
- var s, e;
1197
- return ((e = (s = t.choices) == null ? void 0 : s[0]) == null ? void 0 : e.delta) ?? {};
1198
- };
1199
- function Vs(t, s, e, n, a) {
1200
- const {
1201
- id: m,
1202
- function: { arguments: i, result: d }
1203
- } = t[0], r = e[m];
1204
- if (r && (r.status = "success", r.content = JSON.stringify({ arguments: i, result: d }, null, 2), re.emit("notification", {
1205
- type: "tool",
1206
- delta: s,
1207
- toolCallData: structuredClone(Z(r)),
1208
- chatMessage: structuredClone(Z(n))
1209
- }), a)) {
1210
- const { t: l } = $();
1211
- n.content += l("toolCall.context", {
1212
- toolName: r.name,
1213
- toolParams: JSON.stringify(i),
1214
- toolResult: JSON.stringify(d)
1215
- }) + `
1216
-
1217
- `;
1218
- }
1219
- }
1220
- function Zs(t, s, e, n, a) {
1221
- t.forEach((m) => {
1222
- const {
1223
- id: i,
1224
- function: { name: d, arguments: r }
1225
- } = m;
1226
- let l;
1227
- if (i)
1228
- a.inProcessToolCallId = i, l = de({
1229
- type: "tool",
1230
- name: d,
1231
- formatPretty: !0,
1232
- status: "running",
1233
- content: JSON.stringify({ arguments: r || "" }, null, 2),
1234
- id: i
1235
- }), e[i] = l, n.messages.push(l);
1236
- else {
1237
- l = e[a.inProcessToolCallId];
1238
- const p = JSON.parse(l.content).arguments + (r || "");
1239
- l.content = JSON.stringify({ arguments: p }, null, 2);
1240
- }
1241
- re.emit("notification", {
1242
- type: "tool",
1243
- delta: s,
1244
- toolCallData: l,
1245
- chatMessage: structuredClone(Z(n))
1246
- });
1247
- });
1248
- }
1249
- function Ie(t, s, e) {
1250
- let a = e.messages[e.messages.length - 1];
1251
- return (a == null ? void 0 : a.type) === "reasoning" ? a.content += t : (a = {
1252
- type: "reasoning",
1253
- content: t,
1254
- thinking: !0
1255
- }, e.messages.push(a)), we(s, e), a;
1256
- }
1257
- function Le(t) {
1258
- (t == null ? void 0 : t.type) === "reasoning" && (t.thinking = !1);
1259
- }
1260
- function we(t, s) {
1261
- const e = s.messages[s.messages.length - 1];
1262
- e && re.emit("notification", {
1263
- type: e.type,
1264
- delta: t,
1265
- chatMessage: structuredClone(Z(s))
1266
- });
1267
- }
1268
- function Ys(t, s, e) {
1269
- e.messages.length > 0 && e.messages[e.messages.length - 1].type === "markdown" ? e.messages[e.messages.length - 1].content += t : e.messages.push({
1270
- type: "markdown",
1271
- content: t
1272
- }), we(s, e);
1273
- }
1274
- function Xs(t, s, e) {
1275
- e.messages.length > 0 && e.messages[e.messages.length - 1].type === "schema-card" ? e.messages[e.messages.length - 1].content += t : e.messages.push({
1276
- type: "schema-card",
1277
- content: t,
1278
- id: At()
1279
- }), we(s, e);
1280
- }
1281
- function Fe(t) {
1282
- t.unWatchReasoning = ue(() => [...t.chatMessage.messages], (s) => {
1283
- var e, n;
1284
- t.handleReasoning && ((e = s[s.length - 1]) == null ? void 0 : e.type) !== "reasoning" && (t.handleReasoning = !1, Le(t.reasoningMessage), (n = t.unWatchReasoning) == null || n.call(t));
1285
- }, { flush: "sync" });
1286
- }
1287
- const Qs = [
1288
- {
1289
- name: "init",
1290
- match: (t, s) => !1,
1291
- handler: (t, s) => !1,
1292
- start: (t, s) => {
1293
- const e = de({
1294
- role: "assistant",
1295
- content: "",
1296
- messages: []
1297
- });
1298
- return t.chatMessage = e, t.handlers = s, s.onData(e), !1;
1299
- },
1300
- end: (t) => {
1301
- t.handlers.onDone(), re.emit("notification", {
1302
- type: "done",
1303
- delta: {},
1304
- chatMessage: structuredClone(Z(t.chatMessage))
1305
- });
1306
- }
1307
- },
1308
- {
1309
- name: "finish-info",
1310
- match: (t, s) => {
1311
- var a;
1312
- const { choices: e, usage: n } = t;
1313
- return ((a = e == null ? void 0 : e[0]) == null ? void 0 : a.finish_reason) && !!n;
1314
- },
1315
- handler: (t, s) => (s.chatMessage.finishInfo = t, !0)
1316
- },
1317
- {
1318
- name: "reasoning",
1319
- match: (t, s) => !!j(t).reasoning_content,
1320
- handler: (t, s) => {
1321
- const e = j(t);
1322
- return s.reasoningMessage = Ie(e.reasoning_content, e, s.chatMessage), s.handleReasoning || (Fe(s), s.handleReasoning = !0), !0;
1323
- },
1324
- start: (t, s) => {
1325
- t.handleReasoning = !1;
1326
- },
1327
- end: (t) => {
1328
- var s;
1329
- (s = t.unWatchReasoning) == null || s.call(t), t.handleReasoning && (t.handleReasoning = !1, Le(t.reasoningMessage));
1330
- }
1331
- },
1332
- {
1333
- name: "toolCall",
1334
- match: (t, s) => {
1335
- var n;
1336
- return ((n = j(t).tool_calls) == null ? void 0 : n.length) > 0;
1337
- },
1338
- handler: (t, s) => {
1339
- const e = j(t);
1340
- return Zs(e.tool_calls, e, s.toolCallIdMap, s.chatMessage, s.toolCallStatus), !0;
1341
- },
1342
- start: (t, s) => {
1343
- t.toolCallIdMap = {}, t.toolCallStatus = { inProcessToolCallId: null };
1344
- }
1345
- },
1346
- {
1347
- name: "toolResult",
1348
- match: (t, s) => {
1349
- var n;
1350
- return ((n = j(t).tool_calls_result) == null ? void 0 : n.length) > 0;
1351
- },
1352
- handler: (t, s) => {
1353
- const e = j(t);
1354
- return Vs(e.tool_calls_result, e, s.toolCallIdMap, s.chatMessage, s.chatConfig.addToolCallContext), !0;
1355
- }
1356
- },
1357
- {
1358
- name: "content",
1359
- match: (t, s) => !!j(t).content,
1360
- handler: (t, s) => {
1361
- const e = j(t);
1362
- return s.delta = e, s.patternExtractor.handleContent(e.content), s.chatMessage.content += e.content, !0;
1363
- },
1364
- start: (t, s) => {
1365
- const e = new Te({
1366
- onNormalWrite: (n) => Ys(n, t.delta, t.chatMessage),
1367
- onHandledWrite: (n) => {
1368
- t.reasoningMessage = Ie(n, t.delta, t.chatMessage), t.handleReasoning || (Fe(t), t.handleReasoning = !0);
1369
- },
1370
- regExpMap: new Ks().regExpMap
1371
- });
1372
- t.patternExtractor = new Te({
1373
- onNormalWrite: (n) => e.handleContent(n),
1374
- onHandledWrite: (n) => Xs(n, t.delta, t.chatMessage)
1375
- });
1376
- }
1377
- }
1378
- ], en = { class: "sender-container" }, tn = { class: "attachments-container" }, sn = { class: "footer-text" }, nn = /* @__PURE__ */ Q({
1379
- __name: "GenuiChat",
1380
- props: {
1381
- url: {},
1382
- model: {},
1383
- temperature: {},
1384
- messages: {},
1385
- chatConfig: {},
1386
- requiredCompleteFieldSelectors: {},
1387
- customComponents: {},
1388
- customSnippets: {},
1389
- customExamples: {},
1390
- customActions: {},
1391
- rendererSlots: {},
1392
- thinkComponent: { type: [Object, Function] },
1393
- roles: {},
1394
- features: {},
1395
- customFetch: { type: Function }
1396
- },
1397
- setup(t, { expose: s }) {
1398
- var Me;
1399
- const e = t, n = ut(kt, null), { t: a } = $(), m = D(() => {
1400
- var u;
1401
- const c = (u = e.features) == null ? void 0 : u.supportImage;
1402
- return !!(c && (c == null ? void 0 : c.enabled) !== !1);
1403
- }), i = D(() => {
1404
- var y, b;
1405
- const c = (b = (y = e.features) == null ? void 0 : y.supportImage) == null ? void 0 : b.supportedFileTypes;
1406
- return {
1407
- file: {
1408
- disabled: !1,
1409
- accept: c == null ? void 0 : c.map((k) => Ut[k.toLowerCase()]).join(",")
1410
- }
1411
- };
1412
- }), d = {
1413
- assistant: {
1414
- placement: "start",
1415
- avatar: se(St, { style: { fontSize: "32px" } }),
1416
- maxWidth: "100%",
1417
- customContentField: "messages"
1418
- },
1419
- user: {
1420
- placement: "end",
1421
- maxWidth: "90%",
1422
- avatar: se(Mt, { style: { fontSize: "32px" } }),
1423
- customContentField: "messages"
1424
- }
1425
- }, r = (c) => {
1426
- if (!c)
1427
- return;
1428
- const u = {};
1429
- return Object.keys(c).forEach((y) => {
1430
- u[y] = (b) => {
1431
- const k = D(() => b.bubbleProps.role !== "assistant" ? !0 : b.index !== h.value.messages.value.length - 1 || !O.value), T = he(c[y]);
1432
- return T ? T({ ...b, isFinished: k.value, messageManager: h.value, chatMessage: h.value.messages.value[b.index] }) : null;
1433
- };
1434
- }), u;
1435
- }, l = D(() => {
1436
- var u;
1437
- const c = { ...d };
1438
- for (const y in e.roles) {
1439
- const b = y;
1440
- c[b] = {
1441
- ...d[b],
1442
- ...e.roles[b],
1443
- slots: r((u = e.roles[b]) == null ? void 0 : u.slots)
1444
- };
1445
- }
1446
- return c;
1447
- }), o = (c) => c.filter((u) => u.role === "assistant").reduce((u, y) => {
1448
- const b = y.messages;
1449
- return Array.isArray(b) ? u.concat(...b) : u;
1450
- }, []), p = (c) => o(P.value).find((y) => "id" in y && y.id === c), C = (c) => {
1451
- const u = c[Tt], y = p(u);
1452
- y && (y.state = JSON.parse(JSON.stringify(c.state || {}))), te();
1453
- }, f = ({ llmFriendlyMessage: c, humanFriendlyMessage: u, context: y }) => {
1454
- C(y), h.value.addMessage({
1455
- role: "user",
1456
- content: c,
1457
- messages: [{ type: "text", content: u }]
1458
- }), h.value.send();
1459
- }, A = D(() => ({
1460
- chat: f,
1461
- generating: O.value
1462
- }));
1463
- dt(xt, A);
1464
- const { continueChatAction: S, saveStateAction: B } = Ps({ chat: f, saveState: C }), O = D(() => oe.includes(h.value.messageState.status)), z = new Ne({
1465
- defaultAttrs: { class: "markdown-content" },
1466
- mdConfig: { html: !0 }
1467
- }), N = D(() => {
1468
- const c = P.value[P.value.length - 1];
1469
- if ((c == null ? void 0 : c.role) !== "assistant")
1470
- return null;
1471
- const u = c == null ? void 0 : c.messages;
1472
- return !Array.isArray(u) || !(u != null && u.length) ? null : u[u.length - 1].id;
1473
- }), q = {
1474
- "custom-text": (c) => se("span", { class: "tr-bubble__body-text" }, c.content),
1475
- "schema-card": (c) => {
1476
- var b, k;
1477
- const u = {};
1478
- e.customComponents && e.customComponents.forEach((T) => {
1479
- T.ref && T.component && (u[T.component] = T.ref);
1480
- });
1481
- const y = {};
1482
- return e.customActions && e.customActions.forEach((T) => {
1483
- T.name && (y[T.name] = T);
1484
- }), se(
1485
- "div",
1486
- {},
1487
- se(
1488
- Et,
1489
- {
1490
- ...c,
1491
- requiredCompleteFieldSelectors: e.requiredCompleteFieldSelectors || [],
1492
- generating: N.value === c.id ? O.value : !1,
1493
- customComponents: u,
1494
- customActions: {
1495
- ...y,
1496
- continueChat: S,
1497
- saveState: B
1498
- },
1499
- key: c.id
1500
- },
1501
- {
1502
- header: he((b = e.rendererSlots) == null ? void 0 : b.header),
1503
- footer: he((k = e.rendererSlots) == null ? void 0 : k.footer)
1504
- }
1505
- )
1506
- );
1507
- },
1508
- tool: As,
1509
- reasoning: fs,
1510
- markdown: z,
1511
- templateData: ds,
1512
- "loading-text": e.thinkComponent || Ns,
1513
- "error-text": zs
1514
- }, Y = I(Qs), w = new Nt({
1515
- getChatOptions: () => ({
1516
- url: e.url,
1517
- model: e.model || "",
1518
- temperature: e.temperature ?? 0.3,
1519
- chatConfig: e.chatConfig || { addToolCallContext: !1, showThinkingResult: !1 },
1520
- customComponents: e.customComponents || [],
1521
- customSnippets: e.customSnippets || [],
1522
- customExamples: e.customExamples || [],
1523
- customActions: [...e.customActions || [], S, B],
1524
- customFetch: e.customFetch
1525
- })
1526
- });
1527
- w.setResponseHandlers(Y.value);
1528
- const g = new yt({
1529
- provider: "custom",
1530
- providerImplementation: w
1531
- });
1532
- let v = Ws({
1533
- client: g,
1534
- autoSave: !1,
1535
- events: {
1536
- onReceiveData(c, u, y) {
1537
- u.value.push(c), y();
1538
- },
1539
- onLoaded(c) {
1540
- var u;
1541
- if (c.length || (R(), te()), (u = e.messages) != null && u.length) {
1542
- const y = h.value.messages.value;
1543
- y.splice(0, y.length, ...e.messages);
1544
- }
1545
- },
1546
- onFinish(c, u) {
1547
- (c == null ? void 0 : c.type) === "error" && u.messages.value.push({
1548
- role: "assistant",
1549
- content: "",
1550
- messages: [{ type: "error-text", content: c.error.message }]
1551
- }), te();
1552
- }
1553
- }
1554
- });
1555
- const { messageManager: h, createConversation: R, updateTitle: J, state: G, saveConversations: te } = v, P = D(() => h.value.messages.value), X = D({
1556
- get: () => h.value.inputMessage.value,
1557
- set: (c) => {
1558
- h.value.inputMessage.value = c;
1559
- }
1560
- }), Ue = (c) => {
1561
- X.value = c;
1562
- };
1563
- (Me = e.messages) != null && Me.length && P.value.splice(0, P.value.length, ...e.messages);
1564
- const { attachments: ne, templateData: U, clearAttachments: He, processAttachments: ze, handleFilesSelected: qe, handleTemplateEdit: Je } = Wt(), Ge = (c) => {
1565
- const u = Je(U, X.value);
1566
- X.value = "", U.value = u;
1567
- }, Ce = D(() => {
1568
- var y;
1569
- let c = P.value;
1570
- if (h.value.messageState.status === H.PROCESSING)
1571
- return [
1572
- ...c,
1573
- {
1574
- role: "assistant",
1575
- content: a("loading.thinking"),
1576
- loading: !0
1577
- }
1578
- ];
1579
- const u = P.value[P.value.length - 1];
1580
- if (O.value && (u == null ? void 0 : u.role) === "assistant") {
1581
- const b = Array.isArray(u == null ? void 0 : u.messages) ? u.messages : [];
1582
- if (!b.some((T) => T.type === "loading-text"))
1583
- return [
1584
- ...c.slice(0, -1),
1585
- {
1586
- ...u,
1587
- messages: [
1588
- ...b,
1589
- {
1590
- type: "loading-text",
1591
- emitter: re,
1592
- message: u,
1593
- showThinkingResult: (y = e.chatConfig) == null ? void 0 : y.showThinkingResult
1594
- }
1595
- ]
1596
- }
1597
- ];
1598
- }
1599
- return c;
1600
- }), je = (c) => {
1601
- var b;
1602
- const u = (b = G.conversations.find(
1603
- (k) => k.id === G.currentId
1604
- )) == null ? void 0 : b.title, y = a("conversation.newConversation");
1605
- if (u === y && G.currentId) {
1606
- const k = typeof c == "string" ? c : JSON.stringify(c);
1607
- J(G.currentId, k.substring(0, 20));
1608
- }
1609
- }, be = () => {
1610
- X.value = "", U.value = [], He();
1611
- }, We = (c) => {
1612
- c && (ne.value = ne.value.filter((u) => c.name !== u.name), U.value = U.value.filter((u) => u.type !== "template" || u.content !== c.name));
1613
- }, Ke = async (c) => {
1614
- const u = c, y = [];
1615
- let b = [];
1616
- const k = ne.value.slice(), T = U.value.slice(), pe = {
1617
- role: "user",
1618
- content: u
1619
- };
1620
- if (P.value.push(pe), k.length > 0) {
1621
- const Se = await ze(k, e.features || {});
1622
- if (!Se) {
1623
- h.value.send(), le();
1624
- return;
1625
- }
1626
- b = T.map((ge) => ge.type === "template" ? Se.apiContent.find((st) => st.filename === ge.content) : {
1627
- type: "text",
1628
- text: ge.content
1629
- }), T.length > 0 && y.push({
1630
- type: "templateData",
1631
- templateData: T,
1632
- attachments: k
1633
- }), pe.content = b, pe.messages = y;
1634
- }
1635
- h.value.send(), be(), je(u), te(), le();
1636
- }, Ve = () => {
1637
- R(), te();
1638
- }, Ze = () => {
1639
- h.value.abortRequest(), te();
1640
- }, me = I(), { width: Ye } = qs(me), { scrollToBottom: le, scrollToBottomWithRetry: Xe, autoScrollToBottom: Qe, isLastMessageInBottom: et } = Lt(me), tt = Pt(Qe, 400);
1641
- return ue(() => P.value, tt, { deep: !0 }), ue(
1642
- () => G.currentId,
1643
- () => {
1644
- Xe(10, 150);
1645
- }
1646
- ), s({
1647
- setInputMessage: Ue,
1648
- handleNewConversation: Ve,
1649
- getConversation: () => v,
1650
- // experimental, not stable
1651
- getResponseHandlers: () => Y.value,
1652
- // experimental, not stable
1653
- setResponseHandlers: (c) => {
1654
- Y.value = c, w.setResponseHandlers(c);
1655
- },
1656
- getMessageRenderers: () => q,
1657
- setMessageRenderer: (c, u) => {
1658
- q[c] = u;
1659
- }
1660
- }), (c, u) => {
1661
- var y, b;
1662
- return x(), E("div", {
1663
- class: V(["tg-chat-container", { dark: ((y = M(n)) == null ? void 0 : y.theme) === "dark" }]),
1664
- style: Re((b = e.chatConfig) != null && b.showThinkingResult ? {} : { "--thinking-display": "none" })
1665
- }, [
1666
- _("div", {
1667
- class: "messages-container",
1668
- ref_key: "messagesContainer",
1669
- ref: me,
1670
- style: Re({ "--messages-container-width": M(Ye) + "px" })
1671
- }, [
1672
- Ce.value.length ? (x(), $e(M(gt), {
1673
- key: 0,
1674
- "content-renderers": q
1675
- }, {
1676
- default: W(() => [
1677
- F(M(ht), {
1678
- items: Ce.value,
1679
- roles: l.value,
1680
- "auto-scroll": ""
1681
- }, null, 8, ["items", "roles"])
1682
- ]),
1683
- _: 1
1684
- })) : mt(c.$slots, "empty", { key: 1 }, void 0, !0)
1685
- ], 4),
1686
- _("div", en, [
1687
- Ae(_("div", {
1688
- class: V(["scroll-to-bottom-button", { "is-generating": O.value }]),
1689
- onClick: u[0] || (u[0] = //@ts-ignore
1690
- (...k) => M(le) && M(le)(...k))
1691
- }, [
1692
- F(M(ye), { class: "icon-arrow-down" })
1693
- ], 2), [
1694
- [De, !M(et)]
1695
- ]),
1696
- F(M(ft), {
1697
- modelValue: X.value,
1698
- "onUpdate:modelValue": u[1] || (u[1] = (k) => X.value = k),
1699
- placeholder: M(oe).includes(M(h).messageState.status) ? M(a)("placeholder.thinking") : M(a)("placeholder.input"),
1700
- clearable: !0,
1701
- "allow-files": m.value,
1702
- buttonGroup: i.value,
1703
- loading: M(oe).includes(M(h).messageState.status),
1704
- onFilesSelected: u[2] || (u[2] = (k) => M(qe)(k, X.value)),
1705
- "template-data": M(U),
1706
- "onUpdate:templateData": [
1707
- u[3] || (u[3] = (k) => Be(U) ? U.value = k : null),
1708
- Ge
1709
- ],
1710
- showWordLimit: !0,
1711
- maxLength: 1e3,
1712
- onClear: be,
1713
- onSubmit: Ke,
1714
- onCancel: Ze
1715
- }, pt({ _: 2 }, [
1716
- M(ne).length > 0 ? {
1717
- name: "header",
1718
- fn: W(() => [
1719
- _("div", tn, [
1720
- F(ss, {
1721
- attachments: M(ne),
1722
- onRemove: We
1723
- }, null, 8, ["attachments"])
1724
- ])
1725
- ]),
1726
- key: "0"
1727
- } : void 0
1728
- ]), 1032, ["modelValue", "placeholder", "allow-files", "buttonGroup", "loading", "template-data"]),
1729
- _("div", sn, L(M(a)("footer.aiGenerated")), 1)
1730
- ])
1731
- ], 6);
1732
- };
1733
- }
1734
- }), hn = /* @__PURE__ */ ee(nn, [["__scopeId", "data-v-c5592237"]]), fn = {
1735
- enabled: !0,
1736
- maxImageSize: 10,
1737
- maxFilesPerRequest: 3,
1738
- supportedFileTypes: ["jpg", "jpeg", "png", "gif", "webp", "bmp", "heic", "tiff"]
1739
- };
1740
- export {
1741
- fn as D,
1742
- Ds as E,
1743
- hn as G,
1744
- Gs as I,
1745
- Js as M,
1746
- Ks as T,
1747
- Pe as a,
1748
- Pt as b,
1749
- re as e,
1750
- Lt as s,
1751
- he as t,
1752
- Ws as u
1753
- };