feat: base shortcut code

This commit is contained in:
2025-01-18 21:54:26 +01:00
parent a820b29ea9
commit 3abe88c7a2
29 changed files with 5982 additions and 123 deletions

View File

@@ -0,0 +1,32 @@
import { getMessage } from '@utils/anthropicClient';
import { ShortcutsResponse } from '../types';
export async function anthropicCommand(
parameters: Record<string, string> | undefined
): Promise<ShortcutsResponse> {
try {
if (!parameters || !parameters['question']) {
return {
success: false,
message: 'Sorry. Need to provide a question.'
};
}
const response = await getMessage(
'I want to know ' +
parameters['question'] +
'. Structure the response in a manner suitable for spoken communication.'
);
return {
success: true,
message: response
};
} catch (error) {
console.error(error);
return {
success: false,
message: 'Sorry. There was a problem with Anthropic.'
};
}
}

View File

@@ -0,0 +1,11 @@
import { pingCommand } from './ping';
describe('Ping Command', () => {
it('should return success response', async () => {
const response = await pingCommand();
expect(response.success).toBe(true);
expect(response.message).toBe('The system is operational.');
expect(response.data).toHaveProperty('timestamp');
});
});

11
utils/commands/ping.ts Normal file
View File

@@ -0,0 +1,11 @@
import { ShortcutsResponse } from '../types';
export async function pingCommand(): Promise<ShortcutsResponse> {
return {
success: true,
message: 'The system is operational.',
data: {
timestamp: new Date().toISOString()
}
};
}

View File

@@ -0,0 +1,12 @@
import { timeCommand } from './time';
describe('Time Command', () => {
it('should return current time', async () => {
const response = await timeCommand();
expect(response.success).toBe(true);
expect(response.message).toMatch(/It's currently \d{1,2}:\d{2} [AP]M/);
expect(response.data).toHaveProperty('timestamp');
expect(response.data).toHaveProperty('formattedTime');
});
});

19
utils/commands/time.ts Normal file
View File

@@ -0,0 +1,19 @@
import { ShortcutsResponse } from '../types';
export async function timeCommand(): Promise<ShortcutsResponse> {
const now = new Date();
const timeString = now.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: 'numeric',
hour12: true
});
return {
success: true,
message: `It's currently ${timeString}`,
data: {
timestamp: now.toISOString(),
formattedTime: timeString
}
};
}