mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
refactor(ide): extract IDE context types into a separate file (#8037)
This commit is contained in:
@@ -47,7 +47,7 @@ import {
|
||||
MalformedJsonResponseEvent,
|
||||
NextSpeakerCheckEvent,
|
||||
} from '../telemetry/types.js';
|
||||
import type { IdeContext, File } from '../ide/ideContext.js';
|
||||
import type { IdeContext, File } from '../ide/types.js';
|
||||
import { handleFallback } from '../fallback/handler.js';
|
||||
|
||||
export function isThinkingSupported(model: string) {
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
import * as fs from 'node:fs';
|
||||
import { isSubpath } from '../utils/paths.js';
|
||||
import { detectIde, type DetectedIde, getIdeInfo } from '../ide/detect-ide.js';
|
||||
import type { DiffUpdateResult } from '../ide/ideContext.js';
|
||||
import {
|
||||
ideContext,
|
||||
IdeContextNotificationSchema,
|
||||
IdeDiffAcceptedNotificationSchema,
|
||||
IdeDiffClosedNotificationSchema,
|
||||
CloseDiffResponseSchema,
|
||||
} from '../ide/ideContext.js';
|
||||
type DiffUpdateResult,
|
||||
} from './ideContext.js';
|
||||
import { IdeContextNotificationSchema } from './types.js';
|
||||
import { getIdeProcessInfo } from './process-utils.js';
|
||||
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
||||
|
||||
@@ -5,11 +5,8 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import {
|
||||
createIdeContextStore,
|
||||
FileSchema,
|
||||
IdeContextSchema,
|
||||
} from './ideContext.js';
|
||||
import { createIdeContextStore } from './ideContext.js';
|
||||
import { FileSchema, IdeContextSchema } from './types.js';
|
||||
|
||||
describe('ideContext', () => {
|
||||
describe('createIdeContextStore', () => {
|
||||
|
||||
@@ -5,42 +5,7 @@
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* Zod schema for validating a file context from the IDE.
|
||||
*/
|
||||
export const FileSchema = z.object({
|
||||
path: z.string(),
|
||||
timestamp: z.number(),
|
||||
isActive: z.boolean().optional(),
|
||||
selectedText: z.string().optional(),
|
||||
cursor: z
|
||||
.object({
|
||||
line: z.number(),
|
||||
character: z.number(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
export type File = z.infer<typeof FileSchema>;
|
||||
|
||||
export const IdeContextSchema = z.object({
|
||||
workspaceState: z
|
||||
.object({
|
||||
openFiles: z.array(FileSchema).optional(),
|
||||
isTrusted: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
export type IdeContext = z.infer<typeof IdeContextSchema>;
|
||||
|
||||
/**
|
||||
* Zod schema for validating the 'ide/contextUpdate' notification from the IDE.
|
||||
*/
|
||||
export const IdeContextNotificationSchema = z.object({
|
||||
jsonrpc: z.literal('2.0'),
|
||||
method: z.literal('ide/contextUpdate'),
|
||||
params: IdeContextSchema,
|
||||
});
|
||||
import type { IdeContext } from './types.js';
|
||||
|
||||
export const IdeDiffAcceptedNotificationSchema = z.object({
|
||||
jsonrpc: z.literal('2.0'),
|
||||
|
||||
70
packages/core/src/ide/types.ts
Normal file
70
packages/core/src/ide/types.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* A file that is open in the IDE.
|
||||
*/
|
||||
export const FileSchema = z.object({
|
||||
/**
|
||||
* The absolute path to the file.
|
||||
*/
|
||||
path: z.string(),
|
||||
/**
|
||||
* The unix timestamp of when the file was last focused.
|
||||
*/
|
||||
timestamp: z.number(),
|
||||
/**
|
||||
* Whether the file is the currently active file. Only one file can be active at a time.
|
||||
*/
|
||||
isActive: z.boolean().optional(),
|
||||
/**
|
||||
* The text that is currently selected in the active file.
|
||||
*/
|
||||
selectedText: z.string().optional(),
|
||||
/**
|
||||
* The cursor position in the active file.
|
||||
*/
|
||||
cursor: z
|
||||
.object({
|
||||
/**
|
||||
* The 1-based line number.
|
||||
*/
|
||||
line: z.number(),
|
||||
/**
|
||||
* The 1-based character offset.
|
||||
*/
|
||||
character: z.number(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
export type File = z.infer<typeof FileSchema>;
|
||||
|
||||
/**
|
||||
* The context of the IDE.
|
||||
*/
|
||||
export const IdeContextSchema = z.object({
|
||||
workspaceState: z
|
||||
.object({
|
||||
/**
|
||||
* The list of files that are currently open.
|
||||
*/
|
||||
openFiles: z.array(FileSchema).optional(),
|
||||
/**
|
||||
* Whether the workspace is trusted.
|
||||
*/
|
||||
isTrusted: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
export type IdeContext = z.infer<typeof IdeContextSchema>;
|
||||
|
||||
export const IdeContextNotificationSchema = z.object({
|
||||
jsonrpc: z.literal('2.0'),
|
||||
method: z.literal('ide/contextUpdate'),
|
||||
params: IdeContextSchema,
|
||||
});
|
||||
@@ -65,6 +65,7 @@ export * from './ide/ide-installer.js';
|
||||
export { getIdeInfo, DetectedIde } from './ide/detect-ide.js';
|
||||
export { type IdeInfo } from './ide/detect-ide.js';
|
||||
export * from './ide/constants.js';
|
||||
export * from './ide/types.js';
|
||||
|
||||
// Export Shell Execution Service
|
||||
export * from './services/shellExecutionService.js';
|
||||
|
||||
Reference in New Issue
Block a user