feat: enrich search with msglib display entities
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
|
||||
"isphere-ai-bridge/internal/isphere"
|
||||
"isphere-ai-bridge/internal/msglib"
|
||||
)
|
||||
|
||||
const ToolNameSearchContacts = "isphere_search_contacts"
|
||||
@@ -20,6 +21,10 @@ type SearchContactsArgs struct {
|
||||
}
|
||||
|
||||
func RegisterISphereContactTools(server *mcp.Server, source ReceiveMessagesSource) {
|
||||
RegisterISphereContactToolsWithDisplayEntities(server, source, nil)
|
||||
}
|
||||
|
||||
func RegisterISphereContactToolsWithDisplayEntities(server *mcp.Server, source ReceiveMessagesSource, displaySource DisplayEntitySource) {
|
||||
if source == nil {
|
||||
source = isphere.EncryptedPacketLogSource{}
|
||||
}
|
||||
@@ -36,7 +41,19 @@ func RegisterISphereContactTools(server *mcp.Server, source ReceiveMessagesSourc
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
contacts := isphere.SearchContactsFromMessages(messages.Messages, isphere.SearchContactsQuery{Query: input.Query, Limit: input.Limit})
|
||||
logContacts := isphere.SearchContactsFromMessages(messages.Messages, isphere.SearchContactsQuery{Query: input.Query, Limit: input.Limit})
|
||||
contacts := logContacts
|
||||
if displaySource != nil {
|
||||
entities, err := displaySource.DisplayEntities(ctx, msglib.DisplayEntitiesOptions{
|
||||
EntityType: msglib.EntityTypeContacts,
|
||||
Query: input.Query,
|
||||
Limit: displayEntityQueryLimit(input.Limit),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
contacts = mergeContacts(contactsFromDisplayEntities(entities), logContacts.Contacts, input.Limit)
|
||||
}
|
||||
return nil, searchContactsResultToMap(contacts, started, time.Now().UTC()), nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user