Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update summarization responce to include permalink preview. #98

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/post_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (p *Plugin) botDM(userID string, post *model.Post) error {
p.modifyPostForBot(userID, post)

if err := p.pluginAPI.Post.DM(p.botid, userID, post); err != nil {
return err
return errors.Wrap(err, "failed to post DM")
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ func (p *Plugin) startNewSummaryThread(postIDToSummarize string, context ai.Conv
return nil, err
}

siteURL := p.API.GetConfig().ServiceSettings.SiteURL
post := &model.Post{
Message: fmt.Sprintf("A summary of [this thread](/_redirect/pl/%s):\n", postIDToSummarize),
Message: fmt.Sprintf("Sure, I will summarize this thread: %s/_redirect/pl/%s\n", *siteURL, postIDToSummarize),
}
post.AddProp(ThreadIDProp, postIDToSummarize)

Expand Down
41 changes: 41 additions & 0 deletions webapp/src/components/llmbot_post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import PostText from './post_text';
import IconRegenerate from './assets/icon_regenerate';
import IconCancel from './assets/icon_cancel';

const PostMessagePreview = (window as any).Components.PostMessagePreview;

const FixPostHover = createGlobalStyle<{disableHover?: string}>`
${(props) => props.disableHover && css`
&&&& {
Expand Down Expand Up @@ -134,6 +136,19 @@ export const LLMBotPost = (props: Props) => {
};

const requesterIsCurrentUser = (props.post.props?.llm_requester_user_id === currentUserId);
const isThreadSummaryPost = (props.post.props?.referenced_thread && props.post.props?.referenced_thread !== '');

let permalinkView = null;
if (PostMessagePreview) { // Ignore permalink if version does not exporrt PostMessagePreview
const permalinkData = extractPermalinkData(props.post);
if (permalinkData !== null) {
permalinkView = (
<PostMessagePreview
metadata={permalinkData}
/>
);
}
}

return (
<PostBody
Expand All @@ -143,6 +158,11 @@ export const LLMBotPost = (props: Props) => {
onMouseMove={stopPropagationIfGenerating}
>
<FixPostHover disableHover={generating ? props.post.id : ''}/>
{isThreadSummaryPost && permalinkView &&
<>
{permalinkView}
</>
}
<PostText
message={message}
channelID={props.post.channel_id}
Expand All @@ -169,3 +189,24 @@ export const LLMBotPost = (props: Props) => {
</PostBody>
);
};

type PermalinkData = {
channel_display_name: string
channel_id: string
post_id: string
team_name: string
post: {
message: string
user_id: string
}
}

function extractPermalinkData(post: any): PermalinkData | null {
for (const embed of post?.metadata?.embeds || []) {
if (embed.type === 'permalink') {
return embed.data;
}
}
return null;
}