+ {shown.length
+ ? "Files from these folders are available in this topic's chat."
+ : "Link a Teams channel or OneDrive folder to explore its files in this topic's chat."}
+
+ {note &&
{note}
}
+ {error && (
+
+ {error}
+
+ )}
+
+ );
+}
diff --git a/packages/collaboration/src/features/collaboration/live/live-state.ts b/packages/collaboration/src/features/collaboration/live/live-state.ts
index 3351eab5fa..0ababc9302 100644
--- a/packages/collaboration/src/features/collaboration/live/live-state.ts
+++ b/packages/collaboration/src/features/collaboration/live/live-state.ts
@@ -306,6 +306,26 @@ export function mapTopicFiles(rows: unknown): TopicFile[] {
}));
}
+/** A topic's linked M365 folders, as BrainGetTopic and BrainLinkTopicM365Folder answer them. */
+export function mapTopicM365Folders(
+ rows: unknown,
+): import("@/features/connectors/api/m365-folders").TopicM365Folder[] {
+ return list(rows).map((folder) => ({
+ linkId: str(folder.linkId),
+ kind:
+ (folder.kind as "drive_folder" | "channel_files") ?? "drive_folder",
+ displayName: str(folder.displayName),
+ driveId: opt(folder.driveId),
+ itemId: opt(folder.itemId),
+ teamId: opt(folder.teamId),
+ channelId: opt(folder.channelId),
+ siteId: opt(folder.siteId),
+ webUrl: opt(folder.webUrl),
+ state: (folder.state as "ok" | "no_access") ?? "ok",
+ checkedAt: opt(folder.checkedAt),
+ }));
+}
+
export function mapTopic(row: Row): Topic {
const stats = (row.stats ?? {}) as Row;
return {
@@ -339,6 +359,7 @@ export function mapTopic(row: Row): Topic {
origin: opt(folder.origin),
})),
files: mapTopicFiles(row.files),
+ m365Folders: mapTopicM365Folders(row.m365Folders),
stats: {
threads: Number(stats.threads ?? 0),
openItems: Number(stats.openItems ?? 0),
diff --git a/packages/collaboration/src/features/collaboration/state/collaboration.types.ts b/packages/collaboration/src/features/collaboration/state/collaboration.types.ts
index f3a8d10f82..cb630ce95b 100644
--- a/packages/collaboration/src/features/collaboration/state/collaboration.types.ts
+++ b/packages/collaboration/src/features/collaboration/state/collaboration.types.ts
@@ -1,3 +1,4 @@
+import type { TopicM365Folder as ApiTopicM365Folder } from "@/features/connectors/api/m365-folders";
import type { SourceAttachment } from "@/features/connectors/types";
import type { DisplayBody } from "@/features/email/message-body";
@@ -49,6 +50,9 @@ export interface TopicFile {
webUrl?: string;
}
+/** A Microsoft 365 folder (Teams channel or OneDrive folder) linked to a topic. */
+export type TopicM365Folder = ApiTopicM365Folder;
+
export interface Topic {
id: string;
name: string;
@@ -65,6 +69,8 @@ export interface Topic {
folders?: { id: string; path: string; origin?: string | null }[];
/** OneDrive and Teams files the owner linked to the topic. */
files?: TopicFile[];
+ /** Microsoft 365 folders (Teams channels, OneDrive folders) linked to the topic. */
+ m365Folders?: TopicM365Folder[];
stats: { threads: number; openItems: number; lastActivity: string };
isSample: boolean;
}
diff --git a/packages/collaboration/src/features/connectors/api/m365-folders.ts b/packages/collaboration/src/features/connectors/api/m365-folders.ts
new file mode 100644
index 0000000000..d10ffaa4d0
--- /dev/null
+++ b/packages/collaboration/src/features/connectors/api/m365-folders.ts
@@ -0,0 +1,157 @@
+import { z } from "@semoss/ui/next";
+import { callPixel, type InsightActions, pixel } from "@/lib/pixel";
+
+export const topicM365FolderSchema = z.object({
+ linkId: z.string(),
+ kind: z.enum(["drive_folder", "channel_files"]),
+ displayName: z.string(),
+ driveId: z.string().optional().nullable(),
+ itemId: z.string().optional().nullable(),
+ teamId: z.string().optional().nullable(),
+ channelId: z.string().optional().nullable(),
+ siteId: z.string().optional().nullable(),
+ webUrl: z.string().optional().nullable(),
+ state: z.enum(["ok", "no_access"]),
+ checkedAt: z.string().optional().nullable(),
+});
+export type TopicM365Folder = z.infer;
+
+const folderPointerSchema = z.object({
+ kind: z.enum(["drive_folder", "channel_files"]),
+ displayName: z.string(),
+ linkId: z.string().optional(),
+ driveId: z.string().optional(),
+ itemId: z.string().optional(),
+ teamId: z.string().optional(),
+ channelId: z.string().optional(),
+ siteId: z.string().optional(),
+ webUrl: z.string().optional(),
+});
+export type FolderPointer = z.infer;
+
+// OneDrive folder browser
+const oneDriveFolderSchema = z.object({
+ id: z.string(),
+ name: z.string(),
+ driveId: z.string(),
+ itemId: z.string(),
+ webUrl: z.string().optional(),
+ isFolder: z.boolean().optional(),
+});
+export type OneDriveFolder = z.infer;
+
+const oneDriveFoldersSchema = z.object({
+ files: z.array(oneDriveFolderSchema),
+});
+
+// Teams browser
+const teamSchema = z.object({
+ id: z.string(),
+ displayName: z.string(),
+});
+export type Team = z.infer;
+
+const teamsListSchema = z.object({
+ teams: z.array(teamSchema),
+});
+
+const teamChannelSchema = z.object({
+ id: z.string(),
+ displayName: z.string(),
+ webUrl: z.string().optional(),
+});
+export type TeamChannel = z.infer;
+
+const channelsListSchema = z.object({
+ channels: z.array(teamChannelSchema),
+});
+
+const listLinksSchema = z.object({
+ topicId: z.string(),
+ folders: z.array(topicM365FolderSchema),
+});
+
+const linkResultSchema = z.object({
+ topicId: z.string(),
+ folders: z.array(topicM365FolderSchema),
+});
+
+/** List the M365 folders linked to a topic (OneDrive, Teams channels). */
+export async function listTopicM365Folders(
+ actions: InsightActions,
+ topicId: string,
+): Promise {
+ return (
+ await callPixel(
+ actions,
+ pixel("BrainListTopicM365Folders", { topicId }),
+ listLinksSchema,
+ )
+ ).folders;
+}
+
+/** List OneDrive folders available to the user (from their drive and shared folders). */
+export async function listAvailableOneDriveFolders(
+ actions: InsightActions,
+): Promise {
+ return (
+ await callPixel(
+ actions,
+ pixel("MicrosoftOneDriveListFiles"),
+ oneDriveFoldersSchema,
+ )
+ ).files;
+}
+
+/** List Microsoft Teams available to the user. */
+export async function listAvailableTeams(
+ actions: InsightActions,
+): Promise {
+ return (
+ await callPixel(
+ actions,
+ pixel("MicrosoftTeamsListTeams"),
+ teamsListSchema,
+ )
+ ).teams;
+}
+
+/** List channels in a Microsoft Teams team. */
+export async function listTeamChannels(
+ actions: InsightActions,
+ teamId: string,
+): Promise {
+ return (
+ await callPixel(
+ actions,
+ pixel("MicrosoftTeamsListChannels", { teamId }),
+ channelsListSchema,
+ )
+ ).channels;
+}
+
+/** Link an M365 folder (OneDrive or Teams channel) to a topic. */
+export function linkTopicM365Folder(
+ actions: InsightActions,
+ topicId: string,
+ folder: FolderPointer,
+): Promise {
+ return callPixel(
+ actions,
+ pixel("BrainLinkTopicM365Folder", { topicId, ...folder }),
+ linkResultSchema,
+ ).then((result) => result.folders);
+}
+
+/** Unlink an M365 folder from a topic. */
+export function unlinkTopicM365Folder(
+ actions: InsightActions,
+ topicId: string,
+ linkId: string,
+): Promise {
+ return callPixel(
+ actions,
+ pixel("BrainLinkTopicM365Folder", { topicId, linkId, remove: true }),
+ linkResultSchema,
+ ).then((result) => result.folders);
+}