@code-inspector/core
Advanced tools
| /** | ||
| * AI 模块 - 客户端 AI 聊天功能相关类型、模板和样式 | ||
| */ | ||
| import { TemplateResult } from 'lit'; | ||
| /** | ||
| * 设置项目根路径(用于将绝对路径转为相对路径) | ||
| */ | ||
| export declare function setProjectRoot(root: string): void; | ||
| /** | ||
| * 工具调用信息 | ||
| */ | ||
| export interface ToolCall { | ||
| id: string; | ||
| name: string; | ||
| input?: Record<string, any>; | ||
| result?: string; | ||
| isError?: boolean; | ||
| isComplete?: boolean; | ||
| } | ||
| /** | ||
| * 消息内容块 | ||
| */ | ||
| export interface ContentBlock { | ||
| type: 'text' | 'tool'; | ||
| content?: string; | ||
| tool?: ToolCall; | ||
| } | ||
| /** | ||
| * 聊天消息类型 | ||
| */ | ||
| export interface ChatMessage { | ||
| role: 'user' | 'assistant'; | ||
| content: string; | ||
| blocks?: ContentBlock[]; | ||
| } | ||
| /** | ||
| * 聊天上下文信息(当前选中的元素) | ||
| */ | ||
| export interface ChatContext { | ||
| file: string; | ||
| line: number; | ||
| column: number; | ||
| name: string; | ||
| } | ||
| /** | ||
| * 聊天状态接口 | ||
| */ | ||
| export interface ChatState { | ||
| showChatModal: boolean; | ||
| chatMessages: ChatMessage[]; | ||
| chatInput: string; | ||
| chatLoading: boolean; | ||
| chatContext: ChatContext | null; | ||
| currentTools: Map<string, ToolCall>; | ||
| chatTheme: 'light' | 'dark'; | ||
| turnStatus: 'idle' | 'running' | 'done' | 'interrupt'; | ||
| turnDuration: number; | ||
| isDragging: boolean; | ||
| chatModel: string; | ||
| } | ||
| /** | ||
| * 聊天功能处理器接口 | ||
| */ | ||
| export interface ChatHandlers { | ||
| closeChatModal: () => void; | ||
| clearChatMessages: () => void; | ||
| handleChatInput: (e: Event) => void; | ||
| handleChatKeyDown: (e: KeyboardEvent) => void; | ||
| sendChatMessage: () => void; | ||
| toggleTheme: () => void; | ||
| interruptChat: () => void; | ||
| handleDragStart: (e: MouseEvent) => void; | ||
| handleDragMove: (e: MouseEvent) => void; | ||
| handleDragEnd: () => void; | ||
| handleOverlayClick: () => void; | ||
| } | ||
| /** | ||
| * 更新聊天框位置(使用 floating-ui) | ||
| * @param referenceEl 参考元素(选中的 DOM 元素) | ||
| * @param floatingEl 浮动元素(聊天框) | ||
| * @returns cleanup 函数 | ||
| */ | ||
| export declare function updateChatModalPosition(referenceEl: HTMLElement | null, floatingEl: HTMLElement | null): (() => void) | null; | ||
| /** | ||
| * 渲染聊天框模板 | ||
| */ | ||
| export declare function renderChatModal(state: ChatState, handlers: ChatHandlers): TemplateResult; | ||
| /** | ||
| * 聊天框样式 - 命令行风格 | ||
| */ | ||
| export declare const chatStyles: import("lit").CSSResult; | ||
| /** | ||
| * 流式事件处理器 | ||
| */ | ||
| export interface StreamHandlers { | ||
| onText: (content: string) => void; | ||
| onToolStart: (toolId: string, toolName: string, index: number) => void; | ||
| onToolInput: (index: number, input: Record<string, any>) => void; | ||
| onToolResult: (toolUseId: string, content: string, isError?: boolean) => void; | ||
| onError: (error: Error) => void; | ||
| onSessionId?: (sessionId: string) => void; | ||
| onProjectRoot?: (cwd: string) => void; | ||
| onModel?: (model: string) => void; | ||
| } | ||
| /** | ||
| * 获取 AI 模型信息 | ||
| */ | ||
| export declare function fetchModelInfo(ip: string, port: number): Promise<string>; | ||
| /** | ||
| * 发送聊天消息到服务器 | ||
| */ | ||
| export declare function sendChatToServer(ip: string, port: number, message: string, context: ChatContext | null, history: ChatMessage[], handlers: StreamHandlers, signal?: AbortSignal, sessionId?: string | null): Promise<void>; |
| import type { AIOptions } from '../shared'; | ||
| import type { AIContext, AIMessage } from './ai'; | ||
| export interface ProviderCallbacks { | ||
| sendSSE: (data: object | string) => void; | ||
| onEnd: () => void; | ||
| } | ||
| export interface ProviderResult { | ||
| abort: () => void; | ||
| } | ||
| /** | ||
| * 获取模型信息 | ||
| * 优先使用用户配置,否则通过 CLI 的 system 事件获取(无 API 消耗) | ||
| */ | ||
| export declare function getModelInfo(aiOptions: AIOptions | undefined): Promise<string>; | ||
| /** | ||
| * Claude provider 统一入口 | ||
| * ai.ts 只需调用此函数,不感知 CLI/SDK 细节 | ||
| */ | ||
| export declare function handleClaudeRequest(message: string, context: AIContext | null, history: AIMessage[], sessionId: string | undefined, cwd: string, aiOptions: AIOptions | undefined, callbacks: ProviderCallbacks): ProviderResult; |
| /// <reference types="node" /> | ||
| /** | ||
| * AI 功能模块 - 处理与 AI Agent 的交互 | ||
| * 通过 provider 模式支持不同的 AI 后端 | ||
| */ | ||
| import http from 'http'; | ||
| import type { AIOptions } from '../shared'; | ||
| /** | ||
| * AI 上下文信息 | ||
| */ | ||
| export interface AIContext { | ||
| file: string; | ||
| line: number; | ||
| column: number; | ||
| name: string; | ||
| } | ||
| /** | ||
| * AI 消息 | ||
| */ | ||
| export interface AIMessage { | ||
| role: 'user' | 'assistant'; | ||
| content: string; | ||
| } | ||
| /** | ||
| * AI 请求体 | ||
| */ | ||
| export interface AIRequest { | ||
| message: string; | ||
| context: AIContext; | ||
| history: AIMessage[]; | ||
| sessionId?: string; | ||
| } | ||
| /** | ||
| * 从 behavior 配置中提取 AI 选项 | ||
| */ | ||
| export declare function getAIOptions(behavior?: { | ||
| ai?: { | ||
| claudeCode?: boolean | AIOptions; | ||
| }; | ||
| }): AIOptions | undefined; | ||
| /** | ||
| * 处理 AI 请求 | ||
| */ | ||
| export declare function handleAIRequest(req: http.IncomingMessage, res: http.ServerResponse, corsHeaders: Record<string, string>, aiOptions: AIOptions | undefined, projectRootPath: string): Promise<void>; | ||
| /** | ||
| * 处理 AI 模型信息请求 | ||
| */ | ||
| export declare function handleAIModelRequest(res: http.ServerResponse, corsHeaders: Record<string, string>, aiOptions: AIOptions | undefined): Promise<void>; |
| /** | ||
| * 浏览器环境 console 彩色输出工具 | ||
| * | ||
| * 使用方式类似 chalk,基于浏览器 console 的 %c 机制实现: | ||
| * @example | ||
| * ```ts | ||
| * // 单行输出 | ||
| * browserChalk.blue('[plugin]').green(' ready').log(); | ||
| * | ||
| * // 多行输出 | ||
| * browserChalk | ||
| * .blue('[plugin]') | ||
| * .line() | ||
| * .green('• line1') | ||
| * .line() | ||
| * .yellow('• line2') | ||
| * .log(); | ||
| * ``` | ||
| */ | ||
| interface ChainResult { | ||
| text: string; | ||
| styles: string[]; | ||
| } | ||
| export declare class BrowserChalkChain { | ||
| private parts; | ||
| push(text: string, style: string): this; | ||
| /** 换行 */ | ||
| line(): this; | ||
| /** 合并另一个 chain 的内容 */ | ||
| merge(other: BrowserChalkChain): this; | ||
| /** 构建最终的 text 和 styles 数组 */ | ||
| build(): ChainResult; | ||
| /** 直接 console.log 输出 */ | ||
| log(): void; | ||
| /** 直接 console.warn 输出 */ | ||
| warn(): void; | ||
| /** 直接 console.error 输出 */ | ||
| error(): void; | ||
| /** console.groupCollapsed 输出,label 为当前 chain 内容,fn 中输出 group 内容 */ | ||
| groupCollapsed(fn: () => void): void; | ||
| group(fn: () => void): void; | ||
| blue(t: string): this; | ||
| green(t: string): this; | ||
| yellow(t: string): this; | ||
| red(t: string): this; | ||
| gray(t: string): this; | ||
| text(t: string): this; | ||
| styled(t: string, css: string): this; | ||
| /** 无参数:给上一个 part 追加 bold;有参数:输出纯 bold 文本 */ | ||
| bold(t?: string): this; | ||
| style(style: string): this; | ||
| } | ||
| type ChalkFactory = { | ||
| [K in 'blue' | 'green' | 'yellow' | 'red' | 'gray' | 'text']: (t: string) => BrowserChalkChain; | ||
| } & { | ||
| bold: (t?: string) => BrowserChalkChain; | ||
| styled: (t: string, css: string) => BrowserChalkChain; | ||
| }; | ||
| export declare const browserChalk: ChalkFactory; | ||
| export {}; |
+7
-2
| { | ||
| "name": "@code-inspector/core", | ||
| "version": "1.4.2", | ||
| "version": "2.0.0-beta.1", | ||
| "main": "dist/index.js", | ||
@@ -44,3 +44,4 @@ "module": "./dist/index.mjs", | ||
| "dotenv": "^16.1.4", | ||
| "launch-ide": "1.4.0", | ||
| "launch-ide": "1.4.2", | ||
| "marked": "^17.0.1", | ||
| "portfinder": "^1.0.28" | ||
@@ -53,2 +54,3 @@ }, | ||
| "@babel/plugin-transform-typescript": "^7.21.3", | ||
| "@floating-ui/dom": "^1.7.5", | ||
| "@types/node": "^18.14.1", | ||
@@ -66,2 +68,5 @@ "@vue/babel-plugin-jsx": "^1.1.1", | ||
| }, | ||
| "optionalDependencies": { | ||
| "@anthropic-ai/claude-agent-sdk": "^0.2.29" | ||
| }, | ||
| "scripts": { | ||
@@ -68,0 +73,0 @@ "dev": "vite", |
| import { LitElement, TemplateResult } from 'lit'; | ||
| import { ChatMessage, ChatContext, ToolCall } from './ai'; | ||
| interface Position { | ||
@@ -45,8 +46,10 @@ left?: string; | ||
| locate: boolean; | ||
| copy: boolean | string; | ||
| copy: boolean | undefined | string; | ||
| target: string; | ||
| targetNode: HTMLElement | null; | ||
| ip: string; | ||
| ai: boolean; | ||
| private wheelThrottling; | ||
| modeKey: string; | ||
| defaultAction: string; | ||
| position: { | ||
@@ -105,2 +108,24 @@ top: number; | ||
| internalTarget: boolean; | ||
| internalAI: boolean; | ||
| showChatModal: boolean; | ||
| chatMessages: ChatMessage[]; | ||
| chatInput: string; | ||
| chatLoading: boolean; | ||
| chatContext: ChatContext | null; | ||
| currentTools: Map<string, ToolCall>; | ||
| chatSessionId: string | null; | ||
| chatTheme: 'light' | 'dark'; | ||
| turnStatus: 'idle' | 'running' | 'done' | 'interrupt'; | ||
| turnDuration: number; | ||
| chatModel: string; | ||
| private chatAbortController; | ||
| private turnTimerInterval; | ||
| private turnStartTime; | ||
| isDragging: boolean; | ||
| private dragStartX; | ||
| private dragStartY; | ||
| private modalStartX; | ||
| private modalStartY; | ||
| private wasDragging; | ||
| private chatPositionCleanup; | ||
| inspectorSwitchRef: HTMLDivElement; | ||
@@ -117,2 +142,6 @@ codeInspectorContainerRef: HTMLDivElement; | ||
| onChange: () => void; | ||
| action: string; | ||
| fn: () => void; | ||
| key: number; | ||
| available: () => boolean; | ||
| }[]; | ||
@@ -153,2 +182,6 @@ private eventListeners; | ||
| buildTargetUrl: () => string; | ||
| locateCode: () => void; | ||
| copyCode: () => void; | ||
| targetCode: () => void; | ||
| dispatchCustomEvent: (action: 'locate' | 'copy' | 'target' | 'chat' | string) => void; | ||
| trackCode: () => void; | ||
@@ -185,5 +218,23 @@ private handleModeShortcut; | ||
| closeSettingsModal: () => void; | ||
| private clearAllActions; | ||
| toggleLocate: () => void; | ||
| toggleCopy: () => void; | ||
| toggleTarget: () => void; | ||
| toggleAICode: () => void; | ||
| openChatModal: () => void; | ||
| closeChatModal: () => void; | ||
| clearChatMessages: () => void; | ||
| toggleTheme: () => void; | ||
| handleChatInput: (e: Event) => void; | ||
| handleChatKeyDown: (e: KeyboardEvent) => void; | ||
| private scrollPending; | ||
| private scrollChatToBottom; | ||
| private startTurnTimer; | ||
| private stopTurnTimer; | ||
| interruptChat: () => void; | ||
| handleChatDragStart: (e: MouseEvent) => void; | ||
| handleChatDragMove: (e: MouseEvent) => void; | ||
| handleChatDragEnd: () => void; | ||
| handleOverlayClick: () => void; | ||
| sendChatMessage: () => Promise<void>; | ||
| /** | ||
@@ -201,4 +252,4 @@ * Attach all event listeners | ||
| render(): TemplateResult<1>; | ||
| static styles: import("lit").CSSResult; | ||
| static styles: import("lit").CSSResult[]; | ||
| } | ||
| export {}; |
| /// <reference types="node" /> | ||
| /** | ||
| * 本地服务器模块 - 处理 IDE 打开和 AI 请求 | ||
| */ | ||
| import http from 'http'; | ||
| import type { PathType, CodeOptions, RecordInfo } from '../shared'; | ||
| import type { CodeOptions, RecordInfo } from '../shared'; | ||
| export declare function getEnvVars(): Record<string, string>; | ||
| /** 项目根目录 */ | ||
| export declare const ProjectRootPath: string; | ||
| /** | ||
| * 获取相对路径 | ||
| */ | ||
| export declare function getRelativePath(filePath: string): string; | ||
| export declare function getRelativeOrAbsolutePath(filePath: string, pathType?: PathType): string; | ||
| export declare function createServer(callback: (port: number) => any, options?: CodeOptions, record?: RecordInfo): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>; | ||
| /** | ||
| * 根据用户配置返回绝对路径或者相对路径 | ||
| */ | ||
| export declare function getRelativeOrAbsolutePath(filePath: string, pathType?: 'relative' | 'absolute'): string; | ||
| /** | ||
| * 创建 HTTP 服务器 | ||
| */ | ||
| export declare function createServer(callback: (port: number) => void, options?: CodeOptions, record?: RecordInfo): http.Server; | ||
| /** | ||
| * 启动服务器 | ||
| */ | ||
| export declare function startServer(options: CodeOptions, record: RecordInfo): Promise<void>; |
@@ -5,2 +5,45 @@ /// <reference types="node" /> | ||
| export type HotKey = 'ctrlKey' | 'altKey' | 'metaKey' | 'shiftKey'; | ||
| export type AIOptions = { | ||
| /** | ||
| * @zh 指定使用的 Agent 类型。'cli' 使用本地 Claude Code CLI,'sdk' 使用 Claude Agent SDK。默认为 'cli' | ||
| * @en Specify the agent type to use. 'cli' uses local Claude Code CLI, 'sdk' uses Claude Agent SDK. Defaults to 'cli' | ||
| */ | ||
| agent?: 'cli' | 'sdk'; | ||
| /** | ||
| * @zh SDK 选项,参数格式继承 @anthropic-ai/claude-agent-sdk 官方 SDK 的 Options 类型 | ||
| * @en SDK options, parameter format follows the official @anthropic-ai/claude-agent-sdk Options type | ||
| * @see https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk | ||
| */ | ||
| sdkOptions?: { | ||
| /** 允许自动执行的工具列表 */ | ||
| allowedTools?: string[]; | ||
| /** 禁止的工具列表 */ | ||
| disallowedTools?: string[]; | ||
| /** 使用的模型 */ | ||
| model?: string; | ||
| /** 最大执行轮数,默认为 20 */ | ||
| maxTurns?: number; | ||
| /** | ||
| * 权限模式。默认为 'bypassPermissions' | ||
| * - 'default' 需要用户确认 | ||
| * - 'acceptEdits' 自动接受编辑 | ||
| * - 'bypassPermissions' 绕过所有权限检查 | ||
| */ | ||
| permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions'; | ||
| /** 系统提示 */ | ||
| systemPrompt?: string | { | ||
| type: 'preset'; | ||
| preset: 'claude_code'; | ||
| append?: string; | ||
| }; | ||
| /** 环境变量,传递给 Claude Code 进程。默认为 process.env */ | ||
| env?: Record<string, string | undefined>; | ||
| /** MCP 服务器配置 */ | ||
| mcpServers?: Record<string, any>; | ||
| /** 最大思考 token 数 */ | ||
| maxThinkingTokens?: number; | ||
| /** 最大预算(美元) */ | ||
| maxBudgetUsd?: number; | ||
| }; | ||
| }; | ||
| export type Behavior = { | ||
@@ -10,3 +53,6 @@ locate?: boolean; | ||
| target?: string; | ||
| defaultAction?: 'copy' | 'locate' | 'target' | 'all'; | ||
| ai?: { | ||
| claudeCode?: boolean | AIOptions; | ||
| }; | ||
| defaultAction?: 'copy' | 'locate' | 'target' | 'ai'; | ||
| }; | ||
@@ -13,0 +59,0 @@ export type RecordInfo = { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
12331707
0.09%26
18.18%3585
10.92%7
40%16
6.67%3
50%33
3.13%3
50%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
Updated