thalovant

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 19 Imported by: 0

README

Thalovant Go SDK

Go SDK for direct Thalovant hub HTTPS clients and agents.

Full documentation: https://docs.thalovant.com/developers/sdks/go/

go get github.com/thalovant/thalovant-go-sdk
package main

import (
	"context"
	"fmt"

	thalovant "github.com/thalovant/thalovant-go-sdk"
)

func main() {
	client, err := thalovant.NewClientFromFile("_identity.json")
	if err != nil {
		panic(err)
	}
	reply, err := client.Ask(context.Background(), "Tell me a short clean joke.", thalovant.RequestOptions{})
	if err != nil {
		panic(err)
	}
	fmt.Println(reply.Text)
}

Status

This is an alpha SDK scaffold with identity, event, session, conversation, AES-GCM preshared-key helpers, and an HTTP transport shape compatible with the Thalovant SDK contract. The live transport targets the preshared-key HTTP path used by Thalovant public hubs.

Generic Client Context

context := thalovant.BuildClientContext(nil, thalovant.ClientContextOptions{
	UserID:       "user-42",
	UserName:     "Ada",
	AuthProvider: "oidc",
	Roles:        []string{"member"},
	Platform:     "kiosk",
	Source:       "checkout-kiosk",
	Channel:      "chat",
})

reply, err := client.Ask(ctx, "Show the next instruction.", thalovant.RequestOptions{Context: context})

Actions, Codes, And Rich Output

conversation := client.Conversation(thalovant.ConversationOptions{SessionID: "work-session"})

_ = conversation.SendAction(ctx, `/choose{"id":"42"}`, thalovant.ActionOptions{Title: "Choose item"})
_ = conversation.SendCode(ctx, "SN-001-XYZ", thalovant.CodeOptions{Kind: "qr", Label: "serial"})

items := reply.DisplayItems(600)

Identity files may include default_path for hubs exposed behind a reverse proxy path, for example /public.

Development

go test ./...

Documentation

Index

Constants

View Source
const (
	EventRecognizerLoopUtterance = "recognizer_loop:utterance"
	EventSpeak                   = "speak"
	EventUtteranceHandled        = "ovos.utterance.handled"
	EventIntentFailure           = "complete_intent_failure"
	EventPolicyDenied            = "hive.policy.denied"
	DefaultUserAgent             = "ThalovantGoSDK/0.2.0"
)

Variables

View Source
var (
	ErrIdentity   = errors.New("thalovant identity error")
	ErrConnection = errors.New("thalovant connection error")
	ErrTimeout    = errors.New("thalovant timeout")
	ErrRuntime    = errors.New("thalovant runtime error")
)

Functions

func DecryptFromJSON

func DecryptFromJSON(key string, raw string) (string, error)

func EncryptAsJSON

func EncryptAsJSON(key string, plaintext string) (string, error)

func EventMatchesContext

func EventMatchesContext(event Event, expected Context) bool

func NewRequestID

func NewRequestID() string

func NewSessionID

func NewSessionID() string

func RequestIDFromContext

func RequestIDFromContext(context Context) string

func RichMediaFromData

func RichMediaFromData(data Data) map[string]any

func RuntimeCryptoKey

func RuntimeCryptoKey(raw string) []byte

func SessionIDFromContext

func SessionIDFromContext(context Context) string

func StripSSML

func StripSSML(text string) string

Types

type ActionOptions

type ActionOptions struct {
	Title     string
	Lang      string
	Context   Context
	SessionID string
	RequestID string
}

type Client

type Client struct {
	Identity  Identity
	Transport *HTTPTransport
}

func NewClient

func NewClient(identity Identity) *Client

func NewClientFromEnv

func NewClientFromEnv() (*Client, error)

func NewClientFromFile

func NewClientFromFile(path string) (*Client, error)

func (*Client) Ask

func (c *Client) Ask(ctx context.Context, text string, opts RequestOptions) (Reply, error)

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

func (*Client) Conversation

func (c *Client) Conversation(opts ConversationOptions) Conversation

func (*Client) Emit

func (c *Client) Emit(ctx context.Context, eventType string, data Data, eventContext Context) error

func (*Client) Healthcheck

func (c *Client) Healthcheck() TransportHealth

func (*Client) SendAction

func (c *Client) SendAction(ctx context.Context, payload string, opts ActionOptions) error

func (*Client) SendCode

func (c *Client) SendCode(ctx context.Context, value string, opts CodeOptions) error

func (*Client) SendUtterance

func (c *Client) SendUtterance(ctx context.Context, text string, opts RequestOptions) error

type ClientContextOptions

type ClientContextOptions struct {
	UserID       string
	UserName     string
	AuthToken    string
	AuthProvider string
	AuthClaims   map[string]any
	Roles        []string
	Platform     string
	Source       string
	Destination  string
	Channel      string
	DeviceID     string
	Locale       string
	Metadata     map[string]any
	SessionID    string
}

type CodeOptions

type CodeOptions struct {
	Kind      string
	Label     string
	Lang      string
	Context   Context
	SessionID string
	RequestID string
}

type Context

type Context map[string]any

func BuildClientContext

func BuildClientContext(base Context, opts ClientContextOptions) Context

func ContextWithCorrelation

func ContextWithCorrelation(raw Context, sessionID, siteID, lang, requestID string) Context

func MergeContext

func MergeContext(base, extra Context) Context

type Conversation

type Conversation struct {
	Client  *Client
	Options ConversationOptions
}

func (Conversation) Ask

func (c Conversation) Ask(ctx context.Context, text string, opts RequestOptions) (Reply, error)

func (Conversation) SendAction

func (c Conversation) SendAction(ctx context.Context, payload string, opts ActionOptions) error

func (Conversation) SendCode

func (c Conversation) SendCode(ctx context.Context, value string, opts CodeOptions) error

func (Conversation) SendUtterance

func (c Conversation) SendUtterance(ctx context.Context, text string, opts RequestOptions) error

type ConversationOptions

type ConversationOptions struct {
	SessionID string
	Lang      string
	Context   Context
}

type Data

type Data map[string]any

func UtterancePayload

func UtterancePayload(text, lang string) Data

type DisplayItem

type DisplayItem struct {
	Kind    string
	Text    string
	Data    any
	Title   string
	Payload string
	URL     string
	Silent  bool
}

func DisplayItemsFromEventData

func DisplayItemsFromEventData(data Data, eventName string, maxTextChars int) []DisplayItem

type Event

type Event struct {
	Name    string
	Data    Data
	Context Context
	Raw     any
}

func (Event) DisplayItems

func (e Event) DisplayItems(maxTextChars int) []DisplayItem

func (Event) DisplayText

func (e Event) DisplayText() string

func (Event) IsFailure

func (e Event) IsFailure() bool

func (Event) RequestID

func (e Event) RequestID() string

func (Event) RichMedia

func (e Event) RichMedia() map[string]any

func (Event) SessionID

func (e Event) SessionID() string

func (Event) Text

func (e Event) Text() string

func (Event) Utterances

func (e Event) Utterances() []string

type HTTPTransport

type HTTPTransport struct {
	Identity     Identity
	UserAgent    string
	PollInterval time.Duration
	HTTPClient   *http.Client
	BusEvents    chan Event
	// contains filtered or unexported fields
}

func NewHTTPTransport

func NewHTTPTransport(identity Identity) *HTTPTransport

func (*HTTPTransport) Authorization

func (t *HTTPTransport) Authorization() string

func (*HTTPTransport) BaseURL

func (t *HTTPTransport) BaseURL() string

func (*HTTPTransport) Connect

func (t *HTTPTransport) Connect(ctx context.Context) error

func (*HTTPTransport) Disconnect

func (t *HTTPTransport) Disconnect(ctx context.Context) error

func (*HTTPTransport) EmitBus

func (t *HTTPTransport) EmitBus(ctx context.Context, eventType string, data Data, eventContext Context) error

func (*HTTPTransport) Healthcheck

func (t *HTTPTransport) Healthcheck() TransportHealth

func (*HTTPTransport) IsHandshakeComplete

func (t *HTTPTransport) IsHandshakeComplete() bool

func (*HTTPTransport) PollOnce

func (t *HTTPTransport) PollOnce(ctx context.Context) error

type HiveMessage

type HiveMessage struct {
	MsgType      string         `json:"msg_type"`
	Payload      map[string]any `json:"payload"`
	Metadata     map[string]any `json:"metadata"`
	Route        []any          `json:"route"`
	Node         any            `json:"node"`
	TargetSiteID any            `json:"target_site_id"`
	TargetPubKey any            `json:"target_pubkey"`
	SourcePeer   any            `json:"source_peer"`
}

type Identity

type Identity struct {
	AccessKey     string `json:"access_key"`
	Password      string `json:"password"`
	CryptoKey     string `json:"crypto_key,omitempty"`
	SiteID        string `json:"site_id"`
	DefaultMaster string `json:"default_master"`
	DefaultPort   int    `json:"default_port"`
	DefaultPath   string `json:"default_path,omitempty"`
	PublicKey     string `json:"public_key,omitempty"`
}

func IdentityFromEnv

func IdentityFromEnv(prefix string) (Identity, error)

func IdentityFromFile

func IdentityFromFile(path string) (Identity, error)

func IdentityFromMap

func IdentityFromMap(values map[string]any) (Identity, error)

func (Identity) EndpointBase

func (i Identity) EndpointBase() string

func (Identity) Summary

func (i Identity) Summary() map[string]any

type Reply

type Reply struct {
	Text         string
	Utterances   []string
	Handled      bool
	OK           bool
	SessionID    string
	RequestID    string
	Events       []Event
	FailureEvent *Event
}

func (Reply) DisplayItems

func (r Reply) DisplayItems(maxTextChars int) []DisplayItem

func (Reply) DisplayText

func (r Reply) DisplayText() string

type RequestOptions

type RequestOptions struct {
	Timeout   time.Duration
	Lang      string
	Context   Context
	SessionID string
	RequestID string
}

type TransportHealth

type TransportHealth struct {
	Connected         bool
	HandshakeComplete bool
	TransportAlive    bool
	LastError         string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL