-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
116 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,59 @@ | ||
import { ChatCompletionFunctions } from 'openai-edge/types/api'; | ||
import { ReactNode } from 'react'; | ||
|
||
/** | ||
* 插件项 | ||
* @template Result - 结果类型,默认为 any | ||
* @template RunnerParams - 运行参数类型,默认为 any | ||
*/ | ||
export interface PluginItem<Result = any, RunnerParams = any> { | ||
/** | ||
* 头像 | ||
*/ | ||
avatar: string; | ||
/** | ||
* 名称 | ||
*/ | ||
name: string; | ||
/** | ||
* 运行器 | ||
* @param params - 运行参数 | ||
* @returns 运行结果的 Promise | ||
*/ | ||
runner: PluginRunner<RunnerParams, Result>; | ||
/** | ||
* 聊天完成函数的模式 | ||
*/ | ||
schema: ChatCompletionFunctions; | ||
} | ||
|
||
/** | ||
* 插件渲染函数 | ||
* @param props - 插件渲染属性 | ||
* @returns React 节点 | ||
*/ | ||
export type PluginRender = (props: PluginRenderProps) => ReactNode; | ||
|
||
/** | ||
* 插件运行器 | ||
* @template Params - 参数类型,默认为 object | ||
* @template Result - 结果类型,默认为 any | ||
* @param params - 运行参数 | ||
* @returns 运行结果的 Promise | ||
*/ | ||
export type PluginRunner<Params = object, Result = any> = (params: Params) => Promise<Result>; | ||
|
||
/** | ||
* 插件渲染属性 | ||
* @template Result - 结果类型,默认为 any | ||
*/ | ||
export interface PluginRenderProps<Result = any> { | ||
/** | ||
* 内容 | ||
*/ | ||
content: Result; | ||
/** | ||
* 名称 | ||
*/ | ||
name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './useOnFinishHydrationSession'; | ||
export * from './useSessionChatInit'; | ||
export * from './useSessionHydrated'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useSessionStore } from '../store'; | ||
import { useSessionHydrated } from './useSessionHydrated'; | ||
|
||
/** | ||
* 用于判断某个会话是否完全被激活 | ||
*/ | ||
export const useSessionChatInit = () => { | ||
const sessionHydrated = useSessionHydrated(); | ||
const [hasActive] = useSessionStore((s) => [!!s.activeId]); | ||
|
||
return sessionHydrated && hasActive; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters