-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathtimezone.ts
More file actions
51 lines (44 loc) · 1.69 KB
/
timezone.ts
File metadata and controls
51 lines (44 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { z } from "zod";
import { PlacesSearcher } from "../../services/PlacesSearcher.js";
import { getCurrentApiKey } from "../../utils/requestContext.js";
const NAME = "maps_timezone";
const DESCRIPTION =
"Get the timezone and current local time for a location. Use when the user asks 'what time is it in Tokyo', needs to coordinate a meeting across timezones, or is planning travel across timezone boundaries. Returns timezone ID, UTC/DST offsets, and computed local time.";
const SCHEMA = {
latitude: z.number().describe("Latitude coordinate"),
longitude: z.number().describe("Longitude coordinate"),
timestamp: z
.number()
.optional()
.describe("Unix timestamp in ms to query timezone at a specific moment (defaults to now)"),
};
export type TimezoneParams = z.infer<z.ZodObject<typeof SCHEMA>>;
async function ACTION(params: any): Promise<{ content: any[]; isError?: boolean }> {
try {
const apiKey = getCurrentApiKey();
const placesSearcher = new PlacesSearcher(apiKey);
const result = await placesSearcher.getTimezone(params.latitude, params.longitude, params.timestamp);
if (!result.success) {
return {
content: [{ type: "text", text: result.error || "Failed to get timezone data" }],
isError: true,
};
}
return {
content: [{ type: "text", text: JSON.stringify(result.data, null, 2) }],
isError: false,
};
} catch (error: any) {
const errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
return {
isError: true,
content: [{ type: "text", text: `Error getting timezone: ${errorMessage}` }],
};
}
}
export const Timezone = {
NAME,
DESCRIPTION,
SCHEMA,
ACTION,
};