Skip to content

Add setModel, getThinkingLevel, setThinkingLevel to ExtensionAPI #509

@badlogic

Description

@badlogic

Summary

Add three methods to ExtensionAPI to enable extensions to change model and thinking level at runtime. This unblocks implementing preset configurations (#347) as an extension rather than built-in.

Motivation

Issue #347 requests preset configurations. Analysis showed that an extension can already:

  • Read config files (Node.js fs)
  • Register CLI flags (--preset)
  • Change active tools (setActiveTools)
  • Append to system prompt (before_agent_start event)
  • Show UI selectors (ctx.ui.select)
  • Find models (ctx.modelRegistry.find)

But it cannot:

  • Set the current model
  • Get/set thinking level

Proposed API Additions

interface ExtensionAPI {
  // ... existing ...

  /** Set the current model. Returns false if model not found or no API key. */
  setModel(model: Model<any>): Promise<boolean>;

  /** Get current thinking level */
  getThinkingLevel(): ThinkingLevel;

  /** Set thinking level (clamped to model capabilities) */
  setThinkingLevel(level: ThinkingLevel): void;
}

Implementation

  1. types.ts - Add API methods and handler types
  2. loader.ts - Wire up handlers in loadExtension()
  3. runner.ts - Accept and distribute handlers in initialize()
  4. agent-session.ts - Provide actual implementations

TUI Reflection

The footer already reads model/thinking from session state on each render. No TUI changes needed.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions