feat: make /transfer bidirectional across telegram and tui
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
|
||||
import { createContextCommand, createElevateCommand, createModelCommand, createQueueCommand, createResearchCommand } from './index.js';
|
||||
import { createContextCommand, createElevateCommand, createModelCommand, createQueueCommand, createResearchCommand, createTransferCommand } from './index.js';
|
||||
|
||||
describe('builtin /model command', () => {
|
||||
it('passes through the full argument string', async () => {
|
||||
@@ -169,3 +169,31 @@ describe('builtin /context command', () => {
|
||||
expect(result).toEqual({ handled: true, text: 'Context command is not available in this session.' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('builtin /transfer command', () => {
|
||||
it('passes through the full target argument string', async () => {
|
||||
const cmd = createTransferCommand();
|
||||
const transferSession = vi.fn(() => 'Session transferred');
|
||||
const result = await cmd.execute(['telegram'], {
|
||||
channel: 'test',
|
||||
senderId: 'user',
|
||||
sessionId: 's1',
|
||||
rawInput: '/transfer telegram',
|
||||
services: { transferSession },
|
||||
});
|
||||
expect(transferSession).toHaveBeenCalledWith('telegram');
|
||||
expect(result).toEqual({ handled: true, text: 'Session transferred' });
|
||||
});
|
||||
|
||||
it('returns not-available when service is missing', async () => {
|
||||
const cmd = createTransferCommand();
|
||||
const result = await cmd.execute(['tui'], {
|
||||
channel: 'test',
|
||||
senderId: 'user',
|
||||
sessionId: 's1',
|
||||
rawInput: '/transfer tui',
|
||||
services: {},
|
||||
});
|
||||
expect(result).toEqual({ handled: true, text: 'Transfer command is not available in this session.' });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -218,6 +218,24 @@ export function createResearchCommand(): CommandDefinition {
|
||||
};
|
||||
}
|
||||
|
||||
export function createTransferCommand(): CommandDefinition {
|
||||
return {
|
||||
name: 'transfer',
|
||||
description: 'Transfer session to another frontend',
|
||||
execute: async (args, ctx) => {
|
||||
if (!ctx.services?.transferSession) {
|
||||
return notAvailable('Transfer command');
|
||||
}
|
||||
|
||||
const target = args.join(' ').trim();
|
||||
return {
|
||||
handled: true,
|
||||
text: await ctx.services.transferSession(target),
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function registerBuiltinCommands(registry: CommandRegistry): void {
|
||||
registry.register(createHelpCommand(registry));
|
||||
registry.register(createStatusCommand());
|
||||
@@ -229,4 +247,5 @@ export function registerBuiltinCommands(registry: CommandRegistry): void {
|
||||
registry.register(createResetCommand());
|
||||
registry.register(createElevateCommand());
|
||||
registry.register(createQueueCommand());
|
||||
registry.register(createTransferCommand());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user