@inspecto-dev/types 0.2.0-alpha.0
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/README.md +14 -0
- package/dist/index.cjs +54 -0
- package/dist/index.d.cts +308 -0
- package/dist/index.d.ts +308 -0
- package/dist/index.js +27 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @inspecto/types
|
|
2
|
+
|
|
3
|
+
`@inspecto/types` contains all shared TypeScript definitions for the Inspecto monorepo.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package serves as the single source of truth for all types and interfaces used across the Inspecto ecosystem, ensuring strict type safety between the build plugin, local server, browser client, and IDE extension.
|
|
8
|
+
|
|
9
|
+
## Core Implementation
|
|
10
|
+
|
|
11
|
+
- **Protocol Types**: Defines the request/response shapes for the local HTTP server (`OpenFileRequest`, `SnippetResponse`, `SendToAiRequest`).
|
|
12
|
+
- **Configuration Types**: Defines the user configuration structure (`InspectoUserConfig`, `UnpluginOptions`, `InspectorOptions`).
|
|
13
|
+
- **Domain Models**: Contains definitions for AI targets (`AiTool`), tool modes (`ToolMode`), and IDE types (`IdeType`).
|
|
14
|
+
- **Constants**: Provides shared constants like `DEFAULT_INTENTS` and tool mode mappings to keep behavior consistent across packages.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AI_TARGET_TYPE: () => AI_TARGET_TYPE,
|
|
24
|
+
DEFAULT_TOOL_MODE: () => DEFAULT_TOOL_MODE,
|
|
25
|
+
VALID_MODES: () => VALID_MODES
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var AI_TARGET_TYPE = {
|
|
29
|
+
"github-copilot": "plugin",
|
|
30
|
+
"claude-code": "plugin",
|
|
31
|
+
gemini: "plugin",
|
|
32
|
+
codex: "plugin",
|
|
33
|
+
coco: "cli"
|
|
34
|
+
};
|
|
35
|
+
var DEFAULT_TOOL_MODE = {
|
|
36
|
+
"github-copilot": "plugin",
|
|
37
|
+
"claude-code": "plugin",
|
|
38
|
+
gemini: "plugin",
|
|
39
|
+
codex: "plugin",
|
|
40
|
+
coco: "cli"
|
|
41
|
+
};
|
|
42
|
+
var VALID_MODES = {
|
|
43
|
+
"github-copilot": ["plugin"],
|
|
44
|
+
"claude-code": ["plugin", "cli"],
|
|
45
|
+
gemini: ["plugin", "cli"],
|
|
46
|
+
codex: ["plugin", "cli"],
|
|
47
|
+
coco: ["cli"]
|
|
48
|
+
};
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
AI_TARGET_TYPE,
|
|
52
|
+
DEFAULT_TOOL_MODE,
|
|
53
|
+
VALID_MODES
|
|
54
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/** Modifier keys that can be used as inspector activation hotkeys */
|
|
2
|
+
type HotKey = 'ctrlKey' | 'altKey' | 'metaKey' | 'shiftKey';
|
|
3
|
+
/**
|
|
4
|
+
* Hotkey configuration.
|
|
5
|
+
* - Array of HotKey: all specified keys must be held simultaneously to activate
|
|
6
|
+
* - false: disable hotkey activation entirely (use programmatic toggle only)
|
|
7
|
+
* @default ['altKey']
|
|
8
|
+
* @example ['ctrlKey', 'shiftKey'] — Ctrl+Shift to activate
|
|
9
|
+
*/
|
|
10
|
+
type HotKeys = HotKey[] | false;
|
|
11
|
+
/** Parsed source location from the data-inspecto attribute */
|
|
12
|
+
interface SourceLocation {
|
|
13
|
+
/** Absolute or relative file path depending on pathType config */
|
|
14
|
+
file: string;
|
|
15
|
+
/** 1-based line number */
|
|
16
|
+
line: number;
|
|
17
|
+
/** 1-based column number */
|
|
18
|
+
column: number;
|
|
19
|
+
/** Optional: component or element name for display */
|
|
20
|
+
name?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Format of the data-inspecto attribute value: "filepath:line:col" */
|
|
23
|
+
type SourceAttrValue = string;
|
|
24
|
+
/**
|
|
25
|
+
* Path type injected into data-inspecto attributes.
|
|
26
|
+
* - 'absolute': full filesystem path (default) — safe across monorepo aliases
|
|
27
|
+
* - 'relative': path relative to project root — shorter, but may break with pnpm virtual store
|
|
28
|
+
*/
|
|
29
|
+
type PathType = 'relative' | 'absolute';
|
|
30
|
+
/** Configuration for the @inspecto/plugin build plugin */
|
|
31
|
+
interface UnpluginOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Additional file extensions to transform beyond .jsx/.tsx/.js/.ts
|
|
34
|
+
* @default []
|
|
35
|
+
*/
|
|
36
|
+
include?: string[];
|
|
37
|
+
/**
|
|
38
|
+
* File path patterns to exclude from transform
|
|
39
|
+
* Matched against absolute file path using picomatch
|
|
40
|
+
* node_modules and dist are always excluded
|
|
41
|
+
* @default []
|
|
42
|
+
*/
|
|
43
|
+
exclude?: string[];
|
|
44
|
+
/**
|
|
45
|
+
* Element tag names to skip source injection.
|
|
46
|
+
* Useful for framework-internal elements that should not carry source data.
|
|
47
|
+
* @default ['template', 'script', 'style', 'Transition', 'TransitionGroup',
|
|
48
|
+
* 'KeepAlive', 'Teleport', 'Suspense', 'Fragment']
|
|
49
|
+
*/
|
|
50
|
+
escapeTags?: string[];
|
|
51
|
+
/**
|
|
52
|
+
* Path type for the injected data-inspecto attribute value.
|
|
53
|
+
* Use 'absolute' (default) to avoid issues with monorepo path aliases
|
|
54
|
+
* and pnpm virtual store symlinks.
|
|
55
|
+
* @default 'absolute'
|
|
56
|
+
*/
|
|
57
|
+
pathType?: PathType;
|
|
58
|
+
/**
|
|
59
|
+
* The attribute name injected on JSX elements.
|
|
60
|
+
* Change only if 'data-inspecto' conflicts with another tool.
|
|
61
|
+
* @default 'data-inspecto'
|
|
62
|
+
*/
|
|
63
|
+
attributeName?: string;
|
|
64
|
+
}
|
|
65
|
+
/** Supported IDEs */
|
|
66
|
+
type IdeType = 'vscode' | 'unknown';
|
|
67
|
+
/** All supported AI tools */
|
|
68
|
+
type AiTool = 'github-copilot' | 'claude-code' | 'gemini' | 'codex' | 'coco';
|
|
69
|
+
/** Backward compatibility alias */
|
|
70
|
+
type AiTarget = AiTool;
|
|
71
|
+
/** Whether the AI target is an editor plugin or a CLI tool */
|
|
72
|
+
type ToolMode = 'plugin' | 'cli' | 'clipboard';
|
|
73
|
+
/** Backward compatibility alias */
|
|
74
|
+
type AiTargetType = ToolMode;
|
|
75
|
+
interface ProviderConfig {
|
|
76
|
+
type?: ToolMode;
|
|
77
|
+
autoSend?: boolean;
|
|
78
|
+
bin?: string;
|
|
79
|
+
args?: string[];
|
|
80
|
+
cwd?: string;
|
|
81
|
+
}
|
|
82
|
+
interface InspectoSettings {
|
|
83
|
+
ide?: IdeType;
|
|
84
|
+
prefer?: string;
|
|
85
|
+
hotKeys?: HotKeys;
|
|
86
|
+
providers?: Record<string, ProviderConfig>;
|
|
87
|
+
/**
|
|
88
|
+
* Whether to inject the raw code snippet into the prompt.
|
|
89
|
+
* Default is false (saves tokens, lets IDE AI read the file directly).
|
|
90
|
+
*/
|
|
91
|
+
includeSnippet?: boolean;
|
|
92
|
+
}
|
|
93
|
+
/** Legacy configuration structure (for backward compatibility during migration) */
|
|
94
|
+
interface LegacyInspectoUserConfig {
|
|
95
|
+
defaultTarget?: AiTool;
|
|
96
|
+
tools: Partial<Record<AiTool, {
|
|
97
|
+
mode: ToolMode;
|
|
98
|
+
cliBinary?: string;
|
|
99
|
+
cliArgs?: string[];
|
|
100
|
+
}>>;
|
|
101
|
+
menuOrder?: AiTool[];
|
|
102
|
+
}
|
|
103
|
+
/** Static mapping: target → type (DEPRECATED: Use config resolution instead) */
|
|
104
|
+
declare const AI_TARGET_TYPE: Record<AiTool, ToolMode>;
|
|
105
|
+
declare const DEFAULT_TOOL_MODE: Record<AiTool, ToolMode>;
|
|
106
|
+
/** Which modes each tool actually supports */
|
|
107
|
+
declare const VALID_MODES: Record<AiTool, ToolMode[]>;
|
|
108
|
+
interface ToolOverrides {
|
|
109
|
+
type?: ToolMode;
|
|
110
|
+
binaryPath?: string;
|
|
111
|
+
args?: string[];
|
|
112
|
+
cwd?: string;
|
|
113
|
+
autoSend?: boolean;
|
|
114
|
+
coldStartDelay?: number;
|
|
115
|
+
}
|
|
116
|
+
interface AiPayload {
|
|
117
|
+
ide: IdeType;
|
|
118
|
+
target: AiTarget;
|
|
119
|
+
targetType: AiTargetType;
|
|
120
|
+
prompt: string;
|
|
121
|
+
filePath?: string;
|
|
122
|
+
line?: number;
|
|
123
|
+
column?: number;
|
|
124
|
+
snippet?: string;
|
|
125
|
+
overrides?: ToolOverrides;
|
|
126
|
+
}
|
|
127
|
+
interface ChannelDef {
|
|
128
|
+
type: ToolMode;
|
|
129
|
+
execute: (payload: AiPayload) => Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
interface IntentLabels {
|
|
132
|
+
copilot?: string;
|
|
133
|
+
claude?: string;
|
|
134
|
+
/** Label for the "copy to clipboard only" fallback */
|
|
135
|
+
clipboard?: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Configuration for a custom intent in the AI menu.
|
|
139
|
+
*/
|
|
140
|
+
interface IntentConfig {
|
|
141
|
+
/** Unique identifier for this intent */
|
|
142
|
+
id?: string;
|
|
143
|
+
/** The text displayed on the intent button */
|
|
144
|
+
label?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Prepend text to the prompt template.
|
|
147
|
+
* Useful for extending built-in prompts without rewriting the whole template.
|
|
148
|
+
*/
|
|
149
|
+
prependPrompt?: string;
|
|
150
|
+
/**
|
|
151
|
+
* Append text to the prompt template.
|
|
152
|
+
* Useful for extending built-in prompts (e.g. "Please reply in Chinese").
|
|
153
|
+
*/
|
|
154
|
+
appendPrompt?: string;
|
|
155
|
+
prompt?: string;
|
|
156
|
+
/**
|
|
157
|
+
* If true, this intent doesn't send a prompt to AI,
|
|
158
|
+
* but rather triggers a built-in action (like 'open-in-editor').
|
|
159
|
+
* @internal For built-in intents only.
|
|
160
|
+
*/
|
|
161
|
+
isAction?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Enabled status.
|
|
164
|
+
* If false, this item is explicitly hidden from the menu without having to remove its configuration.
|
|
165
|
+
*/
|
|
166
|
+
enabled?: boolean;
|
|
167
|
+
}
|
|
168
|
+
type InspectoPromptsConfig = (string | IntentConfig)[] | {
|
|
169
|
+
$replace: true;
|
|
170
|
+
items: (string | IntentConfig)[];
|
|
171
|
+
};
|
|
172
|
+
/** Configuration for the browser-side inspector component */
|
|
173
|
+
interface InspectorOptions {
|
|
174
|
+
/**
|
|
175
|
+
* Hotkeys to hold while clicking to activate inspector.
|
|
176
|
+
* Pass false to disable hotkey activation.
|
|
177
|
+
* @default ['altKey']
|
|
178
|
+
*/
|
|
179
|
+
hotKeys?: HotKeys;
|
|
180
|
+
/**
|
|
181
|
+
* Custom labels for each AI target button.
|
|
182
|
+
* Useful for localization or branding.
|
|
183
|
+
*/
|
|
184
|
+
labels?: IntentLabels;
|
|
185
|
+
/**
|
|
186
|
+
* Placeholder text for the "Ask AI" input box.
|
|
187
|
+
*/
|
|
188
|
+
askPlaceholder?: string;
|
|
189
|
+
/**
|
|
190
|
+
* Base URL of the local HTTP server spun up by the unplugin.
|
|
191
|
+
* Usually auto-detected via the injected __AI_INSPECTOR_PORT__ global.
|
|
192
|
+
* Override only if running in a non-standard setup.
|
|
193
|
+
*/
|
|
194
|
+
serverUrl?: string;
|
|
195
|
+
/**
|
|
196
|
+
* Maximum number of lines to include in the extracted code snippet.
|
|
197
|
+
* Larger values provide more context but may hit AI token limits.
|
|
198
|
+
* @default 100
|
|
199
|
+
*/
|
|
200
|
+
maxSnippetLines?: number;
|
|
201
|
+
/**
|
|
202
|
+
* Whether the inspector panel is visible/active on mount.
|
|
203
|
+
* @default false
|
|
204
|
+
*/
|
|
205
|
+
defaultActive?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Theme for the inspector panel.
|
|
208
|
+
* If 'auto' or undefined, it relies on CSS media queries (prefers-color-scheme)
|
|
209
|
+
* or inherits from the host environment if manually managed.
|
|
210
|
+
*/
|
|
211
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
212
|
+
/**
|
|
213
|
+
* Whether to inject the raw code snippet into the prompt.
|
|
214
|
+
* Default is false (saves tokens, lets IDE AI read the file directly).
|
|
215
|
+
*/
|
|
216
|
+
includeSnippet?: boolean;
|
|
217
|
+
}
|
|
218
|
+
/** POST /open — browser asks server to open file in IDE */
|
|
219
|
+
interface OpenFileRequest {
|
|
220
|
+
file: string;
|
|
221
|
+
line: number;
|
|
222
|
+
column: number;
|
|
223
|
+
}
|
|
224
|
+
/** GET /snippet — browser asks server for source code context */
|
|
225
|
+
interface SnippetRequest {
|
|
226
|
+
file: string;
|
|
227
|
+
line: number;
|
|
228
|
+
column: number;
|
|
229
|
+
/** Max lines to return in snippet, default 100 */
|
|
230
|
+
maxLines?: number;
|
|
231
|
+
}
|
|
232
|
+
interface SnippetResponse {
|
|
233
|
+
/** Extracted code snippet (trimmed to maxSnippetLines) */
|
|
234
|
+
snippet: string;
|
|
235
|
+
/** Actual start line of the returned snippet (1-based) */
|
|
236
|
+
startLine: number;
|
|
237
|
+
/** File path echoed back */
|
|
238
|
+
file: string;
|
|
239
|
+
/** Component or element name if detectable */
|
|
240
|
+
name?: string;
|
|
241
|
+
}
|
|
242
|
+
/** POST /send-to-ai — browser asks server to dispatch context to an AI tool */
|
|
243
|
+
interface SendToAiRequest {
|
|
244
|
+
location: SourceLocation;
|
|
245
|
+
snippet: string;
|
|
246
|
+
/** Prompt template. Server may override with its own template. */
|
|
247
|
+
prompt?: string;
|
|
248
|
+
/** Target AI tool. If not provided, server will resolve it based on config */
|
|
249
|
+
target?: string;
|
|
250
|
+
}
|
|
251
|
+
interface SendToAiResponse {
|
|
252
|
+
success: boolean;
|
|
253
|
+
error?: string;
|
|
254
|
+
/** Error code for structured error handling in the browser */
|
|
255
|
+
errorCode?: AiErrorCode;
|
|
256
|
+
}
|
|
257
|
+
/** Standard error codes returned by the local HTTP server */
|
|
258
|
+
type AiErrorCode = 'IDE_NOT_FOUND' | 'EXTENSION_NOT_INSTALLED' | 'CLIPBOARD_WRITE_FAILED' | 'SNIPPET_TOO_LARGE' | 'FILE_NOT_FOUND' | 'UNKNOWN';
|
|
259
|
+
interface ProviderInfo {
|
|
260
|
+
mode: ToolMode;
|
|
261
|
+
installed: boolean;
|
|
262
|
+
}
|
|
263
|
+
interface IdeInfo {
|
|
264
|
+
ide: IdeType;
|
|
265
|
+
scheme: string;
|
|
266
|
+
providers: Record<AiTool, ProviderInfo>;
|
|
267
|
+
}
|
|
268
|
+
/** GET /config response — browser-facing runtime configuration */
|
|
269
|
+
interface InspectoConfig {
|
|
270
|
+
ide: IdeType;
|
|
271
|
+
providers: Record<AiTool, ProviderInfo>;
|
|
272
|
+
providerOverrides?: Partial<Record<AiTool, ToolOverrides>>;
|
|
273
|
+
prompts?: InspectoPromptsConfig;
|
|
274
|
+
hotKeys?: HotKeys;
|
|
275
|
+
includeSnippet?: boolean;
|
|
276
|
+
}
|
|
277
|
+
/** Shared mutable state managed by the local HTTP server module */
|
|
278
|
+
interface ServerState {
|
|
279
|
+
/** Port the HTTP server is currently listening on */
|
|
280
|
+
port: number | null;
|
|
281
|
+
/** Whether the server is currently running */
|
|
282
|
+
running: boolean;
|
|
283
|
+
/** Absolute path to project root (from git rev-parse or process.cwd()) */
|
|
284
|
+
projectRoot: string;
|
|
285
|
+
/** Absolute path to the config root (where .inspecto lives) */
|
|
286
|
+
configRoot: string;
|
|
287
|
+
/** The directory where the bundler is running (process.cwd()) */
|
|
288
|
+
cwd: string;
|
|
289
|
+
/** Cached IDE info pushed from the extension */
|
|
290
|
+
ideInfo?: IdeInfo | null;
|
|
291
|
+
}
|
|
292
|
+
/** Context passed to each AI strategy when sending code context */
|
|
293
|
+
interface AiStrategyContext {
|
|
294
|
+
location: SourceLocation;
|
|
295
|
+
snippet: string;
|
|
296
|
+
/** Resolved absolute file URI (file:///...) */
|
|
297
|
+
fileUri: string;
|
|
298
|
+
/** Human-readable prompt constructed from location + snippet */
|
|
299
|
+
prompt: string;
|
|
300
|
+
}
|
|
301
|
+
/** Result of executing an AI strategy */
|
|
302
|
+
interface AiStrategyResult {
|
|
303
|
+
success: boolean;
|
|
304
|
+
error?: string;
|
|
305
|
+
errorCode?: AiErrorCode;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export { AI_TARGET_TYPE, type AiErrorCode, type AiPayload, type AiStrategyContext, type AiStrategyResult, type AiTarget, type AiTargetType, type AiTool, type ChannelDef, DEFAULT_TOOL_MODE, type HotKey, type HotKeys, type IdeInfo, type IdeType, type InspectoConfig, type InspectoPromptsConfig, type InspectoSettings, type InspectorOptions, type IntentConfig, type IntentLabels, type LegacyInspectoUserConfig, type OpenFileRequest, type PathType, type ProviderConfig, type ProviderInfo, type SendToAiRequest, type SendToAiResponse, type ServerState, type SnippetRequest, type SnippetResponse, type SourceAttrValue, type SourceLocation, type ToolMode, type ToolOverrides, type UnpluginOptions, VALID_MODES };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/** Modifier keys that can be used as inspector activation hotkeys */
|
|
2
|
+
type HotKey = 'ctrlKey' | 'altKey' | 'metaKey' | 'shiftKey';
|
|
3
|
+
/**
|
|
4
|
+
* Hotkey configuration.
|
|
5
|
+
* - Array of HotKey: all specified keys must be held simultaneously to activate
|
|
6
|
+
* - false: disable hotkey activation entirely (use programmatic toggle only)
|
|
7
|
+
* @default ['altKey']
|
|
8
|
+
* @example ['ctrlKey', 'shiftKey'] — Ctrl+Shift to activate
|
|
9
|
+
*/
|
|
10
|
+
type HotKeys = HotKey[] | false;
|
|
11
|
+
/** Parsed source location from the data-inspecto attribute */
|
|
12
|
+
interface SourceLocation {
|
|
13
|
+
/** Absolute or relative file path depending on pathType config */
|
|
14
|
+
file: string;
|
|
15
|
+
/** 1-based line number */
|
|
16
|
+
line: number;
|
|
17
|
+
/** 1-based column number */
|
|
18
|
+
column: number;
|
|
19
|
+
/** Optional: component or element name for display */
|
|
20
|
+
name?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Format of the data-inspecto attribute value: "filepath:line:col" */
|
|
23
|
+
type SourceAttrValue = string;
|
|
24
|
+
/**
|
|
25
|
+
* Path type injected into data-inspecto attributes.
|
|
26
|
+
* - 'absolute': full filesystem path (default) — safe across monorepo aliases
|
|
27
|
+
* - 'relative': path relative to project root — shorter, but may break with pnpm virtual store
|
|
28
|
+
*/
|
|
29
|
+
type PathType = 'relative' | 'absolute';
|
|
30
|
+
/** Configuration for the @inspecto/plugin build plugin */
|
|
31
|
+
interface UnpluginOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Additional file extensions to transform beyond .jsx/.tsx/.js/.ts
|
|
34
|
+
* @default []
|
|
35
|
+
*/
|
|
36
|
+
include?: string[];
|
|
37
|
+
/**
|
|
38
|
+
* File path patterns to exclude from transform
|
|
39
|
+
* Matched against absolute file path using picomatch
|
|
40
|
+
* node_modules and dist are always excluded
|
|
41
|
+
* @default []
|
|
42
|
+
*/
|
|
43
|
+
exclude?: string[];
|
|
44
|
+
/**
|
|
45
|
+
* Element tag names to skip source injection.
|
|
46
|
+
* Useful for framework-internal elements that should not carry source data.
|
|
47
|
+
* @default ['template', 'script', 'style', 'Transition', 'TransitionGroup',
|
|
48
|
+
* 'KeepAlive', 'Teleport', 'Suspense', 'Fragment']
|
|
49
|
+
*/
|
|
50
|
+
escapeTags?: string[];
|
|
51
|
+
/**
|
|
52
|
+
* Path type for the injected data-inspecto attribute value.
|
|
53
|
+
* Use 'absolute' (default) to avoid issues with monorepo path aliases
|
|
54
|
+
* and pnpm virtual store symlinks.
|
|
55
|
+
* @default 'absolute'
|
|
56
|
+
*/
|
|
57
|
+
pathType?: PathType;
|
|
58
|
+
/**
|
|
59
|
+
* The attribute name injected on JSX elements.
|
|
60
|
+
* Change only if 'data-inspecto' conflicts with another tool.
|
|
61
|
+
* @default 'data-inspecto'
|
|
62
|
+
*/
|
|
63
|
+
attributeName?: string;
|
|
64
|
+
}
|
|
65
|
+
/** Supported IDEs */
|
|
66
|
+
type IdeType = 'vscode' | 'unknown';
|
|
67
|
+
/** All supported AI tools */
|
|
68
|
+
type AiTool = 'github-copilot' | 'claude-code' | 'gemini' | 'codex' | 'coco';
|
|
69
|
+
/** Backward compatibility alias */
|
|
70
|
+
type AiTarget = AiTool;
|
|
71
|
+
/** Whether the AI target is an editor plugin or a CLI tool */
|
|
72
|
+
type ToolMode = 'plugin' | 'cli' | 'clipboard';
|
|
73
|
+
/** Backward compatibility alias */
|
|
74
|
+
type AiTargetType = ToolMode;
|
|
75
|
+
interface ProviderConfig {
|
|
76
|
+
type?: ToolMode;
|
|
77
|
+
autoSend?: boolean;
|
|
78
|
+
bin?: string;
|
|
79
|
+
args?: string[];
|
|
80
|
+
cwd?: string;
|
|
81
|
+
}
|
|
82
|
+
interface InspectoSettings {
|
|
83
|
+
ide?: IdeType;
|
|
84
|
+
prefer?: string;
|
|
85
|
+
hotKeys?: HotKeys;
|
|
86
|
+
providers?: Record<string, ProviderConfig>;
|
|
87
|
+
/**
|
|
88
|
+
* Whether to inject the raw code snippet into the prompt.
|
|
89
|
+
* Default is false (saves tokens, lets IDE AI read the file directly).
|
|
90
|
+
*/
|
|
91
|
+
includeSnippet?: boolean;
|
|
92
|
+
}
|
|
93
|
+
/** Legacy configuration structure (for backward compatibility during migration) */
|
|
94
|
+
interface LegacyInspectoUserConfig {
|
|
95
|
+
defaultTarget?: AiTool;
|
|
96
|
+
tools: Partial<Record<AiTool, {
|
|
97
|
+
mode: ToolMode;
|
|
98
|
+
cliBinary?: string;
|
|
99
|
+
cliArgs?: string[];
|
|
100
|
+
}>>;
|
|
101
|
+
menuOrder?: AiTool[];
|
|
102
|
+
}
|
|
103
|
+
/** Static mapping: target → type (DEPRECATED: Use config resolution instead) */
|
|
104
|
+
declare const AI_TARGET_TYPE: Record<AiTool, ToolMode>;
|
|
105
|
+
declare const DEFAULT_TOOL_MODE: Record<AiTool, ToolMode>;
|
|
106
|
+
/** Which modes each tool actually supports */
|
|
107
|
+
declare const VALID_MODES: Record<AiTool, ToolMode[]>;
|
|
108
|
+
interface ToolOverrides {
|
|
109
|
+
type?: ToolMode;
|
|
110
|
+
binaryPath?: string;
|
|
111
|
+
args?: string[];
|
|
112
|
+
cwd?: string;
|
|
113
|
+
autoSend?: boolean;
|
|
114
|
+
coldStartDelay?: number;
|
|
115
|
+
}
|
|
116
|
+
interface AiPayload {
|
|
117
|
+
ide: IdeType;
|
|
118
|
+
target: AiTarget;
|
|
119
|
+
targetType: AiTargetType;
|
|
120
|
+
prompt: string;
|
|
121
|
+
filePath?: string;
|
|
122
|
+
line?: number;
|
|
123
|
+
column?: number;
|
|
124
|
+
snippet?: string;
|
|
125
|
+
overrides?: ToolOverrides;
|
|
126
|
+
}
|
|
127
|
+
interface ChannelDef {
|
|
128
|
+
type: ToolMode;
|
|
129
|
+
execute: (payload: AiPayload) => Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
interface IntentLabels {
|
|
132
|
+
copilot?: string;
|
|
133
|
+
claude?: string;
|
|
134
|
+
/** Label for the "copy to clipboard only" fallback */
|
|
135
|
+
clipboard?: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Configuration for a custom intent in the AI menu.
|
|
139
|
+
*/
|
|
140
|
+
interface IntentConfig {
|
|
141
|
+
/** Unique identifier for this intent */
|
|
142
|
+
id?: string;
|
|
143
|
+
/** The text displayed on the intent button */
|
|
144
|
+
label?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Prepend text to the prompt template.
|
|
147
|
+
* Useful for extending built-in prompts without rewriting the whole template.
|
|
148
|
+
*/
|
|
149
|
+
prependPrompt?: string;
|
|
150
|
+
/**
|
|
151
|
+
* Append text to the prompt template.
|
|
152
|
+
* Useful for extending built-in prompts (e.g. "Please reply in Chinese").
|
|
153
|
+
*/
|
|
154
|
+
appendPrompt?: string;
|
|
155
|
+
prompt?: string;
|
|
156
|
+
/**
|
|
157
|
+
* If true, this intent doesn't send a prompt to AI,
|
|
158
|
+
* but rather triggers a built-in action (like 'open-in-editor').
|
|
159
|
+
* @internal For built-in intents only.
|
|
160
|
+
*/
|
|
161
|
+
isAction?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Enabled status.
|
|
164
|
+
* If false, this item is explicitly hidden from the menu without having to remove its configuration.
|
|
165
|
+
*/
|
|
166
|
+
enabled?: boolean;
|
|
167
|
+
}
|
|
168
|
+
type InspectoPromptsConfig = (string | IntentConfig)[] | {
|
|
169
|
+
$replace: true;
|
|
170
|
+
items: (string | IntentConfig)[];
|
|
171
|
+
};
|
|
172
|
+
/** Configuration for the browser-side inspector component */
|
|
173
|
+
interface InspectorOptions {
|
|
174
|
+
/**
|
|
175
|
+
* Hotkeys to hold while clicking to activate inspector.
|
|
176
|
+
* Pass false to disable hotkey activation.
|
|
177
|
+
* @default ['altKey']
|
|
178
|
+
*/
|
|
179
|
+
hotKeys?: HotKeys;
|
|
180
|
+
/**
|
|
181
|
+
* Custom labels for each AI target button.
|
|
182
|
+
* Useful for localization or branding.
|
|
183
|
+
*/
|
|
184
|
+
labels?: IntentLabels;
|
|
185
|
+
/**
|
|
186
|
+
* Placeholder text for the "Ask AI" input box.
|
|
187
|
+
*/
|
|
188
|
+
askPlaceholder?: string;
|
|
189
|
+
/**
|
|
190
|
+
* Base URL of the local HTTP server spun up by the unplugin.
|
|
191
|
+
* Usually auto-detected via the injected __AI_INSPECTOR_PORT__ global.
|
|
192
|
+
* Override only if running in a non-standard setup.
|
|
193
|
+
*/
|
|
194
|
+
serverUrl?: string;
|
|
195
|
+
/**
|
|
196
|
+
* Maximum number of lines to include in the extracted code snippet.
|
|
197
|
+
* Larger values provide more context but may hit AI token limits.
|
|
198
|
+
* @default 100
|
|
199
|
+
*/
|
|
200
|
+
maxSnippetLines?: number;
|
|
201
|
+
/**
|
|
202
|
+
* Whether the inspector panel is visible/active on mount.
|
|
203
|
+
* @default false
|
|
204
|
+
*/
|
|
205
|
+
defaultActive?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Theme for the inspector panel.
|
|
208
|
+
* If 'auto' or undefined, it relies on CSS media queries (prefers-color-scheme)
|
|
209
|
+
* or inherits from the host environment if manually managed.
|
|
210
|
+
*/
|
|
211
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
212
|
+
/**
|
|
213
|
+
* Whether to inject the raw code snippet into the prompt.
|
|
214
|
+
* Default is false (saves tokens, lets IDE AI read the file directly).
|
|
215
|
+
*/
|
|
216
|
+
includeSnippet?: boolean;
|
|
217
|
+
}
|
|
218
|
+
/** POST /open — browser asks server to open file in IDE */
|
|
219
|
+
interface OpenFileRequest {
|
|
220
|
+
file: string;
|
|
221
|
+
line: number;
|
|
222
|
+
column: number;
|
|
223
|
+
}
|
|
224
|
+
/** GET /snippet — browser asks server for source code context */
|
|
225
|
+
interface SnippetRequest {
|
|
226
|
+
file: string;
|
|
227
|
+
line: number;
|
|
228
|
+
column: number;
|
|
229
|
+
/** Max lines to return in snippet, default 100 */
|
|
230
|
+
maxLines?: number;
|
|
231
|
+
}
|
|
232
|
+
interface SnippetResponse {
|
|
233
|
+
/** Extracted code snippet (trimmed to maxSnippetLines) */
|
|
234
|
+
snippet: string;
|
|
235
|
+
/** Actual start line of the returned snippet (1-based) */
|
|
236
|
+
startLine: number;
|
|
237
|
+
/** File path echoed back */
|
|
238
|
+
file: string;
|
|
239
|
+
/** Component or element name if detectable */
|
|
240
|
+
name?: string;
|
|
241
|
+
}
|
|
242
|
+
/** POST /send-to-ai — browser asks server to dispatch context to an AI tool */
|
|
243
|
+
interface SendToAiRequest {
|
|
244
|
+
location: SourceLocation;
|
|
245
|
+
snippet: string;
|
|
246
|
+
/** Prompt template. Server may override with its own template. */
|
|
247
|
+
prompt?: string;
|
|
248
|
+
/** Target AI tool. If not provided, server will resolve it based on config */
|
|
249
|
+
target?: string;
|
|
250
|
+
}
|
|
251
|
+
interface SendToAiResponse {
|
|
252
|
+
success: boolean;
|
|
253
|
+
error?: string;
|
|
254
|
+
/** Error code for structured error handling in the browser */
|
|
255
|
+
errorCode?: AiErrorCode;
|
|
256
|
+
}
|
|
257
|
+
/** Standard error codes returned by the local HTTP server */
|
|
258
|
+
type AiErrorCode = 'IDE_NOT_FOUND' | 'EXTENSION_NOT_INSTALLED' | 'CLIPBOARD_WRITE_FAILED' | 'SNIPPET_TOO_LARGE' | 'FILE_NOT_FOUND' | 'UNKNOWN';
|
|
259
|
+
interface ProviderInfo {
|
|
260
|
+
mode: ToolMode;
|
|
261
|
+
installed: boolean;
|
|
262
|
+
}
|
|
263
|
+
interface IdeInfo {
|
|
264
|
+
ide: IdeType;
|
|
265
|
+
scheme: string;
|
|
266
|
+
providers: Record<AiTool, ProviderInfo>;
|
|
267
|
+
}
|
|
268
|
+
/** GET /config response — browser-facing runtime configuration */
|
|
269
|
+
interface InspectoConfig {
|
|
270
|
+
ide: IdeType;
|
|
271
|
+
providers: Record<AiTool, ProviderInfo>;
|
|
272
|
+
providerOverrides?: Partial<Record<AiTool, ToolOverrides>>;
|
|
273
|
+
prompts?: InspectoPromptsConfig;
|
|
274
|
+
hotKeys?: HotKeys;
|
|
275
|
+
includeSnippet?: boolean;
|
|
276
|
+
}
|
|
277
|
+
/** Shared mutable state managed by the local HTTP server module */
|
|
278
|
+
interface ServerState {
|
|
279
|
+
/** Port the HTTP server is currently listening on */
|
|
280
|
+
port: number | null;
|
|
281
|
+
/** Whether the server is currently running */
|
|
282
|
+
running: boolean;
|
|
283
|
+
/** Absolute path to project root (from git rev-parse or process.cwd()) */
|
|
284
|
+
projectRoot: string;
|
|
285
|
+
/** Absolute path to the config root (where .inspecto lives) */
|
|
286
|
+
configRoot: string;
|
|
287
|
+
/** The directory where the bundler is running (process.cwd()) */
|
|
288
|
+
cwd: string;
|
|
289
|
+
/** Cached IDE info pushed from the extension */
|
|
290
|
+
ideInfo?: IdeInfo | null;
|
|
291
|
+
}
|
|
292
|
+
/** Context passed to each AI strategy when sending code context */
|
|
293
|
+
interface AiStrategyContext {
|
|
294
|
+
location: SourceLocation;
|
|
295
|
+
snippet: string;
|
|
296
|
+
/** Resolved absolute file URI (file:///...) */
|
|
297
|
+
fileUri: string;
|
|
298
|
+
/** Human-readable prompt constructed from location + snippet */
|
|
299
|
+
prompt: string;
|
|
300
|
+
}
|
|
301
|
+
/** Result of executing an AI strategy */
|
|
302
|
+
interface AiStrategyResult {
|
|
303
|
+
success: boolean;
|
|
304
|
+
error?: string;
|
|
305
|
+
errorCode?: AiErrorCode;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export { AI_TARGET_TYPE, type AiErrorCode, type AiPayload, type AiStrategyContext, type AiStrategyResult, type AiTarget, type AiTargetType, type AiTool, type ChannelDef, DEFAULT_TOOL_MODE, type HotKey, type HotKeys, type IdeInfo, type IdeType, type InspectoConfig, type InspectoPromptsConfig, type InspectoSettings, type InspectorOptions, type IntentConfig, type IntentLabels, type LegacyInspectoUserConfig, type OpenFileRequest, type PathType, type ProviderConfig, type ProviderInfo, type SendToAiRequest, type SendToAiResponse, type ServerState, type SnippetRequest, type SnippetResponse, type SourceAttrValue, type SourceLocation, type ToolMode, type ToolOverrides, type UnpluginOptions, VALID_MODES };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var AI_TARGET_TYPE = {
|
|
3
|
+
"github-copilot": "plugin",
|
|
4
|
+
"claude-code": "plugin",
|
|
5
|
+
gemini: "plugin",
|
|
6
|
+
codex: "plugin",
|
|
7
|
+
coco: "cli"
|
|
8
|
+
};
|
|
9
|
+
var DEFAULT_TOOL_MODE = {
|
|
10
|
+
"github-copilot": "plugin",
|
|
11
|
+
"claude-code": "plugin",
|
|
12
|
+
gemini: "plugin",
|
|
13
|
+
codex: "plugin",
|
|
14
|
+
coco: "cli"
|
|
15
|
+
};
|
|
16
|
+
var VALID_MODES = {
|
|
17
|
+
"github-copilot": ["plugin"],
|
|
18
|
+
"claude-code": ["plugin", "cli"],
|
|
19
|
+
gemini: ["plugin", "cli"],
|
|
20
|
+
codex: ["plugin", "cli"],
|
|
21
|
+
coco: ["cli"]
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
AI_TARGET_TYPE,
|
|
25
|
+
DEFAULT_TOOL_MODE,
|
|
26
|
+
VALID_MODES
|
|
27
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inspecto-dev/types",
|
|
3
|
+
"version": "0.2.0-alpha.0",
|
|
4
|
+
"description": "Shared TypeScript definitions for the Inspecto monorepo",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/inspecto-dev/inspecto.git",
|
|
13
|
+
"directory": "packages/types"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/inspecto-dev/inspecto/tree/main/packages/types#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/inspecto-dev/inspecto/issues"
|
|
18
|
+
},
|
|
19
|
+
"author": "Inspecto Contributors",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"ai",
|
|
22
|
+
"devtools",
|
|
23
|
+
"inspector",
|
|
24
|
+
"types"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"require": "./dist/index.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"main": "./dist/index.cjs",
|
|
37
|
+
"module": "./dist/index.js",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
41
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"clean": "rm -rf dist"
|
|
44
|
+
}
|
|
45
|
+
}
|