-
Notifications
You must be signed in to change notification settings - Fork 299
feat(reminders): reminders AI toolset #5620
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
Open
evanhutnik
wants to merge
1
commit into
main
Choose a base branch
from
evan/reminders-f
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
213 changes: 213 additions & 0 deletions
213
apps/web/src/lib/core/component/AI/component/tool/Reminders.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,213 @@ | ||
| import { formatDateAndTime } from '@entity'; | ||
| import BellSimple from '@phosphor-icons/core/regular/bell-simple.svg'; | ||
| import Check from '@phosphor-icons/core/regular/check.svg'; | ||
| import Trash from '@phosphor-icons/core/regular/trash.svg'; | ||
| import type { NamedTool } from '@service-cognition/generated/tools/tool'; | ||
| import type { | ||
| ListReminders as ListRemindersTool, | ||
| ReminderEntityType, | ||
| UpdateReminder as UpdateReminderTool, | ||
| } from '@service-cognition/generated/tools/types'; | ||
| import { createSignal, For, Show } from 'solid-js'; | ||
| import { BaseTool } from './BaseTool'; | ||
| import { Tool } from './Tool'; | ||
| import { createToolRenderer } from './ToolRenderer'; | ||
|
|
||
| type ToolReminder = NamedTool< | ||
| 'ListReminders', | ||
| 'response' | ||
| >['data']['reminders'][number]; | ||
|
|
||
| const ENTITY_TYPE_LABELS: Record<ReminderEntityType, string> = { | ||
| document: 'a document', | ||
| ai_chat: 'a chat', | ||
| project: 'a project', | ||
| email: 'an email thread', | ||
| channel: 'a channel', | ||
| call: 'a call', | ||
| calendar_event: 'a calendar event', | ||
| }; | ||
|
|
||
| /** What the list call asked for, in the same voice as the notification tools. */ | ||
| const formatReminderFilters = (filters: ListRemindersTool) => { | ||
| if (filters.reminderIds?.length) { | ||
| const count = filters.reminderIds.length; | ||
| return `${count} reminder${count === 1 ? '' : 's'} by id`; | ||
| } | ||
|
|
||
| const parts = [filters.completed ? 'done' : 'not done']; | ||
| if (filters.overdue != null) { | ||
| parts.push(filters.overdue ? 'overdue' : 'upcoming'); | ||
| } | ||
|
|
||
| let text = `filtered by ${parts.join(' and ')}`; | ||
| if (filters.entityType) { | ||
| text += ` for ${ENTITY_TYPE_LABELS[filters.entityType]}`; | ||
| } | ||
| return text; | ||
| }; | ||
|
|
||
| /** | ||
| * What an update actually changed, so the row is readable without expanding | ||
| * the arguments. Reads off the request rather than the response because the | ||
| * response is the merged reminder and no longer says which fields moved. | ||
| */ | ||
| const formatReminderUpdate = (update: UpdateReminderTool) => { | ||
| const changes: string[] = []; | ||
| if (update.completed === true) changes.push('mark done'); | ||
| if (update.completed === false) changes.push('reopen'); | ||
| if (update.remindAt) | ||
| changes.push(`move to ${formatDateAndTime(update.remindAt)}`); | ||
| if (update.description != null) changes.push('reword'); | ||
| return changes.length > 0 ? changes.join(', ') : 'update'; | ||
| }; | ||
|
|
||
| const ReminderList = (props: { reminders: ToolReminder[] }) => ( | ||
| <Tool.List> | ||
| <div class="max-h-60 overflow-y-auto overscroll-contain"> | ||
| <For each={props.reminders}> | ||
| {(reminder) => ( | ||
| <Tool.ListItem icon={<BellSimple class="size-4" />}> | ||
| <div class="flex min-w-0 items-center justify-between gap-3"> | ||
| <span class="min-w-0 truncate text-ink"> | ||
| {reminder.description} | ||
| </span> | ||
| <span | ||
| class="shrink-0 whitespace-nowrap text-xs" | ||
| classList={{ | ||
| 'text-ink-extra-muted': !reminder.overdue, | ||
| 'text-ink-muted': reminder.overdue, | ||
| }} | ||
| > | ||
| {reminder.overdue ? 'Overdue · ' : ''} | ||
| {formatDateAndTime(reminder.nextRunAt)} | ||
| </span> | ||
| </div> | ||
| </Tool.ListItem> | ||
| )} | ||
| </For> | ||
| </div> | ||
| </Tool.List> | ||
| ); | ||
|
|
||
| const listRemindersHandler = createToolRenderer({ | ||
| name: 'ListReminders', | ||
| render: (ctx) => { | ||
| const [isExpanded, setIsExpanded] = createSignal(false); | ||
| const reminders = () => ctx.response?.data.reminders ?? []; | ||
| const hasResults = () => reminders().length > 0; | ||
| const statusText = () => { | ||
| if (!ctx.response) return undefined; | ||
| const count = reminders().length; | ||
| if (count === 0) return 'No Results'; | ||
| return `${count} reminder${count === 1 ? '' : 's'}`; | ||
| }; | ||
|
|
||
| return ( | ||
| <BaseTool | ||
| align="start" | ||
| icon={BellSimple} | ||
| renderContext={ctx.renderContext} | ||
| type="call" | ||
| response={ | ||
| hasResults() && isExpanded() ? ( | ||
| <ReminderList reminders={reminders()} /> | ||
| ) : undefined | ||
| } | ||
| > | ||
| <div class="flex min-w-0 flex-1 flex-col gap-1"> | ||
| <div class="flex min-w-0 items-center justify-between gap-3 overflow-hidden"> | ||
| <span class="min-w-0 truncate">Read reminders</span> | ||
| <Tool.ResultToggle | ||
| expanded={isExpanded()} | ||
| onToggle={() => setIsExpanded((expanded) => !expanded)} | ||
| showToggle={hasResults()} | ||
| status={statusText()} | ||
| /> | ||
| </div> | ||
| <div class="min-w-0 truncate text-xs text-ink-placeholder"> | ||
| {formatReminderFilters(ctx.tool.data)} | ||
| </div> | ||
| </div> | ||
| </BaseTool> | ||
| ); | ||
| }, | ||
| }); | ||
|
|
||
| const createReminderHandler = createToolRenderer({ | ||
| name: 'CreateReminder', | ||
| render: (ctx) => ( | ||
| <BaseTool | ||
| align="start" | ||
| icon={BellSimple} | ||
| renderContext={ctx.renderContext} | ||
| type="call" | ||
| > | ||
| <div class="flex min-w-0 flex-1 flex-col gap-1"> | ||
| <div class="flex min-w-0 items-center gap-1.5 overflow-hidden"> | ||
| <span class="shrink-0"> | ||
| {ctx.response ? 'Created reminder' : 'Create reminder'} | ||
| </span> | ||
| <span class="min-w-0 truncate text-ink"> | ||
| {ctx.response?.data.description ?? ctx.tool.data.description} | ||
| </span> | ||
| </div> | ||
| <div class="min-w-0 truncate text-xs text-ink-placeholder"> | ||
| {formatDateAndTime( | ||
| ctx.response?.data.nextRunAt ?? ctx.tool.data.remindAt | ||
| )} | ||
| <Show when={ctx.tool.data.entityType}> | ||
| {(entityType) => <> · about {ENTITY_TYPE_LABELS[entityType()]}</>} | ||
| </Show> | ||
| </div> | ||
| </div> | ||
| </BaseTool> | ||
| ), | ||
| }); | ||
|
|
||
| const updateReminderHandler = createToolRenderer({ | ||
| name: 'UpdateReminder', | ||
| render: (ctx) => ( | ||
| <BaseTool | ||
| align="start" | ||
| icon={ctx.tool.data.completed === true ? Check : BellSimple} | ||
| renderContext={ctx.renderContext} | ||
| type="call" | ||
| > | ||
| <div class="flex min-w-0 flex-1 flex-col gap-1"> | ||
| <div class="flex min-w-0 items-center gap-1.5 overflow-hidden"> | ||
| <span class="shrink-0"> | ||
| {ctx.response ? 'Updated reminder' : 'Update reminder'} | ||
| </span> | ||
| <Show when={ctx.response?.data.description}> | ||
| {(description) => ( | ||
| <span class="min-w-0 truncate text-ink">{description()}</span> | ||
| )} | ||
| </Show> | ||
| </div> | ||
| <div class="min-w-0 truncate text-xs text-ink-placeholder"> | ||
| {formatReminderUpdate(ctx.tool.data)} | ||
| <Show when={ctx.response?.data.nextRunAt}> | ||
| {(nextRunAt) => <> · fires {formatDateAndTime(nextRunAt())}</>} | ||
| </Show> | ||
| </div> | ||
| </div> | ||
| </BaseTool> | ||
| ), | ||
| }); | ||
|
|
||
| const deleteReminderHandler = createToolRenderer({ | ||
| name: 'DeleteReminder', | ||
| render: (ctx) => ( | ||
| <BaseTool icon={Trash} renderContext={ctx.renderContext} type="call"> | ||
| {ctx.response ? 'Deleted reminder' : 'Delete reminder'} | ||
| </BaseTool> | ||
| ), | ||
| }); | ||
|
|
||
| export { | ||
| createReminderHandler, | ||
| deleteReminderHandler, | ||
| listRemindersHandler, | ||
| updateReminderHandler, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Show the backend response summary.
Lines 101-103 reconstruct the status from the current page length. The backend summary reports the total count, overdue count, and whether more results exist. This status hides those values when the response is paginated.
Proposed fix
const statusText = () => { if (!ctx.response) return undefined; - const count = reminders().length; - if (count === 0) return 'No Results'; - return `${count} reminder${count === 1 ? '' : 's'}`; + return ctx.response.data.summary; };📝 Committable suggestion
🤖 Prompt for AI Agents