@compilr-dev/agents 0.5.7 → 0.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/agent.d.ts CHANGED
@@ -151,6 +151,10 @@ export type AgentEvent = {
151
151
  type: 'iteration_limit_extended';
152
152
  newMaxIterations: number;
153
153
  addedIterations: number;
154
+ } | {
155
+ type: 'model_changed';
156
+ previousModel: string;
157
+ newModel: string;
154
158
  } | {
155
159
  type: 'llm_retry';
156
160
  attempt: number;
@@ -1128,6 +1132,17 @@ export declare class Agent {
1128
1132
  * Check if pins are enabled
1129
1133
  */
1130
1134
  hasPins(): boolean;
1135
+ /**
1136
+ * Get the current model ID for this agent.
1137
+ */
1138
+ getModel(): string;
1139
+ /**
1140
+ * Change the model for subsequent LLM calls. Same provider only.
1141
+ * Takes effect on the next chat() call, not mid-stream.
1142
+ *
1143
+ * @param modelId - The new model ID (e.g., 'claude-opus-4-20250514')
1144
+ */
1145
+ setModel(modelId: string): void;
1131
1146
  /** @deprecated Use addPin() instead */
1132
1147
  addAnchor(input: AnchorInput): Anchor | undefined;
1133
1148
  /** @deprecated Use getPin() instead */
package/dist/agent.js CHANGED
@@ -523,6 +523,27 @@ export class Agent {
523
523
  hasPins() {
524
524
  return this.pinManager !== undefined;
525
525
  }
526
+ // --- Model management -------------------------------------------------------
527
+ /**
528
+ * Get the current model ID for this agent.
529
+ */
530
+ getModel() {
531
+ return this.provider.getModel();
532
+ }
533
+ /**
534
+ * Change the model for subsequent LLM calls. Same provider only.
535
+ * Takes effect on the next chat() call, not mid-stream.
536
+ *
537
+ * @param modelId - The new model ID (e.g., 'claude-opus-4-20250514')
538
+ */
539
+ setModel(modelId) {
540
+ if (!modelId || typeof modelId !== 'string') {
541
+ throw new Error('modelId must be a non-empty string');
542
+ }
543
+ const previousModel = this.provider.getModel();
544
+ this.provider.setModel(modelId);
545
+ this.onEvent?.({ type: 'model_changed', previousModel, newModel: modelId });
546
+ }
526
547
  // --- Deprecated aliases (use pin methods instead) --------------------------
527
548
  /** @deprecated Use addPin() instead */
528
549
  addAnchor(input) {
@@ -72,13 +72,15 @@ export interface ClaudeProviderConfig {
72
72
  export declare class ClaudeProvider implements LLMProvider {
73
73
  readonly name = "claude";
74
74
  private readonly client;
75
- private readonly defaultModel;
75
+ private defaultModel;
76
76
  private readonly defaultMaxTokens;
77
77
  private readonly enablePromptCaching;
78
78
  private readonly enableTokenEfficientTools;
79
79
  private readonly enableExtendedContext;
80
80
  private readonly estimateTokensFn;
81
81
  constructor(config: ClaudeProviderConfig);
82
+ getModel(): string;
83
+ setModel(modelId: string): void;
82
84
  /**
83
85
  * Send messages and stream the response
84
86
  */
@@ -46,6 +46,12 @@ export class ClaudeProvider {
46
46
  this.estimateTokensFn =
47
47
  config.estimateTokens ?? ((s) => Math.ceil(s.length / 4));
48
48
  }
49
+ getModel() {
50
+ return this.defaultModel;
51
+ }
52
+ setModel(modelId) {
53
+ this.defaultModel = modelId;
54
+ }
49
55
  /**
50
56
  * Send messages and stream the response
51
57
  */
@@ -50,10 +50,12 @@ export interface GeminiNativeProviderConfig {
50
50
  export declare class GeminiNativeProvider implements LLMProvider {
51
51
  readonly name = "gemini";
52
52
  private readonly client;
53
- private readonly defaultModel;
53
+ private defaultModel;
54
54
  private readonly defaultMaxTokens;
55
55
  private readonly estimateTokensFn;
56
56
  constructor(config: GeminiNativeProviderConfig);
57
+ getModel(): string;
58
+ setModel(modelId: string): void;
57
59
  /**
58
60
  * Send messages and stream the response
59
61
  */
@@ -45,6 +45,12 @@ export class GeminiNativeProvider {
45
45
  this.estimateTokensFn =
46
46
  config.estimateTokens ?? ((s) => Math.ceil(s.length / 4));
47
47
  }
48
+ getModel() {
49
+ return this.defaultModel;
50
+ }
51
+ setModel(modelId) {
52
+ this.defaultModel = modelId;
53
+ }
48
54
  /**
49
55
  * Send messages and stream the response
50
56
  */
@@ -78,7 +78,10 @@ export declare class MockProvider implements LLMProvider {
78
78
  private readonly throwOnEmpty;
79
79
  private callCount;
80
80
  private readonly callHistory;
81
+ private mockModel;
81
82
  constructor(config?: MockProviderConfig);
83
+ getModel(): string;
84
+ setModel(modelId: string): void;
82
85
  /**
83
86
  * Add a response (text string or structured response with tool calls)
84
87
  */
@@ -38,10 +38,17 @@ export class MockProvider {
38
38
  throwOnEmpty;
39
39
  callCount = 0;
40
40
  callHistory = [];
41
+ mockModel = 'mock-model';
41
42
  constructor(config = {}) {
42
43
  this.defaultDelay = config.defaultDelay ?? 0;
43
44
  this.throwOnEmpty = config.throwOnEmpty ?? true;
44
45
  }
46
+ getModel() {
47
+ return this.mockModel;
48
+ }
49
+ setModel(modelId) {
50
+ this.mockModel = modelId;
51
+ }
45
52
  /**
46
53
  * Add a response (text string or structured response with tool calls)
47
54
  */
@@ -121,11 +121,13 @@ export declare abstract class OpenAICompatibleProvider implements LLMProvider {
121
121
  */
122
122
  abstract readonly name: string;
123
123
  protected readonly baseUrl: string;
124
- protected readonly defaultModel: string;
124
+ protected defaultModel: string;
125
125
  protected readonly defaultMaxTokens: number;
126
126
  protected readonly timeout: number;
127
127
  protected readonly estimateTokensFn: (text: string) => number;
128
128
  constructor(config: OpenAICompatibleConfig);
129
+ getModel(): string;
130
+ setModel(modelId: string): void;
129
131
  /**
130
132
  * Get authentication headers for API requests
131
133
  * @returns Headers object with auth credentials
@@ -46,6 +46,12 @@ export class OpenAICompatibleProvider {
46
46
  this.estimateTokensFn =
47
47
  config.estimateTokens ?? ((s) => Math.ceil(s.length / 4));
48
48
  }
49
+ getModel() {
50
+ return this.defaultModel;
51
+ }
52
+ setModel(modelId) {
53
+ this.defaultModel = modelId;
54
+ }
49
55
  /**
50
56
  * Extract cache statistics from response headers.
51
57
  * Override in subclasses for providers that return cache stats in headers (e.g., Fireworks).
@@ -239,4 +239,15 @@ export interface LLMProvider {
239
239
  * Count tokens in messages (optional, provider-specific)
240
240
  */
241
241
  countTokens?(messages: Message[]): Promise<number>;
242
+ /**
243
+ * Get the current default model ID.
244
+ */
245
+ getModel(): string;
246
+ /**
247
+ * Change the default model for subsequent calls. Same provider only.
248
+ * Takes effect on the next chat() call, not mid-stream.
249
+ *
250
+ * @param modelId - The new model ID (e.g., 'claude-opus-4-20250514')
251
+ */
252
+ setModel(modelId: string): void;
242
253
  }
@@ -32,6 +32,8 @@ export declare class RateLimitedProvider implements LLMProvider {
32
32
  private readonly rateLimiter;
33
33
  private readonly retryConfig;
34
34
  constructor(provider: LLMProvider, config?: RateLimitRetryConfig);
35
+ getModel(): string;
36
+ setModel(modelId: string): void;
35
37
  /**
36
38
  * Get the rate limiter instance for statistics
37
39
  */
@@ -38,6 +38,12 @@ export class RateLimitedProvider {
38
38
  this.rateLimiter = config.rateLimit ? createRateLimiter(config.rateLimit) : createRateLimiter();
39
39
  this.retryConfig = config.retry ?? {};
40
40
  }
41
+ getModel() {
42
+ return this.provider.getModel();
43
+ }
44
+ setModel(modelId) {
45
+ this.provider.setModel(modelId);
46
+ }
41
47
  /**
42
48
  * Get the rate limiter instance for statistics
43
49
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compilr-dev/agents",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
4
4
  "description": "Lightweight multi-LLM agent library for building CLI AI assistants",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",