moving `/save`, `/resume` to `/chat <save|resume>` (#1355)
This commit is contained in:
parent
f741630572
commit
335802f4dd
|
@ -651,14 +651,25 @@ Add any other context about the problem here.
|
|||
},
|
||||
},
|
||||
{
|
||||
name: 'save',
|
||||
description: 'save conversation checkpoint. Usage: /save [tag]',
|
||||
action: async (_mainCommand, subCommand, _args) => {
|
||||
const tag = (subCommand || '').trim();
|
||||
name: 'chat',
|
||||
description:
|
||||
'Manage conversation history. Usage: /chat <save|resume> [tag]',
|
||||
action: async (_mainCommand, subCommand, args) => {
|
||||
const tag = (args || '').trim();
|
||||
const logger = new Logger(config?.getSessionId() || '');
|
||||
await logger.initialize();
|
||||
const chat = await config?.getGeminiClient()?.getChat();
|
||||
const history = chat?.getHistory() || [];
|
||||
if (!chat) {
|
||||
addMessage({
|
||||
type: MessageType.ERROR,
|
||||
content: 'No chat client available for conversation status.',
|
||||
timestamp: new Date(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
switch (subCommand) {
|
||||
case 'save': {
|
||||
const history = chat.getHistory();
|
||||
if (history.length > 0) {
|
||||
await logger.saveCheckpoint(chat?.getHistory() || [], tag);
|
||||
addMessage({
|
||||
|
@ -673,35 +684,11 @@ Add any other context about the problem here.
|
|||
timestamp: new Date(),
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'resume',
|
||||
description:
|
||||
'resume from conversation checkpoint. Usage: /resume [tag]',
|
||||
completion: async () => {
|
||||
const geminiDir = config?.getProjectTempDir();
|
||||
if (!geminiDir) {
|
||||
return [];
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const files = await fs.readdir(geminiDir);
|
||||
return files
|
||||
.filter(
|
||||
(file) =>
|
||||
file.startsWith('checkpoint-') && file.endsWith('.json'),
|
||||
)
|
||||
.map((file) =>
|
||||
file.replace('checkpoint-', '').replace('.json', ''),
|
||||
);
|
||||
} catch (_err) {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
action: async (_mainCommand, subCommand, _args) => {
|
||||
const tag = (subCommand || '').trim();
|
||||
const logger = new Logger(config?.getSessionId() || '');
|
||||
await logger.initialize();
|
||||
case 'resume':
|
||||
case 'restore':
|
||||
case 'load': {
|
||||
const conversation = await logger.loadCheckpoint(tag);
|
||||
if (conversation.length === 0) {
|
||||
addMessage({
|
||||
|
@ -711,23 +698,15 @@ Add any other context about the problem here.
|
|||
});
|
||||
return;
|
||||
}
|
||||
const chat = await config?.getGeminiClient()?.getChat();
|
||||
if (!chat) {
|
||||
addMessage({
|
||||
type: MessageType.ERROR,
|
||||
content: 'No chat client available to resume conversation.',
|
||||
timestamp: new Date(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
clearItems();
|
||||
chat.clearHistory();
|
||||
const rolemap: { [key: string]: MessageType } = {
|
||||
user: MessageType.USER,
|
||||
model: MessageType.GEMINI,
|
||||
};
|
||||
let i = 0;
|
||||
let hasSystemPrompt = false;
|
||||
let i = 0;
|
||||
for (const item of conversation) {
|
||||
i += 1;
|
||||
const text =
|
||||
|
@ -746,7 +725,8 @@ Add any other context about the problem here.
|
|||
if (i > 2 || !hasSystemPrompt) {
|
||||
addItem(
|
||||
{
|
||||
type: (item.role && rolemap[item.role]) || MessageType.GEMINI,
|
||||
type:
|
||||
(item.role && rolemap[item.role]) || MessageType.GEMINI,
|
||||
text,
|
||||
} as HistoryItemWithoutId,
|
||||
i,
|
||||
|
@ -755,6 +735,37 @@ Add any other context about the problem here.
|
|||
}
|
||||
console.clear();
|
||||
refreshStatic();
|
||||
return;
|
||||
}
|
||||
default:
|
||||
addMessage({
|
||||
type: MessageType.ERROR,
|
||||
content: `Unknown /chat command: ${subCommand}. Available: save, resume`,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
},
|
||||
completion: async () => {
|
||||
const geminiDir = config?.getProjectTempDir();
|
||||
if (!geminiDir) {
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
const files = await fs.readdir(geminiDir);
|
||||
return files
|
||||
.filter(
|
||||
(file) =>
|
||||
file.startsWith('checkpoint-') && file.endsWith('.json'),
|
||||
)
|
||||
.map(
|
||||
(file) =>
|
||||
'resume ' +
|
||||
file.replace('checkpoint-', '').replace('.json', ''),
|
||||
);
|
||||
} catch (_err) {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue