feat: llm support struct output (#17994)
Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: zxhlyh <jasonapring2015@outlook.com>
This commit is contained in:
@@ -10,7 +10,7 @@ const merge = <T extends Record<string, any>>(
|
||||
|
||||
export type _Events = Record<EventType, unknown>
|
||||
|
||||
export type UseSubcribeOption = {
|
||||
export type UseSubscribeOption = {
|
||||
/**
|
||||
* Whether the subscription is enabled.
|
||||
* @default true
|
||||
@@ -22,21 +22,21 @@ export type ExtendedOn<Events extends _Events> = {
|
||||
<Key extends keyof Events>(
|
||||
type: Key,
|
||||
handler: Handler<Events[Key]>,
|
||||
options?: UseSubcribeOption,
|
||||
options?: UseSubscribeOption,
|
||||
): void;
|
||||
(
|
||||
type: '*',
|
||||
handler: WildcardHandler<Events>,
|
||||
option?: UseSubcribeOption,
|
||||
option?: UseSubscribeOption,
|
||||
): void;
|
||||
}
|
||||
|
||||
export type UseMittReturn<Events extends _Events> = {
|
||||
useSubcribe: ExtendedOn<Events>;
|
||||
useSubscribe: ExtendedOn<Events>;
|
||||
emit: Emitter<Events>['emit'];
|
||||
}
|
||||
|
||||
const defaultSubcribeOption: UseSubcribeOption = {
|
||||
const defaultSubscribeOption: UseSubscribeOption = {
|
||||
enabled: true,
|
||||
}
|
||||
|
||||
@@ -52,12 +52,12 @@ function useMitt<Events extends _Events>(
|
||||
emitterRef.current = mitt
|
||||
}
|
||||
const emitter = emitterRef.current
|
||||
const useSubcribe: ExtendedOn<Events> = (
|
||||
const useSubscribe: ExtendedOn<Events> = (
|
||||
type: string,
|
||||
handler: any,
|
||||
option?: UseSubcribeOption,
|
||||
option?: UseSubscribeOption,
|
||||
) => {
|
||||
const { enabled } = merge(defaultSubcribeOption, option)
|
||||
const { enabled } = merge(defaultSubscribeOption, option)
|
||||
useEffect(() => {
|
||||
if (enabled) {
|
||||
emitter.on(type, handler)
|
||||
@@ -67,7 +67,7 @@ function useMitt<Events extends _Events>(
|
||||
}
|
||||
return {
|
||||
emit: emitter.emit,
|
||||
useSubcribe,
|
||||
useSubscribe,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user