mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-29 21:33:54 +00:00
feat: hooks
This commit is contained in:
parent
c39a97bb7d
commit
fdc30ae262
@ -5,6 +5,7 @@ import { TextAttributes } from "@opentui/core"
|
||||
import { Global } from "@/global"
|
||||
import path from "path"
|
||||
import { useToast } from "../ui/toast"
|
||||
import { useDialog } from "../ui/dialog"
|
||||
import { Keybind } from "@/util/keybind"
|
||||
|
||||
interface Hook {
|
||||
@ -12,8 +13,8 @@ interface Hook {
|
||||
name: string
|
||||
description?: string
|
||||
remote_environment_name?: string
|
||||
code_execution_instructions?: string
|
||||
predefined_code_snippet?: string
|
||||
customExecutionInstructions?: string
|
||||
customExecutionCode?: string
|
||||
execute_as_static_script?: boolean
|
||||
execute_as_python_tool?: boolean
|
||||
secrets_injected?: boolean
|
||||
@ -56,6 +57,7 @@ function HookStatus(props: { hook: Hook }) {
|
||||
|
||||
export function DialogTfHooks(props: { onSelect?: (hook: Hook) => void }) {
|
||||
const toast = useToast()
|
||||
const dialog = useDialog()
|
||||
const { theme } = useTheme()
|
||||
const [, setRef] = createSignal<DialogSelectRef<unknown>>()
|
||||
const [loading, setLoading] = createSignal(false)
|
||||
@ -175,6 +177,7 @@ export function DialogTfHooks(props: { onSelect?: (hook: Hook) => void }) {
|
||||
onSelect={(option) => {
|
||||
if (option.value.id === "loading" || option.value.id === "empty") return
|
||||
props.onSelect?.(option.value)
|
||||
dialog.clear()
|
||||
}}
|
||||
/>
|
||||
)
|
||||
|
||||
@ -378,15 +378,19 @@ export function Prompt(props: PromptProps) {
|
||||
<DialogTfHooks
|
||||
onSelect={(hook) => {
|
||||
const parts = []
|
||||
if (hook.code_execution_instructions) parts.push(hook.code_execution_instructions)
|
||||
if (hook.predefined_code_snippet) parts.push("\n\n```python\n" + hook.predefined_code_snippet + "\n```")
|
||||
if (hook.customExecutionInstructions) parts.push(hook.customExecutionInstructions)
|
||||
if (hook.customExecutionCode) parts.push("\n\n```python\n" + hook.customExecutionCode + "\n```")
|
||||
const text = parts.join("")
|
||||
if (text) {
|
||||
input.setText(text)
|
||||
setStore("prompt", { input: text, parts: [] })
|
||||
input.gotoBufferEnd()
|
||||
setTimeout(() => {
|
||||
if (input && !input.isDestroyed) {
|
||||
input.setText(text)
|
||||
input.gotoBufferEnd()
|
||||
input.focus()
|
||||
}
|
||||
}, 0)
|
||||
}
|
||||
dialog.clear()
|
||||
}}
|
||||
/>
|
||||
))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user