mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-24 04:52:43 -07:00
fix: lint errors in teleportation module
This commit is contained in:
@@ -52,6 +52,7 @@ export default tseslint.config(
|
||||
'packages/test-utils/**',
|
||||
'.gemini/skills/**',
|
||||
'**/*.d.ts',
|
||||
'packages/core/src/teleportation/trajectory_teleporter.min.js',
|
||||
],
|
||||
},
|
||||
eslint.configs.recommended,
|
||||
|
||||
101
packages/core/src/teleportation/discovery.ts
Normal file
101
packages/core/src/teleportation/discovery.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import { trajectoryToJson } from './teleporter.js';
|
||||
import { convertAgyToCliRecord } from './converter.js';
|
||||
import { partListUnionToString } from '../core/geminiRequest.js';
|
||||
|
||||
export interface AgySessionInfo {
|
||||
id: string;
|
||||
path: string;
|
||||
mtime: string;
|
||||
displayName?: string;
|
||||
messageCount?: number;
|
||||
}
|
||||
|
||||
const AGY_CONVERSATIONS_DIR = path.join(
|
||||
os.homedir(),
|
||||
'.gemini',
|
||||
'jetski',
|
||||
'conversations',
|
||||
);
|
||||
|
||||
/**
|
||||
* Lists all Antigravity sessions found on disk.
|
||||
*/
|
||||
export async function listAgySessions(): Promise<AgySessionInfo[]> {
|
||||
try {
|
||||
const files = await fs.readdir(AGY_CONVERSATIONS_DIR);
|
||||
const sessions: AgySessionInfo[] = [];
|
||||
|
||||
for (const file of files) {
|
||||
if (file.endsWith('.pb')) {
|
||||
const filePath = path.join(AGY_CONVERSATIONS_DIR, file);
|
||||
const stats = await fs.stat(filePath);
|
||||
const id = path.basename(file, '.pb');
|
||||
|
||||
let details = {};
|
||||
try {
|
||||
const data = await fs.readFile(filePath);
|
||||
const json = trajectoryToJson(data);
|
||||
details = extractAgyDetails(json);
|
||||
} catch (_error) {
|
||||
// Ignore errors during parsing
|
||||
}
|
||||
|
||||
sessions.push({
|
||||
id,
|
||||
path: filePath,
|
||||
mtime: stats.mtime.toISOString(),
|
||||
...details,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return sessions;
|
||||
} catch (_error) {
|
||||
// If directory doesn't exist, just return empty list
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function extractAgyDetails(json: unknown): {
|
||||
displayName?: string;
|
||||
messageCount?: number;
|
||||
} {
|
||||
try {
|
||||
const record = convertAgyToCliRecord(json);
|
||||
const messages = record.messages || [];
|
||||
|
||||
// Find first user message for display name
|
||||
const firstUserMsg = messages.find((m) => m.type === 'user');
|
||||
const displayName = firstUserMsg
|
||||
? partListUnionToString(firstUserMsg.content).slice(0, 100)
|
||||
: 'Antigravity Session';
|
||||
|
||||
return {
|
||||
displayName,
|
||||
messageCount: messages.length,
|
||||
};
|
||||
} catch (_error) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the raw binary data of an Antigravity session.
|
||||
*/
|
||||
export async function loadAgySession(id: string): Promise<Buffer | null> {
|
||||
const filePath = path.join(AGY_CONVERSATIONS_DIR, `${id}.pb`);
|
||||
try {
|
||||
return await fs.readFile(filePath);
|
||||
} catch (_error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
26
packages/core/src/teleportation/teleporter.ts
Normal file
26
packages/core/src/teleportation/teleporter.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { createRequire } from 'node:module';
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
// Import the bundled teleporter which contains the protobuf definitions and decryption logic
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
const teleporter = require('./trajectory_teleporter.min.js');
|
||||
|
||||
/**
|
||||
* Decrypts and parses an Antigravity trajectory file (.pb) into JSON.
|
||||
*/
|
||||
export function trajectoryToJson(data: Buffer): unknown {
|
||||
return teleporter.trajectoryToJson(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a JSON trajectory back to encrypted binary format.
|
||||
*/
|
||||
export function jsonToTrajectory(json: unknown): Buffer {
|
||||
return teleporter.jsonToTrajectory(json);
|
||||
}
|
||||
Reference in New Issue
Block a user