MCPcopy Index your code
hub / github.com/anomalyco/opencode / BasicTool

Function BasicTool

packages/session-ui/src/components/basic-tool.tsx:83–298  ·  view source on GitHub ↗
(props: BasicToolProps)

Source from the content-addressed store, hash-verified

81}
82
83export function BasicTool(props: BasicToolProps) {
84 const [state, setState] = createStore({
85 open: props.defaultOpen ?? false,
86 ready: !props.defer && (props.defaultOpen ?? false),
87 })
88 const open = () => props.open ?? state.open
89 const ready = () => state.ready
90 const pending = () => props.status === "pending" || props.status === "running"
91 const hasChildren = () => (props.defer ? "children" in props : props.children)
92 const dynamicTrigger = typeof props.trigger === "function" ? props.trigger(open) : undefined
93
94 let cancelReady: (() => void) | undefined
95
96 const cancel = () => {
97 cancelReady?.()
98 cancelReady = undefined
99 }
100
101 const scheduleReady = (initial = false) => {
102 cancel()
103 cancelReady = (initial ? scheduleDeferredMount : scheduleFrameMount)(() => {
104 cancelReady = undefined
105 if (!open()) return
106 setState("ready", true)
107 })
108 }
109
110 onCleanup(cancel)
111
112 onMount(() => {
113 if (props.defer && open()) scheduleReady(true)
114 })
115
116 const setOpen = (value: boolean) => {
117 if (props.open === undefined) setState("open", value)
118 props.onOpenChange?.(value)
119 }
120
121 createEffect(() => {
122 if (!props.forceOpen) return
123 if (open()) return
124 setOpen(true)
125 })
126
127 createEffect(
128 on(
129 open,
130 (value) => {
131 if (!props.defer) return
132 if (!value) {
133 cancel()
134 setState("ready", false)
135 return
136 }
137
138 scheduleReady()
139 },
140 { defer: true },

Callers

nothing calls this directly

Calls 12

scheduleReadyFunction · 0.85
setStateFunction · 0.85
animateFunction · 0.85
hasChildrenFunction · 0.85
openFunction · 0.70
setOpenFunction · 0.70
cancelFunction · 0.70
triggerFunction · 0.70
readyFunction · 0.70
onFunction · 0.50
hrefFunction · 0.50
stopMethod · 0.45

Tested by

no test coverage detected