@@ -13,15 +13,15 @@ import {
1313import path from "path"
1414import { stat } from "fs/promises"
1515import { fileURLToPath , pathToFileURL } from "url"
16- import type { Context , Dialog , Page , Slot , Toast } from "@opencode-ai/plugin/tui/context"
16+ import type { Context , Dialog , Page , Slot , SlotMap , SlotName , Toast } from "@opencode-ai/plugin/tui/context"
1717import { createStore , produce , reconcile as reconcileStore } from "solid-js/store"
1818import { useRenderer } from "@opentui/solid"
1919import { useConfig } from "../config"
2020import { useClient } from "../context/client"
2121import { useData } from "../context/data"
2222import { Keymap } from "../context/keymap"
2323import { useRoute } from "../context/route"
24- import { useTuiLifecycle } from "../context/runtime"
24+ import { useTuiApp , useTuiLifecycle , useTuiPaths } from "../context/runtime"
2525import { useLocation } from "../context/location"
2626import { useTheme } from "../context/theme"
2727import { DialogAlert } from "../ui/dialog-alert"
@@ -31,6 +31,7 @@ import { DialogSelect } from "../ui/dialog-select"
3131import { useDialog } from "../ui/dialog"
3232import { useToast } from "../ui/toast"
3333import { useAttention } from "../context/attention"
34+ import { abbreviateHome } from "../util/path-format"
3435import { builtins } from "./builtins"
3536
3637export interface PackageResolver {
@@ -47,7 +48,7 @@ type Value = {
4748 readonly ready : ( ) => boolean
4849 readonly list : ( ) => ReadonlyArray < State >
4950 readonly route : ( id : string , name : string ) => Page [ "render" ] | undefined
50- readonly slot : ( name : string ) => ReadonlyArray < Slot >
51+ readonly slot : < Name extends SlotName > ( name : Name ) => ReadonlyArray < Slot < Name > >
5152 readonly activate : ( id : string ) => Promise < boolean >
5253 readonly deactivate : ( id : string ) => Promise < boolean >
5354}
@@ -75,6 +76,8 @@ export function PluginProvider(props: ParentProps<{ packages: PackageResolver }>
7576 const shortcuts = Keymap . useShortcuts ( )
7677 const keymapState = Keymap . useState ( )
7778 const lifecycle = useTuiLifecycle ( )
79+ const app = useTuiApp ( )
80+ const paths = useTuiPaths ( )
7881 const location = useLocation ( )
7982 const theme = useTheme ( )
8083 const dialog = useDialog ( )
@@ -120,7 +123,6 @@ export function PluginProvider(props: ParentProps<{ packages: PackageResolver }>
120123 dialog . setCentered ( options . centered ?? false )
121124 } ,
122125 clear ( ) {
123- if ( ! activeDialog ) return
124126 dialog . clear ( )
125127 } ,
126128 alert ( options ) {
@@ -218,11 +220,12 @@ export function PluginProvider(props: ParentProps<{ packages: PackageResolver }>
218220 get location ( ) {
219221 return location . current
220222 } ,
223+ app : { version : app . version , channel : app . channel } ,
221224 renderer,
222225 client : client . api ,
223226 data,
224227 attention,
225- theme : theme . themeV2 ,
228+ theme,
226229 keymap : {
227230 layer : Keymap . createLayer ,
228231 dispatch : keymap . dispatch ,
@@ -235,6 +238,9 @@ export function PluginProvider(props: ParentProps<{ packages: PackageResolver }>
235238 ui : {
236239 dialog : dialogApi ,
237240 toast : toastApi ,
241+ format : {
242+ path : ( value ) => abbreviateHome ( value , paths . home ) ,
243+ } ,
238244 router : {
239245 register ( page ) {
240246 if ( store . registrations [ item . plugin . id ] ?. routes [ page . name ] )
@@ -530,7 +536,16 @@ export function PluginRoute(props: { readonly fallback: (id: string, name: strin
530536 return < > { content ( ) } </ >
531537}
532538
533- export function PluginSlot ( props : { readonly name : string ; readonly input ?: Record < string , any > } ) {
539+ export function PluginSlot < Name extends SlotName > ( props : {
540+ readonly name : Name
541+ readonly input : SlotMap [ Name ]
542+ readonly mode : "all" | "replace"
543+ } ) {
534544 const plugins = usePlugin ( )
535- return < For each = { plugins . slot ( props . name ) } > { ( render ) => render ( props . input ?? { } ) } </ For >
545+ const renderers = createMemo ( ( ) => {
546+ const items = plugins . slot ( props . name )
547+ if ( props . mode === "replace" ) return items . slice ( - 1 )
548+ return items
549+ } )
550+ return < For each = { renderers ( ) } > { ( render ) => render ( props . input ) } </ For >
536551}
0 commit comments