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.

chore(ai): call records in search tools (#2883)

gbirmanec25f7f43ae4
diff --git a/js/app/packages/core/component/AI/component/tool/Search.tsx b/js/app/packages/core/component/AI/component/tool/Search.tsx
index a3a1f75910..f7bbb83b82 100644
--- a/js/app/packages/core/component/AI/component/tool/Search.tsx
+++ b/js/app/packages/core/component/AI/component/tool/Search.tsx
@@ -1,269 +1,49 @@
-import { fileTypeToBlockName } from '@core/constant/allBlocks';
import CaretRight from '@icon/regular/caret-right.svg?component-solid';
import MagnifyingGlass from '@phosphor-icons/core/regular/magnifying-glass.svg';
import type { NamedTool } from '@service-cognition/generated/tools/tool';
import { useSplitLayout } from 'app/component/split-layout/layout';
-import { useChannelsContext } from '@core/context/channels';
import { createMemo, createSignal, For, Show } from 'solid-js';
import { BaseTool } from './BaseTool';
import { createToolRenderer, type ToolRenderContext } from './ToolRenderer';
import { ListEntity } from '@entity';
-import type { WithNotification } from '@entity/types/notification';
-import type {
- EntityData,
- ChatEntity,
- ChannelEntity,
- EmailEntity,
- ProjectEntity,
- DocumentEntity,
-} from '@entity/types/entity';
-import type { ContentHitData, SearchData } from '@entity/types/search';
+import { useSearchResponseItemMapper } from '@queries/soup/transform-utils';
+import { getEntityClickContent } from '@channel/Attachments/attachment-utils';
type UnifiedSearchResult = NamedTool<
'NameSearch',
'response'
>['data']['results'][number];
-type EntityWithSearch = EntityData & { search: SearchData };
-
-function searchResultsToEntities(
- results: UnifiedSearchResult[],
- channelsById: Record<string, { name?: string | null }>
-): EntityWithSearch[] {
- const entityMap = new Map<
- string,
- {
- entity: EntityData;
- contentHits: ContentHitData[];
- nameHighlight: string | null;
- }
- >();
-
- for (const result of results) {
- let key: string;
- let entity: EntityData;
- let contentHits: ContentHitData[] = [];
- let nameHighlight: string | null = null;
-
- switch (result.type) {
- case 'document': {
- key = result.document_id;
- entity = {
- id: result.document_id,
- type: 'document',
- name: result.document_name || 'Document',
- ownerId: result.owner_id,
- fileType: result.file_type ?? undefined,
- projectId: result.metadata?.project_id ?? undefined,
- createdAt: result.metadata?.created_at ?? null,
- updatedAt: result.metadata?.updated_at ?? null,
- subType: result.sub_type === 'task' ? { type: 'task' } : undefined,
- } as DocumentEntity;
-
- for (const sr of result.document_search_results) {
- if (sr.highlight.name) nameHighlight = sr.highlight.name;
- if (sr.highlight.content?.length) {
- for (const content of sr.highlight.content) {
- if (result.file_type === 'md' && sr.node_id) {
- contentHits.push({
- type: 'md',
- content,
- location: { type: 'md', nodeId: sr.node_id },
- });
- } else if (result.file_type === 'pdf') {
- contentHits.push({ content });
- } else {
- contentHits.push({ content });
- }
- }
- }
- }
- break;
- }
- case 'chat': {
- key = result.chat_id;
- entity = {
- id: result.chat_id,
- type: 'chat',
- name: result.name || 'Chat',
- ownerId: result.owner_id,
- projectId: result.metadata?.project_id ?? undefined,
- createdAt: result.metadata?.created_at ?? null,
- updatedAt: result.metadata?.updated_at ?? null,
- } satisfies ChatEntity;
-
- for (const sr of result.chat_search_results) {
- if (sr.highlight.name) nameHighlight = sr.highlight.name;
- if (sr.highlight.content?.length) {
- for (const content of sr.highlight.content) {
- contentHits.push({ content });
- }
- }
- }
- break;
- }
- case 'email': {
- key = result.thread_id;
- entity = {
- id: result.thread_id,
- type: 'email',
- name: result.subject || result.name || 'Email',
- ownerId: result.owner_id,
- isRead: result.is_read,
- isDraft: result.is_draft,
- isImportant: result.is_important,
- done: false,
- snippet: result.snippet ?? undefined,
- participants: result.participants.map((p) => ({
- email: p.email,
- name: p.name ?? undefined,
- })),
- senderEmail: result.email_message_search_results[0]?.sender,
- senderName: result.email_message_search_results[0]?.pretty_sender,
- updatedAt: result.updated_at,
- createdAt: result.created_at,
- } satisfies EmailEntity;
-
- for (const sr of result.email_message_search_results) {
- if (sr.highlight.name) nameHighlight = sr.highlight.name;
- if (sr.highlight.content?.length) {
- for (const content of sr.highlight.content) {
- contentHits.push({
- type: 'email',
- content,
- sender: sr.pretty_sender,
- senderId: sr.sender,
- sentAt: sr.sent_at ?? result.created_at,
- location: {
- type: 'email',
- messageId: sr.message_id ?? '',
- },
- });
- }
- }
- }
- break;
- }
- case 'channel': {
- key = result.channel_id;
- entity = {
- id: result.channel_id,
- type: 'channel',
- name: channelsById[result.channel_id]?.name ?? 'Channel',
- ownerId: result.owner_id ?? '',
- channelType:
- (result.channel_type as ChannelEntity['channelType']) ?? 'public',
- createdAt: result.metadata?.created_at ?? null,
- updatedAt: result.metadata?.updated_at ?? null,
- } satisfies ChannelEntity;
-
- for (const sr of result.channel_message_search_results) {
- if (sr.highlight.content?.length) {
- for (const content of sr.highlight.content) {
- contentHits.push({
- type: 'channel',
- id: sr.message_id ?? '',
- content,
- senderId: sr.sender_id ?? '',
- sentAt: sr.created_at ?? '',
- location: {
- type: 'channel',
- threadId: sr.thread_id ?? undefined,
- messageId: sr.message_id ?? '',
- },
- });
- }
- }
- }
- break;
- }
- case 'project': {
- key = result.id;
- entity = {
- id: result.id,
- type: 'project',
- name: result.name || 'Project',
- ownerId: result.owner_id,
- createdAt: result.metadata?.created_at ?? null,
- updatedAt: result.metadata?.updated_at ?? null,
- } satisfies ProjectEntity;
-
- for (const sr of result.project_search_results) {
- if (sr.highlight.name) nameHighlight = sr.highlight.name;
- if (sr.highlight.content?.length) {
- for (const content of sr.highlight.content) {
- contentHits.push({ content });
- }
- }
- }
- break;
- }
- default:
- continue;
- }
-
- const existing = entityMap.get(key);
- if (existing) {
- existing.contentHits.push(...contentHits);
- if (nameHighlight) existing.nameHighlight = nameHighlight;
- } else {
- entityMap.set(key, { entity, contentHits, nameHighlight });
- }
- }
-
- return Array.from(entityMap.values()).map(
- ({ entity, contentHits, nameHighlight }) => ({
- ...entity,
- search: {
- nameHighlight,
- senderHighlightTerms: null,
- contentHitData: contentHits.length > 0 ? contentHits : null,
- source: 'service' as const,
- },
- })
- );
-}
+const getToolSearchQuery = (
+ ctx: ToolRenderContext<'ContentSearch' | 'NameSearch'>
+) => {
+ return 'query' in ctx.tool.data ? ctx.tool.data.query : ctx.tool.data.name;
+};
const UnifiedSearchToolResponse = (props: {
results: UnifiedSearchResult[];
+ query: string;
}) => {
- const channelsCtx = useChannelsContext();
- const entities = createMemo(() =>
- searchResultsToEntities(props.results, channelsCtx.channelsById())
- );
-
+ const mapResponseItem = useSearchResponseItemMapper();
const { replaceOrInsertSplit } = useSplitLayout();
- const getClickHandler = (entity: EntityData) => {
- switch (entity.type) {
- case 'document': {
- const blockName = fileTypeToBlockName(
- (entity as DocumentEntity).fileType
- );
- return () => replaceOrInsertSplit({ type: blockName, id: entity.id });
- }
- case 'chat':
- return () => replaceOrInsertSplit({ type: 'chat', id: entity.id });
- case 'email':
- return () => replaceOrInsertSplit({ type: 'email', id: entity.id });
- case 'channel':
- return () => replaceOrInsertSplit({ type: 'channel', id: entity.id });
- case 'project':
- return () => replaceOrInsertSplit({ type: 'project', id: entity.id });
- default:
- return undefined;
- }
- };
+ const entities = createMemo(() =>
+ props.results.flatMap(
+ (result) => mapResponseItem(result, props.query) ?? []
+ )
+ );
return (
<div class="max-h-[480px] overflow-y-auto">
<For each={entities()}>
{(entity) => {
- const clickHandler = getClickHandler(entity);
+ if (!entity) return null;
return (
<ListEntity
- entity={entity as WithNotification<EntityData>}
- onClick={clickHandler}
+ entity={entity}
+ onClick={() =>
+ replaceOrInsertSplit(getEntityClickContent(entity))
+ }
/>
);
}}
@@ -272,16 +52,10 @@ const UnifiedSearchToolResponse = (props: {
);
};
-function SearchText(props: {
- ctx: ToolRenderContext<'ContentSearch' | 'NameSearch'>;
-}) {
- const ctx = props.ctx;
- const queryString =
- 'query' in ctx.tool.data ? ctx.tool.data.query : ctx.tool.data.name;
-
+function SearchText(props: { query: string }) {
return (
<span>
- Search <span class="text-accent"> {queryString} </span>
+ Search <span class="text-accent"> {props.query} </span>
</span>
);
}
@@ -294,6 +68,7 @@ const createHandler = (name: 'NameSearch' | 'ContentSearch') =>
const results = () => ctx.response?.data.results ?? [];
const hitCount = () => results().length;
const hasResults = () => hitCount() > 0;
+ const query = () => getToolSearchQuery(ctx);
const statusText = () => {
if (!ctx.response) return undefined;
if (hitCount() === 0) return 'No Results';
@@ -308,13 +83,13 @@ const createHandler = (name: 'NameSearch' | 'ContentSearch') =>
type="call"
response={
hasResults() && isExpanded() ? (
- <UnifiedSearchToolResponse results={results()} />
+ <UnifiedSearchToolResponse results={results()} query={query()} />
) : undefined
}
>
<div class="flex min-w-0 flex-1 items-center justify-between gap-3">
<div class="flex min-w-0 flex-1 items-center gap-2">
- <SearchText ctx={ctx} />
+ <SearchText query={query()} />
</div>
<div class="flex shrink-0 items-center gap-1">
<Show when={statusText()}>
diff --git a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts b/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
index a902a7048b..7e3e511723 100644
--- a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
@@ -100,11 +100,11 @@ export interface BashCodeExecutionToolError {
*/
/**
- * Search for items by their content. For documents, this searches the document body text. For emails, this searches the email message body. For chats, this searches the message content. This tool finds items based on what's inside them, not their titles or names.
+ * Search for items by their content. For documents, this searches the document body text. For emails, this searches the email message body. For chats, this searches the message content. For call records, this searches the call transcript text. This tool finds items based on what's inside them, not their titles or names.
*/
export interface ContentSearch {
/**
- * Which types of items to search. Leave empty to search all types. Examples: ['documents'], ['emails', 'documents'], ['channels']
+ * Which types of items to search. Leave empty to search all types. Examples: ['documents'], ['emails', 'documents'], ['channels'], ['call_records']
*/
entityTypes: (
| 'documents'
@@ -115,7 +115,7 @@ export interface ContentSearch {
| 'call_records'
)[];
/**
- * The text content to search for. This searches within the body of documents, emails, and messages.
+ * The text content to search for. This searches within the body of documents, emails, messages, and call transcripts.
*/
query: string;
}
@@ -1043,11 +1043,11 @@ export interface ListEntitiesResponse {
*/
/**
- * Search for items by their name or title. For documents, this searches the document name. For emails, this searches the subject line. For chats, this searches the chat title. For projects (folders), this searches the project name. This tool finds items based on what they're called, not their content.
+ * Search for items by their name or title. For documents, this searches the document name. For emails, this searches the subject line. For chats, this searches the chat title. For projects (folders), this searches the project name. For call records, this searches the channel name the call took place in. This tool finds items based on what they're called, not their content.
*/
export interface NameSearch {
/**
- * Which types of items to search. Leave empty to search all types. Examples: ['documents'], ['emails', 'documents'], ['channels']
+ * Which types of items to search. Leave empty to search all types. Examples: ['documents'], ['emails', 'documents'], ['channels'], ['call_records']
*/
entityTypes: (
| 'documents'
@@ -1058,7 +1058,7 @@ export interface NameSearch {
| 'call_records'
)[];
/**
- * The name or title to search for. For emails, this is the subject line. For channels, this can be the channel name or participant names.
+ * The name or title to search for. For emails, this is the subject line. For channels, this can be the channel name or participant names. For call records, this is the channel name the call belongs to.
*/
name: string;
}
diff --git a/rust/cloud-storage/ai_tools/src/search/search_service/content.rs b/rust/cloud-storage/ai_tools/src/search/search_service/content.rs
index 1c4e522a95..c239524e4b 100644
--- a/rust/cloud-storage/ai_tools/src/search/search_service/content.rs
+++ b/rust/cloud-storage/ai_tools/src/search/search_service/content.rs
@@ -14,17 +14,17 @@ use std::sync::Arc;
#[derive(Debug, JsonSchema, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
#[schemars(
- description = "Search for items by their content. For documents, this searches the document body text. For emails, this searches the email message body. For chats, this searches the message content. This tool finds items based on what's inside them, not their titles or names.",
+ description = "Search for items by their content. For documents, this searches the document body text. For emails, this searches the email message body. For chats, this searches the message content. For call records, this searches the call transcript text. This tool finds items based on what's inside them, not their titles or names.",
title = "ContentSearch"
)]
pub struct ContentSearch {
#[schemars(
- description = "The text content to search for. This searches within the body of documents, emails, and messages."
+ description = "The text content to search for. This searches within the body of documents, emails, messages, and call transcripts."
)]
pub query: String,
#[schemars(
- description = "Which types of items to search. Leave empty to search all types. Examples: ['documents'], ['emails', 'documents'], ['channels']"
+ description = "Which types of items to search. Leave empty to search all types. Examples: ['documents'], ['emails', 'documents'], ['channels'], ['call_records']"
)]
#[serde(default)]
pub entity_types: Vec<UnifiedSearchIndex>,
diff --git a/rust/cloud-storage/ai_tools/src/search/search_service/name.rs b/rust/cloud-storage/ai_tools/src/search/search_service/name.rs
index cb4fd087aa..4dab0debc3 100644
--- a/rust/cloud-storage/ai_tools/src/search/search_service/name.rs
+++ b/rust/cloud-storage/ai_tools/src/search/search_service/name.rs
@@ -14,17 +14,17 @@ use std::sync::Arc;
#[derive(Debug, JsonSchema, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
#[schemars(
- description = "Search for items by their name or title. For documents, this searches the document name. For emails, this searches the subject line. For chats, this searches the chat title. For projects (folders), this searches the project name. This tool finds items based on what they're called, not their content.",
+ description = "Search for items by their name or title. For documents, this searches the document name. For emails, this searches the subject line. For chats, this searches the chat title. For projects (folders), this searches the project name. For call records, this searches the channel name the call took place in. This tool finds items based on what they're called, not their content.",
title = "NameSearch"
)]
pub struct NameSearch {
#[schemars(
- description = "The name or title to search for. For emails, this is the subject line. For channels, this can be the channel name or participant names."
+ description = "The name or title to search for. For emails, this is the subject line. For channels, this can be the channel name or participant names. For call records, this is the channel name the call belongs to."
)]
pub name: String,
#[schemars(
- description = "Which types of items to search. Leave empty to search all types. Examples: ['documents'], ['emails', 'documents'], ['channels']"
+ description = "Which types of items to search. Leave empty to search all types. Examples: ['documents'], ['emails', 'documents'], ['channels'], ['call_records']"
)]
#[serde(default)]
pub entity_types: Vec<UnifiedSearchIndex>,