advisor.ts
commands/advisor.ts
110
Lines
3182
Bytes
0
Exports
6
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file lives in the command layer. It likely turns a user action into concrete program behavior.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with commands, planner-verifier-agents. It contains 110 lines, 6 detected imports, and 0 detected exports.
Important relationships
Detected exports
- No clear exports detected.
Keywords
advisormodeladvisormodeltextcontextcurrentnormalizedmodelbasemodelresolvedmodelutils
Detected imports
../commands.js../types/command.js../utils/advisor.js../utils/model/model.js../utils/model/validateModel.js../utils/settings/settings.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
import type { Command } from '../commands.js'
import type { LocalCommandCall } from '../types/command.js'
import {
canUserConfigureAdvisor,
isValidAdvisorModel,
modelSupportsAdvisor,
} from '../utils/advisor.js'
import {
getDefaultMainLoopModelSetting,
normalizeModelStringForAPI,
parseUserSpecifiedModel,
} from '../utils/model/model.js'
import { validateModel } from '../utils/model/validateModel.js'
import { updateSettingsForSource } from '../utils/settings/settings.js'
const call: LocalCommandCall = async (args, context) => {
const arg = args.trim().toLowerCase()
const baseModel = parseUserSpecifiedModel(
context.getAppState().mainLoopModel ?? getDefaultMainLoopModelSetting(),
)
if (!arg) {
const current = context.getAppState().advisorModel
if (!current) {
return {
type: 'text',
value:
'Advisor: not set\nUse "/advisor <model>" to enable (e.g. "/advisor opus").',
}
}
if (!modelSupportsAdvisor(baseModel)) {
return {
type: 'text',
value: `Advisor: ${current} (inactive)\nThe current model (${baseModel}) does not support advisors.`,
}
}
return {
type: 'text',
value: `Advisor: ${current}\nUse "/advisor unset" to disable or "/advisor <model>" to change.`,
}
}
if (arg === 'unset' || arg === 'off') {
const prev = context.getAppState().advisorModel
context.setAppState(s => {
if (s.advisorModel === undefined) return s
return { ...s, advisorModel: undefined }
})
updateSettingsForSource('userSettings', { advisorModel: undefined })
return {
type: 'text',
value: prev
? `Advisor disabled (was ${prev}).`
: 'Advisor already unset.',
}
}
const normalizedModel = normalizeModelStringForAPI(arg)
const resolvedModel = parseUserSpecifiedModel(arg)
const { valid, error } = await validateModel(resolvedModel)
if (!valid) {
return {
type: 'text',
value: error
? `Invalid advisor model: ${error}`
: `Unknown model: ${arg} (${resolvedModel})`,
}
}
if (!isValidAdvisorModel(resolvedModel)) {
return {
type: 'text',
value: `The model ${arg} (${resolvedModel}) cannot be used as an advisor`,
}
}
context.setAppState(s => {
if (s.advisorModel === normalizedModel) return s
return { ...s, advisorModel: normalizedModel }
})
updateSettingsForSource('userSettings', { advisorModel: normalizedModel })
if (!modelSupportsAdvisor(baseModel)) {
return {
type: 'text',
value: `Advisor set to ${normalizedModel}.\nNote: Your current model (${baseModel}) does not support advisors. Switch to a supported model to use the advisor.`,
}
}
return {
type: 'text',
value: `Advisor set to ${normalizedModel}.`,
}
}
const advisor = {
type: 'local',
name: 'advisor',
description: 'Configure the advisor model',
argumentHint: '[<model>|off]',
isEnabled: () => canUserConfigureAdvisor(),
get isHidden() {
return !canUserConfigureAdvisor()
},
supportsNonInteractive: true,
load: () => Promise.resolve({ call }),
} satisfies Command
export default advisor