27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
// Resolve the active session workspace from the optional host sessions face.
|
|
// The probe is deliberately defensive: the panel must work without the service.
|
|
export function resolveWorkspace(ctx: any): string | undefined {
|
|
try {
|
|
const sessions = ctx !== undefined && ctx !== null && typeof ctx.get === 'function' ? ctx.get('sessions') : undefined
|
|
if (sessions === undefined || sessions === null) return undefined
|
|
const current = typeof sessions.current === 'function' ? sessions.current() : sessions.current
|
|
const candidates = [
|
|
current?.cwd,
|
|
current?.header?.cwd,
|
|
current?.session?.cwd,
|
|
current?.session?.header?.cwd,
|
|
typeof sessions.cwd === 'function' ? sessions.cwd() : undefined,
|
|
]
|
|
for (const candidate of candidates) {
|
|
if (typeof candidate === 'string' && candidate.trim() !== '') return candidate
|
|
}
|
|
} catch {
|
|
/* no sessions face -> omit the workspace argument */
|
|
}
|
|
return undefined
|
|
}
|
|
|
|
export function workspaceQuery(workspace: string | undefined): string {
|
|
return workspace === undefined ? '' : '?workspace=' + encodeURIComponent(workspace)
|
|
}
|