提交 d86688c9 authored 作者: 王鹏飞's avatar 王鹏飞

Initial commit

上级
{
"globals": {
"$": true,
"$$": true,
"$computed": true,
"$customRef": true,
"$ref": true,
"$shallowRef": true,
"$toRef": true,
"Component": true,
"ComponentPublicInstance": true,
"ComputedRef": true,
"EffectScope": true,
"ExtractDefaultPropTypes": true,
"ExtractPropTypes": true,
"ExtractPublicPropTypes": true,
"InjectionKey": true,
"PropType": true,
"Ref": true,
"VNode": true,
"WritableComputedRef": true,
"asyncComputed": true,
"autoResetRef": true,
"computed": true,
"computedAsync": true,
"computedEager": true,
"computedInject": true,
"computedWithControl": true,
"controlledComputed": true,
"controlledRef": true,
"createApp": true,
"createEventHook": true,
"createGlobalState": true,
"createInjectionState": true,
"createReactiveFn": true,
"createReusableTemplate": true,
"createSharedComposable": true,
"createTemplatePromise": true,
"createUnrefFn": true,
"customRef": true,
"debouncedRef": true,
"debouncedWatch": true,
"defineAsyncComponent": true,
"defineComponent": true,
"eagerComputed": true,
"effectScope": true,
"extendRef": true,
"getCurrentInstance": true,
"getCurrentScope": true,
"h": true,
"ignorableWatch": true,
"inject": true,
"injectLocal": true,
"isDefined": true,
"isProxy": true,
"isReactive": true,
"isReadonly": true,
"isRef": true,
"makeDestructurable": true,
"markRaw": true,
"nextTick": true,
"onActivated": true,
"onBeforeMount": true,
"onBeforeRouteLeave": true,
"onBeforeRouteUpdate": true,
"onBeforeUnmount": true,
"onBeforeUpdate": true,
"onClickOutside": true,
"onDeactivated": true,
"onErrorCaptured": true,
"onKeyStroke": true,
"onLongPress": true,
"onMounted": true,
"onRenderTracked": true,
"onRenderTriggered": true,
"onScopeDispose": true,
"onServerPrefetch": true,
"onStartTyping": true,
"onUnmounted": true,
"onUpdated": true,
"pausableWatch": true,
"provide": true,
"provideLocal": true,
"reactify": true,
"reactifyObject": true,
"reactive": true,
"reactiveComputed": true,
"reactiveOmit": true,
"reactivePick": true,
"readonly": true,
"ref": true,
"refAutoReset": true,
"refDebounced": true,
"refDefault": true,
"refThrottled": true,
"refWithControl": true,
"resolveComponent": true,
"resolveRef": true,
"resolveUnref": true,
"shallowReactive": true,
"shallowReadonly": true,
"shallowRef": true,
"syncRef": true,
"syncRefs": true,
"templateRef": true,
"throttledRef": true,
"throttledWatch": true,
"toRaw": true,
"toReactive": true,
"toRef": true,
"toRefs": true,
"toValue": true,
"triggerRef": true,
"tryOnBeforeMount": true,
"tryOnBeforeUnmount": true,
"tryOnMounted": true,
"tryOnScopeDispose": true,
"tryOnUnmounted": true,
"unref": true,
"unrefElement": true,
"until": true,
"useActiveElement": true,
"useAnimate": true,
"useArrayDifference": true,
"useArrayEvery": true,
"useArrayFilter": true,
"useArrayFind": true,
"useArrayFindIndex": true,
"useArrayFindLast": true,
"useArrayIncludes": true,
"useArrayJoin": true,
"useArrayMap": true,
"useArrayReduce": true,
"useArraySome": true,
"useArrayUnique": true,
"useAsyncQueue": true,
"useAsyncState": true,
"useAttrs": true,
"useBase64": true,
"useBattery": true,
"useBluetooth": true,
"useBreakpoints": true,
"useBroadcastChannel": true,
"useBrowserLocation": true,
"useCached": true,
"useClipboard": true,
"useClipboardItems": true,
"useCloned": true,
"useColorMode": true,
"useConfirmDialog": true,
"useCounter": true,
"useCssModule": true,
"useCssVar": true,
"useCssVars": true,
"useCurrentElement": true,
"useCycleList": true,
"useDark": true,
"useDateFormat": true,
"useDebounce": true,
"useDebounceFn": true,
"useDebouncedRefHistory": true,
"useDeviceMotion": true,
"useDeviceOrientation": true,
"useDevicePixelRatio": true,
"useDevicesList": true,
"useDisplayMedia": true,
"useDocumentVisibility": true,
"useDraggable": true,
"useDropZone": true,
"useElementBounding": true,
"useElementByPoint": true,
"useElementHover": true,
"useElementSize": true,
"useElementVisibility": true,
"useEventBus": true,
"useEventListener": true,
"useEventSource": true,
"useEyeDropper": true,
"useFavicon": true,
"useFetch": true,
"useFileDialog": true,
"useFileSystemAccess": true,
"useFocus": true,
"useFocusWithin": true,
"useFps": true,
"useFullscreen": true,
"useGamepad": true,
"useGeolocation": true,
"useIdle": true,
"useImage": true,
"useInfiniteScroll": true,
"useIntersectionObserver": true,
"useInterval": true,
"useIntervalFn": true,
"useKeyModifier": true,
"useLastChanged": true,
"useLink": true,
"useLocalStorage": true,
"useMagicKeys": true,
"useManualRefHistory": true,
"useMediaControls": true,
"useMediaQuery": true,
"useMemoize": true,
"useMemory": true,
"useMounted": true,
"useMouse": true,
"useMouseInElement": true,
"useMousePressed": true,
"useMutationObserver": true,
"useNavigatorLanguage": true,
"useNetwork": true,
"useNow": true,
"useObjectUrl": true,
"useOffsetPagination": true,
"useOnline": true,
"usePageLeave": true,
"useParallax": true,
"useParentElement": true,
"usePerformanceObserver": true,
"usePermission": true,
"usePointer": true,
"usePointerLock": true,
"usePointerSwipe": true,
"usePreferredColorScheme": true,
"usePreferredContrast": true,
"usePreferredDark": true,
"usePreferredLanguages": true,
"usePreferredReducedMotion": true,
"usePrevious": true,
"useRafFn": true,
"useRefHistory": true,
"useResizeObserver": true,
"useRoute": true,
"useRouter": true,
"useScreenOrientation": true,
"useScreenSafeArea": true,
"useScriptTag": true,
"useScroll": true,
"useScrollLock": true,
"useSessionStorage": true,
"useShare": true,
"useSlots": true,
"useSorted": true,
"useSpeechRecognition": true,
"useSpeechSynthesis": true,
"useStepper": true,
"useStorage": true,
"useStorageAsync": true,
"useStyleTag": true,
"useSupported": true,
"useSwipe": true,
"useTemplateRefsList": true,
"useTextDirection": true,
"useTextSelection": true,
"useTextareaAutosize": true,
"useThrottle": true,
"useThrottleFn": true,
"useThrottledRefHistory": true,
"useTimeAgo": true,
"useTimeout": true,
"useTimeoutFn": true,
"useTimeoutPoll": true,
"useTimestamp": true,
"useTitle": true,
"useToNumber": true,
"useToString": true,
"useToggle": true,
"useTransition": true,
"useUrlSearchParams": true,
"useUserMedia": true,
"useVModel": true,
"useVModels": true,
"useVibrate": true,
"useVirtualList": true,
"useWakeLock": true,
"useWebNotification": true,
"useWebSocket": true,
"useWebWorker": true,
"useWebWorkerFn": true,
"useWindowFocus": true,
"useWindowScroll": true,
"useWindowSize": true,
"watch": true,
"watchArray": true,
"watchAtMost": true,
"watchDebounced": true,
"watchDeep": true,
"watchEffect": true,
"watchIgnorable": true,
"watchImmediate": true,
"watchOnce": true,
"watchPausable": true,
"watchPostEffect": true,
"watchSyncEffect": true,
"watchThrottled": true,
"watchTriggerable": true,
"watchWithFilter": true,
"whenever": true
}
}
/* eslint-env node */
module.exports = {
root: true,
extends: ['plugin:vue/vue3-essential', 'eslint:recommended', './.eslintrc-auto-import.json'],
parserOptions: {
ecmaVersion: 'latest'
}
}
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local
/cypress/videos/
/cypress/screenshots/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.tsbuildinfo
# skyagents
This template should help get you started developing with Vue 3 in Vite.
## Recommended IDE Setup
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
## Customize configuration
See [Vite Configuration Reference](https://vitejs.dev/config/).
## Project Setup
```sh
npm install
```
### Compile and Hot-Reload for Development
```sh
npm run dev
```
### Compile and Minify for Production
```sh
npm run build
```
### Lint with [ESLint](https://eslint.org/)
```sh
npm run lint
```
import fs from 'node:fs'
import path from 'node:path'
import chalk from 'chalk'
import OSS from 'ali-oss'
const log = console.log
const __dirname = path.resolve()
const client = new OSS({
region: 'oss-cn-beijing',
accessKeyId: 'LTAIOTuuLTaWoGJj',
accessKeySecret: 'dE5tTGm2lh35eItct2krW2DeH2lf2I',
bucket: 'webapp-pub'
})
async function uploadTarget(src, dist) {
try {
const result = await client.put(dist, path.join(__dirname, src))
log(chalk.green('上传成功', result.url))
} catch (e) {
log(chalk.red('上传失败', src))
log(e)
}
}
function generateUploadTarget(src, dist) {
fs.readdir(path.join(__dirname, src), function (err, files) {
if (err) {
log(err)
return
}
files.forEach(function (file) {
const _src = src + '/' + file
const _dist = dist + '/' + file
const stats = fs.statSync(path.join(__dirname, _src))
// 判断是否为文件
stats.isFile() && uploadTarget(_src, _dist)
// 判断是否为文件夹
stats.isDirectory() && generateUploadTarget(_src, _dist)
})
})
}
generateUploadTarget('./dist', '/plugins/sky-agents')
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title></title>
</head>
<body>
<ul>
<li>互联⽹是什么</li>
<li>李彦宏</li>
<li>马云</li>
<li>雷军</li>
</ul>
<script src="../dist/sky-agent.umd.cjs"></script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
},
"types": ["element-plus/global"]
},
"exclude": ["node_modules", "dist"]
}
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "skyagents",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore",
"deploy": "node ./deploy.mjs",
"release": "npm run build && npm run deploy"
},
"dependencies": {
"@floating-ui/vue": "^1.0.6",
"@microsoft/fetch-event-source": "^2.0.1",
"@vueuse/core": "^10.9.0",
"axios": "^1.6.7",
"blueimp-md5": "^2.19.0",
"element-plus": "^2.6.0",
"vue": "^3.4.15"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.3",
"ali-oss": "^6.20.0",
"chalk": "^5.3.0",
"eslint": "^8.49.0",
"eslint-plugin-vue": "^9.17.0",
"unplugin-auto-import": "^0.17.5",
"unplugin-vue-components": "^0.26.0",
"vite": "^5.0.11",
"vite-plugin-css-injected-by-js": "^3.4.0"
}
}
<script setup>
import { useTextSelection, watchDebounced } from '@vueuse/core'
import { useFloating } from '@floating-ui/vue'
import { useChat } from '@/composables/useChat'
const state = useTextSelection()
const reference = ref(null)
const floating = ref(null)
const { floatingStyles } = useFloating(reference, floating)
const dialogVisible = ref(false)
const userChatInput = ref('')
watchDebounced(
state.text,
value => {
if (value && !dialogVisible.value) {
userChatInput.value = value
floating.value.style.display = 'block'
const [rect] = state.rects.value
reference.value = {
getBoundingClientRect() {
return rect
}
}
} else {
floating.value.style.display = ''
}
},
{ debounce: 200, maxWait: 1000 }
)
const { messages, post } = useChat()
async function postMessage() {
if (!userChatInput.value) return
console.log(userChatInput.value)
messages.value.push({ role: 'user', content: userChatInput.value })
post({ userChatInput: userChatInput.value, chatId: '', agentId: 'f3846153ba784b6d86bdcd5533259c88' })
userChatInput.value = ''
}
async function handleSearch() {
dialogVisible.value = true
await postMessage()
}
async function handleSend() {
await postMessage()
}
const chatRef = ref()
function scrollToBottom() {
if (!chatRef.value) return
const parentEl = chatRef.value.parentElement
parentEl.scrollTo(0, parentEl.scrollHeight)
}
watch(messages.value, () => nextTick(() => scrollToBottom()))
</script>
<template>
<ul>
<li>互联⽹是什么</li>
<li>李彦宏</li>
<li>马云</li>
<li>雷军</li>
</ul>
<div id="tooltip-box" ref="floating" :style="floatingStyles" @click="handleSearch">搜索</div>
<el-drawer v-model="dialogVisible" :close-on-click-modal="false" size="50%">
<div class="chat" ref="chatRef">
<div class="chat-message" v-for="(item, index) in messages" :key="index">
<div class="chat-message-item" v-html="item.content"></div>
</div>
</div>
<template #footer>
<div class="chat-footer">
<el-input size="large" v-model="userChatInput" @keyup.enter="handleSend"></el-input>
<el-button size="large" type="primary" @click="handleSend">发送</el-button>
</div>
</template>
</el-drawer>
</template>
<style>
#tooltip-box {
display: none;
width: max-content;
position: absolute;
top: 0;
left: 0;
background: #222;
color: white;
font-weight: bold;
padding: 5px;
border-radius: 4px;
font-size: 14px;
cursor: pointer;
}
.chat-message {
display: flex;
flex-direction: row;
}
.chat-message-item {
max-width: 100%;
padding: 10px;
margin: 10px 0;
border-radius: 10px;
border: 1px solid #dedede;
}
.chat-message-item:hover {
background-color: #f1f5f9;
}
.chat-footer {
display: flex;
align-items: center;
column-gap: 10px;
}
</style>
import httpRequest from '@/utils/axios'
export function fetchAgents() {
return httpRequest.get('/openapi/agents')
}
import md5 from 'blueimp-md5'
import { fetchEventSource } from '@microsoft/fetch-event-source'
import { fetchAgents } from '@/api/chat'
export function useChat() {
const authKey = 'f3846153ba784b6d86bdcd5533259c88'
const authSecret = 'HO4IyLEwEOHpeOXBxaLQUOqWslJRGs1M'
const messages = ref([])
async function post(data) {
const timestamp = Date.now()
const sign = md5(`${authKey}${authSecret}${timestamp}`)
await fetchEventSource('/openapi/agent/chat/stream/v1', {
method: 'POST',
headers: { authKey, timestamp, sign, 'Content-Type': 'application/json' },
body: JSON.stringify(data),
onmessage(res) {
console.log(res.data)
const message = JSON.parse(res.data)
const conversationId = message.conversationId
const messageId = messages.value.findIndex(session => session.conversationId === conversationId)
if (messageId === -1) {
messages.value.push({ conversationId, role: 'bot', content: message.content })
} else {
messages.value[messageId].content + message.content
}
}
})
}
async function getAgents() {
await fetchAgents()
}
return { messages, post, getAgents }
}
import { createApp } from 'vue'
import App from './App.vue'
const root = document.createElement('div')
root.setAttribute('id', 'zj-chat')
document.body.appendChild(root)
createApp(App).mount('#zj-chat')
import axios from 'axios'
import md5 from 'blueimp-md5'
const httpRequest = axios.create({
// baseURL: 'https://model-platform-skyagents.tiangong.cn',
timeout: 60000,
withCredentials: true
})
// 请求拦截
httpRequest.interceptors.request.use(
function (config) {
// const UUID = 'f3846153ba784b6d86bdcd5533259c88'
const authKey = 'f3846153ba784b6d86bdcd5533259c88'
const authSecret = 'HO4IyLEwEOHpeOXBxaLQUOqWslJRGs1M'
const timestamp = Date.now()
const sign = md5(`${authKey}${authSecret}${timestamp}`)
config.headers = { ...config.headers, authKey, timestamp, sign }
return config
},
function (error) {
return Promise.reject(error)
}
)
// // 响应拦截
// httpRequest.interceptors.response.use(
// function (response) {
// const { data } = response
// return data
// },
// function (error) {
// if (error.response) {
// console.log(error)
// }
// return Promise.reject(error.response || error)
// }
// )
export default httpRequest
import { fileURLToPath, URL } from 'node:url'
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
// https://vitejs.dev/config/
export default defineConfig({
define: {
'process.env': process.env
},
plugins: [
vue(),
AutoImport({ imports: ['vue'], eslintrc: { enabled: true }, resolvers: [ElementPlusResolver()] }),
Components({ resolvers: [ElementPlusResolver()] }),
cssInjectedByJsPlugin()
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
open: true,
proxy: {
// '/api/resource': {
// target: 'http://com-resource-admin-test.ezijing.com/',
// changeOrigin: true,
// rewrite: path => path.replace(/^\/api\/resource/, '')
// },
'/openapi': 'https://model-platform-skyagents.tiangong.cn'
}
},
build: {
lib: {
entry: resolve(__dirname, 'src/main.js'),
name: 'SkyAgent',
fileName: 'sky-agent'
}
}
})
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论