Skip to content
Open
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
4 changes: 2 additions & 2 deletions packages/elements/src/confirmation/Confirmation.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import type { ToolUIPart } from 'ai'
import type { HTMLAttributes } from 'vue'
import type { ExtendedToolState } from '../types'
import type { ToolUIPartApproval } from './context'
import { Alert } from '@repo/shadcn-vue/components/ui/alert'
import { cn } from '@repo/shadcn-vue/lib/utils'
Expand All @@ -9,7 +9,7 @@ import { ConfirmationKey } from './context'

const props = defineProps<{
approval?: ToolUIPartApproval
state: ToolUIPart['state']
state: ExtendedToolState
class?: HTMLAttributes['class']
}>()

Expand Down
4 changes: 2 additions & 2 deletions packages/elements/src/confirmation/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ToolUIPart } from 'ai'
import type { InjectionKey, Ref } from 'vue'
import type { ExtendedToolState } from '../types'
import { inject } from 'vue'

export type ToolUIPartApproval
Expand Down Expand Up @@ -32,7 +32,7 @@ export type ToolUIPartApproval

export interface ConfirmationContextValue {
approval: Ref<ToolUIPartApproval>
state: Ref<ToolUIPart['state']>
state: Ref<ExtendedToolState>
}

export const ConfirmationKey: InjectionKey<ConfirmationContextValue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function handleClick() {
<Button
v-if="showScrollButton"
:class="cn('absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full', props.class)"
aria-label="Scroll to bottom"
size="icon"
type="button"
variant="outline"
Expand Down
1 change: 1 addition & 0 deletions packages/elements/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export * from './sources'
export * from './suggestion'
export * from './task'
export * from './tool'
export type { ExtendedToolState } from './types'
export * from './web-preview'
3 changes: 3 additions & 0 deletions packages/elements/src/loader/Loader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const props = withDefaults(defineProps<Props>(), {
<template>
<div
:class="cn('inline-flex animate-spin items-center justify-center', props.class)"
aria-label="Loading"
aria-live="polite"
role="status"
v-bind="$attrs"
>
<LoaderIcon :size="props.size" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ onMounted(() => {
sr.onstart = () => isListening.value = true
sr.onend = () => isListening.value = false

sr.onresult = (event: any) => {
sr.onresult = (event: SpeechRecognitionEvent) => {
let finalTranscript = ''
for (let i = event.resultIndex; i < event.results.length; i++) {
const result = event.results[i]
Expand All @@ -96,7 +96,7 @@ onMounted(() => {
}
}

sr.onerror = (event: any) => {
sr.onerror = (event: SpeechRecognitionErrorEvent) => {
console.error('Speech recognition error:', event.error)
isListening.value = false
}
Expand Down
8 changes: 4 additions & 4 deletions packages/elements/src/tool/ToolStatusBadge.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- StatusBadge.vue -->
<script setup lang="ts">
import type { ToolUIPart } from 'ai'
import type { Component } from 'vue'
import type { ExtendedToolState } from '../types'
import { Badge } from '@repo/shadcn-vue/components/ui/badge'
import {
CheckCircleIcon,
Expand All @@ -12,11 +12,11 @@ import {
import { computed } from 'vue'

const props = defineProps<{
state: ToolUIPart['state']
state: ExtendedToolState
}>()

const label = computed(() => {
const labels: Record<ToolUIPart['state'], string> = {
const labels: Record<ExtendedToolState, string> = {
'input-streaming': 'Pending',
'input-available': 'Running',
'approval-requested': 'Awaiting Approval',
Expand All @@ -29,7 +29,7 @@ const label = computed(() => {
})

const icon = computed<Component>(() => {
const icons: Record<ToolUIPart['state'], Component> = {
const icons: Record<ExtendedToolState, Component> = {
'input-streaming': CircleIcon,
'input-available': ClockIcon,
'approval-requested': ClockIcon,
Expand Down
1 change: 1 addition & 0 deletions packages/elements/src/tool/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export type { ExtendedToolState } from '../types'
export { default as Tool } from './Tool.vue'
export { default as ToolContent } from './ToolContent.vue'
export { default as ToolHeader } from './ToolHeader.vue'
Expand Down
15 changes: 15 additions & 0 deletions packages/elements/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ToolUIPart } from 'ai'

/**
* Extended tool state type that includes approval-related states
* beyond what the base AI SDK provides.
*
* This type is used across multiple components including:
* - Tool components (ToolStatusBadge)
* - Confirmation components
*/
export type ExtendedToolState
= | ToolUIPart['state']
| 'approval-requested'
| 'approval-responded'
| 'output-denied'
3 changes: 2 additions & 1 deletion packages/examples/src/confirmation-accepted.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import type { ExtendedToolState } from '@repo/elements/tool'
import {
Confirmation,
ConfirmationAccepted,
Expand All @@ -15,7 +16,7 @@ const approval = {
approved: true,
}

const state = 'approval-responded'
const state: ExtendedToolState = 'approval-responded'
</script>

<template>
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/src/confirmation-rejected.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import type { ExtendedToolState } from '@repo/elements/tool'
import {
Confirmation,
ConfirmationAccepted,
Expand All @@ -16,7 +17,7 @@ const approval = ref({
approved: false,
})

const state = ref('output-denied')
const state = ref<ExtendedToolState>('output-denied')
</script>

<template>
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/src/confirmation.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import type { ExtendedToolState } from '@repo/elements/tool'
import {
Confirmation,
ConfirmationAccepted,
Expand All @@ -14,7 +15,7 @@ import { nanoid } from 'nanoid'
import { ref } from 'vue'

const approval = ref({ id: nanoid() })
const state = ref<'approval-requested' | 'approval-responded'>('approval-requested')
const state = ref<ExtendedToolState>('approval-requested')

function handleReject() {
// In production, call respondToConfirmationRequest with approved: false
Expand Down