char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Refactor Built-In Tools naming (Server/Browser) (#27271)0021a77de

char/aliceai-t5-moe
1.4 KiB38 linesraw
1/**
2 * Browser executor for the `get_datetime` tool. It runs in the browser, so it
3 * reports the user's own clock and time zone instead of the server's UTC time -
4 * a chat about "tomorrow" means the user's tomorrow, not the host's.
5 *
6 * @see buildGetDatetimeToolDefinition in constants/get-datetime.ts - tool schema sent to the LLM
7 */
8
9import type { ToolExecutionResult } from '$lib/types';
10
11function pad(value: number): string {
12	return String(value).padStart(2, '0');
13}
14
15/** ISO 8601 in local time, e.g. `2026-08-17T14:05:09+02:00` */
16function localIsoString(date: Date): string {
17	// getTimezoneOffset() counts minutes behind UTC, ISO 8601 counts them ahead
18	const offset = -date.getTimezoneOffset();
19	const sign = offset < 0 ? '-' : '+';
20	const absOffset = Math.abs(offset);
21	const day = `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
22	const time = `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
23
24	return `${day}T${time}${sign}${pad(Math.floor(absOffset / 60))}:${pad(absOffset % 60)}`;
25}
26
27/** The `result` field keeps the shape the `get_datetime` renderer already reads. */
28export function executeGetDatetimeTool(): ToolExecutionResult {
29	const now = new Date();
30
31	return {
32		content: JSON.stringify({
33			result: localIsoString(now),
34			timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
35		}),
36		isError: false
37	};
38}