Skip to content

Commit cd65ac4

Browse files
authored
refactor(confirmation): simplify approval type and tighten inject typing (#108)
1 parent 3f5fbbc commit cd65ac4

File tree

2 files changed

+2
-32
lines changed

2 files changed

+2
-32
lines changed

apps/www/content/3.components/1.chatbot/confirmation.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,6 @@ export type ToolUIPartApproval
194194
approved: boolean
195195
reason?: string
196196
}
197-
| {
198-
id: string
199-
approved: true
200-
reason?: string
201-
}
202-
| {
203-
id: string
204-
approved: true
205-
reason?: string
206-
}
207-
| {
208-
id: string
209-
approved: false
210-
reason?: string
211-
}
212197
| undefined
213198

214199
export interface ConfirmationContextValue {
@@ -220,7 +205,7 @@ export const ConfirmationKey: InjectionKey<ConfirmationContextValue>
220205
= Symbol('ConfirmationContext')
221206

222207
export function useConfirmationContext() {
223-
const context = inject<ConfirmationContextValue | null>(ConfirmationKey, null)
208+
const context = inject(ConfirmationKey)
224209
if (!context)
225210
throw new Error('Confirmation components must be used within <Confirmation>')
226211
return context

packages/elements/src/confirmation/context.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ export type ToolUIPartApproval
1313
approved: boolean
1414
reason?: string
1515
}
16-
| {
17-
id: string
18-
approved: true
19-
reason?: string
20-
}
21-
| {
22-
id: string
23-
approved: true
24-
reason?: string
25-
}
26-
| {
27-
id: string
28-
approved: false
29-
reason?: string
30-
}
3116
| undefined
3217

3318
export interface ConfirmationContextValue {
@@ -39,7 +24,7 @@ export const ConfirmationKey: InjectionKey<ConfirmationContextValue>
3924
= Symbol('ConfirmationContext')
4025

4126
export function useConfirmationContext() {
42-
const context = inject<ConfirmationContextValue | null>(ConfirmationKey, null)
27+
const context = inject(ConfirmationKey)
4328
if (!context)
4429
throw new Error('Confirmation components must be used within <Confirmation>')
4530
return context

0 commit comments

Comments
 (0)