@truefoundry/trueforge-ui 0.2.4 → 0.3.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +85 -0
- package/README.md +55 -23
- package/dist/AgentCodeSnippets-NZOFJE57.js +74 -0
- package/dist/AgentCodeSnippets-NZOFJE57.js.map +1 -0
- package/dist/AgentMetricChart-JPU3MFQ2.js +15 -0
- package/dist/AgentOverview-EEBHJC32.js +167 -0
- package/dist/AgentOverview-EEBHJC32.js.map +1 -0
- package/dist/AgentSessionEventTimeline-26Z6IB3B.js +79 -0
- package/dist/AgentSessionEventTimeline-26Z6IB3B.js.map +1 -0
- package/dist/AgentSessionEventTimelineChart-CGCU7WBK.js +504 -0
- package/dist/AgentSessionEventTimelineChart-CGCU7WBK.js.map +1 -0
- package/dist/AgentSessions-3MPDZASK.js +275 -0
- package/dist/AgentSessions-3MPDZASK.js.map +1 -0
- package/dist/{ConnectorSettings-ODC3LVHN.js → ConnectorSettings-MXFRWWR6.js} +8 -6
- package/dist/{ConnectorSettings-ODC3LVHN.js.map → ConnectorSettings-MXFRWWR6.js.map} +1 -1
- package/dist/{DockLayout-TEOWEMSV.js → DockLayout-LM4AFMFY.js} +12 -11
- package/dist/{DockLayout-TEOWEMSV.js.map → DockLayout-LM4AFMFY.js.map} +1 -1
- package/dist/DrawerLayout-JR3O6RRB.js +184 -0
- package/dist/DrawerLayout-JR3O6RRB.js.map +1 -0
- package/dist/{ModelSettings-CKQ5CVAC.js → ModelSettings-G7IFNC2Y.js} +8 -6
- package/dist/{ModelSettings-CKQ5CVAC.js.map → ModelSettings-G7IFNC2Y.js.map} +1 -1
- package/dist/OpenUiFenceBlock-2TV5TQ6P.js +9 -0
- package/dist/OpenUiFenceBlock-2TV5TQ6P.js.map +1 -0
- package/dist/{SandboxSettings-HSCPYUOC.js → SandboxSettings-NXAANMAX.js} +8 -6
- package/dist/{SandboxSettings-HSCPYUOC.js.map → SandboxSettings-NXAANMAX.js.map} +1 -1
- package/dist/SchedulesPage-KKLUDO6B.js +15 -0
- package/dist/SchedulesPage-KKLUDO6B.js.map +1 -0
- package/dist/{SettingsBuilder-MYWRFXRI.js → SettingsBuilder-L34IQ56S.js} +26 -22
- package/dist/SettingsBuilder-L34IQ56S.js.map +1 -0
- package/dist/{ShellRouteSync-T4WLY57Q.js → ShellRouteSync-CEBETGEJ.js} +95 -22
- package/dist/ShellRouteSync-CEBETGEJ.js.map +1 -0
- package/dist/SidebarLayout-A2HJPPHS.js +308 -0
- package/dist/SidebarLayout-A2HJPPHS.js.map +1 -0
- package/dist/{SkillSettings-ECH6SHZ7.js → SkillSettings-FGGMSUNO.js} +8 -6
- package/dist/{SkillSettings-ECH6SHZ7.js.map → SkillSettings-FGGMSUNO.js.map} +1 -1
- package/dist/{TrueForgeUIWithRouter-KMHPOKLN.js → TrueForgeUIWithRouter-MZVJWJMB.js} +15 -11
- package/dist/{TrueForgeUIWithRouter-KMHPOKLN.js.map → TrueForgeUIWithRouter-MZVJWJMB.js.map} +1 -1
- package/dist/{WidgetLayout-4ZIG3RXV.js → WidgetLayout-6QM45OQQ.js} +19 -15
- package/dist/WidgetLayout-6QM45OQQ.js.map +1 -0
- package/dist/chunk-2XPPBEYF.js +74 -0
- package/dist/chunk-2XPPBEYF.js.map +1 -0
- package/dist/chunk-6O6FWUDW.js +1376 -0
- package/dist/chunk-6O6FWUDW.js.map +1 -0
- package/dist/chunk-7Z2C2K7F.js +578 -0
- package/dist/chunk-7Z2C2K7F.js.map +1 -0
- package/dist/{chunk-FXCYLEFB.js → chunk-BSIPI3KV.js} +18 -2
- package/dist/chunk-BSIPI3KV.js.map +1 -0
- package/dist/{chunk-255AE5NI.js → chunk-CYHJDKFB.js} +118 -33
- package/dist/chunk-CYHJDKFB.js.map +1 -0
- package/dist/chunk-DJUFS2BW.js +27 -0
- package/dist/chunk-DJUFS2BW.js.map +1 -0
- package/dist/chunk-DMMZSZTN.js +252 -0
- package/dist/chunk-DMMZSZTN.js.map +1 -0
- package/dist/chunk-FJW36PD7.js +180 -0
- package/dist/chunk-FJW36PD7.js.map +1 -0
- package/dist/chunk-M62XY4NC.js +555 -0
- package/dist/chunk-M62XY4NC.js.map +1 -0
- package/dist/{chunk-JRRCAKEP.js → chunk-MPNSO7E6.js} +2 -2
- package/dist/{chunk-CFLVPV5M.js → chunk-QC42MLAK.js} +7 -2
- package/dist/chunk-QC42MLAK.js.map +1 -0
- package/dist/chunk-RDXBMTP5.js +32 -0
- package/dist/chunk-RDXBMTP5.js.map +1 -0
- package/dist/chunk-SFZNIO6U.js +18 -0
- package/dist/chunk-SFZNIO6U.js.map +1 -0
- package/dist/chunk-U7KURWW3.js +840 -0
- package/dist/chunk-U7KURWW3.js.map +1 -0
- package/dist/chunk-WVE3F724.js +200 -0
- package/dist/chunk-WVE3F724.js.map +1 -0
- package/dist/{chunk-IFLE7OMM.js → chunk-XAU7QFG3.js} +180 -38
- package/dist/chunk-XAU7QFG3.js.map +1 -0
- package/dist/chunk-Y6S4OVVQ.js +16 -0
- package/dist/chunk-Y6S4OVVQ.js.map +1 -0
- package/dist/chunk-ZKNUMH2M.js +119 -0
- package/dist/chunk-ZKNUMH2M.js.map +1 -0
- package/dist/chunk-ZTMKFZQ3.js +13214 -0
- package/dist/chunk-ZTMKFZQ3.js.map +1 -0
- package/dist/{createTrueFoundryServer-B72bU-J7.d.ts → createTrueFoundryServer-CmZnBh_l.d.ts} +15 -4
- package/dist/index.d.ts +1199 -161
- package/dist/index.js +699 -69
- package/dist/index.js.map +1 -1
- package/dist/plugins/trueforge-agent-server-adapter/index.d.ts +552 -12
- package/dist/plugins/trueforge-agent-server-adapter/index.js +506 -188
- package/dist/plugins/trueforge-agent-server-adapter/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +11 -10
- package/dist/DrawerLayout-2JOQ4EDZ.js +0 -159
- package/dist/DrawerLayout-2JOQ4EDZ.js.map +0 -1
- package/dist/OpenUiFenceBlock-3EFPY4JW.js +0 -9
- package/dist/SettingsBuilder-MYWRFXRI.js.map +0 -1
- package/dist/ShellRouteSync-T4WLY57Q.js.map +0 -1
- package/dist/SidebarLayout-6MHQYW45.js +0 -239
- package/dist/SidebarLayout-6MHQYW45.js.map +0 -1
- package/dist/WidgetLayout-4ZIG3RXV.js.map +0 -1
- package/dist/chunk-255AE5NI.js.map +0 -1
- package/dist/chunk-72LC2M3R.js +0 -567
- package/dist/chunk-72LC2M3R.js.map +0 -1
- package/dist/chunk-CFLVPV5M.js.map +0 -1
- package/dist/chunk-FXCYLEFB.js.map +0 -1
- package/dist/chunk-IFLE7OMM.js.map +0 -1
- package/dist/chunk-IWPDSPVA.js +0 -2068
- package/dist/chunk-IWPDSPVA.js.map +0 -1
- package/dist/chunk-OZTNBS6V.js +0 -75
- package/dist/chunk-OZTNBS6V.js.map +0 -1
- package/dist/chunk-PUFYHFND.js +0 -91
- package/dist/chunk-PUFYHFND.js.map +0 -1
- package/dist/chunk-WQULF5AT.js +0 -460
- package/dist/chunk-WQULF5AT.js.map +0 -1
- package/dist/chunk-XRTTKGKN.js +0 -6825
- package/dist/chunk-XRTTKGKN.js.map +0 -1
- package/dist/chunk-YIWUG6MC.js +0 -101
- package/dist/chunk-YIWUG6MC.js.map +0 -1
- /package/dist/{OpenUiFenceBlock-3EFPY4JW.js.map → AgentMetricChart-JPU3MFQ2.js.map} +0 -0
- /package/dist/{chunk-JRRCAKEP.js.map → chunk-MPNSO7E6.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/ServerContext.tsx","../src/utils/sessionShareUrl.ts","../src/server/settingsChrome.ts","../src/server/ShellModeContext.tsx","../src/server/draftSpecPreferences.ts"],"sourcesContent":["'use client';\n\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';\n\nimport type {\n AgentBuilderCapabilitiesResponse,\n AgentMetricsServer,\n AgentSessionsServer,\n AgentUIServer,\n CatalogServer,\n ScheduleServer,\n} from './types.js';\n\nconst ServerContext = createContext<AgentUIServer | null>(null);\nconst ServerCapabilitiesContext = createContext<{\n capabilities: AgentBuilderCapabilitiesResponse['data'] | null;\n refresh: () => void;\n} | null>(null);\n\nexport function ServerProvider({ server, children }: { server: AgentUIServer; children: ReactNode }) {\n const [capabilities, setCapabilities] = useState<AgentBuilderCapabilitiesResponse['data'] | null>(null);\n const cancelActiveRequestRef = useRef<(() => void) | null>(null);\n const refreshCapabilities = useCallback(() => {\n cancelActiveRequestRef.current?.();\n let cancelled = false;\n cancelActiveRequestRef.current = () => {\n cancelled = true;\n };\n void server\n .getCapabilities()\n .then(response => {\n if (!cancelled) setCapabilities(response.data);\n })\n .catch(() => {\n // Preserve the last known capabilities when a refresh fails.\n });\n }, [server]);\n\n useEffect(() => {\n setCapabilities(null);\n refreshCapabilities();\n return () => {\n cancelActiveRequestRef.current?.();\n };\n }, [refreshCapabilities]);\n\n const capabilitiesValue = useMemo(\n () => ({ capabilities, refresh: refreshCapabilities }),\n [capabilities, refreshCapabilities],\n );\n\n return (\n <ServerContext.Provider value={server}>\n <ServerCapabilitiesContext.Provider value={capabilitiesValue}>{children}</ServerCapabilitiesContext.Provider>\n </ServerContext.Provider>\n );\n}\n\nexport function useServer(): AgentUIServer {\n const server = useContext(ServerContext);\n if (server == null) {\n throw new Error('useServer must be used within a ServerProvider.');\n }\n return server;\n}\n\nexport function useOptionalServer(): AgentUIServer | null {\n return useContext(ServerContext);\n}\n\nexport function useServerCapabilities(): AgentBuilderCapabilitiesResponse['data'] | null {\n return useContext(ServerCapabilitiesContext)?.capabilities ?? null;\n}\n\nexport function useOptionalRefreshServerCapabilities(): (() => void) | null {\n return useContext(ServerCapabilitiesContext)?.refresh ?? null;\n}\n\nexport function useCatalogServer(): CatalogServer {\n const server = useServer();\n if (server.catalog == null) {\n throw new Error('useCatalogServer requires AgentUIServer.catalog. Pass catalog to createTrueFoundryServer.');\n }\n return server.catalog;\n}\n\nexport function useOptionalCatalogServer(): CatalogServer | null {\n return useOptionalServer()?.catalog ?? null;\n}\n\nexport function useAgentSessionsServer(): AgentSessionsServer {\n const sessions = useServer().sessions;\n if (sessions == null) {\n throw new Error('useAgentSessionsServer requires AgentUIServer.sessions.');\n }\n return sessions;\n}\n\nexport function useOptionalAgentSessionsServer(): AgentSessionsServer | null {\n return useOptionalServer()?.sessions ?? null;\n}\n\nexport function useAgentMetricsServer(): AgentMetricsServer {\n const metrics = useServer().metrics;\n if (metrics == null) {\n throw new Error('useAgentMetricsServer requires AgentUIServer.metrics.');\n }\n return metrics;\n}\n\nexport function useOptionalAgentMetricsServer(): AgentMetricsServer | null {\n return useOptionalServer()?.metrics ?? null;\n}\n\nexport function useScheduleServer(): ScheduleServer {\n const server = useServer();\n if (server.schedules == null) {\n throw new Error('useScheduleServer requires AgentUIServer.schedules. Pass schedules to createTrueFoundryServer.');\n }\n return server.schedules;\n}\n\nexport function useOptionalScheduleServer(): ScheduleServer | null {\n return useOptionalServer()?.schedules ?? null;\n}\n","export const SESSION_ID_QUERY = 'sessionId';\nexport const AGENT_ID_QUERY = 'agentId';\nexport const AGENT_TAB_QUERY = 'tab';\nexport const SESSIONS_VIEW_QUERY = 'view';\nexport const SESSIONS_VIEW_VALUE = 'sessions';\nexport const SESSION_START_TIME_QUERY = 's_sts';\nexport const SESSION_END_TIME_QUERY = 's_ets';\nexport const SESSION_TIME_WINDOW_QUERY = 's_tw';\nexport const SESSION_TIME_BUFFER_MS = 5 * 60 * 1000;\nexport const SESSION_CUSTOM_RANGE_MAX_DAYS = 70;\nexport const DEFAULT_SESSION_TIME_WINDOW_MS = 30 * 24 * 60 * 60 * 1000;\n\nexport type LibraryAgentTab = 'overview' | 'sessions' | 'code' | 'metrics';\n\nexport type SessionTimeRange = {\n startTs: number;\n endTs: number;\n timeWindowMs?: number;\n};\n\nexport type SessionShareSearch = {\n sessionId: string | null;\n agentId: string | null;\n tab: LibraryAgentTab | null;\n view: typeof SESSIONS_VIEW_VALUE | null;\n timeRange: SessionTimeRange | null;\n};\n\nexport type SessionShareWrite = {\n sessionId?: string | null;\n agentId?: string | null;\n tab?: LibraryAgentTab | null;\n view?: typeof SESSIONS_VIEW_VALUE | null;\n timeRange?: SessionTimeRange | null;\n};\n\nfunction parseLibraryAgentTab(value: string | null): LibraryAgentTab | null {\n if (value === 'overview' || value === 'sessions' || value === 'code' || value === 'metrics') return value;\n return null;\n}\n\nfunction nonEmpty(value: string | null): string | null {\n return value != null && value.length > 0 ? value : null;\n}\n\nfunction parseMs(value: string | null): number | null {\n if (value == null || value.length === 0) return null;\n const parsed = Number(value);\n return Number.isFinite(parsed) ? parsed : null;\n}\n\nexport function defaultSessionTimeRange(now = Date.now()): SessionTimeRange {\n return {\n startTs: now - DEFAULT_SESSION_TIME_WINDOW_MS,\n endTs: now,\n timeWindowMs: DEFAULT_SESSION_TIME_WINDOW_MS,\n };\n}\n\nexport function sessionTimeRangeFromCreatedAt(createdAt: string): SessionTimeRange | null {\n const createdAtMs = new Date(createdAt).getTime();\n if (Number.isNaN(createdAtMs)) return null;\n return {\n startTs: createdAtMs - SESSION_TIME_BUFFER_MS,\n endTs: createdAtMs + SESSION_TIME_BUFFER_MS,\n };\n}\n\nexport function resolveSessionTimeRange(range: SessionTimeRange, now = Date.now()): { startTs: number; endTs: number } {\n if (range.timeWindowMs != null) {\n return { startTs: now - range.timeWindowMs, endTs: now };\n }\n return { startTs: range.startTs, endTs: range.endTs };\n}\n\nexport function readSessionShareSearch(search: string): SessionShareSearch {\n const params = new URLSearchParams(search.startsWith('?') ? search.slice(1) : search);\n const startTs = parseMs(params.get(SESSION_START_TIME_QUERY));\n const endTs = parseMs(params.get(SESSION_END_TIME_QUERY));\n const timeWindowMs = parseMs(params.get(SESSION_TIME_WINDOW_QUERY));\n const view = params.get(SESSIONS_VIEW_QUERY);\n return {\n sessionId: nonEmpty(params.get(SESSION_ID_QUERY)),\n agentId: nonEmpty(params.get(AGENT_ID_QUERY)),\n tab: parseLibraryAgentTab(params.get(AGENT_TAB_QUERY)),\n view: view === SESSIONS_VIEW_VALUE ? SESSIONS_VIEW_VALUE : null,\n timeRange:\n startTs != null && endTs != null\n ? { startTs, endTs }\n : timeWindowMs != null\n ? { startTs: Date.now() - timeWindowMs, endTs: Date.now(), timeWindowMs }\n : null,\n };\n}\n\n/** Library details tab: `tab=` wins; a matching share `sessionId` still opens Sessions. */\nexport function libraryAgentTabFromSearch(share: SessionShareSearch, agentId: string): LibraryAgentTab {\n if (share.tab != null) return share.tab;\n return share.sessionId != null && share.agentId === agentId ? 'sessions' : 'overview';\n}\n\nexport function writeSessionShareSearch(params: URLSearchParams, next: SessionShareWrite): void {\n if (next.sessionId === null) params.delete(SESSION_ID_QUERY);\n else if (next.sessionId != null) params.set(SESSION_ID_QUERY, next.sessionId);\n if (next.agentId === null) params.delete(AGENT_ID_QUERY);\n else if (next.agentId != null) params.set(AGENT_ID_QUERY, next.agentId);\n if (next.tab === null) params.delete(AGENT_TAB_QUERY);\n else if (next.tab != null) params.set(AGENT_TAB_QUERY, next.tab);\n if (next.view === null) params.delete(SESSIONS_VIEW_QUERY);\n else if (next.view != null) params.set(SESSIONS_VIEW_QUERY, next.view);\n if (next.timeRange === null) {\n params.delete(SESSION_START_TIME_QUERY);\n params.delete(SESSION_END_TIME_QUERY);\n params.delete(SESSION_TIME_WINDOW_QUERY);\n } else if (next.timeRange != null) {\n if (next.timeRange.timeWindowMs != null) {\n params.set(SESSION_TIME_WINDOW_QUERY, String(next.timeRange.timeWindowMs));\n params.delete(SESSION_START_TIME_QUERY);\n params.delete(SESSION_END_TIME_QUERY);\n } else {\n params.set(SESSION_START_TIME_QUERY, String(next.timeRange.startTs));\n params.set(SESSION_END_TIME_QUERY, String(next.timeRange.endTs));\n params.delete(SESSION_TIME_WINDOW_QUERY);\n }\n }\n}\n\n/** Share link for a library or global session. Works with or without `withRouter`. */\nexport function buildAgentSessionShareUrl({\n sessionId,\n agentId,\n createdAt,\n view,\n href = typeof window === 'undefined' ? '' : window.location.href,\n}: {\n sessionId: string;\n agentId?: string;\n createdAt?: string;\n view?: typeof SESSIONS_VIEW_VALUE | null;\n href?: string;\n}): string {\n const url = new URL(href);\n writeSessionShareSearch(url.searchParams, {\n sessionId,\n agentId: agentId == null || agentId.length === 0 ? null : agentId,\n ...(view === undefined ? {} : { view }),\n timeRange: createdAt == null ? undefined : sessionTimeRangeFromCreatedAt(createdAt),\n });\n return url.toString();\n}\n\nexport const SESSION_SHARE_CHANGE_EVENT = 'trueforge-session-share';\n\nexport function replaceSessionShareSearch(next: SessionShareWrite): string {\n const url = new URL(window.location.href);\n writeSessionShareSearch(url.searchParams, next);\n window.history.replaceState(window.history.state, '', url);\n window.dispatchEvent(new Event(SESSION_SHARE_CHANGE_EVENT));\n return url.search;\n}\n","import type { CatalogServer } from './types.js';\n\n/**\n * Whether Settings chrome is available: sidebar button and `/settings` route.\n * Matches the gate in {@link ShellActions}.\n */\nexport function isSettingsChromeEnabled({\n catalog,\n capabilities,\n}: {\n catalog: CatalogServer | null | undefined;\n capabilities: { settings?: { enabled?: boolean } } | null | undefined;\n}): boolean {\n return catalog != null && capabilities?.settings?.enabled !== false;\n}\n","'use client';\n\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';\n\nimport { replaceSessionShareSearch } from '../utils/sessionShareUrl.js';\nimport {\n readDraftSpecPreferences,\n selectDraftSpecPreferences,\n withCapabilitiesSandbox,\n writeDraftSpecPreferences,\n type DraftPreferenceKind,\n} from './draftSpecPreferences.js';\nimport {\n useOptionalCatalogServer,\n useOptionalRefreshServerCapabilities,\n useOptionalScheduleServer,\n useServerCapabilities,\n} from './ServerContext.js';\nimport { isSettingsChromeEnabled } from './settingsChrome.js';\nimport type { AgentLibraryEntry, AgentSpec } from './types.js';\n\n/** Host-facing shell configuration for agent / library / composer chrome. */\nexport type AgentConfig =\n | { mode: 'SingleAgent'; name: string }\n | { mode: 'AgentLibrary' }\n | { mode: 'AgentComposer'; defaultAgentSpec?: AgentSpec }\n | { mode: 'AgentLibraryWithComposer'; defaultAgentSpec?: AgentSpec };\n\nexport const DEFAULT_AGENT_CONFIG: AgentConfig = {\n mode: 'AgentLibraryWithComposer',\n};\n\n/**\n * Active chat binding. Mutability (`isMutable`) decides draft vs named runtime.\n * `isCreateAgent` (mutable only) splits New Agent builder chrome from simple New Chat.\n */\nexport type ShellMode =\n | { status: 'idle' }\n | {\n status: 'active';\n isMutable: boolean;\n /**\n * Mutable only: true = Agent builder (config drawer + Save); false = simple chat.\n * Always false when `isMutable` is false (Try / named).\n */\n isCreateAgent: boolean;\n /** Identity for immutable bind + history filter. */\n agentId?: string;\n /** Display / welcome label (often same as agentId). */\n agentName?: string;\n /** Seed for mutable (draft) runtime. */\n agentSpec?: AgentSpec;\n locked: boolean;\n };\n\n/** Library / New Chat / New Agent create intent. */\nexport type SelectLibraryAgentRequest = {\n isMutable: boolean;\n /**\n * Mutable only. When omitted: true if Edit identity is present, else false (New Chat).\n */\n isCreateAgent?: boolean;\n agentId?: string;\n agentName?: string;\n agentSpec?: AgentSpec;\n};\n\nexport type SettingsSection = 'models' | 'connectors' | 'skills' | 'sandbox';\n\ntype ShellModeContextValue = {\n mode: ShellMode;\n /** Host agentConfig mode (capabilities source). */\n agentConfigMode: AgentConfig['mode'];\n /** Agents chrome. */\n isLibraryEnabled: boolean;\n /** Mutable composer / Save Agent chrome (host capability). */\n isComposerEnabled: boolean;\n /** Sidebar / list New Chat control. */\n isNewChatEnabled: boolean;\n settingsOpen: boolean;\n settingsSection: SettingsSection;\n setSettingsOpen: (open: boolean, section?: SettingsSection) => void;\n agentConfigOpen: boolean;\n setAgentConfigOpen: (open: boolean) => void;\n /** Agents main-pane overlay (sidebar layout). */\n libraryOpen: boolean;\n libraryAgentId: string | null;\n setLibraryAgentId: (id: string | null) => void;\n setLibraryOpen: (open: boolean) => void;\n /** All-user sessions browser (includes drafts). */\n sessionsOpen: boolean;\n setSessionsOpen: (open: boolean) => void;\n openLibraryAgent: (agentId: string) => void;\n closeLibraryAgent: () => void;\n schedulesOpen: boolean;\n setSchedulesOpen: (open: boolean) => void;\n /**\n * Bind from Agents (Try = immutable, Edit = mutable + agentSpec).\n * Prefer this over `selectAgent` / `openDraft` when both fields are available.\n */\n selectLibraryAgent: (req: SelectLibraryAgentRequest) => void;\n /**\n * Attach identity + agentSpec to the *current* mutable chat without remounting.\n * Used after `saveAgent` so the same draft session continues as an editable agent.\n */\n bindMutableAgent: (req: { agentId: string; agentName: string; agentSpec: AgentSpec }) => void;\n /** @deprecated Prefer `selectLibraryAgent({ isMutable: false, agentName })`. */\n selectAgent: (agentName: string) => void;\n /** Open a simple New Chat (mutable, no agent-builder chrome). */\n openDraft: () => void;\n /** Open New Agent builder (mutable + Agent Config drawer). */\n openAgentBuilder: () => void;\n /** Remember plain-draft composer choices as the seed for future New Chat / New Agent. */\n rememberDraftSpec: (agentSpec: AgentSpec, kind?: DraftPreferenceKind) => void;\n /**\n * Open a history session, remounting when mutability/identity changes.\n * Prefer explicit `isMutable` from the session row; when omitted, agentName\n * present → immutable and agentName absent → mutable. Immutable rows may omit\n * `agentName` when the registry agent was deleted.\n * `isCreateAgent` is only applied when mutable (default false when omitted).\n */\n openHistorySession: (req: {\n sessionId: string;\n agentName?: string;\n isMutable?: boolean;\n isCreateAgent?: boolean;\n }) => void;\n /** Reset current chat; no-op when idle. */\n clearChat: () => void;\n /** Return library-only mode to its idle landing; no-op in other modes. */\n openLibraryHome: () => void;\n /** Remount key for the chat runtime when binding changes. */\n runtimeKey: string;\n /**\n * History list filter forwarded as `listSessions({ agentId })`.\n * `null` = All chats. Only meaningful when `isLibraryEnabled`.\n */\n historyAgentFilter: string | null;\n setHistoryAgentFilter: (agentId: string | null) => void;\n /** Effective `listSessionsAgentId` for the runtime (SingleAgent locks to name). */\n listSessionsAgentId: string | undefined;\n /** Session to open after a binding remount (history click across mutability). */\n pendingSessionId: string | undefined;\n /**\n * Bumped when the Agents catalog may have changed (e.g. after saveAgent).\n * Library chrome should re-fetch when this changes.\n */\n agentsListEpoch: number;\n invalidateAgentsList: () => void;\n};\n\nconst ShellModeContext = createContext<ShellModeContextValue | null>(null);\n\nconst FALLBACK_MUTABLE_SPEC: AgentSpec = {\n model: { name: 'openai-main/gpt-4.1' },\n};\n\nfunction mutableSeedFromConfig(config: AgentConfig): AgentSpec {\n if (config.mode === 'AgentComposer' || config.mode === 'AgentLibraryWithComposer') {\n return config.defaultAgentSpec ?? FALLBACK_MUTABLE_SPEC;\n }\n return FALLBACK_MUTABLE_SPEC;\n}\n\nfunction initialMode(config: AgentConfig, mutableSeed: AgentSpec): ShellMode {\n switch (config.mode) {\n case 'SingleAgent':\n return {\n status: 'active',\n isMutable: false,\n isCreateAgent: false,\n agentId: config.name,\n agentName: config.name,\n locked: true,\n };\n case 'AgentLibrary':\n return { status: 'idle' };\n case 'AgentComposer':\n case 'AgentLibraryWithComposer':\n return {\n status: 'active',\n isMutable: true,\n isCreateAgent: false,\n agentSpec: mutableSeed,\n locked: false,\n };\n }\n}\n\nfunction resolveMutableIsCreateAgent(req: SelectLibraryAgentRequest): boolean {\n if (req.isCreateAgent !== undefined) return req.isCreateAgent;\n return req.agentId != null || req.agentName != null;\n}\n\nfunction libraryAgentId(agent: Pick<AgentLibraryEntry, 'agentId' | 'name'>): string {\n return agent.agentId ?? agent.name;\n}\n\nexport function ShellModeProvider({\n agentConfig = DEFAULT_AGENT_CONFIG,\n initialSettingsOpen = false,\n children,\n}: {\n agentConfig?: AgentConfig;\n /** Open settings on first paint (e.g. host boot with no models). Does not re-open later. */\n initialSettingsOpen?: boolean;\n children: ReactNode;\n}) {\n const capabilities = useServerCapabilities();\n const catalog = useOptionalCatalogServer();\n const refreshCapabilities = useOptionalRefreshServerCapabilities();\n const scheduleServer = useOptionalScheduleServer();\n const chatSeedRef = useRef(\n readDraftSpecPreferences('chat') ?? selectDraftSpecPreferences(mutableSeedFromConfig(agentConfig), 'chat'),\n );\n const agentSeedRef = useRef(\n readDraftSpecPreferences('agent') ?? selectDraftSpecPreferences(mutableSeedFromConfig(agentConfig), 'agent'),\n );\n\n const isLibraryEnabled = agentConfig.mode === 'AgentLibrary' || agentConfig.mode === 'AgentLibraryWithComposer';\n const isComposerEnabled = agentConfig.mode === 'AgentComposer' || agentConfig.mode === 'AgentLibraryWithComposer';\n const isNewChatEnabled = agentConfig.mode !== 'AgentLibrary';\n const locked = agentConfig.mode === 'SingleAgent';\n\n const [mode, setMode] = useState<ShellMode>(() => initialMode(agentConfig, chatSeedRef.current));\n const [mutableEpoch, setMutableEpoch] = useState(0);\n const [clearEpoch, setClearEpoch] = useState(0);\n const [agentsListEpoch, setAgentsListEpoch] = useState(0);\n const [settingsOpenState, setSettingsOpenState] = useState(initialSettingsOpen);\n const [settingsSection, setSettingsSection] = useState<SettingsSection>('models');\n const [agentConfigOpenState, setAgentConfigOpenState] = useState(false);\n const [libraryOpenState, setLibraryOpenState] = useState(false);\n const [sessionsOpenState, setSessionsOpenState] = useState(false);\n const [libraryAgentId, setLibraryAgentId] = useState<string | null>(null);\n const [schedulesOpenState, setSchedulesOpenState] = useState(false);\n const [historyAgentFilter, setHistoryAgentFilter] = useState<string | null>(null);\n const [pendingSessionId, setPendingSessionId] = useState<string | undefined>(undefined);\n const settingsEnabled = isSettingsChromeEnabled({ catalog, capabilities });\n const settingsOpen = settingsEnabled && settingsOpenState;\n const schedulesEnabled = scheduleServer != null;\n const schedulesOpen = schedulesEnabled && schedulesOpenState;\n const libraryOpen = isLibraryEnabled && libraryOpenState;\n const sessionsOpen = sessionsOpenState;\n const setSessionsOpen = useCallback((open: boolean) => {\n if (open) {\n setSettingsOpenState(false);\n setAgentConfigOpenState(false);\n setLibraryOpenState(false);\n setLibraryAgentId(null);\n setSchedulesOpenState(false);\n } else {\n replaceSessionShareSearch({ view: null });\n }\n setSessionsOpenState(open);\n }, []);\n const setLibraryOpen = useCallback(\n (open: boolean) => {\n if (!isLibraryEnabled) return;\n if (open) {\n setSettingsOpenState(false);\n setAgentConfigOpenState(false);\n setSessionsOpen(false);\n setSchedulesOpenState(false);\n }\n setLibraryAgentId(null);\n setLibraryOpenState(open);\n },\n [isLibraryEnabled, setSessionsOpen],\n );\n const openLibraryAgent = useCallback(\n (agentId: string) => {\n if (!isLibraryEnabled) return;\n setSettingsOpenState(false);\n setAgentConfigOpenState(false);\n setSessionsOpen(false);\n setSchedulesOpenState(false);\n setLibraryOpenState(true);\n setLibraryAgentId(agentId);\n },\n [isLibraryEnabled, setSessionsOpen],\n );\n const closeLibraryAgent = useCallback(() => {\n setLibraryAgentId(null);\n }, []);\n const setSettingsOpen = useCallback(\n (open: boolean, section?: SettingsSection) => {\n if (section !== undefined) {\n setSettingsSection(section);\n }\n if (open) {\n setAgentConfigOpenState(false);\n setLibraryOpenState(false);\n setLibraryAgentId(null);\n setSessionsOpen(false);\n setSchedulesOpenState(false);\n }\n setSettingsOpenState(settingsEnabled && open);\n },\n [setSessionsOpen, settingsEnabled],\n );\n const setAgentConfigOpen = useCallback(\n (open: boolean) => {\n if (open) {\n setSettingsOpenState(false);\n setLibraryOpenState(false);\n setLibraryAgentId(null);\n setSessionsOpen(false);\n setSchedulesOpenState(false);\n }\n setAgentConfigOpenState(open);\n },\n [setSessionsOpen],\n );\n const setSchedulesOpen = useCallback(\n (open: boolean) => {\n if (open) {\n setSettingsOpenState(false);\n setAgentConfigOpenState(false);\n setLibraryOpenState(false);\n setLibraryAgentId(null);\n setSessionsOpen(false);\n }\n setSchedulesOpenState(schedulesEnabled && open);\n },\n [schedulesEnabled, setSessionsOpen],\n );\n\n useEffect(() => {\n if (!settingsEnabled) {\n setSettingsOpenState(false);\n }\n }, [settingsEnabled]);\n\n useEffect(() => {\n if (!schedulesEnabled) {\n setSchedulesOpenState(false);\n }\n }, [schedulesEnabled]);\n\n const invalidateAgentsList = useCallback(() => {\n setAgentsListEpoch(n => n + 1);\n }, []);\n\n const lockedAgentName = agentConfig.mode === 'SingleAgent' ? agentConfig.name : '';\n const effectiveMode: ShellMode = useMemo(() => {\n if (!locked) return mode;\n return {\n status: 'active',\n isMutable: false,\n isCreateAgent: false,\n agentId: lockedAgentName,\n agentName: lockedAgentName,\n locked: true,\n };\n }, [locked, lockedAgentName, mode]);\n const agentConfigOpen =\n effectiveMode.status === 'active' && effectiveMode.isMutable && effectiveMode.isCreateAgent && agentConfigOpenState;\n\n useEffect(() => {\n if (effectiveMode.status !== 'active' || !effectiveMode.isMutable || !effectiveMode.isCreateAgent) {\n setAgentConfigOpenState(false);\n }\n }, [effectiveMode]);\n\n const listSessionsAgentId = useMemo(() => {\n if (locked) return lockedAgentName;\n if (!isLibraryEnabled) return undefined;\n return historyAgentFilter ?? undefined;\n }, [locked, lockedAgentName, isLibraryEnabled, historyAgentFilter]);\n\n const bumpEpoch = useCallback((isMutable: boolean) => {\n if (isMutable) setMutableEpoch(n => n + 1);\n else setClearEpoch(n => n + 1);\n }, []);\n\n const selectLibraryAgent = useCallback(\n (req: SelectLibraryAgentRequest) => {\n if (req.isMutable) {\n if (!isComposerEnabled) return;\n setSettingsOpen(false);\n setLibraryOpenState(false);\n setLibraryAgentId(null);\n setSessionsOpen(false);\n setSchedulesOpen(false);\n setPendingSessionId(undefined);\n const isCreateAgent = resolveMutableIsCreateAgent(req);\n const kind: DraftPreferenceKind = isCreateAgent ? 'agent' : 'chat';\n setMode({\n status: 'active',\n isMutable: true,\n isCreateAgent,\n agentId: req.agentId,\n agentName: req.agentName,\n agentSpec: req.agentSpec ?? (kind === 'agent' ? agentSeedRef.current : chatSeedRef.current),\n locked: false,\n });\n setAgentConfigOpenState(isCreateAgent);\n bumpEpoch(true);\n return;\n }\n if (!isLibraryEnabled) return;\n const agentName = req.agentName ?? req.agentId;\n if (agentName == null) return;\n setSettingsOpen(false);\n setLibraryOpenState(false);\n setLibraryAgentId(null);\n setSessionsOpen(false);\n setSchedulesOpen(false);\n setPendingSessionId(undefined);\n setAgentConfigOpenState(false);\n setMode({\n status: 'active',\n isMutable: false,\n isCreateAgent: false,\n agentId: req.agentId ?? agentName,\n agentName,\n locked: false,\n });\n bumpEpoch(false);\n },\n [isComposerEnabled, isLibraryEnabled, bumpEpoch, setSettingsOpen, setSessionsOpen, setSchedulesOpen],\n );\n\n const bindMutableAgent = useCallback(\n (req: { agentId: string; agentName: string; agentSpec: AgentSpec }) => {\n if (!isComposerEnabled) return;\n setMode(prev => {\n if (prev.status !== 'active' || !prev.isMutable) return prev;\n return {\n status: 'active',\n isMutable: true,\n isCreateAgent: true,\n agentId: req.agentId,\n agentName: req.agentName,\n agentSpec: req.agentSpec,\n locked: false,\n };\n });\n },\n [isComposerEnabled],\n );\n\n const selectAgent = useCallback(\n (name: string) => {\n selectLibraryAgent({ isMutable: false, agentId: name, agentName: name });\n },\n [selectLibraryAgent],\n );\n\n const openDraft = useCallback(() => {\n if (!isComposerEnabled) return;\n refreshCapabilities?.();\n selectLibraryAgent({ isMutable: true, isCreateAgent: false, agentSpec: chatSeedRef.current });\n }, [isComposerEnabled, refreshCapabilities, selectLibraryAgent]);\n\n const openAgentBuilder = useCallback(() => {\n if (!isComposerEnabled) return;\n refreshCapabilities?.();\n selectLibraryAgent({ isMutable: true, isCreateAgent: true, agentSpec: agentSeedRef.current });\n }, [isComposerEnabled, refreshCapabilities, selectLibraryAgent]);\n\n const sandboxEnabled = capabilities?.sandbox.enabled;\n const rememberDraftSpec = useCallback(\n (agentSpec: AgentSpec, kind: DraftPreferenceKind = 'chat') => {\n const selected = selectDraftSpecPreferences(agentSpec, kind);\n const preferences = kind === 'agent' ? withCapabilitiesSandbox(selected, sandboxEnabled) : selected;\n if (kind === 'chat') {\n chatSeedRef.current = preferences;\n } else {\n agentSeedRef.current = preferences;\n }\n writeDraftSpecPreferences(kind, preferences);\n },\n [sandboxEnabled],\n );\n\n const openHistorySession = useCallback(\n ({\n sessionId,\n agentName,\n isMutable: isMutableOpt,\n isCreateAgent: isCreateAgentOpt,\n }: {\n sessionId: string;\n agentName?: string;\n isMutable?: boolean;\n isCreateAgent?: boolean;\n }) => {\n setSettingsOpen(false);\n setLibraryOpenState(false);\n setLibraryAgentId(null);\n setSessionsOpen(false);\n setSchedulesOpen(false);\n setPendingSessionId(sessionId);\n const isMutable = isMutableOpt ?? agentName == null;\n if (isMutable) {\n if (!isComposerEnabled) return;\n const isCreateAgent = isCreateAgentOpt === true;\n setMode({\n status: 'active',\n isMutable: true,\n isCreateAgent,\n agentSpec: isCreateAgent ? agentSeedRef.current : chatSeedRef.current,\n locked: false,\n });\n setAgentConfigOpenState(isCreateAgent);\n bumpEpoch(true);\n return;\n }\n // Immutable: allow orphaned refs (deleted agent → no agentName).\n if (locked) {\n if (agentName == null || lockedAgentName !== agentName) return;\n } else if (!isLibraryEnabled) {\n return;\n }\n setAgentConfigOpenState(false);\n setMode({\n status: 'active',\n isMutable: false,\n isCreateAgent: false,\n locked: false,\n ...(agentName != null ? { agentId: agentName, agentName } : {}),\n });\n bumpEpoch(false);\n },\n [\n isLibraryEnabled,\n isComposerEnabled,\n locked,\n lockedAgentName,\n bumpEpoch,\n setSettingsOpen,\n setSessionsOpen,\n setSchedulesOpen,\n ],\n );\n\n const clearChat = useCallback(() => {\n if (effectiveMode.status === 'idle') return;\n setPendingSessionId(undefined);\n if (effectiveMode.isMutable) {\n // Preserve Edit / builder vs chat intent; blank drafts fall back to host seed.\n const kind: DraftPreferenceKind = effectiveMode.isCreateAgent ? 'agent' : 'chat';\n setMode({\n status: 'active',\n isMutable: true,\n isCreateAgent: effectiveMode.isCreateAgent,\n agentId: effectiveMode.agentId,\n agentName: effectiveMode.agentName,\n agentSpec: effectiveMode.agentSpec ?? (kind === 'agent' ? agentSeedRef.current : chatSeedRef.current),\n locked: false,\n });\n setAgentConfigOpenState(effectiveMode.isCreateAgent);\n bumpEpoch(true);\n return;\n }\n bumpEpoch(false);\n }, [effectiveMode, bumpEpoch]);\n\n const openLibraryHome = useCallback(() => {\n // Only library-only mode has an idle landing; other modes root via openDraft / clearChat.\n if (!isLibraryEnabled || isComposerEnabled) return;\n setPendingSessionId(undefined);\n setSettingsOpen(false);\n setLibraryOpenState(false);\n setLibraryAgentId(null);\n setSchedulesOpen(false);\n setMode({ status: 'idle' });\n bumpEpoch(false);\n }, [isLibraryEnabled, isComposerEnabled, setSettingsOpen, setSchedulesOpen, bumpEpoch]);\n\n // Mutable remounts are driven only by mutableEpoch (library Edit / New Chat / Clear).\n // Agent id and model must not be in the key — saveAgent binds those onto the same draft.\n const runtimeKey = useMemo(() => {\n if (effectiveMode.status === 'idle') return 'idle';\n if (effectiveMode.isMutable) {\n return `mut:${pendingSessionId ?? ''}:${mutableEpoch}`;\n }\n const id = effectiveMode.agentId ?? effectiveMode.agentName ?? '';\n return `immut:${id}:${pendingSessionId ?? ''}:${clearEpoch}`;\n }, [effectiveMode, mutableEpoch, clearEpoch, pendingSessionId]);\n\n const value = useMemo<ShellModeContextValue>(\n () => ({\n mode: effectiveMode,\n agentConfigMode: agentConfig.mode,\n isLibraryEnabled,\n isComposerEnabled,\n isNewChatEnabled,\n settingsOpen,\n settingsSection,\n setSettingsOpen,\n agentConfigOpen,\n setAgentConfigOpen,\n libraryOpen,\n libraryAgentId,\n setLibraryAgentId,\n setLibraryOpen,\n sessionsOpen,\n setSessionsOpen,\n openLibraryAgent,\n closeLibraryAgent,\n schedulesOpen,\n setSchedulesOpen,\n selectLibraryAgent,\n bindMutableAgent,\n selectAgent,\n openDraft,\n openAgentBuilder,\n rememberDraftSpec,\n openHistorySession,\n clearChat,\n openLibraryHome,\n runtimeKey,\n historyAgentFilter,\n setHistoryAgentFilter,\n listSessionsAgentId,\n pendingSessionId,\n agentsListEpoch,\n invalidateAgentsList,\n }),\n [\n effectiveMode,\n agentConfig.mode,\n isLibraryEnabled,\n isComposerEnabled,\n isNewChatEnabled,\n settingsOpen,\n settingsSection,\n setSettingsOpen,\n agentConfigOpen,\n setAgentConfigOpen,\n libraryOpen,\n libraryAgentId,\n setLibraryOpen,\n sessionsOpen,\n setSessionsOpen,\n openLibraryAgent,\n closeLibraryAgent,\n schedulesOpen,\n setSchedulesOpen,\n selectLibraryAgent,\n bindMutableAgent,\n selectAgent,\n openDraft,\n openAgentBuilder,\n rememberDraftSpec,\n openHistorySession,\n clearChat,\n openLibraryHome,\n runtimeKey,\n historyAgentFilter,\n listSessionsAgentId,\n pendingSessionId,\n agentsListEpoch,\n invalidateAgentsList,\n ],\n );\n\n return <ShellModeContext.Provider value={value}>{children}</ShellModeContext.Provider>;\n}\n\nexport function useShellMode(): ShellModeContextValue {\n const ctx = useContext(ShellModeContext);\n if (ctx == null) {\n throw new Error('useShellMode must be used within a ShellModeProvider.');\n }\n return ctx;\n}\n\nexport function useOptionalShellMode(): ShellModeContextValue | null {\n return useContext(ShellModeContext);\n}\n\n/** True when the shell is bound to a mutable (editable) agentSpec. */\nexport function shellIsMutable(mode: ShellMode): boolean {\n return mode.status === 'active' && mode.isMutable;\n}\n\n/** True when the shell is in New Agent / Edit builder chrome. */\nexport function shellIsCreateAgent(mode: ShellMode): boolean {\n return mode.status === 'active' && mode.isMutable && mode.isCreateAgent;\n}\n\nexport { libraryAgentId };\n","import type { AgentSpec } from './types.js';\n\n/** @deprecated Migrated into chat/agent keys on first read. */\nexport const DRAFT_SPEC_PREFERENCES_STORAGE_KEY = 'tfy-aui-draft-spec-preferences';\nexport const CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY = 'tfy-aui-chat-draft-spec-preferences';\nexport const AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY = 'tfy-aui-agent-draft-spec-preferences';\n\nexport type DraftPreferenceKind = 'chat' | 'agent';\n\ntype StoredDraftSpecPreferences = {\n version: 1;\n spec: AgentSpec;\n};\n\nfunction isObject(value: unknown): value is object {\n return typeof value === 'object' && value !== null;\n}\n\nfunction isMountList(value: unknown): boolean {\n return Array.isArray(value) && value.every(isObject);\n}\n\nfunction isAgentSpec(value: unknown): value is AgentSpec {\n if (!isObject(value)) return false;\n const model = Reflect.get(value, 'model');\n if (!isObject(model) || typeof Reflect.get(model, 'name') !== 'string') return false;\n\n const params = Reflect.get(model, 'params');\n if (params !== undefined && !isObject(params)) return false;\n\n const skills = Reflect.get(value, 'skills');\n if (skills !== undefined && !isMountList(skills)) return false;\n\n const mcpServers = Reflect.get(value, 'mcpServers');\n if (mcpServers !== undefined && !isMountList(mcpServers)) return false;\n\n const config = Reflect.get(value, 'config');\n return config === undefined || isObject(config);\n}\n\nfunction isStoredDraftSpecPreferences(value: unknown): value is StoredDraftSpecPreferences {\n return isObject(value) && Reflect.get(value, 'version') === 1 && isAgentSpec(Reflect.get(value, 'spec'));\n}\n\nfunction storageKeyForKind(kind: DraftPreferenceKind): string {\n return kind === 'chat' ? CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY : AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY;\n}\n\n/** New Chat: model (+ reasoning params), skills, and MCP only — no runtime config. */\nexport function selectChatDraftSpecPreferences(spec: AgentSpec): AgentSpec {\n return {\n model: spec.model,\n ...(spec.skills !== undefined ? { skills: spec.skills } : {}),\n ...(spec.mcpServers !== undefined ? { mcpServers: spec.mcpServers } : {}),\n };\n}\n\n/** New Agent: full composer seed including runtime config (sandbox, ask-user, …). */\nexport function selectAgentDraftSpecPreferences(spec: AgentSpec): AgentSpec {\n return {\n ...selectChatDraftSpecPreferences(spec),\n ...(spec.config !== undefined ? { config: spec.config } : {}),\n };\n}\n\nexport function selectDraftSpecPreferences(spec: AgentSpec, kind: DraftPreferenceKind): AgentSpec {\n return kind === 'chat' ? selectChatDraftSpecPreferences(spec) : selectAgentDraftSpecPreferences(spec);\n}\n\nfunction readSandboxEnabled(spec: AgentSpec): boolean | undefined {\n if (spec.config === undefined) return undefined;\n // `sandbox` is persisted on draft config but is not part of AgentRuntimeConfig.\n const sandbox = Reflect.get(spec.config, 'sandbox');\n if (!isObject(sandbox)) return undefined;\n const enabled = Reflect.get(sandbox, 'enabled');\n return typeof enabled === 'boolean' ? enabled : undefined;\n}\n\n/** Disable sandbox when unavailable; availability must not override the user's runtime choice. */\nexport function withCapabilitiesSandbox(spec: AgentSpec, sandboxEnabled: boolean | null | undefined): AgentSpec {\n if (sandboxEnabled !== false || readSandboxEnabled(spec) === false) return spec;\n const config = {\n ...spec.config,\n sandbox: { ...spec.config?.sandbox, enabled: false },\n };\n return {\n ...spec,\n config,\n };\n}\n\nfunction readStoredSpec(key: string): AgentSpec | null {\n if (typeof window === 'undefined') return null;\n try {\n const stored: unknown = JSON.parse(window.localStorage.getItem(key) ?? 'null');\n return isStoredDraftSpecPreferences(stored) ? stored.spec : null;\n } catch {\n return null;\n }\n}\n\nfunction writeStoredSpec(key: string, spec: AgentSpec): boolean {\n if (typeof window === 'undefined') return false;\n try {\n const stored: StoredDraftSpecPreferences = { version: 1, spec };\n window.localStorage.setItem(key, JSON.stringify(stored));\n return true;\n } catch {\n // Storage can be unavailable or full; in-memory carry-over still works.\n return false;\n }\n}\n\n/** One-shot split of the pre-split shared key into chat + agent stores. */\nfunction migrateLegacyDraftPreferences(): void {\n if (typeof window === 'undefined') return;\n const legacy = readStoredSpec(DRAFT_SPEC_PREFERENCES_STORAGE_KEY);\n if (legacy == null) return;\n\n const chatReady =\n readStoredSpec(CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY) != null ||\n writeStoredSpec(CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY, selectChatDraftSpecPreferences(legacy));\n const agentReady =\n readStoredSpec(AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY) != null ||\n writeStoredSpec(AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY, selectAgentDraftSpecPreferences(legacy));\n\n // Keep the legacy key if either destination write failed so a later read can retry.\n if (!chatReady || !agentReady) return;\n\n try {\n window.localStorage.removeItem(DRAFT_SPEC_PREFERENCES_STORAGE_KEY);\n } catch {\n // Ignore quota / private-mode failures; next read still prefers kind keys.\n }\n}\n\nexport function readDraftSpecPreferences(kind: DraftPreferenceKind): AgentSpec | null {\n migrateLegacyDraftPreferences();\n const stored = readStoredSpec(storageKeyForKind(kind));\n return stored == null ? null : selectDraftSpecPreferences(stored, kind);\n}\n\nexport function writeDraftSpecPreferences(kind: DraftPreferenceKind, spec: AgentSpec): void {\n writeStoredSpec(storageKeyForKind(kind), selectDraftSpecPreferences(spec, kind));\n}\n"],"mappings":";AAEA,SAAS,eAAe,aAAa,YAAY,WAAW,SAAS,QAAQ,gBAAgC;AAmDvG;AAxCN,IAAM,gBAAgB,cAAoC,IAAI;AAC9D,IAAM,4BAA4B,cAGxB,IAAI;AAEP,SAAS,eAAe,EAAE,QAAQ,SAAS,GAAmD;AACnG,QAAM,CAAC,cAAc,eAAe,IAAI,SAA0D,IAAI;AACtG,QAAM,yBAAyB,OAA4B,IAAI;AAC/D,QAAM,sBAAsB,YAAY,MAAM;AAC5C,2BAAuB,UAAU;AACjC,QAAI,YAAY;AAChB,2BAAuB,UAAU,MAAM;AACrC,kBAAY;AAAA,IACd;AACA,SAAK,OACF,gBAAgB,EAChB,KAAK,cAAY;AAChB,UAAI,CAAC,UAAW,iBAAgB,SAAS,IAAI;AAAA,IAC/C,CAAC,EACA,MAAM,MAAM;AAAA,IAEb,CAAC;AAAA,EACL,GAAG,CAAC,MAAM,CAAC;AAEX,YAAU,MAAM;AACd,oBAAgB,IAAI;AACpB,wBAAoB;AACpB,WAAO,MAAM;AACX,6BAAuB,UAAU;AAAA,IACnC;AAAA,EACF,GAAG,CAAC,mBAAmB,CAAC;AAExB,QAAM,oBAAoB;AAAA,IACxB,OAAO,EAAE,cAAc,SAAS,oBAAoB;AAAA,IACpD,CAAC,cAAc,mBAAmB;AAAA,EACpC;AAEA,SACE,oBAAC,cAAc,UAAd,EAAuB,OAAO,QAC7B,8BAAC,0BAA0B,UAA1B,EAAmC,OAAO,mBAAoB,UAAS,GAC1E;AAEJ;AAEO,SAAS,YAA2B;AACzC,QAAM,SAAS,WAAW,aAAa;AACvC,MAAI,UAAU,MAAM;AAClB,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACnE;AAC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,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,gBAAAJ,KAAC,iBAAiB,UAAjB,EAA0B,OAAe,UAAS;AAC5D;AAEO,SAAS,eAAsC;AACpD,QAAM,MAAMQ,YAAW,gBAAgB;AACvC,MAAI,OAAO,MAAM;AACf,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AACA,SAAO;AACT;AAEO,SAAS,uBAAqD;AACnE,SAAOA,YAAW,gBAAgB;AACpC;AAGO,SAAS,eAAe,MAA0B;AACvD,SAAO,KAAK,WAAW,YAAY,KAAK;AAC1C;AAGO,SAAS,mBAAmB,MAA0B;AAC3D,SAAO,KAAK,WAAW,YAAY,KAAK,aAAa,KAAK;AAC5D;","names":["createContext","useCallback","useContext","useEffect","useMemo","useRef","useState","jsx","createContext","useRef","useState","libraryAgentId","useCallback","useEffect","useMemo","useContext"]}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearScheduleShareSearch
|
|
3
|
+
} from "./chunk-2XPPBEYF.js";
|
|
4
|
+
import {
|
|
5
|
+
readSessionShareSearch,
|
|
6
|
+
writeSessionShareSearch
|
|
7
|
+
} from "./chunk-U7KURWW3.js";
|
|
8
|
+
|
|
9
|
+
// src/routing/paths.ts
|
|
10
|
+
var DEFAULTS = {
|
|
11
|
+
root: "/",
|
|
12
|
+
settings: "/settings",
|
|
13
|
+
library: "/library",
|
|
14
|
+
libraryAgent: "/library/:agentId",
|
|
15
|
+
schedules: "/schedules",
|
|
16
|
+
agent: "/agents/:agentName",
|
|
17
|
+
session: "/sessions/:sessionId",
|
|
18
|
+
sessionsBrowser: "/sessions"
|
|
19
|
+
};
|
|
20
|
+
function normalizePath(path) {
|
|
21
|
+
const trimmed = path.trim();
|
|
22
|
+
const withLead = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
23
|
+
return withLead.length > 1 && withLead.endsWith("/") ? withLead.slice(0, -1) : withLead;
|
|
24
|
+
}
|
|
25
|
+
function resolveOptional(value, fallback) {
|
|
26
|
+
if (value === false) return null;
|
|
27
|
+
return normalizePath(value ?? fallback);
|
|
28
|
+
}
|
|
29
|
+
function resolveRoutesConfig(routes) {
|
|
30
|
+
const paths = routes?.paths;
|
|
31
|
+
return {
|
|
32
|
+
basename: routes?.basename ?? "",
|
|
33
|
+
root: normalizePath(paths?.root ?? DEFAULTS.root),
|
|
34
|
+
settings: resolveOptional(paths?.settings, DEFAULTS.settings),
|
|
35
|
+
library: resolveOptional(paths?.library, DEFAULTS.library),
|
|
36
|
+
libraryAgent: resolveOptional(paths?.libraryAgent, DEFAULTS.libraryAgent),
|
|
37
|
+
schedules: resolveOptional(paths?.schedules, DEFAULTS.schedules),
|
|
38
|
+
agent: resolveOptional(paths?.agent, DEFAULTS.agent),
|
|
39
|
+
session: resolveOptional(paths?.session, DEFAULTS.session),
|
|
40
|
+
sessionsBrowser: resolveOptional(paths?.sessionsBrowser, DEFAULTS.sessionsBrowser)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function splitSegments(path) {
|
|
44
|
+
return path.split("/").filter((segment) => segment.length > 0);
|
|
45
|
+
}
|
|
46
|
+
function fillTemplate(template, value) {
|
|
47
|
+
return "/" + splitSegments(template).map((segment) => segment.startsWith(":") ? encodeURIComponent(value) : segment).join("/");
|
|
48
|
+
}
|
|
49
|
+
function buildPath(place, routes) {
|
|
50
|
+
switch (place.type) {
|
|
51
|
+
case "root":
|
|
52
|
+
return routes.root;
|
|
53
|
+
case "settings":
|
|
54
|
+
return routes.settings;
|
|
55
|
+
case "library":
|
|
56
|
+
return routes.library;
|
|
57
|
+
case "libraryAgent":
|
|
58
|
+
return routes.libraryAgent == null ? null : fillTemplate(routes.libraryAgent, place.agentId);
|
|
59
|
+
case "schedules":
|
|
60
|
+
return routes.schedules;
|
|
61
|
+
case "agent":
|
|
62
|
+
return routes.agent == null ? null : fillTemplate(routes.agent, place.agentName);
|
|
63
|
+
case "session":
|
|
64
|
+
return routes.session == null ? null : fillTemplate(routes.session, place.sessionId);
|
|
65
|
+
case "sessionsBrowser":
|
|
66
|
+
return routes.sessionsBrowser;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function buildSessionResumeHref({
|
|
70
|
+
sessionId,
|
|
71
|
+
routes,
|
|
72
|
+
href = typeof window === "undefined" ? "http://localhost/" : window.location.href
|
|
73
|
+
}) {
|
|
74
|
+
const sessionPath = buildPath({ type: "session", sessionId }, routes);
|
|
75
|
+
if (sessionPath == null) return null;
|
|
76
|
+
const url = new URL(href);
|
|
77
|
+
const basename = routes.basename.endsWith("/") ? routes.basename.slice(0, -1) : routes.basename;
|
|
78
|
+
url.pathname = `${basename}${sessionPath}` || "/";
|
|
79
|
+
url.search = sanitizeSearchForPlace({ type: "session", sessionId }, url.search);
|
|
80
|
+
url.hash = "";
|
|
81
|
+
return url.toString();
|
|
82
|
+
}
|
|
83
|
+
function sanitizeSearchForPlace(place, search) {
|
|
84
|
+
if (place.type === "settings") return search;
|
|
85
|
+
const params = new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
|
|
86
|
+
if (place.type === "sessionsBrowser") {
|
|
87
|
+
writeSessionShareSearch(params, { tab: null });
|
|
88
|
+
clearScheduleShareSearch(params);
|
|
89
|
+
} else if (place.type === "libraryAgent") {
|
|
90
|
+
const share = readSessionShareSearch(search);
|
|
91
|
+
writeSessionShareSearch(params, {
|
|
92
|
+
view: null,
|
|
93
|
+
timeRange: null,
|
|
94
|
+
...share.sessionId != null && share.agentId !== place.agentId ? { sessionId: null, agentId: null } : {}
|
|
95
|
+
});
|
|
96
|
+
clearScheduleShareSearch(params);
|
|
97
|
+
} else if (place.type === "schedules") {
|
|
98
|
+
writeSessionShareSearch(params, {
|
|
99
|
+
sessionId: null,
|
|
100
|
+
agentId: null,
|
|
101
|
+
tab: null,
|
|
102
|
+
view: null,
|
|
103
|
+
timeRange: null
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
writeSessionShareSearch(params, {
|
|
107
|
+
sessionId: null,
|
|
108
|
+
agentId: null,
|
|
109
|
+
tab: null,
|
|
110
|
+
view: null,
|
|
111
|
+
timeRange: null
|
|
112
|
+
});
|
|
113
|
+
clearScheduleShareSearch(params);
|
|
114
|
+
}
|
|
115
|
+
const next = params.toString();
|
|
116
|
+
return next.length > 0 ? `?${next}` : "";
|
|
117
|
+
}
|
|
118
|
+
function decodeSegment(segment) {
|
|
119
|
+
try {
|
|
120
|
+
return decodeURIComponent(segment);
|
|
121
|
+
} catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function matchTemplate(template, segments) {
|
|
126
|
+
const templateSegments = splitSegments(template);
|
|
127
|
+
if (templateSegments.length !== segments.length) return null;
|
|
128
|
+
let param = null;
|
|
129
|
+
for (const [i, tpl] of templateSegments.entries()) {
|
|
130
|
+
const seg = segments[i];
|
|
131
|
+
if (seg === void 0) return null;
|
|
132
|
+
if (tpl.startsWith(":")) {
|
|
133
|
+
const decoded = decodeSegment(seg);
|
|
134
|
+
if (decoded == null) return null;
|
|
135
|
+
param = decoded;
|
|
136
|
+
} else if (tpl !== seg) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return param;
|
|
141
|
+
}
|
|
142
|
+
function matchPath(pathname, routes) {
|
|
143
|
+
const normalized = normalizePath(pathname);
|
|
144
|
+
const segments = splitSegments(normalized);
|
|
145
|
+
if (routes.settings != null && normalized === routes.settings) {
|
|
146
|
+
return { type: "settings" };
|
|
147
|
+
}
|
|
148
|
+
if (routes.library != null && normalized === routes.library) {
|
|
149
|
+
return { type: "library" };
|
|
150
|
+
}
|
|
151
|
+
if (routes.sessionsBrowser != null && normalized === routes.sessionsBrowser) {
|
|
152
|
+
return { type: "sessionsBrowser" };
|
|
153
|
+
}
|
|
154
|
+
if (routes.libraryAgent != null) {
|
|
155
|
+
const agentId = matchTemplate(routes.libraryAgent, segments);
|
|
156
|
+
if (agentId != null) return { type: "libraryAgent", agentId };
|
|
157
|
+
}
|
|
158
|
+
if (routes.schedules != null && normalized === routes.schedules) {
|
|
159
|
+
return { type: "schedules" };
|
|
160
|
+
}
|
|
161
|
+
if (routes.agent != null) {
|
|
162
|
+
const agentName = matchTemplate(routes.agent, segments);
|
|
163
|
+
if (agentName != null) return { type: "agent", agentName };
|
|
164
|
+
}
|
|
165
|
+
if (routes.session != null) {
|
|
166
|
+
const sessionId = matchTemplate(routes.session, segments);
|
|
167
|
+
if (sessionId != null) return { type: "session", sessionId };
|
|
168
|
+
}
|
|
169
|
+
if (normalized === routes.root) {
|
|
170
|
+
return { type: "root" };
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
function matchLocation({
|
|
175
|
+
pathname,
|
|
176
|
+
search,
|
|
177
|
+
routes
|
|
178
|
+
}) {
|
|
179
|
+
const matched = matchPath(pathname, routes);
|
|
180
|
+
if (matched == null || matched.type !== "root") return matched;
|
|
181
|
+
const { agentId } = readSessionShareSearch(search);
|
|
182
|
+
return agentId != null ? { type: "libraryAgent", agentId } : matched;
|
|
183
|
+
}
|
|
184
|
+
function placesEqual(a, b) {
|
|
185
|
+
if (a.type !== b.type) return false;
|
|
186
|
+
if (a.type === "agent" && b.type === "agent") return a.agentName === b.agentName;
|
|
187
|
+
if (a.type === "libraryAgent" && b.type === "libraryAgent") return a.agentId === b.agentId;
|
|
188
|
+
if (a.type === "session" && b.type === "session") return a.sessionId === b.sessionId;
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export {
|
|
193
|
+
resolveRoutesConfig,
|
|
194
|
+
buildPath,
|
|
195
|
+
buildSessionResumeHref,
|
|
196
|
+
sanitizeSearchForPlace,
|
|
197
|
+
matchLocation,
|
|
198
|
+
placesEqual
|
|
199
|
+
};
|
|
200
|
+
//# sourceMappingURL=chunk-WVE3F724.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/routing/paths.ts"],"sourcesContent":["import { clearScheduleShareSearch } from '../utils/scheduleShareUrl.js';\nimport { readSessionShareSearch, writeSessionShareSearch } from '../utils/sessionShareUrl.js';\nimport type { ResolvedRoutes, RoutePlace, RoutesConfig } from './types.js';\n\nconst DEFAULTS = {\n root: '/',\n settings: '/settings',\n library: '/library',\n libraryAgent: '/library/:agentId',\n schedules: '/schedules',\n agent: '/agents/:agentName',\n session: '/sessions/:sessionId',\n sessionsBrowser: '/sessions',\n} as const;\n\nfunction normalizePath(path: string): string {\n const trimmed = path.trim();\n const withLead = trimmed.startsWith('/') ? trimmed : `/${trimmed}`;\n // Drop a trailing slash except for the root itself.\n return withLead.length > 1 && withLead.endsWith('/') ? withLead.slice(0, -1) : withLead;\n}\n\nfunction resolveOptional(value: string | false | undefined, fallback: string): string | null {\n if (value === false) return null;\n return normalizePath(value ?? fallback);\n}\n\nexport function resolveRoutesConfig(routes?: RoutesConfig): ResolvedRoutes {\n const paths = routes?.paths;\n return {\n basename: routes?.basename ?? '',\n root: normalizePath(paths?.root ?? DEFAULTS.root),\n settings: resolveOptional(paths?.settings, DEFAULTS.settings),\n library: resolveOptional(paths?.library, DEFAULTS.library),\n libraryAgent: resolveOptional(paths?.libraryAgent, DEFAULTS.libraryAgent),\n schedules: resolveOptional(paths?.schedules, DEFAULTS.schedules),\n agent: resolveOptional(paths?.agent, DEFAULTS.agent),\n session: resolveOptional(paths?.session, DEFAULTS.session),\n sessionsBrowser: resolveOptional(paths?.sessionsBrowser, DEFAULTS.sessionsBrowser),\n };\n}\n\nfunction splitSegments(path: string): string[] {\n return path.split('/').filter(segment => segment.length > 0);\n}\n\n/** Fill a single-param template (`/agents/:agentName`) with an encoded value. */\nfunction fillTemplate(template: string, value: string): string {\n return (\n '/' +\n splitSegments(template)\n .map(segment => (segment.startsWith(':') ? encodeURIComponent(value) : segment))\n .join('/')\n );\n}\n\n/** Build the URL path for a place, or `null` when that place has no configured route. */\nexport function buildPath(place: RoutePlace, routes: ResolvedRoutes): string | null {\n switch (place.type) {\n case 'root':\n return routes.root;\n case 'settings':\n return routes.settings;\n case 'library':\n return routes.library;\n case 'libraryAgent':\n return routes.libraryAgent == null ? null : fillTemplate(routes.libraryAgent, place.agentId);\n case 'schedules':\n return routes.schedules;\n case 'agent':\n return routes.agent == null ? null : fillTemplate(routes.agent, place.agentName);\n case 'session':\n return routes.session == null ? null : fillTemplate(routes.session, place.sessionId);\n case 'sessionsBrowser':\n return routes.sessionsBrowser;\n }\n}\n\n/**\n * Absolute href that boots the shell on a history session (`/sessions/:id`).\n * Includes `routes.basename` and clears place-owned share query keys.\n */\nexport function buildSessionResumeHref({\n sessionId,\n routes,\n href = typeof window === 'undefined' ? 'http://localhost/' : window.location.href,\n}: {\n sessionId: string;\n routes: ResolvedRoutes;\n href?: string;\n}): string | null {\n const sessionPath = buildPath({ type: 'session', sessionId }, routes);\n if (sessionPath == null) return null;\n const url = new URL(href);\n const basename = routes.basename.endsWith('/') ? routes.basename.slice(0, -1) : routes.basename;\n url.pathname = `${basename}${sessionPath}` || '/';\n url.search = sanitizeSearchForPlace({ type: 'session', sessionId }, url.search);\n url.hash = '';\n return url.toString();\n}\n\n/**\n * Remove query state owned by a different shell place while preserving host\n * parameters. Settings is an overlay, so it retains the underlying place state.\n */\nexport function sanitizeSearchForPlace(place: RoutePlace, search: string): string {\n if (place.type === 'settings') return search;\n\n const params = new URLSearchParams(search.startsWith('?') ? search.slice(1) : search);\n if (place.type === 'sessionsBrowser') {\n writeSessionShareSearch(params, { tab: null });\n clearScheduleShareSearch(params);\n } else if (place.type === 'libraryAgent') {\n const share = readSessionShareSearch(search);\n writeSessionShareSearch(params, {\n view: null,\n timeRange: null,\n ...(share.sessionId != null && share.agentId !== place.agentId ? { sessionId: null, agentId: null } : {}),\n });\n clearScheduleShareSearch(params);\n } else if (place.type === 'schedules') {\n writeSessionShareSearch(params, {\n sessionId: null,\n agentId: null,\n tab: null,\n view: null,\n timeRange: null,\n });\n // Keep `agent` / `status` / `q` — owned by the schedules place.\n } else {\n writeSessionShareSearch(params, {\n sessionId: null,\n agentId: null,\n tab: null,\n view: null,\n timeRange: null,\n });\n clearScheduleShareSearch(params);\n }\n const next = params.toString();\n return next.length > 0 ? `?${next}` : '';\n}\n\n/** Percent-decode a segment; `null` when the URL carries a malformed escape. */\nfunction decodeSegment(segment: string): string | null {\n try {\n return decodeURIComponent(segment);\n } catch {\n return null;\n }\n}\n\n/** Match a single-param template against concrete segments; returns the decoded param or null. */\nfunction matchTemplate(template: string, segments: string[]): string | null {\n const templateSegments = splitSegments(template);\n if (templateSegments.length !== segments.length) return null;\n let param: string | null = null;\n for (const [i, tpl] of templateSegments.entries()) {\n const seg = segments[i];\n if (seg === undefined) return null;\n if (tpl.startsWith(':')) {\n // A malformed escape is an unusable id, so the path simply does not match.\n const decoded = decodeSegment(seg);\n if (decoded == null) return null;\n param = decoded;\n } else if (tpl !== seg) {\n return null;\n }\n }\n return param;\n}\n\n/** Parse a (basename-relative) pathname into a place, or `null` when unrecognized. */\nexport function matchPath(pathname: string, routes: ResolvedRoutes): RoutePlace | null {\n const normalized = normalizePath(pathname);\n const segments = splitSegments(normalized);\n\n if (routes.settings != null && normalized === routes.settings) {\n return { type: 'settings' };\n }\n if (routes.library != null && normalized === routes.library) {\n return { type: 'library' };\n }\n if (routes.sessionsBrowser != null && normalized === routes.sessionsBrowser) {\n return { type: 'sessionsBrowser' };\n }\n if (routes.libraryAgent != null) {\n const agentId = matchTemplate(routes.libraryAgent, segments);\n if (agentId != null) return { type: 'libraryAgent', agentId };\n }\n if (routes.schedules != null && normalized === routes.schedules) {\n return { type: 'schedules' };\n }\n if (routes.agent != null) {\n const agentName = matchTemplate(routes.agent, segments);\n if (agentName != null) return { type: 'agent', agentName };\n }\n if (routes.session != null) {\n const sessionId = matchTemplate(routes.session, segments);\n if (sessionId != null) return { type: 'session', sessionId };\n }\n if (normalized === routes.root) {\n return { type: 'root' };\n }\n return null;\n}\n\n/** Pathname place, or library agent from `?agentId=` when the path is root. */\nexport function matchLocation({\n pathname,\n search,\n routes,\n}: {\n pathname: string;\n search: string;\n routes: ResolvedRoutes;\n}): RoutePlace | null {\n const matched = matchPath(pathname, routes);\n if (matched == null || matched.type !== 'root') return matched;\n const { agentId } = readSessionShareSearch(search);\n return agentId != null ? { type: 'libraryAgent', agentId } : matched;\n}\n\nexport function placesEqual(a: RoutePlace, b: RoutePlace): boolean {\n if (a.type !== b.type) return false;\n if (a.type === 'agent' && b.type === 'agent') return a.agentName === b.agentName;\n if (a.type === 'libraryAgent' && b.type === 'libraryAgent') return a.agentId === b.agentId;\n if (a.type === 'session' && b.type === 'session') return a.sessionId === b.sessionId;\n return true;\n}\n"],"mappings":";;;;;;;;;AAIA,IAAM,WAAW;AAAA,EACf,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS;AAAA,EACT,cAAc;AAAA,EACd,WAAW;AAAA,EACX,OAAO;AAAA,EACP,SAAS;AAAA,EACT,iBAAiB;AACnB;AAEA,SAAS,cAAc,MAAsB;AAC3C,QAAM,UAAU,KAAK,KAAK;AAC1B,QAAM,WAAW,QAAQ,WAAW,GAAG,IAAI,UAAU,IAAI,OAAO;AAEhE,SAAO,SAAS,SAAS,KAAK,SAAS,SAAS,GAAG,IAAI,SAAS,MAAM,GAAG,EAAE,IAAI;AACjF;AAEA,SAAS,gBAAgB,OAAmC,UAAiC;AAC3F,MAAI,UAAU,MAAO,QAAO;AAC5B,SAAO,cAAc,SAAS,QAAQ;AACxC;AAEO,SAAS,oBAAoB,QAAuC;AACzE,QAAM,QAAQ,QAAQ;AACtB,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY;AAAA,IAC9B,MAAM,cAAc,OAAO,QAAQ,SAAS,IAAI;AAAA,IAChD,UAAU,gBAAgB,OAAO,UAAU,SAAS,QAAQ;AAAA,IAC5D,SAAS,gBAAgB,OAAO,SAAS,SAAS,OA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