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:
Joel
2025-04-18 16:53:43 +08:00
committed by GitHub
parent da9269ca97
commit 775dc47abe
82 changed files with 4190 additions and 276 deletions

View File

@@ -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,
}
}