Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ wsh editconfig
| ai:apiversion | string | for Azure AI only (when apitype is "azure", this will default to "2023-05-15") |
| ai:orgid | string | |
| ai:maxtokens | int | max tokens to pass to API |
| ai:maxtokensfield | string | name of the max tokens field in request to be compatible with the model api (default: max_tokens) |
| ai:timeoutms | int | timeout (in milliseconds) for AI calls |
| conn:askbeforewshinstall | bool | set to false to disable popup asking if you want to install wsh extensions on new machines |
| term:fontsize | float | the fontsize for the terminal block |
Expand Down
1 change: 1 addition & 0 deletions frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ declare global {
"ai:orgid"?: string;
"ai:apiversion"?: string;
"ai:maxtokens"?: number;
"ai:maxtokensfield"?: string;
"ai:timeoutms"?: number;
"ai:fontsize"?: number;
"ai:fixedfontsize"?: number;
Expand Down
1 change: 1 addition & 0 deletions pkg/wconfig/metaconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
ConfigKey_AiOrgID = "ai:orgid"
ConfigKey_AIApiVersion = "ai:apiversion"
ConfigKey_AiMaxTokens = "ai:maxtokens"
ConfigKey_AiMaxTokensField = "ai:maxtokensfield"
ConfigKey_AiTimeoutMs = "ai:timeoutms"
ConfigKey_AiFontSize = "ai:fontsize"
ConfigKey_AiFixedFontSize = "ai:fixedfontsize"
Expand Down
32 changes: 32 additions & 0 deletions pkg/wconfig/settingsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type AiSettingsType struct {
AiOrgID string `json:"ai:orgid,omitempty"`
AIApiVersion string `json:"ai:apiversion,omitempty"`
AiMaxTokens float64 `json:"ai:maxtokens,omitempty"`
AiMaxTokensField string `json:"ai:maxtokensfield,omitempty"`
AiTimeoutMs float64 `json:"ai:timeoutms,omitempty"`
AiFontSize float64 `json:"ai:fontsize,omitempty"`
AiFixedFontSize float64 `json:"ai:fixedfontsize,omitempty"`
Expand All @@ -66,6 +67,7 @@ type SettingsType struct {
AiOrgID string `json:"ai:orgid,omitempty"`
AIApiVersion string `json:"ai:apiversion,omitempty"`
AiMaxTokens float64 `json:"ai:maxtokens,omitempty"`
AiMaxTokensField string `json:"ai:maxtokensfield,omitempty"`
AiTimeoutMs float64 `json:"ai:timeoutms,omitempty"`
AiFontSize float64 `json:"ai:fontsize,omitempty"`
AiFixedFontSize float64 `json:"ai:fixedfontsize,omitempty"`
Expand Down Expand Up @@ -405,6 +407,9 @@ func ReadFullConfig() FullConfigType {
continue
} else {
configPart, errs = readConfigPart(jsonTag, simpleMerge)
if jsonTag == "settings" {
configPart = normalizeSettingsAliases(configPart)
}
Comment on lines +410 to +412
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Alias normalization is only applied to "settings"; consider normalizing inside "presets" too

If users set aliases within presets (e.g., in aipresets.json), those aliases won’t be normalized here. Consider normalizing aliases for each preset entry to keep behavior consistent.

Proposed change:

-      if jsonTag == "settings" {
-        configPart = normalizeSettingsAliases(configPart)
-      }
+      if jsonTag == "settings" {
+        configPart = normalizeSettingsAliases(configPart)
+      } else if jsonTag == "presets" {
+        // Normalize aliases within each preset map
+        for name, raw := range configPart {
+          if sub, ok := raw.(map[string]any); ok {
+            mm := waveobj.MetaMapType(sub)
+            configPart[name] = normalizeSettingsAliases(mm)
+          }
+        }
+      }

To check whether presets rely on aliases today, run:


🏁 Script executed:

#!/bin/bash
# Scan for ai:maxtokensfield and aliases across repo to gauge current usage.
rg -n --hidden -S $'ai:maxtokensfield|ai:max_tokens_field|ai:max_tokens_param|ai:maxtokenfields|ai:max_tokens'

Length of output: 1240


Ensure alias normalization for “presets” as well

Users can define the same ai:… aliases in your aipresets.json under the presets key, but our loader only normalizes aliases inside the top‐level settings section. We should apply the same normalizeSettingsAliases logic to each preset entry so that aliases like ai:maxtokensfield are handled consistently.

Files/locations to update:

  • pkg/wconfig/settingsconfig.go (around lines 410–412)

Suggested diff:

@@ -409,6 +409,16 @@
       if jsonTag == "settings" {
         configPart = normalizeSettingsAliases(configPart)
       }
+      else if jsonTag == "presets" {
+        // Normalize aliases in each preset entry
+        for name, raw := range configPart {
+          if subMap, ok := raw.(map[string]any); ok {
+            mm := waveobj.MetaMapType(subMap)
+            configPart[name] = normalizeSettingsAliases(mm)
+          }
+        }
+      }

This ensures any alias mappings under "presets" get normalized exactly as they are under "settings".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if jsonTag == "settings" {
configPart = normalizeSettingsAliases(configPart)
}
if jsonTag == "settings" {
configPart = normalizeSettingsAliases(configPart)
} else if jsonTag == "presets" {
// Normalize aliases in each preset entry
for name, raw := range configPart {
if subMap, ok := raw.(map[string]any); ok {
mm := waveobj.MetaMapType(subMap)
configPart[name] = normalizeSettingsAliases(mm)
}
}
}
🤖 Prompt for AI Agents
In pkg/wconfig/settingsconfig.go around lines 410 to 412, the code currently
normalizes aliases only for the "settings" section but not for the "presets"
section. To fix this, add logic to iterate over each entry in the "presets" key
and apply the normalizeSettingsAliases function to each preset entry, ensuring
alias normalization is consistent for both "settings" and "presets".

}
fullConfig.ConfigErrors = append(fullConfig.ConfigErrors, errs...)
if configPart != nil {
Expand Down Expand Up @@ -458,6 +463,32 @@ func getConfigKeyNamespace(key string) string {
return key[:colonIdx]
}

// Alias map for settings keys to support alternate names in user config.
// Canonical key is on the right-hand side.
var settingsAliasKeyMap = map[string]string{
"ai:max_tokens": "ai:maxtokens",
"ai:max_tokens_param": "ai:maxtokensfield",
"ai:max_tokens_field": "ai:maxtokensfield",
"ai:maxtokenfields": "ai:maxtokensfield",
"ai:maxtokenfield": "ai:maxtokensfield",
}
// normalizeSettingsAliases rewrites known alias keys in-place to their canonical forms.
// If both alias and canonical exist, the canonical value wins and the alias is removed.
func normalizeSettingsAliases(m waveobj.MetaMapType) waveobj.MetaMapType {
if m == nil {
return nil
}
for alias, canonical := range settingsAliasKeyMap {
if val, ok := m[alias]; ok {
if _, exists := m[canonical]; !exists {
m[canonical] = val
}
delete(m, alias)
}
}
return m
}

func orderConfigKeys(m waveobj.MetaMapType) []string {
keys := make([]string, 0, len(m))
for k := range m {
Expand Down Expand Up @@ -561,6 +592,7 @@ func SetBaseConfigValue(toMerge waveobj.MetaMapType) error {
if m == nil {
m = make(waveobj.MetaMapType)
}
toMerge = normalizeSettingsAliases(toMerge)
for configKey, val := range toMerge {
ctype := getConfigKeyType(configKey)
if ctype == nil {
Expand Down
18 changes: 18 additions & 0 deletions schema/aipresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
"ai:maxtokens": {
"type": "number"
},
"ai:maxtokensfield": {
"type": "string"
},
"ai:max_tokens_field": {
"type": "string",
"deprecated": true,
"description": "Alias of ai:maxtokensfield"
},
"ai:max_tokens_param": {
"type": "string",
"deprecated": true,
"description": "Alias of ai:maxtokensfield"
},
"ai:maxtokenfields": {
"type": "string",
"deprecated": true,
"description": "Alias of ai:maxtokensfield"
},
"ai:timeoutms": {
"type": "number"
},
Expand Down
3 changes: 3 additions & 0 deletions schema/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"ai:maxtokens": {
"type": "number"
},
"ai:maxtokensfield": {
"type": "string"
},
"ai:timeoutms": {
"type": "number"
},
Expand Down