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 { Global } from "@/global"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { useToast } from "../ui/toast"
|
import { useToast } from "../ui/toast"
|
||||||
|
import { useDialog } from "../ui/dialog"
|
||||||
import { Keybind } from "@/util/keybind"
|
import { Keybind } from "@/util/keybind"
|
||||||
|
|
||||||
interface Hook {
|
interface Hook {
|
||||||
@ -12,8 +13,8 @@ interface Hook {
|
|||||||
name: string
|
name: string
|
||||||
description?: string
|
description?: string
|
||||||
remote_environment_name?: string
|
remote_environment_name?: string
|
||||||
code_execution_instructions?: string
|
customExecutionInstructions?: string
|
||||||
predefined_code_snippet?: string
|
customExecutionCode?: string
|
||||||
execute_as_static_script?: boolean
|
execute_as_static_script?: boolean
|
||||||
execute_as_python_tool?: boolean
|
execute_as_python_tool?: boolean
|
||||||
secrets_injected?: boolean
|
secrets_injected?: boolean
|
||||||
@ -56,6 +57,7 @@ function HookStatus(props: { hook: Hook }) {
|
|||||||
|
|
||||||
export function DialogTfHooks(props: { onSelect?: (hook: Hook) => void }) {
|
export function DialogTfHooks(props: { onSelect?: (hook: Hook) => void }) {
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
|
const dialog = useDialog()
|
||||||
const { theme } = useTheme()
|
const { theme } = useTheme()
|
||||||
const [, setRef] = createSignal<DialogSelectRef<unknown>>()
|
const [, setRef] = createSignal<DialogSelectRef<unknown>>()
|
||||||
const [loading, setLoading] = createSignal(false)
|
const [loading, setLoading] = createSignal(false)
|
||||||
@ -175,6 +177,7 @@ export function DialogTfHooks(props: { onSelect?: (hook: Hook) => void }) {
|
|||||||
onSelect={(option) => {
|
onSelect={(option) => {
|
||||||
if (option.value.id === "loading" || option.value.id === "empty") return
|
if (option.value.id === "loading" || option.value.id === "empty") return
|
||||||
props.onSelect?.(option.value)
|
props.onSelect?.(option.value)
|
||||||
|
dialog.clear()
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -378,15 +378,19 @@ export function Prompt(props: PromptProps) {
|
|||||||
<DialogTfHooks
|
<DialogTfHooks
|
||||||
onSelect={(hook) => {
|
onSelect={(hook) => {
|
||||||
const parts = []
|
const parts = []
|
||||||
if (hook.code_execution_instructions) parts.push(hook.code_execution_instructions)
|
if (hook.customExecutionInstructions) parts.push(hook.customExecutionInstructions)
|
||||||
if (hook.predefined_code_snippet) parts.push("\n\n```python\n" + hook.predefined_code_snippet + "\n```")
|
if (hook.customExecutionCode) parts.push("\n\n```python\n" + hook.customExecutionCode + "\n```")
|
||||||
const text = parts.join("")
|
const text = parts.join("")
|
||||||
if (text) {
|
if (text) {
|
||||||
input.setText(text)
|
|
||||||
setStore("prompt", { input: text, parts: [] })
|
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