Skip to content

feat: add remote control page, update next dependency #3501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/sites/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@opentiny/vue-docs",
"type": "module",
"version": "3.24.0",
"version": "3.24.3",
"license": "MIT",
"scripts": {
"start": "vite",
Expand All @@ -27,8 +27,7 @@
"@docsearch/css": "^3.8.0",
"@docsearch/js": "^3.8.0",
"@docsearch/react": "npm:@docsearch/css",
"@opentiny/next": "0.1.2",
"@opentiny/next-vue": "0.0.1-alpha.1",
"@opentiny/next-vue": "0.0.1",
"@opentiny/tiny-robot": "0.2.1",
"@opentiny/tiny-robot-kit": "0.2.1",
"@opentiny/tiny-robot-svgs": "0.2.1",
Expand Down
4 changes: 2 additions & 2 deletions examples/sites/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { iconClose } from '@opentiny/vue-icon'
import { appData } from './tools'
import useTheme from './tools/useTheme'
import { useNextClient } from '@opentiny/next-vue'
import { globalConversation } from './composable/utils'
import { globalConversation, $session } from './composable/utils'

export default defineComponent({
name: 'AppVue',
Expand All @@ -33,7 +33,7 @@ export default defineComponent({

const { sessionId } = useNextClient({
clientInfo: { name: 'tiny-vue-website', version: '1.0.0' },
proxyOptions: { url: 'https://39.108.160.245/sse', token: '' }
proxyOptions: { url: 'https://agent.icjs.ink/sse', token: '', sessionId: $session.sessionId }
})

watch(
Expand Down
117 changes: 117 additions & 0 deletions examples/sites/src/components/MessageCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<template>
<div class="message-card" :class="role">
<div class="avatar">
<component :is="avatarIcon" class="avatar-icon" />
</div>
<div class="content">
<div class="role-name">{{ roleName }}</div>
<div class="message">{{ message }}</div>
<div class="time">{{ formatTime }}</div>
</div>
</div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { IconAi, IconUser } from '@opentiny/tiny-robot-svgs'

interface Props {
role: 'user' | 'assistant'
message: string
timestamp: number
}

const props = defineProps<Props>()

const roleName = computed(() => (props.role === 'assistant' ? '智能助手' : '我'))

const avatarIcon = computed(() => (props.role === 'assistant' ? IconAi : IconUser))

const formatTime = computed(() => {
const date = new Date(props.timestamp)
return date.toLocaleTimeString('zh-CN', {
hour: '2-digit',
minute: '2-digit',
hour12: false
})
})
</script>

<style scoped lang="less">
.message-card {
display: flex;
margin: 16px;
gap: 12px;
max-width: 80%;

&.assistant {
margin-right: auto;

.content {
background-color: #f0f2f5;
}

.avatar-icon {
color: #2080f0;
}
}

&.user {
margin-left: auto;
flex-direction: row-reverse;

.content {
background-color: #e8f5e9;
}

.avatar-icon {
color: #18a058;
}
}

.avatar {
width: 40px;
height: 40px;
border-radius: 50%;
overflow: hidden;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
background-color: #f5f7fa;

.avatar-icon {
width: 24px;
height: 24px;
}
}

.content {
padding: 12px;
border-radius: 12px;
position: relative;
min-width: 120px;
max-width: calc(100% - 60px);

.role-name {
font-size: 14px;
color: #666;
margin-bottom: 4px;
}

.message {
font-size: 16px;
line-height: 1.5;
word-break: break-word;
white-space: pre-wrap;
}

.time {
font-size: 12px;
color: #999;
margin-top: 4px;
text-align: right;
}
}
}
</style>
8 changes: 4 additions & 4 deletions examples/sites/src/composable/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

import type { ChatMessage, ChatCompletionResponse, StreamHandler } from '@opentiny/tiny-robot-kit'
import type { ChatCompletionRequest } from '@opentiny/tiny-robot-kit'
import { ref, type Ref } from 'vue'
import { ref, reactive, type Ref } from 'vue'

export { $local } from './storage'
export { $local, $session } from './storage'

export const showTinyRobot = ref(true)

export const globalConversation = {
export const globalConversation = reactive({
id: '',
sessionId: ''
}
})
/**
* 处理SSE流式响应
* @param response fetch响应对象
Expand Down
6 changes: 6 additions & 0 deletions examples/sites/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Docs = () => import('@/views/docs/docs.vue')
const Overview = () => import('@/views/overview.vue')
const Features = () => import('@/views/features.vue')
const Comprehensive = () => import('@/views/comprehensive/index.vue')
const Remoter = () => import('@/views/remoter/index.vue')

const context = import.meta.env.VITE_CONTEXT

Expand All @@ -24,6 +25,11 @@ let routes = [
component: Comprehensive,
name: 'comprehensive'
},
{
path: `${context}:all?/zh-CN/:theme/remoter`,
component: Remoter,
name: 'remoter'
},
// 文档
{
path: `${context}:all?/:lang/:theme/docs/:docId`,
Expand Down
21 changes: 5 additions & 16 deletions examples/sites/src/views/comprehensive/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ watch(
const encryptedId = CryptoJS.AES.encrypt(newVal, 'secret-session-id').toString()

const secretId = encodeURIComponent(encryptedId)
sessionUrl.value = 'http://39.108.160.245?id=' + secretId
sessionUrl.value = `https://agent.icjs.ink?id=${secretId}`
}
},
{ immediate: true }
Expand Down Expand Up @@ -202,9 +202,7 @@ watch(
border-radius: 12px;
padding: 32px;
width: 460px;
box-shadow:
0 20px 25px -5px rgba(0, 0, 0, 0.1),
0 10px 10px -5px rgba(0, 0, 0, 0.04);
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.qr-modal-header {
Expand Down Expand Up @@ -267,22 +265,13 @@ watch(

@keyframes glow {
0% {
box-shadow:
0 0 5px rgba(22, 119, 255, 0.2),
0 0 10px rgba(22, 119, 255, 0.2),
0 0 15px rgba(22, 119, 255, 0.2);
box-shadow: 0 0 5px rgba(22, 119, 255, 0.2), 0 0 10px rgba(22, 119, 255, 0.2), 0 0 15px rgba(22, 119, 255, 0.2);
}
50% {
box-shadow:
0 0 10px rgba(22, 119, 255, 0.3),
0 0 20px rgba(22, 119, 255, 0.3),
0 0 30px rgba(22, 119, 255, 0.3);
box-shadow: 0 0 10px rgba(22, 119, 255, 0.3), 0 0 20px rgba(22, 119, 255, 0.3), 0 0 30px rgba(22, 119, 255, 0.3);
}
100% {
box-shadow:
0 0 5px rgba(22, 119, 255, 0.2),
0 0 10px rgba(22, 119, 255, 0.2),
0 0 15px rgba(22, 119, 255, 0.2);
box-shadow: 0 0 5px rgba(22, 119, 255, 0.2), 0 0 10px rgba(22, 119, 255, 0.2), 0 0 15px rgba(22, 119, 255, 0.2);
}
}

Expand Down
63 changes: 63 additions & 0 deletions examples/sites/src/views/remoter/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<script setup lang="ts">
// 导入 CryptoJS 库
import CryptoJS from 'crypto-js'
import { reactive } from 'vue'
import { TinyButton, TinyDrawer } from '@opentiny/vue'
import RobotChat from '../../components/tiny-robot-chat.vue'
import Sound from './sound.vue'
import { globalConversation } from '../../composable/utils'

// 加密密钥,需要和生成二维码的页面保持一致
const secretKey = 'secret-session-id'
Comment on lines +10 to +11
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical security issue: Hardcoded encryption key

The secret key is hardcoded in the client-side code, which is a significant security vulnerability. Anyone can view this key and decrypt the session IDs.

Consider these more secure alternatives:

  1. Use server-side decryption and only pass the decrypted session ID to the client
  2. Use environment variables or configuration management for the key
  3. Implement proper key rotation and management
🤖 Prompt for AI Agents
In examples/sites/src/views/remoter/index.vue around lines 10 to 11, the
secretKey is hardcoded in the client-side code, posing a critical security risk.
To fix this, remove the hardcoded key from the client code and instead retrieve
the secret key securely from the server or use environment variables injected at
build time. Implement server-side decryption of session IDs and only send
decrypted data to the client, ensuring the key is never exposed in the frontend
code. Also, consider adding key rotation and secure key management practices.

// 获取 URL 参数
const urlParams = new URLSearchParams(window.location.search)
const encryptedId = urlParams.get('id')
const state = reactive({ isShow: true, showChat: false, showSound: false })

if (encryptedId) {
// 解密 id
const bytes = CryptoJS.AES.decrypt(encryptedId, secretKey)
const originalText = bytes.toString(CryptoJS.enc.Utf8)
// 存储解密后的 id 到 window.sessionId
globalConversation.sessionId = originalText
}
const showMoter = (type) => {
state.isShow = false
state[type] = true
}
Comment on lines +24 to +27
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve function naming and parameter clarity

The function name "showMoter" appears to be a typo, and the parameter name type is too generic for its specific use case.

-const showMoter = (type) => {
+const showController = (controllerType: 'showChat' | 'showSound') => {
   state.isShow = false
-  state[type] = true
+  state[controllerType] = true
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const showMoter = (type) => {
state.isShow = false
state[type] = true
}
const showController = (controllerType: 'showChat' | 'showSound') => {
state.isShow = false
state[controllerType] = true
}
🤖 Prompt for AI Agents
In examples/sites/src/views/remoter/index.vue around lines 24 to 27, rename the
function "showMoter" to a more descriptive and correctly spelled name that
reflects its purpose, such as "showMotor" or "displayMotor". Also, rename the
parameter "type" to a more specific name that clearly indicates what kind of
value it expects, for example "motorType" or "sectionName". Update all
references to this function and parameter accordingly.

</script>

<template>
<div>
<RobotChat v-if="state.showChat" />
<Sound v-if="state.showSound" />
<tiny-drawer
v-if="state.isShow"
title="请选择控制器"
placement="bottom"
:mask-closable="false"
:show-close="false"
v-model:visible="state.isShow"
height="400px"
>
<div class="link-box">
<tiny-button @click="showMoter('showSound')" type="info" size="large">语音控制器</tiny-button>

<tiny-button @click="showMoter('showChat')" type="info" size="large">综合控制器</tiny-button>
Comment on lines +44 to +46
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update function calls to match refactored name

If you apply the suggested refactor above, update these function calls accordingly.

-        <tiny-button @click="showMoter('showSound')" type="info" size="large">语音控制器</tiny-button>
+        <tiny-button @click="showController('showSound')" type="info" size="large">语音控制器</tiny-button>

-        <tiny-button @click="showMoter('showChat')" type="info" size="large">综合控制器</tiny-button>
+        <tiny-button @click="showController('showChat')" type="info" size="large">综合控制器</tiny-button>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<tiny-button @click="showMoter('showSound')" type="info" size="large">语音控制器</tiny-button>
<tiny-button @click="showMoter('showChat')" type="info" size="large">综合控制器</tiny-button>
<tiny-button @click="showController('showSound')" type="info" size="large">语音控制器</tiny-button>
<tiny-button @click="showController('showChat')" type="info" size="large">综合控制器</tiny-button>
🤖 Prompt for AI Agents
In examples/sites/src/views/remoter/index.vue around lines 44 to 46, the
function calls to showMoter need to be updated to match the refactored function
name. Identify the new function name from the refactor and replace all instances
of showMoter with the updated function name in these button click handlers.

</div>
</tiny-drawer>
</div>
</template>

<style scoped lang="less">
.link-box {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

.tiny-button {
margin-bottom: 20px;
}
}
</style>
Loading
Loading