Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion packages/components/src/bubble/composables/useToolCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BubbleContentRendererProps, ChatMessageContent } from '../index.type'
import { getJsonrepair } from '../utils'
import { useBubbleStore } from './useBubbleStore'

const toolCallStatus = ['running', 'success', 'failed', 'cancelled'] as const
const toolCallStatus = ['running', 'success', 'failed', 'cancelled', 'awaiting-approval', 'denied'] as const
export type ToolCallStatus = (typeof toolCallStatus)[number]

export const useToolCall = (
Expand Down
26 changes: 23 additions & 3 deletions packages/components/src/bubble/renderers/Tool.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<script setup lang="ts">
import { IconArrowDown, IconCancelled, IconError, IconLoading, IconPlugin } from '@opentiny/tiny-robot-svgs'
import {
IconArrowDown,
IconCancelled,
IconClose,
IconError,
IconLoading,
IconPlugin,
IconWarning,
} from '@opentiny/tiny-robot-svgs'
import { type Component, computed, nextTick, ref, useCssModule, watch, watchEffect } from 'vue'
import { ToolCallStatus, useBubbleEventFn, useToolCall } from '../composables'
import { BubbleContentRendererProps, ChatMessageContent } from '../index.type'
Expand All @@ -22,8 +30,14 @@ const textAndIconMap = new Map<string, { text: string; icon: Component }>([
['cancelled', { text: '已取消', icon: IconCancelled }],
])

const approvalTextAndIconMap = new Map<string, { text: string; icon: Component }>([
['awaiting-approval', { text: '等待确认', icon: IconWarning }],
['denied', { text: '已拒绝', icon: IconClose }],
])

const textAndIcon = computed(() => {
return textAndIconMap.get(state.value?.status || '') || { text: '', icon: IconPlugin }
const status = state.value?.status || ''
return textAndIconMap.get(status) || approvalTextAndIconMap.get(status) || { text: '', icon: IconPlugin }
})
Comment thread
xuanlid marked this conversation as resolved.

const prettyJSON = (json: unknown, space = 2) => {
Expand Down Expand Up @@ -193,6 +207,7 @@ const handleClick = () => {
flex-shrink: 0;
display: flex;
align-items: center;
gap: 8px;
}

.header-icon {
Expand All @@ -209,9 +224,14 @@ const handleClick = () => {
}

&.icon-failed,
&.icon-cancelled {
&.icon-cancelled,
&.icon-denied {
color: var(--tr-color-error);
}

&.icon-awaiting-approval {
color: var(--tr-color-warning, #e6a23c);
Comment thread
xuanlid marked this conversation as resolved.
Outdated
}
}

.expand-icon {
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/message/adapters/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const createNativeMessageAdapter = (): MessageStateAdapter => {
requestState: state.requestState,
processingState: state.processingState,
messages: [...state.messages],
isProcessing: state.requestState === 'processing',
isProcessing: state.requestState === 'processing' || state.requestState === 'paused',
isPaused: state.requestState === 'paused',
} satisfies PublicMessageState
}

Expand Down
6 changes: 5 additions & 1 deletion packages/kit/src/message/adapters/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface VueMessageStateAdapter extends MessageStateAdapter {
processingState: Ref<RequestProcessingState | undefined>
messages: Ref<ChatMessage[]>
isProcessing: ComputedRef<boolean>
isPaused: ComputedRef<boolean>
}

const toReactiveMessage = (message: ChatMessage) => reactive(message) as ChatMessage
Expand Down Expand Up @@ -45,7 +46,8 @@ export const createVueMessageAdapter = (): VueMessageStateAdapter => {
const requestState = ref<RequestState>('idle')
const processingState = ref<RequestProcessingState | undefined>(undefined)
const messages = ref<ChatMessage[]>([])
const isProcessing = computed(() => requestState.value === 'processing')
const isProcessing = computed(() => requestState.value === 'processing' || requestState.value === 'paused')
const isPaused = computed(() => requestState.value === 'paused')
Comment thread
xuanlid marked this conversation as resolved.
Outdated

const initialize = (initialState: InternalMessageState) => {
if (initialized) {
Expand All @@ -72,6 +74,7 @@ export const createVueMessageAdapter = (): VueMessageStateAdapter => {
processingState: processingState.value,
messages: toPlainValue(messages.value),
isProcessing: isProcessing.value,
isPaused: isPaused.value,
} satisfies PublicMessageState
}

Expand Down Expand Up @@ -127,6 +130,7 @@ export const createVueMessageAdapter = (): VueMessageStateAdapter => {
processingState,
messages,
isProcessing,
isPaused,
initialize,
getState,
createMessage,
Expand Down
Loading
Loading