Skip to content

Commit

Permalink
feat(webui): support clear in sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 1, 2021
1 parent a4264e9 commit d23c170
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/plugin-webui/client/views/plugins/plugin-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import type { Registry } from '~/server'
import { ref, computed, defineProps } from 'vue'
import PluginView from './plugin-view.vue'
const show = ref(false)
Expand Down
8 changes: 7 additions & 1 deletion packages/plugin-webui/client/views/sandbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<script lang="ts" setup>
import { ref, watch, nextTick } from 'vue'
import { ref, watch, nextTick, onMounted } from 'vue'
import { send, receive, user, storage } from '~/client'
interface Message {
Expand All @@ -33,6 +33,8 @@ function addMessage(from: 'user' | 'bot', content: string) {
}
}
onMounted(scrollToBottom)
function scrollToBottom() {
panel.value.scrollTop = panel.value.scrollHeight - panel.value.clientHeight
}
Expand All @@ -49,6 +51,10 @@ receive('sandbox', (data) => {
addMessage('bot', data)
})
receive('clear', (data) => {
messages.value = []
})
</script>

<style lang="scss">
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-webui/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export class WebAdapter extends Adapter<'web'> {
server: ctx.app._httpServer,
})

ctx.self('sandbox').command('clear', '清空消息列表')
.action(({ session }) => this.channels[session.channelId].send('clear'))

ctx.all().middleware(async (session, next) => {
if (session.subtype !== 'private') return next()
const state = states[session.uid]
Expand Down

0 comments on commit d23c170

Please sign in to comment.