MCPcopy
hub / github.com/anomalyco/opencode / SessionTabSlot

Function SessionTabSlot

packages/app/src/components/titlebar-tab-strip.tsx:22–121  ·  view source on GitHub ↗
(props: {
  tab: SessionTab
  id: string
  index: () => number
  active: () => boolean
  activeServerKey: ServerConnection.Key
  forceTruncate: boolean
  serverCtx: () => ServerCtx | undefined
  onNavigate: (element: HTMLDivElement) => void
  onClose: () => void
})

Source from the content-addressed store, hash-verified

20const sortableTransition = { duration: 0 }
21
22function SessionTabSlot(props: {
23 tab: SessionTab
24 id: string
25 index: () => number
26 active: () => boolean
27 activeServerKey: ServerConnection.Key
28 forceTruncate: boolean
29 serverCtx: () => ServerCtx | undefined
30 onNavigate: (element: HTMLDivElement) => void
31 onClose: () => void
32}) {
33 const tabs = useTabs()
34 const language = useLanguage()
35 const sortable = useSortable({
36 get id() {
37 return props.id
38 },
39 get index() {
40 return props.index()
41 },
42 })
43 let ref!: HTMLDivElement
44 const sdk = createMemo(() => props.serverCtx()?.sdk ?? null)
45 const cachedSession = createMemo(() => props.serverCtx()?.sync.session.peek(props.tab.sessionId))
46 const [loadedSession] = createResource(
47 () => {
48 const ctx = props.serverCtx()
49 return ctx ? { id: props.tab.sessionId, ctx } : null
50 },
51 ({ id, ctx }) => ctx.sync.session.resolve(id).catch(() => undefined),
52 )
53 const session = createMemo(() => cachedSession() ?? loadedSession())
54 const missingSession = createMemo(() => !!props.serverCtx() && !loadedSession.loading && !session())
55 let prefetched = false
56
57 createEffect(() => {
58 const ctx = props.serverCtx()
59 const value = session()
60 if (!ctx || !value || prefetched) return
61 prefetched = true
62 createRoot((dispose) => {
63 try {
64 void ctx.sync
65 .ensureDirSyncContext(value.directory)
66 .session.sync(value.id)
67 .catch(() => {})
68 .finally(dispose)
69 } catch {
70 dispose()
71 }
72 })
73 })
74
75 createEffect(() => {
76 const value = session()
77 const current = sdk()
78 if (!value || !current) return
79 createTabPromptState(tabs, props.tab, current.scope, {

Callers

nothing calls this directly

Calls 8

createTabPromptStateFunction · 0.90
base64EncodeFunction · 0.90
tabHrefFunction · 0.90
sdkFunction · 0.85
syncMethod · 0.80
activeMethod · 0.80
sessionFunction · 0.70
disposeFunction · 0.50

Tested by

no test coverage detected