Skip to content

Commit 9dd9e36

Browse files
feat(integrations): add Google Drive and Calendar context (#487)
* feat(integrations): add Google Docs and Sheets context * fix(web): register Google context in sent messages * feat(integrations): extend Google to Drive files and Calendar events Drive files, folders and Slides, and Calendar events, now attach, cite, link and watch through the same Google connection as Docs and Sheets. Google, Docs, Sheets, Drive and Calendar icons use the monochrome Simple Icons marks on web and mobile. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(web): label the Google attach menu item just Google Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(web): size the Google picker row icons Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(web): show the Google icon on loading Google link chips Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(web): columns, filters and sort in the Google picker Drive rows show owner and last-modified date; Calendar rows show organizer and start time. Filter by type, owner/organizer and date, and sort, the same way the Granola picker does. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(server): Google previews survive hidden comments and small sheet tabs Drive refuses to list comments to some viewers, which failed the whole read. Sheets rejected the fixed A1:Z100 preview range on tabs smaller than that, and on chart tabs. Comments are now best-effort, and the default range stops at each grid tab's edge. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(web): open link hover previews at once with a loading placeholder Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(web): calendar-style week view for the Google Calendar picker The Calendar tab shows a week strip with previous, next and Today, and an agenda for the picked day (or the whole week) grouped by day with start and end times. Each week is read on its own, and the server merges calendars in start order before trimming, so early events are no longer dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(server): read only the Google calendars the user has ticked Subscribed room calendars filled the 30-event cut with everyone's bookings, hiding the user's own week. Search now reads the primary and selected calendars, up to 100 events. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(google): choose which calendars the picker shows The Calendar tab says it is showing the calendars ticked in Google Calendar, and Filter > Calendars lists every calendar the account can read, or takes a colleague's email, to show other people's events. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(web): show each calendar the Google picker reads as a pill Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(google): find colleagues' calendars by name Filter > Calendars searches the Workspace directory, the way Google Calendar's "Search for people" does, and adds a colleague's calendar. This asks for read-only directory access; older connections are told to reconnect, and typing an email still works without it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(web): searching people in the calendar filter no longer crashes Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(mcp): let agents list Google calendars and find colleagues Adds list_google_calendars and search_google_people, and calendarIds on search_google_files, so agents can do what the picker's calendar filter does. The search tool's status now says Google Drive and Calendar. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 6051883 commit 9dd9e36

124 files changed

Lines changed: 6677 additions & 134 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
812 Bytes
Loading
475 Bytes
Loading
921 Bytes
Loading
511 Bytes
Loading

‎apps/mobile/scripts/sync-context-chip-icons.mjs‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { INTEGRATION_ICONS } from "../../../packages/shared/src/brandMarks.ts";
12
import * as NodeFS from "node:fs";
23
import * as NodeModule from "node:module";
34
import * as NodePath from "node:path";
@@ -92,8 +93,20 @@ for (const name of lucideIcons) {
9293
await renderIcon(name, await lucideSvg(name));
9394
}
9495
await renderIcon("skill", skillSvg);
95-
96-
const tokens = [...lucideIcons, "skill"].sort();
96+
const googleBrands = [
97+
["google-doc", "googleDocs"],
98+
["google-sheet", "googleSheets"],
99+
["google-drive", "googleDrive"],
100+
["google-calendar", "googleCalendar"],
101+
];
102+
for (const [token, brand] of googleBrands) {
103+
const icon = INTEGRATION_ICONS[brand];
104+
await renderIcon(
105+
token,
106+
`<svg viewBox="${icon.viewBox}" fill="currentColor"><path d="${icon.path}"/></svg>`,
107+
);
108+
}
109+
const tokens = [...googleBrands.map(([token]) => token), ...lucideIcons, "skill"].sort();
97110
const generatedSource = `import type { ImageSourcePropType } from "react-native";\n\nexport const CONTEXT_CHIP_ICON_SOURCES = {\n${tokens
98111
.map(
99112
(token) =>

‎apps/mobile/src/components/ComposerContextSheet.tsx‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,32 @@ export function ComposerContextSheet(props: {
555555
</Text>
556556
</View>
557557
) : null}
558+
{record.kind === "google-file" ? (
559+
<View className="gap-3">
560+
<View className="gap-1">
561+
<Text selectable className="text-lg font-t3-semibold text-foreground">
562+
{record.title}
563+
</Text>
564+
</View>
565+
{/^https?:\/\//i.test(record.url) ? (
566+
<Pressable
567+
accessibilityRole="link"
568+
onPress={() => {
569+
void tryOpenExternalUrl(record.url, "markdown-link").then((opened) => {
570+
if (!opened) Dialog.alert("Could not open Google", "Try again later.");
571+
});
572+
}}
573+
className="rounded-xl bg-subtle p-4"
574+
>
575+
<Text className="text-foreground">Open in Google</Text>
576+
</Pressable>
577+
) : null}
578+
{/* Plain text like the other captured context here: exactly what the agent received. */}
579+
<Text selectable className="text-sm text-foreground">
580+
{record.markdown}
581+
</Text>
582+
</View>
583+
) : null}
558584
{record.kind === "granola-note" ? (
559585
<View className="gap-3">
560586
<View className="gap-1">
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
import type { EnvironmentId, GoogleFileSummary, ThreadId } from "@t3tools/contracts";
2+
import { useAtomValue } from "@effect/atom-react";
3+
import { googleFileContextRecord } from "@t3tools/client-runtime/state/google";
4+
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
5+
import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
6+
import * as Cause from "effect/Cause";
7+
import * as Option from "effect/Option";
8+
import { AsyncResult } from "effect/reactivity";
9+
import { useState, type ReactNode } from "react";
10+
import { ActivityIndicator, Alert, FlatList, Pressable, View } from "react-native";
11+
import { useSafeAreaInsets } from "react-native-safe-area-context";
12+
13+
import { relativeTime } from "../lib/time";
14+
import { useEnvironmentServerConfig } from "../state/entities";
15+
import { googleEnvironment } from "../state/google";
16+
import { useDebouncedValue } from "../state/queries";
17+
import { useEnvironmentQuery } from "../state/query";
18+
import { useAtomCommand } from "../state/use-atom-command";
19+
import {
20+
captureComposerDraftInsertion,
21+
insertComposerDraftContext,
22+
type ComposerDraftInsertion,
23+
} from "../state/use-composer-drafts";
24+
import { AppText as Text, AppTextInput } from "./ui/AppText";
25+
import { PickerSheet } from "./PickerSheet";
26+
27+
/** Google allows search request quotas, so typing settles longer before it queries. */
28+
const SEARCH_DEBOUNCE_MS = 400;
29+
30+
/** Google's failures carry a reason; a rate limit deserves a clearer hint than its detail. */
31+
function googleErrorMessage(error: unknown, fallback: string): string {
32+
if (typeof error === "object" && error !== null && "reason" in error) {
33+
if (error.reason === "rate-limited") return "Google is busy. Try again shortly.";
34+
if (error.reason === "not-connected" || error.reason === "revoked") {
35+
return "Google is not connected. Connect it from Settings > Integrations on desktop or web.";
36+
}
37+
if (error.reason === "not-found")
38+
return "Check that the connected Google account can open this document.";
39+
}
40+
return error instanceof Error && error.message.trim() ? error.message : fallback;
41+
}
42+
43+
/** Attach inserts the page into a composer draft; link links it to the thread's tab group. */
44+
export type GoogleFilePickerTarget =
45+
| { readonly mode?: "attach"; readonly environmentId: EnvironmentId; readonly draftKey: string }
46+
| { readonly mode: "link"; readonly environmentId: EnvironmentId; readonly threadId: ThreadId };
47+
48+
type OpenedGoogleFilePicker =
49+
| {
50+
readonly mode: "attach";
51+
readonly environmentId: EnvironmentId;
52+
readonly draftKey: string;
53+
readonly insertion: ComposerDraftInsertion;
54+
}
55+
| { readonly mode: "link"; readonly environmentId: EnvironmentId; readonly threadId: ThreadId };
56+
57+
/**
58+
* A Google file or event picker. The owner renders `sheet` somewhere that outlives composer focus:
59+
* opening the sheet blurs the editor, which can unmount a focus-dependent toolbar.
60+
*/
61+
export function useGoogleFilePicker(target: GoogleFilePickerTarget | null): {
62+
readonly open: (() => void) | undefined;
63+
readonly sheet: ReactNode;
64+
} {
65+
const [opened, setOpened] = useState<OpenedGoogleFilePicker | null>(null);
66+
const serverConfig = useEnvironmentServerConfig(target?.environmentId ?? null);
67+
const enabled = serverConfig?.settings.enableGoogleIntegration === true;
68+
const openedServerConfig = useEnvironmentServerConfig(opened?.environmentId ?? null);
69+
return {
70+
open:
71+
target && enabled
72+
? () =>
73+
setOpened(
74+
target.mode === "link"
75+
? target
76+
: {
77+
...target,
78+
mode: "attach",
79+
insertion: captureComposerDraftInsertion(target.draftKey),
80+
},
81+
)
82+
: undefined,
83+
sheet:
84+
opened && openedServerConfig?.settings.enableGoogleIntegration ? (
85+
<GoogleFilePickerSheet {...opened} onClose={() => setOpened(null)} />
86+
) : null,
87+
};
88+
}
89+
90+
/**
91+
* Attaches a Google file or event at the caret the composer had when the sheet opened, or links it to the
92+
* thread's tab group. Mobile has no Google settings, so an unconnected environment points at
93+
* desktop or web.
94+
*/
95+
function GoogleFilePickerSheet(props: OpenedGoogleFilePicker & { readonly onClose: () => void }) {
96+
const connection = useEnvironmentQuery(
97+
googleEnvironment.connection({ environmentId: props.environmentId, input: {} }),
98+
);
99+
const phase = connection.data?.phase;
100+
return (
101+
<PickerSheet
102+
title={props.mode === "link" ? "Link Google file or event" : "Google file or event"}
103+
onClose={props.onClose}
104+
>
105+
{phase === "connected" ? (
106+
<GoogleFileSearch {...props} />
107+
) : (
108+
<View className="flex-1 items-center justify-center p-6">
109+
{phase === undefined && !connection.error ? (
110+
<ActivityIndicator />
111+
) : (
112+
<Text className="text-center text-foreground-muted">
113+
{connection.error ??
114+
"Google is not connected on this environment. Connect it from Settings > Integrations on desktop or web."}
115+
</Text>
116+
)}
117+
</View>
118+
)}
119+
</PickerSheet>
120+
);
121+
}
122+
123+
function GoogleFileSearch(props: OpenedGoogleFilePicker & { readonly onClose: () => void }) {
124+
const [query, setQuery] = useState("");
125+
const trimmed = query.trim();
126+
const settled = useDebouncedValue(trimmed, SEARCH_DEBOUNCE_MS);
127+
const getFile = useAtomCommand(googleEnvironment.getFile, {
128+
label: "google page fetch",
129+
reportFailure: false,
130+
});
131+
const linkThread = useAtomCommand(googleEnvironment.linkThread, {
132+
label: "google thread link",
133+
reportFailure: false,
134+
});
135+
const [attaching, setAttaching] = useState<string | null>(null);
136+
137+
const link = async (threadId: ThreadId, page: GoogleFileSummary) => {
138+
const result = await linkThread({
139+
environmentId: props.environmentId,
140+
input: { threadId, fileId: page.url },
141+
});
142+
if (result._tag === "Failure") {
143+
Alert.alert(
144+
"Could not link Google file or event",
145+
googleErrorMessage(squashAtomCommandFailure(result), "Try again."),
146+
);
147+
return;
148+
}
149+
props.onClose();
150+
};
151+
152+
const attach = async (page: GoogleFileSummary) => {
153+
if (attaching) return;
154+
setAttaching(page.url);
155+
try {
156+
if (props.mode === "link") {
157+
await link(props.threadId, page);
158+
return;
159+
}
160+
const fetched = await getFile({
161+
environmentId: props.environmentId,
162+
input: { id: page.url },
163+
});
164+
if (fetched._tag === "Failure") {
165+
Alert.alert(
166+
"Could not attach Google file or event",
167+
googleErrorMessage(squashAtomCommandFailure(fetched), "Try again."),
168+
);
169+
return;
170+
}
171+
const record = googleFileContextRecord(fetched.value);
172+
if (
173+
!insertComposerDraftContext(
174+
props.draftKey,
175+
{
176+
text: formatComposerContextReference(record),
177+
context: { version: 1, records: [record] },
178+
},
179+
props.insertion,
180+
)
181+
) {
182+
Alert.alert("Too many context items", "Remove some context from the draft and try again.");
183+
return;
184+
}
185+
props.onClose();
186+
} finally {
187+
setAttaching(null);
188+
}
189+
};
190+
191+
return (
192+
<View className="flex-1">
193+
<View className="px-4 pb-3">
194+
<AppTextInput
195+
accessibilityLabel="Search Google files"
196+
autoFocus
197+
autoCapitalize="none"
198+
autoCorrect={false}
199+
clearButtonMode="while-editing"
200+
placeholder="Search Google"
201+
returnKeyType="search"
202+
value={query}
203+
onChangeText={setQuery}
204+
/>
205+
</View>
206+
{settled ? (
207+
<GoogleFileResults
208+
environmentId={props.environmentId}
209+
query={settled}
210+
pendingInput={settled !== trimmed}
211+
attaching={attaching}
212+
onPick={(page) => void attach(page)}
213+
/>
214+
) : (
215+
<View className="items-center p-6">
216+
{trimmed ? (
217+
<ActivityIndicator />
218+
) : (
219+
<Text className="text-center text-foreground-muted">
220+
Search files and events by title or paste a Google link.
221+
</Text>
222+
)}
223+
</View>
224+
)}
225+
</View>
226+
);
227+
}
228+
229+
/** Mounted only for a settled, non-empty query, so an empty box never spends a search. */
230+
function GoogleFileResults(props: {
231+
readonly environmentId: EnvironmentId;
232+
readonly query: string;
233+
readonly pendingInput: boolean;
234+
readonly attaching: string | null;
235+
readonly onPick: (page: GoogleFileSummary) => void;
236+
}) {
237+
const insets = useSafeAreaInsets();
238+
const result = useAtomValue(
239+
googleEnvironment.files({
240+
environmentId: props.environmentId,
241+
input: { query: props.query, source: "all" },
242+
}),
243+
);
244+
const files = Option.getOrNull(AsyncResult.value(result))?.files ?? [];
245+
const pending = props.pendingInput || result.waiting;
246+
const error =
247+
result._tag === "Failure"
248+
? googleErrorMessage(Cause.squash(result.cause), "Could not search Google.")
249+
: null;
250+
return (
251+
<FlatList
252+
data={files}
253+
keyExtractor={(page) => page.url}
254+
keyboardShouldPersistTaps="handled"
255+
contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 16) }}
256+
ListEmptyComponent={
257+
<View className="items-center p-6">
258+
{pending ? (
259+
<ActivityIndicator />
260+
) : (
261+
<Text
262+
selectable={error !== null}
263+
className={
264+
error ? "text-center text-danger-foreground" : "text-center text-foreground-muted"
265+
}
266+
>
267+
{error ?? "No matching files."}
268+
</Text>
269+
)}
270+
</View>
271+
}
272+
renderItem={({ item }) => (
273+
<Pressable
274+
accessibilityRole="button"
275+
accessibilityLabel={item.title}
276+
disabled={props.attaching !== null}
277+
onPress={() => props.onPick(item)}
278+
className="flex-row items-center gap-3 px-4 py-3 active:bg-subtle disabled:opacity-60"
279+
>
280+
<View className="min-w-0 flex-1 gap-0.5">
281+
<Text className="text-sm text-foreground-muted" numberOfLines={1}>
282+
<Text className="text-sm font-t3-semibold text-foreground">{item.title}</Text>
283+
{` · ${relativeTime(item.updatedAt)}`}
284+
</Text>
285+
<Text className="text-base text-foreground" numberOfLines={2}>
286+
{item.url}
287+
</Text>
288+
</View>
289+
{props.attaching === item.url ? <ActivityIndicator /> : null}
290+
</Pressable>
291+
)}
292+
/>
293+
);
294+
}

‎apps/mobile/src/features/threads/ComposerAttachmentButton.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const GITHUB_ISSUE_ACTION: MenuAction = {
1414
image: "smallcircle.filled.circle",
1515
};
1616
const NOTION_ACTION: MenuAction = { id: "notion", title: "Notion page", image: "doc.text" };
17+
const GOOGLE_ACTION: MenuAction = {
18+
id: "google",
19+
title: "Google file or event",
20+
image: "doc.text",
21+
};
1722
const GRANOLA_ACTION: MenuAction = { id: "granola", title: "Granola note", image: "waveform" };
1823
const SLACK_ACTION: MenuAction = { id: "slack", title: "Slack message", image: "number" };
1924
const DISCORD_ACTION: MenuAction = {
@@ -44,6 +49,7 @@ export function ComposerAttachmentButton(props: {
4449
readonly onPickGitHubIssue?: () => void;
4550
/** Omit to hide the Notion action. See `useNotionPagePicker`. */
4651
readonly onPickNotionPage?: () => void;
52+
readonly onPickGoogleFile?: () => void;
4753
/** Omit to hide the Granola action. See `useGranolaNotePicker`. */
4854
readonly onPickGranolaNote?: () => void;
4955
/** Omit to hide the Slack action. See `useSlackMessagePicker`. */
@@ -62,6 +68,7 @@ export function ComposerAttachmentButton(props: {
6268
...(props.onPickLinearIssue ? [LINEAR_ACTION] : []),
6369
...(props.onPickGitHubIssue ? [GITHUB_ISSUE_ACTION] : []),
6470
...(props.onPickNotionPage ? [NOTION_ACTION] : []),
71+
...(props.onPickGoogleFile ? [GOOGLE_ACTION] : []),
6572
...(props.onPickGranolaNote ? [GRANOLA_ACTION] : []),
6673
...(props.onPickSlackMessage ? [SLACK_ACTION] : []),
6774
...(props.onPickDiscordMessage ? [DISCORD_ACTION] : []),
@@ -107,6 +114,8 @@ export function ComposerAttachmentButton(props: {
107114
props.onPickLinearIssue?.();
108115
} else if (nativeEvent.event === "github-issue") {
109116
props.onPickGitHubIssue?.();
117+
} else if (nativeEvent.event === "google") {
118+
props.onPickGoogleFile?.();
110119
} else if (nativeEvent.event === "notion") {
111120
props.onPickNotionPage?.();
112121
} else if (nativeEvent.event === "granola") {

0 commit comments

Comments
 (0)