Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
wip: model config data models and json schemas
Dane Schneiderb14de7d65371
diff --git a/app/server/model/client.go b/app/server/model/client.goindex 9cc4a766..ce4fb8e3 100644--- a/app/server/model/client.go+++ b/app/server/model/client.go@@ -163,7 +163,7 @@ func createChatCompletionStreamExtended(extendedReq types.ExtendedChatCompletionRequest,) (*ExtendedChatCompletionStream, error) {var openaiReq *types.ExtendedOpenAIChatCompletionRequest- if modelConfig.BaseModelConfig.Provider == shared.ModelProviderOpenAI && !modelConfig.BaseModelConfig.UsesOpenAIResponsesAPI {+ if modelConfig.BaseModelConfig.Provider == shared.ModelProviderOpenAI {openaiReq = extendedReq.ToOpenAI()log.Println("Creating chat completion stream with direct OpenAI provider request")}@@ -183,12 +183,7 @@ func createChatCompletionStreamExtended(// log.Println("request jsonBody", string(jsonBody))// Create new request- var url string- if modelConfig.BaseModelConfig.UsesOpenAIResponsesAPI {- url = baseUrl + "/responses"- } else {- url = baseUrl + "/chat/completions"- }+ url := baseUrl + "/chat/completions"req, err := http.NewRequestWithContext(ctx, "POST", url, bytes.NewReader(jsonBody))if err != nil {diff --git a/app/shared/ai_models_data_models.go b/app/shared/ai_models_data_models.goindex 08791f47..a416118e 100644--- a/app/shared/ai_models_data_models.go+++ b/app/shared/ai_models_data_models.go@@ -18,20 +18,16 @@ const (ModelOutputFormatXml ModelOutputFormat = "xml")-// to help avoid confusion between the model name and the model id+// to help avoid confusion between model tag, model name, and the model idtype ModelName stringtype ModelId string+type ModelTag string-type BaseModelConfig struct {- Provider ModelProvider `json:"provider"`- CustomProvider *string `json:"customProvider,omitempty"`- BaseUrl string `json:"baseUrl"`- ModelName ModelName `json:"modelName"`- ModelId ModelId `json:"modelId"`+type BaseModelShared struct {+ ModelTag ModelTag `json:"modelTag"`MaxTokens int `json:"maxTokens"`MaxOutputTokens int `json:"maxOutputTokens"`ReservedOutputTokens int `json:"reservedOutputTokens"`- ApiKeyEnvVar string `json:"apiKeyEnvVar"`PreferredModelOutputFormat ModelOutputFormat `json:"preferredModelOutputFormat"`SystemPromptDisabled bool `json:"systemPromptDisabled"`RoleParamsDisabled bool `json:"roleParamsDisabled"`@@ -41,17 +37,30 @@ type BaseModelConfig struct {ReasoningEffort ReasoningEffort `json:"reasoningEffort"`IncludeReasoning bool `json:"includeReasoning"`SupportsCacheControl bool `json:"supportsCacheControl"`-- // for openai responses API, not fully implemented yet- UsesOpenAIResponsesAPI bool `json:"usesOpenAIResponsesAPI"`-// for anthropic, single message system prompt needs to be flipped to 'user'SingleMessageNoSystemPrompt bool `json:"singleMessageNoSystemPrompt"`// for openai, token estimate padding percentageTokenEstimatePaddingPct float64 `json:"tokenEstimatePaddingPct"`+}++type BaseModelProviderConfig struct {+ Provider ModelProvider `json:"provider"`+ CustomProvider *string `json:"customProvider,omitempty"`+ ModelName ModelName `json:"modelName"`+ ModelId ModelId `json:"modelId"`+}++type BaseModelConfig struct {+ ApiKeyEnvVar string `json:"apiKeyEnvVar"`+ BaseModelShared+ BaseModelProviderConfig+}- ModelCompatibility+type BaseModelConfigSchema struct {+ SchemaVersion string `json:"schemaVersion"`+ BaseModelShared+ Providers []BaseModelProviderConfig `json:"providers"`}type AvailableModel struct {@@ -72,6 +81,15 @@ func (m *AvailableModel) ModelString() string {return s}+type AvailableModelSchema struct {+ SchemaVersion string `json:"schemaVersion"`+ BaseModelConfigSchema+ Description string `json:"description"`+ DefaultMaxConvoTokens int `json:"defaultMaxConvoTokens"`+ CreatedAt time.Time `json:"createdAt"`+ UpdatedAt time.Time `json:"updatedAt"`+}+type PlannerModelConfig struct {MaxConvoTokens int `json:"maxConvoTokens"`}@@ -90,7 +108,6 @@ type ModelRoleConfig struct {Temperature float32 `json:"temperature"`TopP float32 `json:"topP"`ReservedOutputTokens int `json:"reservedOutputTokens"`- ReasoningEffort ReasoningEffort `json:"reasoningEffort"`LargeContextFallback *ModelRoleConfig `json:"largeContextFallback"`LargeOutputFallback *ModelRoleConfig `json:"largeOutputFallback"`@@ -99,6 +116,9 @@ type ModelRoleConfig struct {StrongModel *ModelRoleConfig `json:"strongModel"`}+type ModelRoleConfigSchema struct {+}+func (m ModelRoleConfig) GetReservedOutputTokens() int {if m.ReservedOutputTokens > 0 {return m.ReservedOutputTokensdiff --git a/app/shared/ai_models_providers.go b/app/shared/ai_models_providers.goindex 1bf49c89..d2d1568a 100644--- a/app/shared/ai_models_providers.go+++ b/app/shared/ai_models_providers.go@@ -65,3 +65,42 @@ var ApiKeyByProvider = map[ModelProvider]string{ModelProviderDeepSeek: DeepSeekApiKeyEnvVar,ModelProviderPerplexity: PerplexityApiKeyEnvVar,}++// these types can come in via JSON config which uses JSON schema with discriminated unions — thus the need for the `omitempty` and pointers on all optional fields+type ModelProviderExtraAuthVars struct {+ Var string `json:"var"`+ IsFilePath *bool `json:"isFilePath,omitempty"`+ Required *bool `json:"required,omitempty"`+}++type ModelProviderConfig struct {+ SchemaVersion string `json:"schemaVersion"`+ Provider ModelProvider `json:"provider"`+ CustomProvider *string `json:"customProvider,omitempty"`+ BaseUrl string `json:"baseUrl"`++ // for local models that don't require auth (ollama, etc.)+ SkipAuth *bool `json:"skipAuth,omitempty"`++ ApiKeyEnvVar *string `json:"apiKeyEnvVar,omitempty"`+ ExtraAuthVars *[]ModelProviderExtraAuthVars `json:"extraAuthVars,omitempty"`+}++var BuiltInModelProviderConfigs = map[ModelProvider]ModelProviderConfig{+ ModelProviderOpenAI: {+ Provider: ModelProviderOpenAI,+ BaseUrl: OpenAIV1BaseUrl,++ SkipAuth: &[]bool{false}[0],+ ApiKeyEnvVar: &[]string{OpenAIEnvVar}[0],+ ExtraAuthVars: &[]ModelProviderExtraAuthVars{},+ },+ ModelProviderOpenRouter: {+ Provider: ModelProviderOpenRouter,+ BaseUrl: OpenRouterBaseUrl,++ SkipAuth: &[]bool{true}[0],+ ApiKeyEnvVar: &[]string{OpenRouterApiKeyEnvVar}[0],+ ExtraAuthVars: &[]ModelProviderExtraAuthVars{},+ },+}diff --git a/app/shared/json-schemas/definitions/auto-modes.schema.json b/app/shared/json-schemas/definitions/auto-modes.schema.jsonnew file mode 100644index 00000000..a2d2dd8e--- /dev/null+++ b/app/shared/json-schemas/definitions/auto-modes.schema.json@@ -0,0 +1,14 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "$id": "https://plandex.ai/schemas/definitions/auto-modes.schema.json",+ "title": "Auto Mode Enum",+ "description": "Reusable enum for auto modes",+ "enum": [+ "full",+ "semi",+ "plus",+ "basic",+ "none",+ "custom"+ ]+}\ No newline at end of filediff --git a/app/shared/json-schemas/definitions/model-providers.schema.json b/app/shared/json-schemas/definitions/model-providers.schema.jsonnew file mode 100644index 00000000..6d71f2d0--- /dev/null+++ b/app/shared/json-schemas/definitions/model-providers.schema.json@@ -0,0 +1,17 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "$id": "https://plandex.ai/schemas/definitions/model-providers.schema.json",+ "title": "Model Provider Enum",+ "description": "Reusable enum for model providers",+ "enum": [+ "openrouter",+ "openai",+ "anthropic",+ "google-ai-studio",+ "google-vertex",+ "azure-openai",+ "deepseek",+ "perplexity",+ "custom"+ ]+}\ No newline at end of filediff --git a/app/shared/json-schemas/definitions/model-roles.schema.json b/app/shared/json-schemas/definitions/model-roles.schema.jsonnew file mode 100644index 00000000..84ae3844--- /dev/null+++ b/app/shared/json-schemas/definitions/model-roles.schema.json@@ -0,0 +1,17 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "$id": "https://plandex.ai/schemas/definitions/model-roles.schema.json",+ "title": "Model Role Enum",+ "description": "Reusable enum for model roles",+ "enum": [+ "planner",+ "coder",+ "architect",+ "summarizer",+ "builder",+ "whole-file-builder",+ "names",+ "commit-messages",+ "auto-continue"+ ]+}\ No newline at end of filediff --git a/app/shared/json-schemas/model-config.schema.json b/app/shared/json-schemas/model-config.schema.jsonnew file mode 100644index 00000000..1a779c99--- /dev/null+++ b/app/shared/json-schemas/model-config.schema.json@@ -0,0 +1,88 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "$id": "https://plandex.ai/schemas/model-config.schema.json",+ "title": "Model Config",+ "description": "Config for a model",+ "type": "object",+ "properties": {+ "schemaVersion": {+ "type": "string",+ "const": "2025-05-01"+ },+ "modelTag": {+ "type": "string"+ },+ "description": {+ "type": "string"+ },+ "defaultMaxConvoTokens": {+ "type": "number"+ },+ "maxTokens": {+ "type": "number"+ },+ "maxOutputTokens": {+ "type": "number"+ },+ "reservedOutputTokens": {+ "type": "number"+ },+ "preferredModelOutputFormat": {+ "type": "string",+ "enum": [+ "xml",+ "tool-call-json"+ ]+ },+ "systemPromptDisabled": {+ "type": "boolean"+ },+ "roleParamsDisabled": {+ "type": "boolean"+ },+ "stopDisabled": {+ "type": "boolean"+ },+ "predictedOutputEnabled": {+ "type": "boolean"+ },+ "reasoningEffortEnabled": {+ "type": "boolean"+ },+ "reasoningEffort": {+ "type": "string",+ "enum": [+ "low",+ "medium",+ "high"+ ]+ },+ "supportsCacheControl": {+ "type": "boolean"+ },+ "singleMessageNoSystemPrompt": {+ "type": "boolean"+ },+ "tokenEstimatePaddingPct": {+ "type": "number"+ },+ "providers": {+ "type": "array",+ "items": {+ "type": "object",+ "$ref": "./model-provider-config.schema.json",+ "minItems": 1+ }+ }+ },+ "required": [+ "schemaVersion",+ "modelTag",+ "description",+ "maxTokens",+ "maxOutputTokens",+ "reservedOutputTokens",+ "preferredModelOutputFormat",+ "providers"+ ]+}\ No newline at end of filediff --git a/app/shared/json-schemas/model-pack-config.schema.json b/app/shared/json-schemas/model-pack-config.schema.jsonnew file mode 100644index 00000000..643e873c--- /dev/null+++ b/app/shared/json-schemas/model-pack-config.schema.json@@ -0,0 +1,13 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "$id": "https://plandex.ai/schemas/model-pack-config.schema.json",+ "title": "Model Pack Config",+ "description": "Config for a model pack",+ "type": "object",+ "properties": {+ "schemaVersion": {+ "type": "string",+ "const": "2025-05-01"+ }+ }+}\ No newline at end of filediff --git a/app/shared/json-schemas/model-provider-config.schema.json b/app/shared/json-schemas/model-provider-config.schema.jsonnew file mode 100644index 00000000..7957cb3a--- /dev/null+++ b/app/shared/json-schemas/model-provider-config.schema.json@@ -0,0 +1,126 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "$id": "https://plandex.ai/schemas/model-provider-config.schema.json",+ "title": "Model Provider Config",+ "description": "Config for a model provider",+ "type": "object",+ "properties": {+ "schemaVersion": {+ "type": "string",+ "const": "2025-05-01"+ },+ "provider": {+ "$ref": "./definitions/model-providers.schema.json"+ },+ "customProvider": {+ "type": "string"+ },+ "baseUrl": {+ "type": "string"+ },+ "skipAuth": {+ "type": "boolean",+ "default": false+ },+ "apiKeyEnvVar": {+ "type": "string"+ },+ "extraAuthVars": {+ "type": "array",+ "items": {+ "type": "object",+ "properties": {+ "var": {+ "type": "string"+ },+ "isFilePath": {+ "type": "boolean"+ },+ "required": {+ "type": "boolean"+ }+ },+ "required": [+ "var"+ ]+ },+ "minItems": 1+ }+ },+ "required": [+ "schemaVersion",+ "provider",+ "baseUrl"+ ],+ "allOf": [+ {+ "if": {+ "properties": {+ "provider": {+ "const": "custom"+ }+ }+ },+ "then": {+ "required": [+ "customProvider"+ ]+ },+ "else": {+ "not": {+ "required": [+ "customProvider"+ ]+ }+ }+ },+ {+ "if": {+ "properties": {+ "skipAuth": {+ "const": false+ }+ }+ },+ "then": {+ "anyOf": [+ {+ "required": [+ "apiKeyEnvVar"+ ]+ },+ {+ "required": [+ "extraAuthVars"+ ]+ }+ ]+ }+ },+ {+ "if": {+ "properties": {+ "skipAuth": {+ "const": true+ }+ }+ },+ "then": {+ "not": {+ "anyOf": [+ {+ "required": [+ "apiKeyEnvVar"+ ]+ },+ {+ "required": [+ "extraAuthVars"+ ]+ }+ ]+ }+ }+ }+ ]+}\ No newline at end of filediff --git a/app/shared/json-schemas/model-role-config.schema.json b/app/shared/json-schemas/model-role-config.schema.jsonnew file mode 100644index 00000000..95054ba3--- /dev/null+++ b/app/shared/json-schemas/model-role-config.schema.json@@ -0,0 +1,29 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "$id": "https://plandex.ai/schemas/model-role-config.schema.json",+ "title": "Model Role Config",+ "description": "Config for a defined model role within a model pack",+ "type": "object",+ "properties": {+ "schemaVersion": {+ "type": "string",+ "const": "2025-05-01"+ },+ "role": {+ "$ref": "./definitions/model-roles.schema.json"+ },+ "temperature": {+ "type": "number"+ },+ "topP": {+ "type": "number"+ },+ "reservedOutputTokens": {+ "type": "number"+ }+ },+ "required": [+ "schemaVersion",+ "role"+ ]+}\ No newline at end of filediff --git a/app/shared/json-schemas/plan-config.schema.json b/app/shared/json-schemas/plan-config.schema.jsonnew file mode 100644index 00000000..6b3a75fe--- /dev/null+++ b/app/shared/json-schemas/plan-config.schema.json@@ -0,0 +1,16 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "$id": "https://plandex.ai/schemas/plan-config.schema.json",+ "title": "Plan Config",+ "description": "Config for a plan",+ "type": "object",+ "properties": {+ "schemaVersion": {+ "type": "string",+ "const": "2025-05-01"+ },+ "autoMode": {+ "$ref": "./definitions/auto-modes.schema.json"+ }+ }+}\ No newline at end of file