Skip to content

Commit 72c9a9d

Browse files
committed
feat(tool): persistent message
1 parent c8cedb3 commit 72c9a9d

16 files changed

Lines changed: 2125 additions & 122 deletions

File tree

packages/components/src/bubble/composables/useToolCall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BubbleContentRendererProps, ChatMessageContent } from '../index.type'
33
import { getJsonrepair } from '../utils'
44
import { useBubbleStore } from './useBubbleStore'
55

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

99
export const useToolCall = (

packages/components/src/bubble/renderers/Tool.vue

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<script setup lang="ts">
2-
import { IconArrowDown, IconCancelled, IconError, IconLoading, IconPlugin } from '@opentiny/tiny-robot-svgs'
2+
import {
3+
IconArrowDown,
4+
IconCancelled,
5+
IconClose,
6+
IconError,
7+
IconLoading,
8+
IconPlugin,
9+
IconWarning,
10+
} from '@opentiny/tiny-robot-svgs'
311
import { type Component, computed, nextTick, ref, useCssModule, watch, watchEffect } from 'vue'
412
import { ToolCallStatus, useBubbleEventFn, useToolCall } from '../composables'
513
import { BubbleContentRendererProps, ChatMessageContent } from '../index.type'
@@ -22,8 +30,14 @@ const textAndIconMap = new Map<string, { text: string; icon: Component }>([
2230
['cancelled', { text: '已取消', icon: IconCancelled }],
2331
])
2432
33+
const approvalTextAndIconMap = new Map<string, { text: string; icon: Component }>([
34+
['awaiting-approval', { text: '等待确认', icon: IconWarning }],
35+
['denied', { text: '已拒绝', icon: IconClose }],
36+
])
37+
2538
const textAndIcon = computed(() => {
26-
return textAndIconMap.get(state.value?.status || '') || { text: '', icon: IconPlugin }
39+
const status = state.value?.status || ''
40+
return textAndIconMap.get(status) || approvalTextAndIconMap.get(status) || { text: '', icon: IconPlugin }
2741
})
2842
2943
const prettyJSON = (json: unknown, space = 2) => {
@@ -193,6 +207,7 @@ const handleClick = () => {
193207
flex-shrink: 0;
194208
display: flex;
195209
align-items: center;
210+
gap: 8px;
196211
}
197212
198213
.header-icon {
@@ -209,9 +224,14 @@ const handleClick = () => {
209224
}
210225
211226
&.icon-failed,
212-
&.icon-cancelled {
227+
&.icon-cancelled,
228+
&.icon-denied {
213229
color: var(--tr-color-error);
214230
}
231+
232+
&.icon-awaiting-approval {
233+
color: var(--tr-color-warning, #e6a23c);
234+
}
215235
}
216236
217237
.expand-icon {

packages/kit/src/message/adapters/native.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const createNativeMessageAdapter = (): MessageStateAdapter => {
2727
requestState: state.requestState,
2828
processingState: state.processingState,
2929
messages: [...state.messages],
30-
isProcessing: state.requestState === 'processing',
30+
isProcessing: state.requestState === 'processing' || state.requestState === 'paused',
3131
isPaused: state.requestState === 'paused',
3232
} satisfies PublicMessageState
3333
}

packages/kit/src/message/adapters/vue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const createVueMessageAdapter = (): VueMessageStateAdapter => {
4646
const requestState = ref<RequestState>('idle')
4747
const processingState = ref<RequestProcessingState | undefined>(undefined)
4848
const messages = ref<ChatMessage[]>([])
49-
const isProcessing = computed(() => requestState.value === 'processing')
49+
const isProcessing = computed(() => requestState.value === 'processing' || requestState.value === 'paused')
5050
const isPaused = computed(() => requestState.value === 'paused')
5151

5252
const initialize = (initialState: InternalMessageState) => {

0 commit comments

Comments
 (0)