Package com.tnsai.tools.productivity
Class GoogleTools
java.lang.Object
com.tnsai.tools.productivity.GoogleTools
Function-shape Google productivity tools — Calendar v3 + Drive v3 via
OAuth2 bearer tokens. Replaces legacy
GoogleCalendarTool +
GoogleDriveTool.
| Method | Endpoint | Idempotent |
|---|---|---|
gcalListEvents(java.lang.String, java.lang.String, java.lang.String, int) | GET /calendar/v3/calendars/{cal}/events | true |
gcalGetEvent(java.lang.String, java.lang.String) | GET /calendar/v3/calendars/{cal}/events/{id} | true |
gcalCreateEvent(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) | POST /calendar/v3/calendars/{cal}/events | false (creates an event) |
gdriveListFiles(java.lang.String, int) | GET /drive/v3/files | true |
gdriveReadFile(java.lang.String) | GET /drive/v3/files/{id}?alt=media | true |
gdriveCreateFile(java.lang.String, java.lang.String, java.lang.String) | POST /upload/drive/v3/files | false (creates a file) |
Uses two access tokens: GOOGLE_CALENDAR_ACCESS_TOKEN and
GOOGLE_DRIVE_ACCESS_TOKEN. In practice a single OAuth flow can
cover both scopes — set the same token on both env vars or pass it twice
to the explicit constructor.
OAuth2 refresh-token rotation is intentionally out-of-scope —
consumers should refresh their tokens externally (the legacy tool didn't
handle this either). For a complete OAuth2 flow, see Google's
AuthorizationCodeFlow client library.
- Since:
- 0.5.7 (Phase 2 batch 34 — built-in tool migration to function shape, see #188)
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor — picks both tokens from env.GoogleTools(String calendarToken, String driveToken) Explicit-tokens constructor (pass the same token twice if a single OAuth flow covers both scopes).GoogleTools(String calendarToken, String driveToken, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper) Full constructor for tests / shared HTTP. -
Method Summary
Modifier and TypeMethodDescriptiongcalCreateEvent(String summary, String start, String end, String description, String location, String calendarId) gcalGetEvent(String eventId, String calendarId) gcalListEvents(String calendarId, String timeMin, String timeMax, int maxResults) gdriveCreateFile(String name, String content, String mimeType) gdriveListFiles(String query, int maxResults) gdriveReadFile(String fileId)
-
Constructor Details
-
GoogleTools
public GoogleTools()Default constructor — picks both tokens from env. -
GoogleTools
Explicit-tokens constructor (pass the same token twice if a single OAuth flow covers both scopes). -
GoogleTools
public GoogleTools(String calendarToken, String driveToken, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper) Full constructor for tests / shared HTTP.
-
-
Method Details
-
gcalListEvents
@Tool(name="gcal_list_events", description="List upcoming Calendar events. {calendarId} defaults to \"primary\". Optional {timeMin}/{timeMax} are ISO-8601 timestamps to bound the window (default: now \u2192 one week ahead). {maxResults} clamps to [1, 100]. Returns the raw JSON event list. Requires GOOGLE_CALENDAR_ACCESS_TOKEN.", keywords={"calendar","google","events","list","schedule"}, idempotent=true) public String gcalListEvents(@ToolParam(description="Calendar id (default \"primary\")",required=false,defaultValue="primary") String calendarId, @ToolParam(description="ISO-8601 lower bound (default = now)",required=false,defaultValue="") String timeMin, @ToolParam(description="ISO-8601 upper bound (default = now + 7 days)",required=false,defaultValue="") String timeMax, @ToolParam(description="Max events (1..100); 0 \u2192 default 10",required=false,defaultValue="0") int maxResults) throws IOException - Throws:
IOException
-
gcalGetEvent
@Tool(name="gcal_get_event", description="Fetch a single Calendar event by id. {calendarId} defaults to \"primary\". Returns the raw JSON event object.", keywords={"calendar","google","event","get"}, idempotent=true) public String gcalGetEvent(@ToolParam(description="Event id") String eventId, @ToolParam(description="Calendar id (default \"primary\")",required=false,defaultValue="primary") String calendarId) throws IOException - Throws:
IOException
-
gcalCreateEvent
@Tool(name="gcal_create_event", description="Create a new Calendar event. {start} + {end} are ISO-8601 timestamps (e.g. \"2026-12-31T17:00:00+03:00\"). {calendarId} defaults to \"primary\". Returns the raw JSON of the created event (with assigned id + htmlLink). NOT idempotent \u2014 every call creates a new event.", keywords={"calendar","google","create","event","schedule"}, idempotent=false) public String gcalCreateEvent(@ToolParam(description="Event title") String summary, @ToolParam(description="Start time (ISO-8601, e.g. \"2026-12-31T17:00:00+03:00\")") String start, @ToolParam(description="End time (ISO-8601)") String end, @ToolParam(description="Optional description",required=false,defaultValue="") String description, @ToolParam(description="Optional location",required=false,defaultValue="") String location, @ToolParam(description="Calendar id (default \"primary\")",required=false,defaultValue="primary") String calendarId) throws IOException - Throws:
IOException
-
gdriveListFiles
@Tool(name="gdrive_list_files", description="List Google Drive files (paginated). Optional {query} uses Drive\'s query syntax (e.g. \"name contains \'report\'\", \"mimeType = \'application/pdf\'\"). {maxResults} clamps to [1, 100]. Returns the raw JSON file list. Requires GOOGLE_DRIVE_ACCESS_TOKEN.", keywords={"drive","google","files","list","search"}, idempotent=true) public String gdriveListFiles(@ToolParam(description="Optional Drive query (e.g. \"name contains \'foo\'\")",required=false,defaultValue="") String query, @ToolParam(description="Max results (1..100); 0 \u2192 default 10",required=false,defaultValue="0") int maxResults) throws IOException - Throws:
IOException
-
gdriveReadFile
@Tool(name="gdrive_read_file", description="Read the raw content of a Google Drive file by id. Works best for text-like files (Docs / Sheets need the export endpoint instead). Returns the file\'s bytes as a UTF-8 string.", keywords={"drive","google","read","file","content"}, idempotent=true) public String gdriveReadFile(@ToolParam(description="Drive file id") String fileId) throws IOException - Throws:
IOException
-
gdriveCreateFile
@Tool(name="gdrive_create_file", description="Create a new Drive file with text content. {mimeType} defaults to \"text/plain\". Returns the raw JSON of the created file (with assigned id). NOT idempotent \u2014 every call creates a new file.", keywords={"drive","google","create","upload","file"}, idempotent=false) public String gdriveCreateFile(@ToolParam(description="File name") String name, @ToolParam(description="File text content") String content, @ToolParam(description="MIME type (default \"text/plain\")",required=false,defaultValue="text/plain") String mimeType) throws IOException - Throws:
IOException
-