{"record":{"id":"138209de1a2f13cb","repo":"farion1231/cc-switch","slug":"pi-form-thinkinglevelmapinvalid","errorCode":null,"errorMessage":"pi.form.thinkingLevelMapInvalid","messagePattern":"pi\\.form\\.thinkingLevelMapInvalid","errorType":"validation","errorClass":"PiFormValidationError","httpStatus":null,"severity":"warning","filePath":"src/components/providers/forms/PiProviderForm.tsx","lineNumber":1160,"sourceCode":"                label: t(\"pi.form.contextWindow\"),\n              }),\n              `#pi-model-context-window-${model.key}`,\n            )\n          : undefined;\n        const maxTokens = includeMaxTokens\n          ? positiveNumber(\n              model.maxTokens,\n              t(\"pi.form.positiveNumberRequired\", {\n                label: t(\"pi.form.maxTokens\"),\n              }),\n              `#pi-model-max-tokens-${model.key}`,\n            )\n          : undefined;\n        if (\n          model.hasThinkingLevelMap &&\n          !isPiThinkingLevelMap(model.thinkingLevelMap)\n        ) {\n          throw new PiFormValidationError(\n            t(\"pi.form.thinkingLevelMapInvalid\"),\n            `#pi-model-thinking-levels-${model.key}`,\n            true,\n          );\n        }\n        // Pi's schema supports rare per-model api/baseUrl overrides. Keep\n        // imported values losslessly, but use the provider-level format and\n        // endpoint as the normal product model.\n        const modelApi =\n          typeof model.passthrough.api === \"string\"\n            ? model.passthrough.api.trim()\n            : \"\";\n        const modelBaseUrl =\n          typeof model.passthrough.baseUrl === \"string\"\n            ? model.passthrough.baseUrl.trim()\n            : \"\";\n        // Existing explicit nodes may be partial overrides of a Pi built-in\n        // provider. Pi inherits the built-in transport in that case, so only","sourceCodeStart":1142,"sourceCodeEnd":1178,"githubUrl":"https://github.com/farion1231/cc-switch/blob/a2e22f330273a5b6ffa87cb8b82b624601bac562/src/components/providers/forms/PiProviderForm.tsx#L1142-L1178","documentation":"Thrown per-model in PiProviderForm's submit() when the row has a thinking-level map enabled (model.hasThinkingLevelMap) but its value fails isPiThinkingLevelMap (src/config/piThinkingProfiles.ts:347-355): the value must be a plain object whose keys are among 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max' and whose values are strings or null. Arrays, unknown level keys, or numeric/boolean values fail. fieldSelector '#pi-model-thinking-levels-{model.key}' with revealAdvanced=true expands the row, opens the thinking map editor, and focuses it (PiProviderForm.tsx:1262-1277).","triggerScenarios":"Hand-editing the thinking map JSON with a typo'd level like 'ultra' or 'x-high'; using numbers ('high': 1) instead of model-name strings or null; leaving a JSON array or nested object in the field; importing a config with an off-spec thinking map.","commonSituations":"Copying thinking configs from other tools whose level names differ; assuming an empty object is fine for 'explicitly no mapping'; version drift when PI_THINKING_LEVELS gains/renames levels between releases.","solutions":["Correct the map so every key is one of off/minimal/low/medium/high/xhigh/max and every value is a string or null","If the row should not override thinking levels, remove the thinking map entirely instead of leaving an invalid one","Validate with isPiThinkingLevelMap live as the user types and disable Save on failure"],"exampleFix":"// before\nthinkingLevelMap: { high: 1, ultra: \"model-x\" }\n\n// after\nthinkingLevelMap: { high: \"model-x-thinking\", medium: null }","handlingStrategy":"type-guard","validationCode":"import { isPiThinkingLevelMap } from \"@/config/piThinkingProfiles\";\nfor (const m of models) {\n  if (m.hasThinkingLevelMap && !isPiThinkingLevelMap(m.thinkingLevelMap)) {\n    setFormError(t(\"pi.form.thinkingLevelMapInvalid\"));\n    return;\n  }\n}","typeGuard":"import { isPiThinkingLevelMap } from \"@/config/piThinkingProfiles\";\n// isPiThinkingLevelMap(value: unknown): value is PiThinkingLevelMap\n// — plain object, keys in {off, minimal, low, medium, high, xhigh, max}, values string | null","tryCatchPattern":"try {\n  await submit(identity);\n} catch (error) {\n  if (error instanceof Error && error.name === \"PiFormValidationError\") { /* the form expands the row AND its thinking-map editor via '#pi-model-thinking-levels-{key}' */ return; }\n  throw error;\n}","preventionTips":["Constrain the thinking-map editor to a dropdown of PI_THINKING_LEVELS instead of free JSON","Run isPiThinkingLevelMap on every change and disable Save on failure","Null is a valid value (level explicitly unset); numbers and unknown keys are not"],"tags":["form-validation","pi","thinking-levels","json","type-guard"],"backgroundTag":null,"analyzedSha":"a2e22f330273a5b6ffa87cb8b82b624601bac562","analyzedAt":"2026-08-16T03:46:07.889Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}