fix: gate previousConversation array format for older servers (#400)

* fix: gate previousConversation array format behind BrowserOS 0.41.0.0

Older servers reject the array format for previousConversation with a
ZodError ("Expected string, received array"). Gate the feature behind
BrowserOS >= 0.41.0.0 which bundles server >= 0.0.64 that accepts both
array and string formats.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: use minServerVersion 0.0.64 for previousConversation gate

Server version is the direct indicator of schema support, more accurate
than using BrowserOS version as a proxy.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: fall back to string format for previousConversation on old servers

Instead of omitting previousConversation entirely on servers < 0.0.64,
serialize the conversation history as a "role: content" string which
old servers accept via their z.string() schema.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Nikhil
2026-03-03 15:58:59 -08:00
committed by GitHub
parent 12f8407fd6
commit 6d736e9158
2 changed files with 14 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import { useEffect, useRef, useState } from 'react'
import { useSearchParams } from 'react-router'
import useDeepCompareEffect from 'use-deep-compare-effect'
import type { Provider } from '@/components/chat/chatComponentTypes'
import { Capabilities, Feature } from '@/lib/browseros/capabilities'
import { useAgentServerUrl } from '@/lib/browseros/useBrowserOSProviders'
import type { ChatAction } from '@/lib/chat-actions/types'
import {
@@ -256,12 +257,20 @@ export const useChatSession = () => {
}[]
}
// Format previous messages from ref (messagesRef doesn't include current message yet)
const supportsArrayConversation = await Capabilities.supports(
Feature.PREVIOUS_CONVERSATION_ARRAY,
)
const previousMessages = messagesRef.current
const previousConversation =
const history =
previousMessages.length > 0
? formatConversationHistory(previousMessages)
: undefined
const previousConversation = history?.length
? supportsArrayConversation
? history
: history.map((m) => `${m.role}: ${m.content}`).join('\n')
: undefined
return {
api: `${agentUrlRef.current}/chat`,

View File

@@ -33,6 +33,8 @@ export enum Feature {
PROXY_SUPPORT = 'PROXY_SUPPORT',
// Workflows feature
WORKFLOW_SUPPORT = 'WORKFLOW_SUPPORT',
// previousConversation as structured array (older servers only accept string)
PREVIOUS_CONVERSATION_ARRAY = 'PREVIOUS_CONVERSATION_ARRAY',
}
/**
@@ -54,6 +56,7 @@ const FEATURE_CONFIG: { [K in Feature]: FeatureConfig } = {
[Feature.WORKSPACE_FOLDER_SUPPORT]: { minBrowserOSVersion: '0.36.4.0' },
[Feature.PROXY_SUPPORT]: { minBrowserOSVersion: '0.39.0.1' },
[Feature.WORKFLOW_SUPPORT]: { minServerVersion: '0.0.41' },
[Feature.PREVIOUS_CONVERSATION_ARRAY]: { minServerVersion: '0.0.64' },
}
function parseVersion(version: string): number[] {