mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
79 lines
1.9 KiB
TypeScript
79 lines
1.9 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import type { HistoryItemStats } from '../types.js';
|
|
import { MessageType } from '../types.js';
|
|
import { formatDuration } from '../utils/formatters.js';
|
|
import {
|
|
type CommandContext,
|
|
type SlashCommand,
|
|
CommandKind,
|
|
} from './types.js';
|
|
import { t } from '../../i18n/index.js';
|
|
|
|
export const statsCommand: SlashCommand = {
|
|
name: 'stats',
|
|
altNames: ['usage'],
|
|
get description() {
|
|
return t('check session stats. Usage: /stats [model|tools]');
|
|
},
|
|
kind: CommandKind.BUILT_IN,
|
|
action: (context: CommandContext) => {
|
|
const now = new Date();
|
|
const { sessionStartTime } = context.session.stats;
|
|
if (!sessionStartTime) {
|
|
context.ui.addItem(
|
|
{
|
|
type: MessageType.ERROR,
|
|
text: t('Session start time is unavailable, cannot calculate stats.'),
|
|
},
|
|
Date.now(),
|
|
);
|
|
return;
|
|
}
|
|
const wallDuration = now.getTime() - sessionStartTime.getTime();
|
|
|
|
const statsItem: HistoryItemStats = {
|
|
type: MessageType.STATS,
|
|
duration: formatDuration(wallDuration),
|
|
};
|
|
|
|
context.ui.addItem(statsItem, Date.now());
|
|
},
|
|
subCommands: [
|
|
{
|
|
name: 'model',
|
|
get description() {
|
|
return t('Show model-specific usage statistics.');
|
|
},
|
|
kind: CommandKind.BUILT_IN,
|
|
action: (context: CommandContext) => {
|
|
context.ui.addItem(
|
|
{
|
|
type: MessageType.MODEL_STATS,
|
|
},
|
|
Date.now(),
|
|
);
|
|
},
|
|
},
|
|
{
|
|
name: 'tools',
|
|
get description() {
|
|
return t('Show tool-specific usage statistics.');
|
|
},
|
|
kind: CommandKind.BUILT_IN,
|
|
action: (context: CommandContext) => {
|
|
context.ui.addItem(
|
|
{
|
|
type: MessageType.TOOL_STATS,
|
|
},
|
|
Date.now(),
|
|
);
|
|
},
|
|
},
|
|
],
|
|
};
|