| 21 | |
| 22 | /** The one symbol a Galaxy or Architecture selection stands for, if it is one. */ |
| 23 | export function sourceTargetOf(context: BrowserChatContext | undefined): SourceTarget | undefined { |
| 24 | if (!context || context.text.length > 128_000) return undefined; |
| 25 | const galaxy = readGalaxyEvidence(context.text); |
| 26 | if (galaxy) { |
| 27 | const [root] = galaxy.roots; |
| 28 | if (galaxy.rootCount !== 1 || !root?.qualifiedName || CONTAINERS.has((root.kind ?? '').toLowerCase())) return undefined; |
| 29 | return { qualifiedName: root.qualifiedName, name: root.name, kind: root.kind, path: root.filePath, startLine: root.startLine, endLine: root.endLine }; |
| 30 | } |
| 31 | let parsed: Record<string, unknown> | undefined; |
| 32 | try { parsed = record(record(JSON.parse(context.text))?.evidence); } catch { return undefined; } |
| 33 | const facts = parsed?.kind === 'current-selection-evidence' ? architectureFacts(parsed) : undefined; |
| 34 | // Source the view already read needs no second read. |
| 35 | return facts?.source ? undefined : facts?.target; |
| 36 | } |
| 37 | |
| 38 | function architectureTarget(context: BrowserChatContext): SourceTarget | undefined { |
| 39 | let parsed: Record<string, unknown> | undefined; |