chore(lint): reduce warning debt across core adapters and model clients
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { ModelClient, Message, ChatRequest, ChatResponse, ModelToolCall, TokenUsage } from '../../models/types.js';
|
||||
import type { ModelClient, Message, ChatRequest, ChatResponse, TokenUsage } from '../../models/types.js';
|
||||
import type { ModelRouter, ModelTier } from '../../models/router.js';
|
||||
import type { Session } from '../../session/index.js';
|
||||
import type { ToolRegistry } from '../../tools/registry.js';
|
||||
@@ -8,7 +8,7 @@ import type { ToolPolicyContext } from '../../tools/policy.js';
|
||||
import { auditLogger } from '../../audit/index.js';
|
||||
import type { Attachment } from '../../channels/types.js';
|
||||
import type { OutboundAttachmentCollector } from './attachments.js';
|
||||
import { buildUserMessage, getMessageText } from '../../models/media.js';
|
||||
import { buildUserMessage } from '../../models/media.js';
|
||||
|
||||
export interface ToolUseEvent {
|
||||
type: 'start' | 'end';
|
||||
@@ -142,7 +142,12 @@ export class NativeAgent {
|
||||
}
|
||||
|
||||
private async toolLoop(): Promise<string> {
|
||||
const tools = this.toolRegistry!.filteredToAnthropicFormat(this._toolPolicyContext);
|
||||
const toolRegistry = this.toolRegistry;
|
||||
const toolExecutor = this.toolExecutor;
|
||||
if (!toolRegistry || !toolExecutor) {
|
||||
throw new Error('Tool loop requires tool registry and executor');
|
||||
}
|
||||
const tools = toolRegistry.filteredToAnthropicFormat(this._toolPolicyContext);
|
||||
|
||||
// Track whether untrusted content (web/fetched/tool output) has been introduced
|
||||
// during this run. Used to harden against prompt injection.
|
||||
@@ -218,7 +223,10 @@ export class NativeAgent {
|
||||
}
|
||||
|
||||
// Safe to assert non-null — wantsToolUse guarantees toolCalls exists and is non-empty
|
||||
const toolCalls = response.toolCalls!;
|
||||
const toolCalls = response.toolCalls;
|
||||
if (!toolCalls || toolCalls.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for repeated tool calls — build a fingerprint from tool names + args
|
||||
const fingerprint = toolCalls
|
||||
@@ -264,7 +272,7 @@ export class NativeAgent {
|
||||
for (const tc of toolCalls) {
|
||||
this.throwIfCancelled();
|
||||
|
||||
const internalName = this.toolRegistry!.getByApiName(tc.name)?.name ?? tc.name;
|
||||
const internalName = toolRegistry.getByApiName(tc.name)?.name ?? tc.name;
|
||||
this.onToolUse?.({ type: 'start', tool: internalName, args: tc.args });
|
||||
|
||||
let elevationUntilMs: number | undefined;
|
||||
@@ -311,7 +319,7 @@ export class NativeAgent {
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const result = await this.toolExecutor!.execute(internalName, tc.args, perCallContext);
|
||||
const result = await toolExecutor.execute(internalName, tc.args, perCallContext);
|
||||
|
||||
this.onToolUse?.({ type: 'end', tool: internalName, result });
|
||||
|
||||
|
||||
@@ -5,11 +5,13 @@ import type { ChatResponse, ModelClient } from '../../models/types.js';
|
||||
import { ToolRegistry, ToolExecutor } from '../../tools/index.js';
|
||||
import { HookEngine } from '../../hooks/engine.js';
|
||||
import { MemoryStore } from '../../memory/store.js';
|
||||
import type { Session } from '../../session/index.js';
|
||||
import { mkdtempSync, rmSync } from 'fs';
|
||||
import { tmpdir } from 'os';
|
||||
import { join } from 'path';
|
||||
import { auditLogger, initAuditLogger } from '../../audit/index.js';
|
||||
import type { AuditLogger } from '../../audit/index.js';
|
||||
import type { Message } from '../../models/types.js';
|
||||
|
||||
describe('AgentOrchestrator', () => {
|
||||
let mockDefaultClient: ModelClient;
|
||||
@@ -468,7 +470,7 @@ describe('AgentOrchestrator', () => {
|
||||
fallbackChain: [],
|
||||
});
|
||||
|
||||
const history: any[] = [
|
||||
const history: Message[] = [
|
||||
{ role: 'user', content: 'u1' },
|
||||
{ role: 'assistant', content: 'a1' },
|
||||
{ role: 'user', content: 'u2' },
|
||||
@@ -476,19 +478,19 @@ describe('AgentOrchestrator', () => {
|
||||
{ role: 'user', content: 'u3' },
|
||||
{ role: 'assistant', content: 'a3' },
|
||||
];
|
||||
const session = {
|
||||
const session: Session = {
|
||||
id: 'session-compact-audit',
|
||||
addMessage: vi.fn((m: any) => { history.push(m); }),
|
||||
addMessage: vi.fn((m: Message) => { history.push(m); }),
|
||||
getHistory: vi.fn(() => [...history]),
|
||||
clear: vi.fn(() => { history.length = 0; }),
|
||||
replaceHistory: vi.fn((msgs: any[]) => {
|
||||
replaceHistory: vi.fn((msgs: Message[]) => {
|
||||
history.length = 0;
|
||||
history.push(...msgs);
|
||||
}),
|
||||
getConfig: vi.fn(() => undefined),
|
||||
setConfig: vi.fn(),
|
||||
deleteConfig: vi.fn(),
|
||||
} as any;
|
||||
};
|
||||
|
||||
const sessionCompact = vi.fn();
|
||||
const previousAuditLogger = auditLogger;
|
||||
@@ -717,27 +719,27 @@ describe('AgentOrchestrator', () => {
|
||||
});
|
||||
|
||||
// Minimal Session stub that supports rollback via replaceHistory().
|
||||
const history: any[] = [];
|
||||
const session = {
|
||||
const history: Message[] = [];
|
||||
const session: Session = {
|
||||
id: 'test',
|
||||
addMessage: vi.fn((m: any) => { history.push(m); }),
|
||||
addMessage: vi.fn((m: Message) => { history.push(m); }),
|
||||
getHistory: vi.fn(() => [...history]),
|
||||
clear: vi.fn(() => { history.length = 0; }),
|
||||
replaceHistory: vi.fn((msgs: any[]) => {
|
||||
replaceHistory: vi.fn((msgs: Message[]) => {
|
||||
history.length = 0;
|
||||
history.push(...msgs);
|
||||
}),
|
||||
getConfig: vi.fn(() => undefined),
|
||||
setConfig: vi.fn(),
|
||||
deleteConfig: vi.fn(),
|
||||
} as any;
|
||||
};
|
||||
|
||||
const registry = new ToolRegistry();
|
||||
registry.register({
|
||||
name: 'test.echo',
|
||||
description: 'echo',
|
||||
inputSchema: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },
|
||||
execute: async (args: any) => ({ success: true, output: String(args.text ?? '') }),
|
||||
execute: async (args: { text?: string }) => ({ success: true, output: String(args.text ?? '') }),
|
||||
});
|
||||
|
||||
const hooks = new HookEngine({ confirm: [], log: [], silent: [] });
|
||||
|
||||
Reference in New Issue
Block a user