Skip to content

Commit d3f2bcc

Browse files
committed
refactor: improve type safety with stricter typing
Replace `any` with `unknown` in Logger interface and use type guard for object checks in cursor-event-mapper. Export CachedToolUse type for reuse in cursor-acp-agent.
1 parent 9d4e0ad commit d3f2bcc

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/cursor-acp-agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { randomUUID } from "node:crypto";
3232
import packageJson from "../package.json" with { type: "json" };
3333
import { CursorCliRunner } from "./cursor-cli-runner.js";
3434
import { CursorAuth, CursorAuthClient } from "./auth.js";
35-
import { mapCursorEventToAcp, RejectedToolCall } from "./cursor-event-mapper.js";
35+
import { CachedToolUse, mapCursorEventToAcp, RejectedToolCall } from "./cursor-event-mapper.js";
3636
import {
3737
availableSlashCommands,
3838
CustomSlashCommand,
@@ -567,7 +567,7 @@ export class CursorAcpAgent implements Agent {
567567
forceRetry: boolean,
568568
): Promise<PromptAttemptResult> {
569569
const rejectedToolCalls: RejectedToolCall[] = [];
570-
const toolUseCache: Record<string, { toolCallId: string; payload: any }> = {};
570+
const toolUseCache: Record<string, CachedToolUse> = {};
571571
const modeSettings = this.modeToRunnerOptions(session, forceRetry);
572572
const assistantTextChunks: string[] = [];
573573

src/cursor-event-mapper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
toolUpdateFromCursorToolResult,
1212
} from "./tools.js";
1313

14-
interface CachedToolUse {
14+
export interface CachedToolUse {
1515
toolCallId: string;
1616
payload: CursorToolPayload;
1717
}
@@ -63,10 +63,10 @@ function formatShellToolResponse(
6363

6464
function assistantTextChunks(event: CursorStreamEvent): string[] {
6565
const message = event.message;
66-
if (!message || typeof message !== "object") {
66+
if (!isObject(message)) {
6767
return [];
6868
}
69-
const content = (message as any).content;
69+
const content = message.content;
7070
if (!Array.isArray(content)) {
7171
return [];
7272
}

src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { Readable, Writable } from "node:stream";
22
import { WritableStream, ReadableStream } from "node:stream/web";
33

44
export interface Logger {
5-
log: (...args: any[]) => void;
6-
error: (...args: any[]) => void;
7-
warn?: (...args: any[]) => void;
8-
info?: (...args: any[]) => void;
5+
log: (...args: unknown[]) => void;
6+
error: (...args: unknown[]) => void;
7+
warn?: (...args: unknown[]) => void;
8+
info?: (...args: unknown[]) => void;
99
}
1010

1111
export function nodeToWebWritable(nodeStream: Writable): WritableStream<Uint8Array> {

0 commit comments

Comments
 (0)