mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 14:41:24 +08:00
Previously, JSON-type custom parameters were incorrectly parsed and stored as objects in the UI layer, causing API requests to fail when getCustomParameters() attempted to JSON.parse() an already-parsed object. Changes: - AssistantModelSettings.tsx: Remove JSON.parse() in onChange handler, store as string - reasoning.ts: Add comments explaining JSON parsing flow - BaseApiClient.ts: Add comments for legacy API clients
This commit is contained in:
parent
d0bd10190d
commit
0836eef1a6
@ -405,6 +405,9 @@ export abstract class BaseApiClient<
|
|||||||
if (!param.name?.trim()) {
|
if (!param.name?.trim()) {
|
||||||
return acc
|
return acc
|
||||||
}
|
}
|
||||||
|
// Parse JSON type parameters (Legacy API clients)
|
||||||
|
// Related: src/renderer/src/pages/settings/AssistantSettings/AssistantModelSettings.tsx:133-148
|
||||||
|
// The UI stores JSON type params as strings, this function parses them before sending to API
|
||||||
if (param.type === 'json') {
|
if (param.type === 'json') {
|
||||||
const value = param.value as string
|
const value = param.value as string
|
||||||
if (value === 'undefined') {
|
if (value === 'undefined') {
|
||||||
|
|||||||
@ -684,6 +684,10 @@ export function getCustomParameters(assistant: Assistant): Record<string, any> {
|
|||||||
if (!param.name?.trim()) {
|
if (!param.name?.trim()) {
|
||||||
return acc
|
return acc
|
||||||
}
|
}
|
||||||
|
// Parse JSON type parameters
|
||||||
|
// Related: src/renderer/src/pages/settings/AssistantSettings/AssistantModelSettings.tsx:133-148
|
||||||
|
// The UI stores JSON type params as strings (e.g., '{"key":"value"}')
|
||||||
|
// This function parses them into objects before sending to the API
|
||||||
if (param.type === 'json') {
|
if (param.type === 'json') {
|
||||||
const value = param.value as string
|
const value = param.value as string
|
||||||
if (value === 'undefined') {
|
if (value === 'undefined') {
|
||||||
|
|||||||
@ -135,12 +135,18 @@ const AssistantModelSettings: FC<Props> = ({ assistant, updateAssistant, updateA
|
|||||||
<Input
|
<Input
|
||||||
value={typeof param.value === 'string' ? param.value : JSON.stringify(param.value, null, 2)}
|
value={typeof param.value === 'string' ? param.value : JSON.stringify(param.value, null, 2)}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
try {
|
// For JSON type parameters, always store the value as a STRING
|
||||||
const jsonValue = JSON.parse(e.target.value)
|
//
|
||||||
onUpdateCustomParameter(index, 'value', jsonValue)
|
// Data Flow:
|
||||||
} catch {
|
// 1. UI stores: { name: "config", value: '{"key":"value"}', type: "json" } ← STRING format
|
||||||
onUpdateCustomParameter(index, 'value', e.target.value)
|
// 2. API parses: getCustomParameters() in src/renderer/src/aiCore/utils/reasoning.ts:687-696
|
||||||
}
|
// calls JSON.parse() to convert string to object
|
||||||
|
// 3. Request sends: The parsed object is sent to the AI provider
|
||||||
|
//
|
||||||
|
// Previously this code was parsing JSON here and storing
|
||||||
|
// the object directly, which caused getCustomParameters() to fail when trying
|
||||||
|
// to JSON.parse() an already-parsed object.
|
||||||
|
onUpdateCustomParameter(index, 'value', e.target.value)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user