File size: 779 Bytes
89565fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * Browser executor for the `get_datetime` tool. It runs in the browser, so it
 * reports the user's own clock and time zone instead of the server's UTC time -
 * a chat about "tomorrow" means the user's tomorrow, not the host's.
 *
 * @see buildGetDatetimeToolDefinition in constants/get-datetime.ts - tool schema sent to the LLM
 */

import { formatLocalIso } from './formatters';
import type { ToolExecutionResult } from '$lib/types';

/** The `result` field keeps the shape the `get_datetime` renderer already reads. */
export function executeGetDatetimeTool(): ToolExecutionResult {
	const now = new Date();

	return {
		content: JSON.stringify({
			result: formatLocalIso(now),
			timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
		}),
		isError: false
	};
}