@code-inspector/core 2.0.0-beta.5 → 2.0.0-beta.6
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/client.iife.js +1 -1
- package/dist/client.umd.js +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +62998 -62247
- package/package.json +3 -2
- package/types/client/ai.d.ts +1 -1
- package/types/server/ai-provider-claude.d.ts +3 -3
- package/types/server/ai-provider-codex.d.ts +12 -0
- package/types/server/ai.d.ts +15 -6
- package/types/shared/type.d.ts +196 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-inspector/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.6",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
"volar-service-pug": "^0.0.63"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@anthropic-ai/claude-agent-sdk": "^0.2.29"
|
|
67
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.29",
|
|
68
|
+
"@openai/codex-sdk": "^0.106.0"
|
|
68
69
|
},
|
|
69
70
|
"scripts": {
|
|
70
71
|
"dev": "vite",
|
package/types/client/ai.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ export declare const chatStyles: import("lit").CSSResult;
|
|
|
95
95
|
export interface StreamHandlers {
|
|
96
96
|
onText: (content: string) => void;
|
|
97
97
|
onToolStart: (toolId: string, toolName: string, index: number) => void;
|
|
98
|
-
onToolInput: (index: number, input: Record<string, any
|
|
98
|
+
onToolInput: (index: number, input: Record<string, any>, toolUseId?: string) => void;
|
|
99
99
|
onToolResult: (toolUseId: string, content: string, isError?: boolean) => void;
|
|
100
100
|
onError: (error: Error) => void;
|
|
101
101
|
onSessionId?: (sessionId: string) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ClaudeCodeOptions } from '../shared';
|
|
2
2
|
import type { AIContext, AIMessage } from './ai';
|
|
3
3
|
export interface ProviderCallbacks {
|
|
4
4
|
sendSSE: (data: object | string) => void;
|
|
@@ -11,9 +11,9 @@ export interface ProviderResult {
|
|
|
11
11
|
* 获取模型信息
|
|
12
12
|
* 优先使用用户配置,否则通过 CLI 的 system 事件获取(无 API 消耗)
|
|
13
13
|
*/
|
|
14
|
-
export declare function getModelInfo(aiOptions:
|
|
14
|
+
export declare function getModelInfo(aiOptions: ClaudeCodeOptions | undefined): Promise<string>;
|
|
15
15
|
/**
|
|
16
16
|
* Claude provider 统一入口
|
|
17
17
|
* ai.ts 只需调用此函数,不感知 CLI/SDK 细节
|
|
18
18
|
*/
|
|
19
|
-
export declare function handleClaudeRequest(message: string, context: AIContext | null, history: AIMessage[], sessionId: string | undefined, cwd: string, aiOptions:
|
|
19
|
+
export declare function handleClaudeRequest(message: string, context: AIContext | null, history: AIMessage[], sessionId: string | undefined, cwd: string, aiOptions: ClaudeCodeOptions | undefined, callbacks: ProviderCallbacks): ProviderResult;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CodexOptions } from '../shared';
|
|
2
|
+
import type { AIContext, AIMessage } from './ai';
|
|
3
|
+
import type { ProviderCallbacks, ProviderResult } from './ai-provider-claude';
|
|
4
|
+
/**
|
|
5
|
+
* 获取模型信息
|
|
6
|
+
* 优先使用用户配置(Codex 暂不通过额外请求探测模型)
|
|
7
|
+
*/
|
|
8
|
+
export declare function getModelInfo(codexOptions: CodexOptions | undefined): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Codex provider 统一入口
|
|
11
|
+
*/
|
|
12
|
+
export declare function handleCodexRequest(message: string, context: AIContext | null, history: AIMessage[], sessionId: string | undefined, cwd: string, codexOptions: CodexOptions | undefined, callbacks: ProviderCallbacks): ProviderResult;
|
package/types/server/ai.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 通过 provider 模式支持不同的 AI 后端
|
|
5
5
|
*/
|
|
6
6
|
import http from 'http';
|
|
7
|
-
import type {
|
|
7
|
+
import type { ClaudeCodeOptions, CodexOptions } from '../shared';
|
|
8
8
|
/**
|
|
9
9
|
* AI 上下文信息
|
|
10
10
|
*/
|
|
@@ -26,23 +26,32 @@ export interface AIMessage {
|
|
|
26
26
|
*/
|
|
27
27
|
export interface AIRequest {
|
|
28
28
|
message: string;
|
|
29
|
-
context: AIContext;
|
|
29
|
+
context: AIContext | null;
|
|
30
30
|
history: AIMessage[];
|
|
31
31
|
sessionId?: string;
|
|
32
32
|
}
|
|
33
|
+
export type AIProviderType = 'claudeCode' | 'codex';
|
|
34
|
+
export type ActiveAIOptions = {
|
|
35
|
+
provider: 'claudeCode';
|
|
36
|
+
options: ClaudeCodeOptions;
|
|
37
|
+
} | {
|
|
38
|
+
provider: 'codex';
|
|
39
|
+
options: CodexOptions;
|
|
40
|
+
};
|
|
33
41
|
/**
|
|
34
42
|
* 从 behavior 配置中提取 AI 选项
|
|
35
43
|
*/
|
|
36
44
|
export declare function getAIOptions(behavior?: {
|
|
37
45
|
ai?: {
|
|
38
|
-
claudeCode?: boolean |
|
|
46
|
+
claudeCode?: boolean | ClaudeCodeOptions;
|
|
47
|
+
codex?: boolean | CodexOptions;
|
|
39
48
|
};
|
|
40
|
-
}):
|
|
49
|
+
}): ActiveAIOptions | undefined;
|
|
41
50
|
/**
|
|
42
51
|
* 处理 AI 请求
|
|
43
52
|
*/
|
|
44
|
-
export declare function handleAIRequest(req: http.IncomingMessage, res: http.ServerResponse, corsHeaders: Record<string, string>, aiOptions:
|
|
53
|
+
export declare function handleAIRequest(req: http.IncomingMessage, res: http.ServerResponse, corsHeaders: Record<string, string>, aiOptions: ActiveAIOptions | undefined, projectRootPath: string): Promise<void>;
|
|
45
54
|
/**
|
|
46
55
|
* 处理 AI 模型信息请求
|
|
47
56
|
*/
|
|
48
|
-
export declare function handleAIModelRequest(res: http.ServerResponse, corsHeaders: Record<string, string>, aiOptions:
|
|
57
|
+
export declare function handleAIModelRequest(res: http.ServerResponse, corsHeaders: Record<string, string>, aiOptions: ActiveAIOptions | undefined): Promise<void>;
|
package/types/shared/type.d.ts
CHANGED
|
@@ -2,55 +2,210 @@
|
|
|
2
2
|
import { Server } from 'http';
|
|
3
3
|
import type { Editor } from 'launch-ide';
|
|
4
4
|
export type HotKey = 'ctrlKey' | 'altKey' | 'metaKey' | 'shiftKey';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @zh Claude Code CLI 配置项
|
|
7
|
+
* @en Claude Code CLI options
|
|
8
|
+
*/
|
|
9
|
+
export type ClaudeCliOptions = {
|
|
10
|
+
/** 允许自动执行的工具列表 */
|
|
11
|
+
allowedTools?: string[];
|
|
12
|
+
/** 禁止的工具列表 */
|
|
13
|
+
disallowedTools?: string[];
|
|
14
|
+
/** 使用的模型 */
|
|
15
|
+
model?: string;
|
|
16
|
+
/** 最大执行轮数,默认为 20 */
|
|
17
|
+
maxTurns?: number;
|
|
18
|
+
/**
|
|
19
|
+
* 权限模式。默认为 'bypassPermissions'
|
|
20
|
+
* - 'default' 需要用户确认
|
|
21
|
+
* - 'acceptEdits' 自动接受编辑
|
|
22
|
+
* - 'bypassPermissions' 绕过所有权限检查
|
|
23
|
+
*/
|
|
24
|
+
permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions';
|
|
25
|
+
/** 系统提示 */
|
|
26
|
+
systemPrompt?: string | {
|
|
27
|
+
type: 'preset';
|
|
28
|
+
preset: 'claude_code';
|
|
29
|
+
append?: string;
|
|
30
|
+
};
|
|
31
|
+
/** 环境变量,传递给 Claude Code 进程。默认为 process.env */
|
|
32
|
+
env?: Record<string, string | undefined>;
|
|
33
|
+
/** MCP 服务器配置 */
|
|
34
|
+
mcpServers?: Record<string, any>;
|
|
35
|
+
/** CLI 最大成本(美元),等价于 `--max-cost` */
|
|
36
|
+
maxCost?: number;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* @zh Claude Code SDK 配置项
|
|
40
|
+
* @en Claude Code SDK options
|
|
41
|
+
*/
|
|
42
|
+
export type ClaudeSdkOptions = {
|
|
43
|
+
/** 允许自动执行的工具列表 */
|
|
44
|
+
allowedTools?: string[];
|
|
45
|
+
/** 禁止的工具列表 */
|
|
46
|
+
disallowedTools?: string[];
|
|
47
|
+
/** 使用的模型 */
|
|
48
|
+
model?: string;
|
|
49
|
+
/** 最大执行轮数,默认为 20 */
|
|
50
|
+
maxTurns?: number;
|
|
51
|
+
/**
|
|
52
|
+
* 权限模式。默认为 'bypassPermissions'
|
|
53
|
+
* - 'default' 需要用户确认
|
|
54
|
+
* - 'acceptEdits' 自动接受编辑
|
|
55
|
+
* - 'bypassPermissions' 绕过所有权限检查
|
|
56
|
+
*/
|
|
57
|
+
permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions';
|
|
58
|
+
/** 系统提示 */
|
|
59
|
+
systemPrompt?: string | {
|
|
60
|
+
type: 'preset';
|
|
61
|
+
preset: 'claude_code';
|
|
62
|
+
append?: string;
|
|
63
|
+
};
|
|
64
|
+
/** 环境变量,传递给 Claude Code 进程。默认为 process.env */
|
|
65
|
+
env?: Record<string, string | undefined>;
|
|
66
|
+
/** MCP 服务器配置 */
|
|
67
|
+
mcpServers?: Record<string, any>;
|
|
68
|
+
/** 最大思考 token 数 */
|
|
69
|
+
maxThinkingTokens?: number;
|
|
70
|
+
/** SDK 最大预算(美元) */
|
|
71
|
+
maxBudgetUsd?: number;
|
|
72
|
+
/** 当 permissionMode='bypassPermissions' 时需要显式开启 */
|
|
73
|
+
allowDangerouslySkipPermissions?: boolean;
|
|
74
|
+
/** 控制读取哪些 settings 文件。默认读取 user/project/local */
|
|
75
|
+
settingSources?: Array<'user' | 'project' | 'local'>;
|
|
76
|
+
/** 透传给 Claude CLI 的额外参数(key 不带 --,null 表示布尔 flag) */
|
|
77
|
+
extraArgs?: Record<string, string | null>;
|
|
78
|
+
};
|
|
79
|
+
export type ClaudeAgentOptions = ClaudeCliOptions | ClaudeSdkOptions;
|
|
80
|
+
export type ClaudeCodeOptions = {
|
|
81
|
+
/**
|
|
82
|
+
* @zh 指定使用的 Agent 类型。'cli' 使用本地 Claude Code CLI。默认为 'cli'
|
|
83
|
+
* @en Specify the agent type to use. 'cli' uses local Claude Code CLI. Defaults to 'cli'
|
|
84
|
+
*/
|
|
85
|
+
agent?: 'cli';
|
|
86
|
+
/**
|
|
87
|
+
* @zh CLI 模式参数
|
|
88
|
+
* @en CLI options
|
|
89
|
+
*/
|
|
90
|
+
options?: ClaudeCliOptions;
|
|
91
|
+
} | {
|
|
92
|
+
/**
|
|
93
|
+
* @zh 指定使用的 Agent 类型。'sdk' 使用 Claude Agent SDK
|
|
94
|
+
* @en Specify the agent type to use. 'sdk' uses Claude Agent SDK
|
|
95
|
+
*/
|
|
96
|
+
agent: 'sdk';
|
|
97
|
+
/**
|
|
98
|
+
* @zh SDK 模式参数
|
|
99
|
+
* @en SDK options
|
|
100
|
+
*/
|
|
101
|
+
options?: ClaudeSdkOptions;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* @zh Codex CLI 配置项
|
|
105
|
+
* @en Codex CLI options
|
|
106
|
+
*/
|
|
107
|
+
export type CodexCliOptions = {
|
|
108
|
+
/** 指定 Codex 模型,等价于 `codex exec -m` */
|
|
109
|
+
model?: string;
|
|
110
|
+
/** 指定 Codex profile,等价于 `codex exec -p` */
|
|
111
|
+
profile?: string;
|
|
112
|
+
/** 指定 sandbox 模式,等价于 `codex exec -s` */
|
|
113
|
+
sandbox?: 'read-only' | 'workspace-write' | 'danger-full-access';
|
|
114
|
+
/** 是否启用 `--full-auto` */
|
|
115
|
+
fullAuto?: boolean;
|
|
116
|
+
/** 是否启用 `--skip-git-repo-check` */
|
|
117
|
+
skipGitRepoCheck?: boolean;
|
|
118
|
+
/** 是否启用 `--ephemeral` */
|
|
119
|
+
ephemeral?: boolean;
|
|
120
|
+
/** 通过 `-c key=value` 透传给 codex cli 的配置 */
|
|
121
|
+
config?: Record<string, string | number | boolean>;
|
|
122
|
+
/** 环境变量,传递给 Codex CLI 进程 */
|
|
123
|
+
env?: Record<string, string | undefined>;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* @zh Codex SDK 配置项
|
|
127
|
+
* @en Codex SDK options
|
|
128
|
+
*/
|
|
129
|
+
export type CodexSdkOptions = {
|
|
130
|
+
/** 指定 Codex 模型 */
|
|
131
|
+
model?: string;
|
|
132
|
+
/** 指定 Codex profile */
|
|
133
|
+
profile?: string;
|
|
134
|
+
/** 透传 Codex 配置 */
|
|
135
|
+
config?: Record<string, string | number | boolean>;
|
|
136
|
+
/** 环境变量 */
|
|
137
|
+
env?: Record<string, string | undefined>;
|
|
138
|
+
/** 是否跳过 git 仓库检查 */
|
|
139
|
+
skipGitRepoCheck?: boolean;
|
|
140
|
+
/** Codex SDK 可执行路径覆盖,等价于 `new Codex({ codexPathOverride })` */
|
|
141
|
+
codexPathOverride?: string;
|
|
142
|
+
/** Codex SDK baseUrl,等价于 `new Codex({ baseUrl })` */
|
|
143
|
+
baseUrl?: string;
|
|
144
|
+
/** Codex SDK apiKey,等价于 `new Codex({ apiKey })` */
|
|
145
|
+
apiKey?: string;
|
|
146
|
+
/** SDK 线程沙箱模式,等价于 `startThread({ sandboxMode })` */
|
|
147
|
+
sandboxMode?: 'read-only' | 'workspace-write' | 'danger-full-access' | {
|
|
148
|
+
type: 'workspace-write';
|
|
149
|
+
writableRoots: string[];
|
|
150
|
+
networkAccess?: boolean;
|
|
151
|
+
excludeTmpdirEnvVar?: boolean;
|
|
152
|
+
} | {
|
|
153
|
+
type: 'danger-full-access';
|
|
154
|
+
networkAccess?: boolean;
|
|
155
|
+
excludeTmpdirEnvVar?: boolean;
|
|
156
|
+
};
|
|
157
|
+
/** SDK 线程工作目录(cwd),默认使用当前项目根目录 */
|
|
158
|
+
cwd?: string;
|
|
159
|
+
/** SDK 推理强度 */
|
|
160
|
+
modelReasoningEffort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
161
|
+
/** SDK web 搜索请求参数 */
|
|
162
|
+
webSearchRequest?: {
|
|
163
|
+
searchContextSize?: 'low' | 'medium' | 'high';
|
|
164
|
+
userLocation?: {
|
|
165
|
+
country?: string;
|
|
166
|
+
region?: string;
|
|
167
|
+
city?: string;
|
|
168
|
+
timezone?: string;
|
|
37
169
|
};
|
|
38
|
-
/** 环境变量,传递给 Claude Code 进程。默认为 process.env */
|
|
39
|
-
env?: Record<string, string | undefined>;
|
|
40
|
-
/** MCP 服务器配置 */
|
|
41
|
-
mcpServers?: Record<string, any>;
|
|
42
|
-
/** 最大思考 token 数 */
|
|
43
|
-
maxThinkingTokens?: number;
|
|
44
|
-
/** 最大预算(美元) */
|
|
45
|
-
maxBudgetUsd?: number;
|
|
46
170
|
};
|
|
171
|
+
/** SDK 是否启用 web 搜索 */
|
|
172
|
+
enableWebSearch?: boolean;
|
|
173
|
+
/** SDK 审批策略 */
|
|
174
|
+
approvalPolicy?: 'on-request' | 'on-failure' | 'never' | 'untrusted';
|
|
175
|
+
/** SDK 额外可写目录 */
|
|
176
|
+
additionalWritableRoots?: string[];
|
|
177
|
+
};
|
|
178
|
+
export type CodexAgentOptions = CodexCliOptions | CodexSdkOptions;
|
|
179
|
+
export type CodexOptions = {
|
|
180
|
+
/**
|
|
181
|
+
* @zh 指定使用的 Agent 类型。'cli' 使用本地 Codex CLI。默认为 'cli'
|
|
182
|
+
* @en Specify the agent type to use. 'cli' uses local Codex CLI. Defaults to 'cli'
|
|
183
|
+
*/
|
|
184
|
+
agent?: 'cli';
|
|
185
|
+
/**
|
|
186
|
+
* @zh CLI 模式参数
|
|
187
|
+
* @en CLI options
|
|
188
|
+
*/
|
|
189
|
+
options?: CodexCliOptions;
|
|
190
|
+
} | {
|
|
191
|
+
/**
|
|
192
|
+
* @zh 指定使用的 Agent 类型。'sdk' 使用 Codex SDK
|
|
193
|
+
* @en Specify the agent type to use. 'sdk' uses Codex SDK
|
|
194
|
+
*/
|
|
195
|
+
agent: 'sdk';
|
|
196
|
+
/**
|
|
197
|
+
* @zh SDK 模式参数
|
|
198
|
+
* @en SDK options
|
|
199
|
+
*/
|
|
200
|
+
options?: CodexSdkOptions;
|
|
47
201
|
};
|
|
48
202
|
export type Behavior = {
|
|
49
203
|
locate?: boolean;
|
|
50
204
|
copy?: boolean | string;
|
|
51
205
|
target?: string;
|
|
52
206
|
ai?: {
|
|
53
|
-
claudeCode?: boolean |
|
|
207
|
+
claudeCode?: boolean | ClaudeCodeOptions;
|
|
208
|
+
codex?: boolean | CodexOptions;
|
|
54
209
|
};
|
|
55
210
|
defaultAction?: 'copy' | 'locate' | 'target' | 'ai';
|
|
56
211
|
};
|