mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 01:34:22 +01:00
fix(TUI): fix agent types agents modal (#1942)
This commit is contained in:
@@ -13,6 +13,7 @@ export namespace Agent {
|
|||||||
name: z.string(),
|
name: z.string(),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
mode: z.union([z.literal("subagent"), z.literal("primary"), z.literal("all")]),
|
mode: z.union([z.literal("subagent"), z.literal("primary"), z.literal("all")]),
|
||||||
|
builtIn: z.boolean(),
|
||||||
topP: z.number().optional(),
|
topP: z.number().optional(),
|
||||||
temperature: z.number().optional(),
|
temperature: z.number().optional(),
|
||||||
permission: z.object({
|
permission: z.object({
|
||||||
@@ -58,6 +59,7 @@ export namespace Agent {
|
|||||||
options: {},
|
options: {},
|
||||||
permission: agentPermission,
|
permission: agentPermission,
|
||||||
mode: "subagent",
|
mode: "subagent",
|
||||||
|
builtIn: true,
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
name: "build",
|
name: "build",
|
||||||
@@ -65,6 +67,7 @@ export namespace Agent {
|
|||||||
options: {},
|
options: {},
|
||||||
permission: agentPermission,
|
permission: agentPermission,
|
||||||
mode: "primary",
|
mode: "primary",
|
||||||
|
builtIn: true,
|
||||||
},
|
},
|
||||||
plan: {
|
plan: {
|
||||||
name: "plan",
|
name: "plan",
|
||||||
@@ -76,6 +79,7 @@ export namespace Agent {
|
|||||||
patch: false,
|
patch: false,
|
||||||
},
|
},
|
||||||
mode: "primary",
|
mode: "primary",
|
||||||
|
builtIn: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for (const [key, value] of Object.entries(cfg.agent ?? {})) {
|
for (const [key, value] of Object.entries(cfg.agent ?? {})) {
|
||||||
@@ -91,6 +95,7 @@ export namespace Agent {
|
|||||||
permission: agentPermission,
|
permission: agentPermission,
|
||||||
options: {},
|
options: {},
|
||||||
tools: {},
|
tools: {},
|
||||||
|
builtIn: false,
|
||||||
}
|
}
|
||||||
const { model, prompt, tools, description, temperature, top_p, mode, permission, ...extra } = value
|
const { model, prompt, tools, description, temperature, top_p, mode, permission, ...extra } = value
|
||||||
item.options = {
|
item.options = {
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ func (r *AppService) Providers(ctx context.Context, opts ...option.RequestOption
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Agent struct {
|
type Agent struct {
|
||||||
|
BuiltIn bool `json:"builtIn,required"`
|
||||||
Mode AgentMode `json:"mode,required"`
|
Mode AgentMode `json:"mode,required"`
|
||||||
Name string `json:"name,required"`
|
Name string `json:"name,required"`
|
||||||
Options map[string]interface{} `json:"options,required"`
|
Options map[string]interface{} `json:"options,required"`
|
||||||
@@ -87,6 +88,7 @@ type Agent struct {
|
|||||||
|
|
||||||
// agentJSON contains the JSON metadata for the struct [Agent]
|
// agentJSON contains the JSON metadata for the struct [Agent]
|
||||||
type agentJSON struct {
|
type agentJSON struct {
|
||||||
|
BuiltIn apijson.Field
|
||||||
Mode apijson.Field
|
Mode apijson.Field
|
||||||
Name apijson.Field
|
Name apijson.Field
|
||||||
Options apijson.Field
|
Options apijson.Field
|
||||||
|
|||||||
@@ -76,20 +76,15 @@ func (a agentSelectItem) Render(
|
|||||||
|
|
||||||
agentName := a.displayName
|
agentName := a.displayName
|
||||||
|
|
||||||
// For user agents and subagents, show description; for built-in, show mode
|
// Determine if agent is built-in or custom using the agent's builtIn field
|
||||||
var displayText string
|
var displayText string
|
||||||
if a.description != "" && (a.mode == "all" || a.mode == "subagent") {
|
if a.agent.BuiltIn {
|
||||||
// User agent or subagent with description
|
displayText = "(built-in)"
|
||||||
|
} else {
|
||||||
|
if a.description != "" {
|
||||||
displayText = a.description
|
displayText = a.description
|
||||||
} else {
|
} else {
|
||||||
// Built-in without description - show mode
|
|
||||||
switch a.mode {
|
|
||||||
case "primary":
|
|
||||||
displayText = "(built-in)"
|
|
||||||
case "all":
|
|
||||||
displayText = "(user)"
|
displayText = "(user)"
|
||||||
default:
|
|
||||||
displayText = ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,23 +201,19 @@ func (a *agentDialog) calculateOptimalWidth(agents []agentSelectItem) int {
|
|||||||
for _, agent := range agents {
|
for _, agent := range agents {
|
||||||
// Calculate the width needed for this item: "AgentName - Description" (visual improvement)
|
// Calculate the width needed for this item: "AgentName - Description" (visual improvement)
|
||||||
itemWidth := len(agent.displayName)
|
itemWidth := len(agent.displayName)
|
||||||
if agent.description != "" && (agent.mode == "all" || agent.mode == "subagent") {
|
|
||||||
// User agent or subagent - use description (capped to maxDescriptionLength)
|
if agent.agent.BuiltIn {
|
||||||
|
itemWidth += len("(built-in)") + 3 // " - "
|
||||||
|
} else {
|
||||||
|
if agent.description != "" {
|
||||||
descLength := len(agent.description)
|
descLength := len(agent.description)
|
||||||
if descLength > maxDescriptionLength {
|
if descLength > maxDescriptionLength {
|
||||||
descLength = maxDescriptionLength
|
descLength = maxDescriptionLength
|
||||||
}
|
}
|
||||||
itemWidth += descLength + 3 // " - "
|
itemWidth += descLength + 3 // " - "
|
||||||
} else {
|
} else {
|
||||||
// Built-in without description - use mode
|
itemWidth += len("(user)") + 3 // " - "
|
||||||
var modeText string
|
|
||||||
switch agent.mode {
|
|
||||||
case "primary":
|
|
||||||
modeText = "(built-in)"
|
|
||||||
case "all":
|
|
||||||
modeText = "(user)"
|
|
||||||
}
|
}
|
||||||
itemWidth += len(modeText) + 3 // " - "
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if itemWidth > maxWidth {
|
if itemWidth > maxWidth {
|
||||||
|
|||||||
Reference in New Issue
Block a user