MCPcopy Create free account
hub / github.com/anomalyco/opencode / currentRoute

Function currentRoute

packages/app/src/context/layout.tsx:129–156  ·  view source on GitHub ↗
(pathname: string, search: string)

Source from the content-addressed store, hash-verified

127}
128
129const currentRoute = (pathname: string, search: string): LayoutRoute => {
130 const parts = pathname.split("/").filter(Boolean)
131 if (parts.length === 0) return { type: "home" }
132
133 if (parts[0] === "new-session") {
134 const draftID = new URLSearchParams(search).get("draftId")
135 if (!draftID) return { type: "home" }
136 return { type: "draft", draftID }
137 }
138
139 if (parts[0] === "server" && parts[2] === "session" && parts[3]) {
140 return {
141 type: "session",
142 sessionId: parts[3],
143 server: requireServerKey(parts[1]),
144 }
145 }
146
147 const dirBase64 = parts[0]
148 const dir = decode64(dirBase64)
149 if (!dir) return { type: "home" }
150
151 if (parts[1] !== "session") return { type: "home" }
152
153 const id = parts[2]
154 if (id) return { type: "session", sessionId: id }
155 return { type: "dir-new-sesssion", dir, dirBase64 }
156}
157
158export const { use: useLayout, provider: LayoutProvider } = createSimpleContext({
159 name: "Layout",

Callers 1

layout.tsxFile · 0.85

Calls 3

requireServerKeyFunction · 0.90
decode64Function · 0.90
getMethod · 0.65

Tested by

no test coverage detected