@compilr-dev/agents 0.5.6 → 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 +15 -0
- package/dist/agent.js +21 -0
- package/dist/index.d.ts +1 -1
- package/dist/permissions/index.d.ts +1 -1
- package/dist/permissions/manager.js +15 -10
- package/dist/permissions/types.d.ts +31 -4
- package/dist/providers/claude.d.ts +3 -1
- package/dist/providers/claude.js +6 -0
- package/dist/providers/gemini-native.d.ts +3 -1
- package/dist/providers/gemini-native.js +6 -0
- package/dist/providers/mock.d.ts +3 -0
- package/dist/providers/mock.js +7 -0
- package/dist/providers/openai-compatible.d.ts +3 -1
- package/dist/providers/openai-compatible.js +6 -0
- package/dist/providers/types.d.ts +11 -0
- package/dist/rate-limit/provider-wrapper.d.ts +2 -0
- package/dist/rate-limit/provider-wrapper.js +6 -0
- package/package.json +1 -1
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) {
|
package/dist/index.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export type { Guardrail, GuardrailInput, GuardrailAction, GuardrailResult, Guard
|
|
|
52
52
|
export { MCPClient, MCPManager, mcpToolToTool, mcpToolsToTools, convertMCPResult, contentBlocksToString, generateToolName, normalizeServerConfig, MCPError, MCPErrorCode, isMCPError, createSDKNotInstalledError, } from './mcp/index.js';
|
|
53
53
|
export type { MCPTransport, MCPConnectionStatus, MCPStdioOptions, MCPHttpOptions, MCPClientConfig, MCPServerConfig, MCPToolDefinition, MCPContentBlock, MCPToolResult, MCPClientEventType, MCPClientEvent, MCPClientEventHandler, MCPManagerOptions, MCPToolConversionOptions, } from './mcp/index.js';
|
|
54
54
|
export { PermissionManager } from './permissions/index.js';
|
|
55
|
-
export type { PermissionLevel, ToolPermission, PermissionRequest, PermissionCheckResult, PermissionHandler, PreviewGenerator, PermissionManagerOptions, PermissionEventType, PermissionEvent, PermissionEventHandler, } from './permissions/index.js';
|
|
55
|
+
export type { PermissionLevel, ToolPermission, PermissionRequest, PermissionCheckResult, PermissionHandler, PermissionHandlerResponse, PreviewGenerator, PermissionManagerOptions, PermissionEventType, PermissionEvent, PermissionEventHandler, } from './permissions/index.js';
|
|
56
56
|
export { ProjectMemoryLoader, createProjectMemoryLoader, loadProjectMemory, hasProjectMemory, getProviderPatterns, getSupportedProviders, getGenericPatterns, PROVIDER_PATTERNS, GENERIC_PATTERNS, } from './memory/index.js';
|
|
57
57
|
export type { LLMProviderName, MemoryFile, ProjectMemory, FilePattern, CombineStrategy, ProjectMemoryOptions, ProjectMemoryEventType, ProjectMemoryEvent, ProjectMemoryEventHandler, MemoryDiscoveryResult, ProviderPatterns, } from './memory/index.js';
|
|
58
58
|
export { UsageTracker, createUsageTracker } from './costs/index.js';
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Permissions module - Tool-level permission management
|
|
3
3
|
*/
|
|
4
4
|
export { PermissionManager } from './manager.js';
|
|
5
|
-
export type { PermissionLevel, ToolPermission, PermissionRequest, PermissionCheckResult, PermissionHandler, PreviewGenerator, PermissionManagerOptions, PermissionEventType, PermissionEvent, PermissionEventHandler, } from './types.js';
|
|
5
|
+
export type { PermissionLevel, ToolPermission, PermissionRequest, PermissionCheckResult, PermissionHandler, PermissionHandlerResponse, PreviewGenerator, PermissionManagerOptions, PermissionEventType, PermissionEvent, PermissionEventHandler, } from './types.js';
|
|
@@ -226,8 +226,8 @@ export class PermissionManager {
|
|
|
226
226
|
return { allowed: true, level, askedUser: false, rule };
|
|
227
227
|
}
|
|
228
228
|
// Ask for permission
|
|
229
|
-
const
|
|
230
|
-
if (allowed) {
|
|
229
|
+
const askResult = await this.askPermission(toolName, input, level, rule);
|
|
230
|
+
if (askResult.allowed) {
|
|
231
231
|
this.sessionGrants.add(toolName);
|
|
232
232
|
this.emit({ type: 'permission:session_granted', toolName, level, input, rule });
|
|
233
233
|
}
|
|
@@ -235,11 +235,11 @@ export class PermissionManager {
|
|
|
235
235
|
this.emit({ type: 'permission:denied', toolName, level, input, rule });
|
|
236
236
|
}
|
|
237
237
|
return {
|
|
238
|
-
allowed,
|
|
238
|
+
allowed: askResult.allowed,
|
|
239
239
|
level,
|
|
240
240
|
askedUser: true,
|
|
241
241
|
rule,
|
|
242
|
-
reason: allowed ? undefined : 'User denied permission',
|
|
242
|
+
reason: askResult.allowed ? undefined : (askResult.reason ?? 'User denied permission'),
|
|
243
243
|
};
|
|
244
244
|
}
|
|
245
245
|
case 'once': {
|
|
@@ -249,19 +249,19 @@ export class PermissionManager {
|
|
|
249
249
|
return { allowed: true, level, askedUser: false, rule };
|
|
250
250
|
}
|
|
251
251
|
// Ask for permission each time (unless session-granted above)
|
|
252
|
-
const
|
|
253
|
-
if (allowed) {
|
|
252
|
+
const askResult = await this.askPermission(toolName, input, level, rule);
|
|
253
|
+
if (askResult.allowed) {
|
|
254
254
|
this.emit({ type: 'permission:granted', toolName, level, input, rule });
|
|
255
255
|
}
|
|
256
256
|
else {
|
|
257
257
|
this.emit({ type: 'permission:denied', toolName, level, input, rule });
|
|
258
258
|
}
|
|
259
259
|
return {
|
|
260
|
-
allowed,
|
|
260
|
+
allowed: askResult.allowed,
|
|
261
261
|
level,
|
|
262
262
|
askedUser: true,
|
|
263
263
|
rule,
|
|
264
|
-
reason: allowed ? undefined : 'User denied permission',
|
|
264
|
+
reason: askResult.allowed ? undefined : (askResult.reason ?? 'User denied permission'),
|
|
265
265
|
};
|
|
266
266
|
}
|
|
267
267
|
}
|
|
@@ -281,7 +281,7 @@ export class PermissionManager {
|
|
|
281
281
|
async askPermission(toolName, input, level, rule) {
|
|
282
282
|
// If no handler, default to allow
|
|
283
283
|
if (!this.handler) {
|
|
284
|
-
return true;
|
|
284
|
+
return { allowed: true };
|
|
285
285
|
}
|
|
286
286
|
const preview = this.previewGenerator(toolName, input);
|
|
287
287
|
const request = {
|
|
@@ -292,7 +292,12 @@ export class PermissionManager {
|
|
|
292
292
|
preview,
|
|
293
293
|
};
|
|
294
294
|
this.emit({ type: 'permission:asked', toolName, level, input, rule });
|
|
295
|
-
|
|
295
|
+
const response = await this.handler(request);
|
|
296
|
+
// Normalize legacy boolean responses (backward compat)
|
|
297
|
+
if (typeof response === 'boolean') {
|
|
298
|
+
return { allowed: response };
|
|
299
|
+
}
|
|
300
|
+
return response;
|
|
296
301
|
}
|
|
297
302
|
/**
|
|
298
303
|
* Grant session-level permission for a tool
|
|
@@ -84,25 +84,52 @@ export interface PermissionCheckResult {
|
|
|
84
84
|
*/
|
|
85
85
|
reason?: string;
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Response shape from a permission handler.
|
|
89
|
+
*
|
|
90
|
+
* Either a plain boolean (legacy — backward compatible) OR a structured
|
|
91
|
+
* object that can carry an optional reason. The reason is delivered to
|
|
92
|
+
* the agent inline with the tool's permission-denied error so the agent
|
|
93
|
+
* sees the user's context immediately, in the same turn.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // Legacy (still supported):
|
|
98
|
+
* return true;
|
|
99
|
+
* return false;
|
|
100
|
+
*
|
|
101
|
+
* // With reason:
|
|
102
|
+
* return { allowed: false, reason: 'Use project_document_add instead' };
|
|
103
|
+
* return { allowed: true };
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export type PermissionHandlerResponse = boolean | {
|
|
107
|
+
allowed: boolean;
|
|
108
|
+
reason?: string;
|
|
109
|
+
};
|
|
87
110
|
/**
|
|
88
111
|
* Handler called when permission is needed
|
|
89
112
|
*
|
|
90
113
|
* @param request - Information about the permission request
|
|
91
|
-
* @returns true to allow
|
|
114
|
+
* @returns true to allow / false to deny — or { allowed, reason? } to
|
|
115
|
+
* carry context (especially useful when denying with a message)
|
|
92
116
|
*
|
|
93
117
|
* @example
|
|
94
118
|
* ```typescript
|
|
95
119
|
* const handler: PermissionHandler = async (request) => {
|
|
96
120
|
* // Show UI prompt to user
|
|
97
|
-
* const
|
|
121
|
+
* const result = await showConfirmDialog(
|
|
98
122
|
* `Allow ${request.toolName}?`,
|
|
99
123
|
* request.description
|
|
100
124
|
* );
|
|
101
|
-
*
|
|
125
|
+
* if (!result.allowed && result.message) {
|
|
126
|
+
* return { allowed: false, reason: result.message };
|
|
127
|
+
* }
|
|
128
|
+
* return result.allowed;
|
|
102
129
|
* };
|
|
103
130
|
* ```
|
|
104
131
|
*/
|
|
105
|
-
export type PermissionHandler = (request: PermissionRequest) =>
|
|
132
|
+
export type PermissionHandler = (request: PermissionRequest) => PermissionHandlerResponse | Promise<PermissionHandlerResponse>;
|
|
106
133
|
/**
|
|
107
134
|
* Preview generator for permission requests
|
|
108
135
|
*
|
|
@@ -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
|
|
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
|
*/
|
package/dist/providers/claude.js
CHANGED
|
@@ -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
|
|
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
|
*/
|
package/dist/providers/mock.d.ts
CHANGED
|
@@ -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
|
*/
|
package/dist/providers/mock.js
CHANGED
|
@@ -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
|
|
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
|
*/
|