Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(ai): top bar share menu (#1275)

Eric Hayesa119956a9dba
diff --git a/js/app/packages/app/component/rightbar/Rightbar.tsx b/js/app/packages/app/component/rightbar/Rightbar.tsx
index f95d38a2ae..cdcca0447c 100644
--- a/js/app/packages/app/component/rightbar/Rightbar.tsx
+++ b/js/app/packages/app/component/rightbar/Rightbar.tsx
@@ -25,6 +25,9 @@ import { CustomScrollbar } from '@core/component/CustomScrollbar';
import { DeprecatedIconButton } from '@core/component/DeprecatedIconButton';
import { DropdownMenuContent, MenuItem } from '@core/component/Menu';
import { ReferencesModal } from '@core/component/ReferencesModal';
+import { ShareButton } from '@core/component/TopBar/ShareButton';
+import { getPermissions } from '@core/component/SharePermissions';
+import type { Permissions } from '@core/component/SharePermissions';
import { Resize } from '@core/component/Resize';
import { ENABLE_REFERENCES_MODAL } from '@core/constant/featureFlags';
import { usePaywallState } from '@core/constant/PaywallState';
@@ -72,12 +75,14 @@ import { SplitlikeContainer } from '../split-layout/components/SplitContainer';
import { Button } from '@ui/components/Button';
import { Hotkey } from '@core/component/Hotkey';
import { setPreviewData } from '@queries/preview';
+import { AccessLevel } from '@service-cognition/generated/schemas/accessLevel';
type ChatData = {
messages: ChatMessageWithAttachments[];
name: string | undefined;
model: Model | undefined;
attachments: Attachment[];
+ userAccessLevel?: AccessLevel;
};
const getChatData = async (chatId: string): Promise<ChatData> => {
@@ -111,7 +116,13 @@ const getChatData = async (chatId: string): Promise<ChatData> => {
.values()
.toArray();
- return { messages, name, model, attachments };
+ return {
+ messages,
+ name,
+ model,
+ attachments,
+ userAccessLevel: chat.userAccessLevel as AccessLevel,
+ };
};
const usePersistentChats = () => {
@@ -174,6 +185,7 @@ function TopBar(props: {
chatId: string | undefined;
setChatId: (chatId: string | undefined) => void;
chatName?: string;
+ userPermissions: Accessor<Permissions>;
}) {
const createNewRightbarChat = () => {
props.setChatId(undefined);
@@ -215,36 +227,47 @@ function TopBar(props: {
<PlusIcon />
</Button>
<div class="grow" />
- <Show when={ENABLE_REFERENCES_MODAL && props.chatId}>
- <ReferencesModal
- documentId={props.chatId!}
- documentName={props.chatName ?? 'New Chat'}
+ <div class="flex items-center gap-1">
+ <Show when={ENABLE_REFERENCES_MODAL && props.chatId}>
+ <ReferencesModal
+ documentId={props.chatId!}
+ documentName={props.chatName ?? 'New Chat'}
+ entityType="chat"
+ />
+ </Show>
+ <Show when={props.chatId}>
+ <ShareButton
+ id={props.chatId!}
+ name={props.chatName ?? 'New Chat'}
+ userPermissions={props.userPermissions()}
+ itemType="chat"
+ />
+ </Show>
+ <DeprecatedIconButton
+ size="sm"
+ icon={NotepadIcon}
+ tooltip={{ label: 'Edit AI Instructions' }}
+ theme="current"
+ onClick={() => {
+ openInstructions();
+ }}
/>
- </Show>
- <DeprecatedIconButton
- size="sm"
- icon={NotepadIcon}
- tooltip={{ label: 'Edit AI Instructions' }}
- theme="current"
- onClick={() => {
- openInstructions();
- }}
- />
- <PersistentChatHistoryButton setChatId={props.setChatId} />
- <DeprecatedIconButton
- size="sm"
- icon={bigChatOpen() ? ContractIcon : ExpandIcon}
- tooltip={{
- label: bigChatOpen()
- ? 'Minimize Assistant Panel'
- : 'Spotlight Assistant Panel',
- hotkeyToken: TOKENS.global.toggleBigChat,
- }}
- theme="current"
- onClick={() => {
- setBigChatOpen((v) => !v);
- }}
- />
+ <PersistentChatHistoryButton setChatId={props.setChatId} />
+ <DeprecatedIconButton
+ size="sm"
+ icon={bigChatOpen() ? ContractIcon : ExpandIcon}
+ tooltip={{
+ label: bigChatOpen()
+ ? 'Minimize Assistant Panel'
+ : 'Spotlight Assistant Panel',
+ hotkeyToken: TOKENS.global.toggleBigChat,
+ }}
+ theme="current"
+ onClick={() => {
+ setBigChatOpen((v) => !v);
+ }}
+ />
+ </div>
</div>
);
}
@@ -262,6 +285,7 @@ export function Rightbar(props: {
attachments: Attachment[];
text: string | undefined;
};
+ userPermissions: Accessor<Permissions>;
setState: {
setChatId: (chatId: string | undefined) => void;
setModel: Setter<Model | undefined>;
@@ -400,6 +424,7 @@ export function Rightbar(props: {
chatId={props.chatId}
setChatId={props.setState.setChatId}
chatName={props.chatName}
+ userPermissions={props.userPermissions}
/>
<div class="flex flex-col flex-1 min-h-0 p-2 w-full items-center">
<Show when={props.messages().length === 0}>
@@ -455,6 +480,9 @@ export const RightbarWrapper = (_props: { isBigChat?: boolean }) => {
const [messages, setMessages] = createSignal<ChatMessageWithAttachments[]>(
[]
);
+ const [userAccessLevel, setUserAccessLevel] = createSignal<
+ AccessLevel | undefined
+ >();
const [model, setModel] = createSignal<Model | undefined>();
const [attachments, setAttachments] = createSignal<Attachment[]>([]);
const [stream, setStream] = createSignal<MessageStream>();
@@ -466,6 +494,7 @@ export const RightbarWrapper = (_props: { isBigChat?: boolean }) => {
}
| undefined
>();
+ const userPermissions = createMemo(() => getPermissions(userAccessLevel()));
const [attachHotkeys, scopeId] = useHotkeyDOMScope('ai-chat');
@@ -476,6 +505,7 @@ export const RightbarWrapper = (_props: { isBigChat?: boolean }) => {
setAttachments(attached);
setText(undefined);
setMessages([]);
+ setUserAccessLevel(undefined);
setInitialChatState({
model: undefined,
attachments: attached,
@@ -564,6 +594,7 @@ export const RightbarWrapper = (_props: { isBigChat?: boolean }) => {
const newChatId = response.chat_id;
setNewChatId(newChatId);
setChatId(newChatId);
+ setUserAccessLevel(AccessLevel.owner);
// TODO: move this into a separate resource so we don't have to refetch history
// refetch history immediately to have the new chat id
@@ -647,11 +678,12 @@ export const RightbarWrapper = (_props: { isBigChat?: boolean }) => {
// load existing server chat
clearChatState();
getChatData(chatId_)
- .then(({ messages, name, model, attachments }) => {
+ .then(({ messages, name, model, attachments, userAccessLevel }) => {
setChatName(name);
setMessages(messages);
setModel(model);
setAttachments(attachments);
+ setUserAccessLevel(userAccessLevel);
setInitialChatState({
model,
attachments,
@@ -747,6 +779,7 @@ export const RightbarWrapper = (_props: { isBigChat?: boolean }) => {
onSend={onSend}
stream={stream}
stopGenerating={stopGenerating}
+ userPermissions={userPermissions}
setState={{
setChatId,
setModel,
diff --git a/js/app/packages/block-chat/component/TopBar.tsx b/js/app/packages/block-chat/component/TopBar.tsx
index 2d42861099..30b90df485 100644
--- a/js/app/packages/block-chat/component/TopBar.tsx
+++ b/js/app/packages/block-chat/component/TopBar.tsx
@@ -91,6 +91,7 @@ export function TopBar() {
documentId={blockId}
documentName={chatName()}
buttonSize="sm"
+ entityType="chat"
/>
<div class="flex items-center">
<SplitPermissionsBadge />
diff --git a/js/app/packages/core/component/References.tsx b/js/app/packages/core/component/References.tsx
index 9332f3418a..2bb2a2194e 100644
--- a/js/app/packages/core/component/References.tsx
+++ b/js/app/packages/core/component/References.tsx
@@ -23,6 +23,7 @@ import { URL_PARAMS as CHANNEL_PARAMS } from '@block-channel/constants';
export type ReferenceProps = {
documentId: string;
+ entityType?: ItemType;
};
function isChannelReference(ref: EntityReference): ref is EntityReference & {
@@ -54,8 +55,9 @@ function isGenericReference(
export function References(props: ReferenceProps) {
const [references] = createResource(async () => {
+ const entityType = props.entityType ?? 'document';
const response = await commsServiceClient.attachmentReferences({
- entity_type: 'document',
+ entity_type: entityType,
entity_id: props.documentId,
});
diff --git a/js/app/packages/core/component/ReferencesModal.tsx b/js/app/packages/core/component/ReferencesModal.tsx
index 9122ff530c..20e08ba81c 100644
--- a/js/app/packages/core/component/ReferencesModal.tsx
+++ b/js/app/packages/core/component/ReferencesModal.tsx
@@ -5,6 +5,7 @@ import { isErr } from '@core/util/maybeResult';
import Quotes from '@icon/regular/quotes.svg';
import BracketLeft from '@macro-icons/macro-group-bracket-left.svg';
import { commsServiceClient } from '@service-comms/client';
+import type { ItemType } from '@service-storage/client';
import { createResource, Suspense } from 'solid-js';
import { References } from './References';
import { Tooltip } from './Tooltip';
@@ -16,6 +17,7 @@ export type ReferencesModalProps = {
documentId: string;
documentName?: string;
buttonSize?: 'sm';
+ entityType?: ItemType;
};
export function ReferencesModal(props: ReferencesModalProps) {
@@ -23,8 +25,9 @@ export function ReferencesModal(props: ReferencesModalProps) {
const [referenceCount] = createResource(
() => props.documentId,
async (id) => {
+ const entityType = props.entityType ?? 'document';
const response = await commsServiceClient.attachmentReferences({
- entity_type: 'document',
+ entity_type: entityType,
entity_id: id,
});
@@ -74,7 +77,10 @@ export function ReferencesModal(props: ReferencesModalProps) {
</div>
}
>
- <References documentId={props.documentId} />
+ <References
+ documentId={props.documentId}
+ entityType={props.entityType}
+ />
</Suspense>
</SplitDrawer>
</>
diff --git a/js/app/packages/core/component/TopBar/ShareButton.tsx b/js/app/packages/core/component/TopBar/ShareButton.tsx
index 7e828c3f53..fb18cc622d 100644
--- a/js/app/packages/core/component/TopBar/ShareButton.tsx
+++ b/js/app/packages/core/component/TopBar/ShareButton.tsx
@@ -6,6 +6,7 @@ import {
type BlockName,
createBlockEffect,
createBlockResource,
+ isInBlock,
useBlockAliasedName,
useBlockId,
useBlockName,
@@ -105,7 +106,7 @@ createBlockEffect(() => {
});
const accessLevelText = (accessLevel?: AccessLevel | null) => {
- const blockName = useBlockName();
+ const blockName = isInBlock() ? useBlockName() : undefined;
switch (accessLevel) {
case 'comment':
if (blockName === 'md' && !ENABLE_MARKDOWN_COMMENTS) {
@@ -147,7 +148,37 @@ interface ShareModalProps {
export function ShareModal(props: ShareModalProps) {
const navigate = useNavigate();
const { track } = withAnalytics();
- const [permissionsResource, { refetch }] = permissionsBlockResource;
+ const isBlockContext = isInBlock();
+ const [fallbackPermissionsResource, { refetch: refetchFallback }] =
+ createResource(
+ () => {
+ if (isBlockContext || !props.id) return;
+ return { id: props.id, itemType: props.itemType };
+ },
+ async (source) => {
+ if (!source) return;
+ const { id, itemType } = source;
+ if (itemType === 'chat') {
+ return cognitionApiServiceClient.getChatPermissions({ id });
+ } else if (itemType === 'document') {
+ return storageServiceClient.getDocumentPermissions({
+ document_id: id,
+ });
+ } else if (itemType === 'project') {
+ if (id === 'trash') {
+ return;
+ }
+ return storageServiceClient.projects.getPermissions({ id });
+ }
+ },
+ { initialValue: undefined }
+ );
+ const permissionsResource = isBlockContext
+ ? permissionsBlockResource[0]
+ : fallbackPermissionsResource;
+ const refetch = isBlockContext
+ ? permissionsBlockResource[1].refetch
+ : refetchFallback;
const userId = useUserId();
const copyPublicLink = createCallback(() => {
@@ -631,13 +662,40 @@ interface ShareButtonProps {
export function ShareButton(props: ShareButtonProps) {
const [isSharePermOpen, setIsSharePermOpen] = createSignal(false);
- const [permissionsResource] = permissionsBlockResource;
- const blockScopeId = blockHotkeyScopeSignal.get;
+ const isBlockContext = isInBlock();
+ const [fallbackPermissionsResource] = createResource(
+ () => {
+ if (isBlockContext || !props.id) return;
+ return { id: props.id, itemType: props.itemType };
+ },
+ async (source) => {
+ if (!source) return;
+ const { id, itemType } = source;
+ if (itemType === 'chat') {
+ return cognitionApiServiceClient.getChatPermissions({ id });
+ } else if (itemType === 'document') {
+ return storageServiceClient.getDocumentPermissions({ document_id: id });
+ } else if (itemType === 'project') {
+ if (id === 'trash') {
+ return;
+ }
+ return storageServiceClient.projects.getPermissions({ id });
+ }
+ },
+ { initialValue: undefined }
+ );
+ const permissionsResource = isBlockContext
+ ? permissionsBlockResource[0]
+ : fallbackPermissionsResource;
const isAuthenticated = useIsAuthenticated();
- const blockType = useBlockAliasedName();
- const blockId = useBlockId();
+ const blockType = isBlockContext
+ ? useBlockAliasedName()
+ : (props.itemType as BlockName | BlockAlias);
+ const blockId = isBlockContext ? useBlockId() : props.id;
onMount(() => {
+ if (!isBlockContext) return;
+ const blockScopeId = blockHotkeyScopeSignal.get;
registerHotkey({
keyDownHandler: () => {
if (!isAuthenticated()) {
@@ -786,8 +844,10 @@ export function ShareOptions(props: {
label?: string | '';
disabled?: boolean;
}) {
- const editPermissionEnabled = blockEditPermissionEnabledSignal();
- const blockName = useBlockName();
+ const editPermissionEnabled = isInBlock()
+ ? blockEditPermissionEnabledSignal()
+ : true;
+ const blockName = isInBlock() ? useBlockName() : undefined;
const options = createMemo(() => {
const optionsList: { value: string; label: string }[] = [];