74b19e091e
resolve_target previously returned a hardcoded "requires_nexus_resolution" placeholder; it now calls Nexus's /api/v1/resolve via a new minimal internal/nexusclient, configurable with -nexus (default localhost:8987). /api/v1/changes ignored the since query param and always returned from sequence 0 (`since = 0` regardless of what was parsed) — fixed to actually parse and use it, so change-cursor polling works. The MCP hexis.execute tool only forwarded capability_id/target_entity_id/ arguments/idempotency_key, silently dropping entity_version, requested_by, origin, correlation_id, causation_id, resolution_evidence, and confirmation_id even though the native HTTP API and domain.ExecuteRequest already supported all of them — MCP callers now get full parity. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018ghELqYhZNLub2TXGMazqA
81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
// Package nexusclient is the minimal Nexus resolve client used by Hexis's
|
|
// hexis.resolve_target MCP tool to turn a free-text query into a canonical
|
|
// entity ID, matching the /api/v1/resolve contract Nexus and Praxis already
|
|
// speak.
|
|
package nexusclient
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type Entity struct {
|
|
ID string `json:"id"`
|
|
Type string `json:"type"`
|
|
DisplayName string `json:"display_name"`
|
|
}
|
|
|
|
type Candidate struct {
|
|
EntityID string `json:"entity_id"`
|
|
DisplayName string `json:"display_name"`
|
|
Score float64 `json:"score"`
|
|
}
|
|
|
|
type ResolveResult struct {
|
|
Status string `json:"status"`
|
|
Entity *Entity `json:"entity,omitempty"`
|
|
Score float64 `json:"score,omitempty"`
|
|
Candidates []Candidate `json:"candidates,omitempty"`
|
|
}
|
|
|
|
type Client interface {
|
|
Resolve(ctx context.Context, query string, types []string) (*ResolveResult, error)
|
|
}
|
|
|
|
type httpClient struct {
|
|
baseURL string
|
|
http *http.Client
|
|
}
|
|
|
|
func New(baseURL string) Client {
|
|
return &httpClient{baseURL: baseURL, http: &http.Client{Timeout: 10 * time.Second}}
|
|
}
|
|
|
|
func (c *httpClient) Resolve(ctx context.Context, query string, types []string) (*ResolveResult, error) {
|
|
body := map[string]any{"query": query}
|
|
if len(types) > 0 {
|
|
body["types"] = types
|
|
}
|
|
data, err := json.Marshal(body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/api/v1/resolve", bytes.NewReader(data))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req.Header.Set("Content-Type", "application/json")
|
|
req.Header.Set("X-Nexus-Version", "v1")
|
|
|
|
resp, err := c.http.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
return nil, fmt.Errorf("nexus resolve: %s", http.StatusText(resp.StatusCode))
|
|
}
|
|
|
|
var result ResolveResult
|
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
|
return nil, fmt.Errorf("decode nexus resolve response: %w", err)
|
|
}
|
|
return &result, nil
|
|
}
|