feat: add msglib display entity extraction
This commit is contained in:
@@ -16,6 +16,12 @@ import (
|
||||
const (
|
||||
Protocol = "isphere.msglib.v1"
|
||||
DefaultPassword = "123"
|
||||
|
||||
EntityTypeContacts = "contacts"
|
||||
EntityTypeGroups = "groups"
|
||||
|
||||
DefaultDisplayEntityLimit = 25
|
||||
MaxDisplayEntityLimit = 100
|
||||
)
|
||||
|
||||
var requestCounter uint64
|
||||
@@ -81,6 +87,21 @@ type DisplaySource struct {
|
||||
PresentColumns []string `json:"present_columns"`
|
||||
}
|
||||
|
||||
type DisplayEntitiesOptions struct {
|
||||
EntityType string
|
||||
Query string
|
||||
Limit int
|
||||
}
|
||||
|
||||
type DisplayEntity struct {
|
||||
EntityType string `json:"entity_type"`
|
||||
SourceTable string `json:"source_table"`
|
||||
JID string `json:"jid"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Confidence float64 `json:"confidence"`
|
||||
MatchedColumns []string `json:"matched_columns"`
|
||||
}
|
||||
|
||||
type SidecarError struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
@@ -118,10 +139,45 @@ func (c *Client) DisplaySources(ctx context.Context) ([]DisplaySource, error) {
|
||||
return out.DisplaySources, nil
|
||||
}
|
||||
|
||||
func (c *Client) DisplayEntities(ctx context.Context, opts DisplayEntitiesOptions) ([]DisplayEntity, error) {
|
||||
entityType := strings.TrimSpace(opts.EntityType)
|
||||
if entityType != EntityTypeContacts && entityType != EntityTypeGroups {
|
||||
return nil, fmt.Errorf("entity_type must be %q or %q", EntityTypeContacts, EntityTypeGroups)
|
||||
}
|
||||
limit := opts.Limit
|
||||
if limit <= 0 {
|
||||
limit = DefaultDisplayEntityLimit
|
||||
}
|
||||
if limit > MaxDisplayEntityLimit {
|
||||
limit = MaxDisplayEntityLimit
|
||||
}
|
||||
|
||||
args := map[string]any{
|
||||
"sqlite_dll_path": c.config.SQLiteDLLPath,
|
||||
"db_path": c.config.DBPath,
|
||||
"password": c.config.Password,
|
||||
"entity_type": entityType,
|
||||
"limit": limit,
|
||||
}
|
||||
if strings.TrimSpace(opts.Query) != "" {
|
||||
args["query"] = strings.TrimSpace(opts.Query)
|
||||
}
|
||||
|
||||
var out displayEntitiesData
|
||||
if err := c.call(ctx, "display_entities", args, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Entities, nil
|
||||
}
|
||||
|
||||
type displaySourcesData struct {
|
||||
DisplaySources []DisplaySource `json:"display_sources"`
|
||||
}
|
||||
|
||||
type displayEntitiesData struct {
|
||||
Entities []DisplayEntity `json:"entities"`
|
||||
}
|
||||
|
||||
type requestEnvelope struct {
|
||||
Protocol string `json:"protocol"`
|
||||
RequestID string `json:"request_id"`
|
||||
|
||||
Reference in New Issue
Block a user