Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(llma): deep-link to skill reference files via ?file= param (#57960)

Andrew Maguirea00e1a5b127f
diff --git a/frontend/src/products.tsx b/frontend/src/products.tsx
index 18a6c8dedf4b..26458eee5d2e 100644
--- a/frontend/src/products.tsx
+++ b/frontend/src/products.tsx
@@ -903,7 +903,13 @@ export const productUrls = {
llmAnalyticsPrompts: (): string => '/llm-analytics/prompts',
llmAnalyticsPrompt: (name: string): string => `/llm-analytics/prompts/${name}`,
llmAnalyticsSkills: (): string => '/llm-analytics/skills',
- llmAnalyticsSkill: (name: string): string => `/llm-analytics/skills/${name}`,
+ llmAnalyticsSkill: (
+ name: string,
+ params?: {
+ file?: string
+ version?: number
+ }
+ ): string => combineUrl(`/llm-analytics/skills/${name}`, params).url,
llmAnalyticsClusters: (runId?: string): string =>
runId ? `/llm-analytics/clusters/${encodeURIComponent(runId)}` : '/llm-analytics/clusters',
llmAnalyticsCluster: (runId: string, clusterId: number): string =>
diff --git a/products/llm_analytics/frontend/skills/LLMSkillScene.tsx b/products/llm_analytics/frontend/skills/LLMSkillScene.tsx
index 8ee914e40a5f..ea9947e2ae08 100644
--- a/products/llm_analytics/frontend/skills/LLMSkillScene.tsx
+++ b/products/llm_analytics/frontend/skills/LLMSkillScene.tsx
@@ -1,7 +1,7 @@
import { useActions, useValues } from 'kea'
import { Form } from 'kea-forms'
import { combineUrl, router } from 'kea-router'
-import { lazy, Suspense, useCallback, useRef, useState } from 'react'
+import { lazy, Suspense, useEffect, useRef, useState } from 'react'
import { IconChevronRight, IconColumns, IconDocument, IconPencil, IconPlus, IconTrash, IconX } from '@posthog/icons'
import { LemonBanner, LemonButton, LemonSelect, LemonTag, LemonTextArea, Link } from '@posthog/lemon-ui'
@@ -19,16 +19,15 @@ import { urls } from 'scenes/urls'
import { SceneContent } from '~/layout/scenes/components/SceneContent'
import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
-import { ApiConfig } from '~/lib/api'
import { ProductKey } from '~/queries/schema/schema-general'
import { AccessControlLevel, AccessControlResourceType } from '~/types'
import { MarkdownOutline } from '../components/MarkdownOutline'
-import { llmSkillsNameFilesRetrieve } from '../generated/api'
-import type { LLMSkillFileApi, LLMSkillFileManifestApi, LLMSkillVersionSummaryApi } from '../generated/api.schemas'
+import type { LLMSkillFileManifestApi, LLMSkillVersionSummaryApi } from '../generated/api.schemas'
import type { SkillFormFileValues } from './llmSkillLogic'
import { SkillLogicProps, SkillMode, isSkill, llmSkillLogic } from './llmSkillLogic'
import { SKILL_NAME_MAX_LENGTH, SKILL_DESCRIPTION_MAX_LENGTH } from './skillConstants'
+import { skillFileLogic } from './skillFileLogic'
import { openArchiveSkillDialog } from './skillSceneComponents'
const MonacoDiffEditor = lazy(() => import('lib/components/MonacoDiffEditor'))
@@ -255,8 +254,10 @@ export function LLMSkillScene(): JSX.Element {
function SkillViewDetails(): JSX.Element {
const { skill, isOutlineExpanded, isDiffVisible, canCompareVersions, compareVersionOptions } =
useValues(llmSkillLogic)
+ const { searchParams } = useValues(router)
const { toggleOutlineExpanded, setCompareVersion } = useActions(llmSkillLogic)
const markdownContainerRef = useRef<HTMLDivElement | null>(null)
+ const selectedFilePath = typeof searchParams?.file === 'string' ? searchParams.file : null
if (!skill || !isSkill(skill)) {
return <></>
@@ -387,6 +388,7 @@ function SkillViewDetails(): JSX.Element {
skillName={skill.name}
file={file}
version={skill.is_latest ? undefined : skill.version}
+ autoOpen={selectedFilePath === file.path}
/>
))}
</div>
@@ -523,49 +525,38 @@ function SkillFileViewer({
skillName,
file,
version,
+ autoOpen = false,
}: {
skillName: string
file: LLMSkillFileManifestApi
version?: number
+ autoOpen?: boolean
}): JSX.Element {
- const [expanded, setExpanded] = useState(false)
- const [content, setContent] = useState<string | null>(null)
- const [loading, setLoading] = useState(false)
+ const logicProps = { skillName, filePath: file.path, version }
+ const { expanded, content, contentLoading } = useValues(skillFileLogic(logicProps))
+ const { toggleExpand, autoOpen: triggerAutoOpen } = useActions(skillFileLogic(logicProps))
+ const containerRef = useRef<HTMLDivElement | null>(null)
- const toggleExpand = useCallback(async () => {
- if (expanded) {
- setExpanded(false)
+ useEffect(() => {
+ if (!autoOpen) {
return
}
- if (content === null) {
- setLoading(true)
- try {
- const fileData: LLMSkillFileApi = await llmSkillsNameFilesRetrieve(
- String(ApiConfig.getCurrentTeamId()),
- skillName,
- file.path,
- { version }
- )
- setContent(fileData.content)
- } catch (e) {
- console.error('Failed to load file content', e)
- setContent('Failed to load file content.')
- } finally {
- setLoading(false)
- }
- }
- setExpanded(true)
- }, [expanded, content, skillName, file.path, version])
+ triggerAutoOpen()
+ const id = requestAnimationFrame(() => {
+ containerRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })
+ })
+ return () => cancelAnimationFrame(id)
+ }, [autoOpen, triggerAutoOpen])
const isMarkdown = file.content_type === 'text/markdown' || file.path.endsWith('.md')
const codeLanguage = isMarkdown ? null : getFileLanguage(file.path, file.content_type)
return (
- <div className="rounded border">
+ <div ref={containerRef} className="rounded border">
<button
type="button"
className="flex w-full cursor-pointer items-center gap-2 border-none bg-transparent px-3 py-2 text-left text-sm hover:bg-fill-secondary"
- onClick={toggleExpand}
+ onClick={() => toggleExpand()}
data-attr={`llma-skill-file-toggle-${file.path}`}
>
<IconChevronRight
@@ -577,7 +568,7 @@ function SkillFileViewer({
</button>
{expanded && (
<div className="border-t bg-bg-light px-3 py-2">
- {loading ? (
+ {contentLoading ? (
<div className="space-y-2">
<LemonSkeleton active className="h-3 w-full" />
<LemonSkeleton active className="h-3 w-3/4" />
diff --git a/products/llm_analytics/frontend/skills/skillFileLogic.ts b/products/llm_analytics/frontend/skills/skillFileLogic.ts
new file mode 100644
index 000000000000..7c083df18707
--- /dev/null
+++ b/products/llm_analytics/frontend/skills/skillFileLogic.ts
@@ -0,0 +1,64 @@
+import { actions, kea, key, listeners, path, props, reducers } from 'kea'
+import { loaders } from 'kea-loaders'
+
+import { ApiConfig } from '~/lib/api'
+
+import { llmSkillsNameFilesRetrieve } from '../generated/api'
+import type { LLMSkillFileApi } from '../generated/api.schemas'
+import type { skillFileLogicType } from './skillFileLogicType'
+
+export interface SkillFileLogicProps {
+ skillName: string
+ filePath: string
+ version?: number
+}
+
+export const skillFileLogic = kea<skillFileLogicType>([
+ path(['scenes', 'llm-analytics', 'skillFileLogic']),
+ props({ skillName: '', filePath: '' } as SkillFileLogicProps),
+ key(({ skillName, filePath, version }) => `skill-file-${skillName}:${filePath}:${version ?? 'latest'}`),
+ actions({
+ toggleExpand: true,
+ autoOpen: true,
+ }),
+ reducers({
+ expanded: [
+ false,
+ {
+ toggleExpand: (state) => !state,
+ autoOpen: () => true,
+ },
+ ],
+ }),
+ loaders(({ props }) => ({
+ content: {
+ __default: null as string | null,
+ loadContent: async () => {
+ try {
+ const fileData: LLMSkillFileApi = await llmSkillsNameFilesRetrieve(
+ String(ApiConfig.getCurrentTeamId()),
+ props.skillName,
+ props.filePath,
+ { version: props.version }
+ )
+ return fileData.content
+ } catch (e) {
+ console.error('Failed to load file content', e)
+ return 'Failed to load file content.'
+ }
+ },
+ },
+ })),
+ listeners(({ actions, values }) => ({
+ toggleExpand: () => {
+ if (values.expanded && values.content === null && !values.contentLoading) {
+ actions.loadContent()
+ }
+ },
+ autoOpen: () => {
+ if (values.content === null && !values.contentLoading) {
+ actions.loadContent()
+ }
+ },
+ })),
+])
diff --git a/products/llm_analytics/manifest.tsx b/products/llm_analytics/manifest.tsx
index 90e9a96633b5..c460128085fe 100644
--- a/products/llm_analytics/manifest.tsx
+++ b/products/llm_analytics/manifest.tsx
@@ -255,7 +255,8 @@ export const manifest: ProductManifest = {
llmAnalyticsPrompts: (): string => '/llm-analytics/prompts',
llmAnalyticsPrompt: (name: string): string => `/llm-analytics/prompts/${name}`,
llmAnalyticsSkills: (): string => '/llm-analytics/skills',
- llmAnalyticsSkill: (name: string): string => `/llm-analytics/skills/${name}`,
+ llmAnalyticsSkill: (name: string, params?: { file?: string; version?: number }): string =>
+ combineUrl(`/llm-analytics/skills/${name}`, params).url,
llmAnalyticsClusters: (runId?: string): string =>
runId ? `/llm-analytics/clusters/${encodeURIComponent(runId)}` : '/llm-analytics/clusters',
llmAnalyticsCluster: (runId: string, clusterId: number): string =>