char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
0021a77de
char/aliceai-t5-moe
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 { 12return 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 18const offset = - date . getTimezoneOffset (); 19const sign = offset < 0 ?'-' :'+' ; 20const absOffset = Math . abs ( offset ); 21const day = ` ${ date . getFullYear ()} - ${ pad ( date . getMonth () + 1 )} - ${ pad ( date . getDate ())} ` ; 22const time = ` ${ pad ( date . getHours ())} : ${ pad ( date . getMinutes ())} : ${ pad ( date . getSeconds ())} ` ; 23 24return ` ${ 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 { 29const now = new Date (); 30 31return { 32content :JSON . stringify ({ 33result :localIsoString ( now ), 34timezone :Intl . DateTimeFormat (). resolvedOptions (). timeZone 35}), 36isError :false 37}; 38}