: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(aio): reorder playground messages with move up and down controls (#113963)
Juraj Majerikf2838b5a6b34
diff --git a/products/ai_observability/frontend/playground/AIObservabilityPlaygroundScene.tsx b/products/ai_observability/frontend/playground/AIObservabilityPlaygroundScene.tsxindex 528b70b840f0..d879da28cb41 100644--- a/products/ai_observability/frontend/playground/AIObservabilityPlaygroundScene.tsx+++ b/products/ai_observability/frontend/playground/AIObservabilityPlaygroundScene.tsx@@ -30,6 +30,7 @@ import {import { AccessControlAction } from 'lib/components/AccessControlAction'import { AnimatedCollapsible } from 'lib/components/AnimatedCollapsible'+import { IconArrowDown, IconArrowUp } from 'lib/lemon-ui/icons'import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'import { CodeEditorResizeable } from 'lib/monaco/CodeEditorResizable'@@ -682,7 +683,13 @@ function MessagesSection({ promptId }: { promptId: string }): JSX.Element {<div className="space-y-3"><SystemMessageDisplay promptId={promptId} />{prompt.messages.map((message, index) => (- <MessageDisplay key={`${promptId}-${index}`} promptId={promptId} index={index} message={message} />+ <MessageDisplay+ key={`${promptId}-${index}`}+ promptId={promptId}+ index={index}+ message={message}+ messageCount={prompt.messages.length}+ />))}</div>)@@ -1029,14 +1036,17 @@ function MessageDisplay({promptId,message,index,+ messageCount,}: {promptId: stringmessage: Messageindex: number+ messageCount: number}): JSX.Element {const { editModal, collapsedSections } = useValues(llmPlaygroundPromptsLogic)const { unfilledVariables } = useValues(llmPlaygroundVariablesLogic)- const { updateMessage, deleteMessage, setEditModal, toggleCollapsed } = useActions(llmPlaygroundPromptsLogic)+ const { updateMessage, deleteMessage, moveMessage, setEditModal, toggleCollapsed } =+ useActions(llmPlaygroundPromptsLogic)const { submitPrompt } = useActions(llmPlaygroundRunLogic)const messageKey = `message:${promptId}:${index}`@@ -1076,6 +1086,24 @@ function MessageDisplay({<><div className="border rounded p-4 py-2 relative group"><div className="absolute top-4 right-4 flex items-center gap-1">+ <LemonButton+ size="small"+ icon={<IconArrowUp />}+ tooltip="Move message up"+ noPadding+ disabledReason={index === 0 ? 'Already the first message' : undefined}+ onClick={() => moveMessage(index, 'up', promptId)}+ data-attr="llma-playground-move-message-up"+ />+ <LemonButton+ size="small"+ icon={<IconArrowDown />}+ tooltip="Move message down"+ noPadding+ disabledReason={index === messageCount - 1 ? 'Already the last message' : undefined}+ onClick={() => moveMessage(index, 'down', promptId)}+ data-attr="llma-playground-move-message-down"+ /><LemonButtonsize="small"icon={<IconCopy />}diff --git a/products/ai_observability/frontend/playground/llmPlaygroundLogic.test.ts b/products/ai_observability/frontend/playground/llmPlaygroundLogic.test.tsindex 41f3d6c6a86f..9d1d26708912 100644--- a/products/ai_observability/frontend/playground/llmPlaygroundLogic.test.ts+++ b/products/ai_observability/frontend/playground/llmPlaygroundLogic.test.ts@@ -609,6 +609,29 @@ describe('llmPlaygroundLogic', () => {expect(llmPlaygroundPromptsLogic.values.messages).toEqual(originalMessages)})+ it('should swap a message with its neighbor and ignore moves past the edges', () => {+ llmPlaygroundPromptsLogic.actions.setMessages([+ { role: 'user', content: 'first' },+ { role: 'assistant', content: 'second' },+ { role: 'user', content: 'third' },+ ])++ llmPlaygroundPromptsLogic.actions.moveMessage(2, 'up')+ expect(llmPlaygroundPromptsLogic.values.messages.map((m) => m.content)).toEqual([+ 'first',+ 'third',+ 'second',+ ])++ llmPlaygroundPromptsLogic.actions.moveMessage(0, 'up')+ llmPlaygroundPromptsLogic.actions.moveMessage(2, 'down')+ expect(llmPlaygroundPromptsLogic.values.messages.map((m) => m.content)).toEqual([+ 'first',+ 'third',+ 'second',+ ])+ })+it('should append a result as an assistant message and start the next user turn', () => {llmPlaygroundPromptsLogic.actions.setMessages([{ role: 'user', content: 'Hello' }])diff --git a/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.ts b/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.tsindex 002b6889e28f..973acbbb9005 100644--- a/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.ts+++ b/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.ts@@ -285,6 +285,15 @@ export interface llmPlaygroundPromptsLogicActions {index: numberpromptId: string | undefined}+ moveMessage: (+ index: number,+ direction: 'down' | 'up',+ promptId?: string+ ) => {+ direction: 'down' | 'up'+ index: number+ promptId: string | undefined+ }removePromptConfig: (promptId: string) => {promptId: string}@@ -521,6 +530,7 @@ export const llmPlaygroundPromptsLogic = kea<llmPlaygroundPromptsLogicType>([clearConversation: (promptId?: string) => ({ promptId }),setMessages: (messages: Message[], promptId?: string) => ({ messages, promptId }),deleteMessage: (index: number, promptId?: string) => ({ index, promptId }),+ moveMessage: (index: number, direction: 'up' | 'down', promptId?: string) => ({ index, direction, promptId }),addMessage: (message?: Partial<Message>, promptId?: string) => ({ message, promptId }),addResultToConversation: (response: string, toolCalls?: MessageToolCall[], promptId?: string) => ({response,@@ -639,6 +649,24 @@ export const llmPlaygroundPromptsLogic = kea<llmPlaygroundPromptsLogicType>([}return { ...prompt, messages: prompt.messages.filter((_, i) => i !== index) }}),+ moveMessage: (+ state: PromptConfig[],+ { index, direction, promptId }: { index: number; direction: 'up' | 'down'; promptId?: string }+ ) =>+ updatePromptConfigs(state, promptId, (prompt) => {+ const target = direction === 'up' ? index - 1 : index + 1+ if (+ index < 0 ||+ index >= prompt.messages.length ||+ target < 0 ||+ target >= prompt.messages.length+ ) {+ return prompt+ }+ const messages = [...prompt.messages]+ ;[messages[index], messages[target]] = [messages[target], messages[index]]+ return { ...prompt, messages }+ }),addMessage: (state: PromptConfig[],{ message, promptId }: { message?: Partial<Message>; promptId?: string }@@ -1005,6 +1033,9 @@ export const llmPlaygroundPromptsLogic = kea<llmPlaygroundPromptsLogicType>([tool_call_count: toolCalls?.length ?? 0,})},+ moveMessage: ({ direction }) => {+ posthog.capture('llma playground message moved', { direction })+ },setTools: ({ tools }) => {posthog.capture('llma playground tools configured', {action: tools ? 'set' : 'clear',