client

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIVersion     = "v1"
	DefaultBaseURL = "https://api.toneclone.ai"
	DefaultTimeout = 30 * time.Second
)

Constants for the API client

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	KeyID      string        `json:"keyId"`
	Name       string        `json:"name"`
	Prefix     string        `json:"prefix"`
	Scopes     []APIKeyScope `json:"scopes"`
	Status     string        `json:"status"`
	CreatedAt  time.Time     `json:"createdAt"`
	LastUsedAt *time.Time    `json:"lastUsedAt,omitempty"`
	ExpiresAt  *time.Time    `json:"expiresAt,omitempty"`
	UsageCount int64         `json:"usageCount"`
}

APIKey represents an API key (for management)

type APIKeyListResponse

type APIKeyListResponse struct {
	Keys []APIKey `json:"keys"`
}

APIKeyListResponse represents the response from listing API keys

type APIKeyScope

type APIKeyScope string

API Key Scope types

const (
	// Read permissions
	ScopePersonasRead  APIKeyScope = "personas:read"
	ScopeKnowledgeRead APIKeyScope = "knowledge:read"
	ScopeTrainingRead  APIKeyScope = "training:read"
	ScopeFilesRead     APIKeyScope = "files:read"
	ScopeWritingRead   APIKeyScope = "writing:read"
	ScopeUserRead      APIKeyScope = "user:read"

	// Write permissions
	ScopePersonasWrite  APIKeyScope = "personas:write"
	ScopeKnowledgeWrite APIKeyScope = "knowledge:write"
	ScopeTrainingWrite  APIKeyScope = "training:write"
	ScopeFilesWrite     APIKeyScope = "files:write"
	ScopeWritingWrite   APIKeyScope = "writing:write"
	ScopeUserWrite      APIKeyScope = "user:write"

	// Text generation
	ScopeTextGenerate APIKeyScope = "text:generate"

	// Admin permissions
	ScopeAdmin APIKeyScope = "admin:all"

	// Wildcard permission
	ScopeAll APIKeyScope = "*"
)

type APIResponse

type APIResponse[T any] struct {
	Data   T      `json:"data,omitempty"`
	Error  string `json:"error,omitempty"`
	Status int    `json:"status,omitempty"`
}

APIResponse represents a generic API response

type BatchFileResult

type BatchFileResult struct {
	FileID     string `json:"file_id,omitempty"`
	Filename   string `json:"filename"`
	Status     string `json:"status"`
	Error      string `json:"error,omitempty"`
	Size       int64  `json:"size,omitempty"`
	Associated bool   `json:"associated"`
}

BatchFileResult represents the result of uploading a single file in a batch

type BatchUploadResponse

type BatchUploadResponse struct {
	Files     []BatchFileResult `json:"files"`
	PersonaID string            `json:"persona_id,omitempty"`
	Summary   struct {
		Total      int `json:"total"`
		Uploaded   int `json:"uploaded"`
		Associated int `json:"associated"`
		Failed     int `json:"failed"`
	} `json:"summary"`
}

BatchUploadResponse represents the response from batch file upload

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents the ToneClone API client

func NewClient

func NewClient(apiKey string, options ...ClientOption) *Client

NewClient creates a new ToneClone API client

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) error

Delete performs a DELETE request

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, result interface{}) error

Get performs a GET request

func (*Client) GetBaseURL

func (c *Client) GetBaseURL() string

GetBaseURL returns the configured base URL

func (*Client) GetUserAgent

func (c *Client) GetUserAgent() string

GetUserAgent returns the configured user agent

func (*Client) Health

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

Health checks the API health

func (*Client) Patch

func (c *Client) Patch(ctx context.Context, path string, body interface{}, result interface{}) error

Patch performs a PATCH request

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body interface{}, result interface{}) error

Post performs a POST request

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body interface{}, result interface{}) error

Put performs a PUT request

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration)

SetTimeout updates the client timeout

func (*Client) ValidateAPIKey

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

ValidateAPIKey validates that the API key is working

func (*Client) WithContext

func (c *Client) WithContext(ctx context.Context) context.Context

WithContext returns a new context with timeout if none is set

type ClientOption

type ClientOption func(*Client)

ClientOption represents a configuration option for the client

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL sets a custom base URL

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient sets a custom HTTP client

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout sets a custom timeout

func WithUserAgent

func WithUserAgent(userAgent string) ClientOption

WithUserAgent sets a custom user agent

type ErrorResponse

type ErrorResponse struct {
	ErrorMsg string `json:"error"`
	Message  string `json:"message,omitempty"`
	Code     string `json:"code,omitempty"`
}

ErrorResponse represents an API error response

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

type FileUpload

type FileUpload struct {
	Filename string
	Reader   io.Reader
}

FileUpload represents a file to be uploaded

type GenerateClient

type GenerateClient struct {
	// contains filtered or unexported fields
}

GenerateClient handles text generation API operations

func NewGenerateClient

func NewGenerateClient(client *Client) *GenerateClient

NewGenerateClient creates a new generate client

func (*GenerateClient) SimpleText

func (g *GenerateClient) SimpleText(ctx context.Context, prompt string, personaID ...string) (string, error)

SimpleText generates text with just a prompt and optional persona

func (*GenerateClient) Text

Text generates text using the specified parameters

type GenerateTextRequest

type GenerateTextRequest struct {
	Prompt           string   `json:"prompt"`
	PersonaID        string   `json:"personaId"`
	KnowledgeCardID  string   `json:"knowledgeCardId,omitempty"`
	KnowledgeCardIDs []string `json:"knowledgeCardIds,omitempty"`
	Context          string   `json:"context,omitempty"`
	SessionID        string   `json:"sessionId,omitempty"`
	Document         string   `json:"document,omitempty"`
	Selection        string   `json:"selection,omitempty"`
	Formality        int      `json:"formality,omitempty"`
	ReadingLevel     int      `json:"readingLevel,omitempty"`
	Length           int      `json:"length,omitempty"`
	Model            string   `json:"model,omitempty"`
	Streaming        *bool    `json:"streaming,omitempty"`
}

GenerateTextRequest represents a text generation request

type GenerateTextResponse

type GenerateTextResponse struct {
	Text            string `json:"text"`
	PersonaID       string `json:"personaId,omitempty"`
	KnowledgeCardID string `json:"knowledgeCardId,omitempty"`
	Model           string `json:"model,omitempty"`
	Tokens          int    `json:"tokens,omitempty"`
}

GenerateTextResponse represents a text generation response

type KnowledgeCard added in v1.0.7

type KnowledgeCard struct {
	PK              string    `json:"PK"`
	SK              string    `json:"SK"`
	KnowledgeCardID string    `json:"knowledgeCardId"`
	UserID          string    `json:"userId"`
	Name            string    `json:"name"`
	Instructions    string    `json:"instructions"`
	CreatedAt       time.Time `json:"createdAt"`
	UpdatedAt       time.Time `json:"updatedAt"`
}

KnowledgeCard represents a writing knowledge card

type KnowledgeCardListResponse added in v1.0.7

type KnowledgeCardListResponse struct {
	KnowledgeCards []KnowledgeCard `json:"knowledgeCards"`
}

KnowledgeCardListResponse represents the response from listing knowledge cards

type KnowledgeClient added in v1.0.7

type KnowledgeClient struct {
	// contains filtered or unexported fields
}

KnowledgeClient handles knowledge-related API operations

func NewKnowledgeClient added in v1.0.7

func NewKnowledgeClient(client *Client) *KnowledgeClient

NewKnowledgeClient creates a new knowledge client

func (*KnowledgeClient) AssociateWithPersona added in v1.0.7

func (k *KnowledgeClient) AssociateWithPersona(ctx context.Context, knowledgeCardID, personaID string) error

AssociateWithPersona associates a knowledge card with a persona

func (*KnowledgeClient) Create added in v1.0.7

func (k *KnowledgeClient) Create(ctx context.Context, knowledge *KnowledgeCard) (*KnowledgeCard, error)

Create creates a new knowledge card

func (*KnowledgeClient) Delete added in v1.0.7

func (k *KnowledgeClient) Delete(ctx context.Context, knowledgeCardID string) error

Delete deletes a knowledge card

func (*KnowledgeClient) DisassociateFromPersona added in v1.0.7

func (k *KnowledgeClient) DisassociateFromPersona(ctx context.Context, knowledgeCardID, personaID string) error

DisassociateFromPersona disassociates a knowledge card from a persona

func (*KnowledgeClient) Get added in v1.0.7

func (k *KnowledgeClient) Get(ctx context.Context, knowledgeCardID string) (*KnowledgeCard, error)

Get retrieves a specific knowledge card by ID

func (*KnowledgeClient) GetPersonaKnowledge added in v1.0.7

func (k *KnowledgeClient) GetPersonaKnowledge(ctx context.Context, personaID string) ([]KnowledgeCard, error)

GetPersonaKnowledge retrieves all knowledge cards associated with a persona

func (*KnowledgeClient) List added in v1.0.7

List retrieves all knowledge cards for the authenticated user

func (*KnowledgeClient) Update added in v1.0.7

func (k *KnowledgeClient) Update(ctx context.Context, knowledgeCardID string, knowledge *KnowledgeCard) (*KnowledgeCard, error)

Update updates an existing knowledge card

type ListOptions

type ListOptions struct {
	Limit  int    `json:"limit,omitempty"`
	Offset int    `json:"offset,omitempty"`
	Sort   string `json:"sort,omitempty"`
	Filter string `json:"filter,omitempty"`
}

ListOptions represents common listing options

type PaginatedResponse

type PaginatedResponse[T any] struct {
	Items      []T  `json:"items"`
	Total      int  `json:"total"`
	Limit      int  `json:"limit"`
	Offset     int  `json:"offset"`
	HasMore    bool `json:"hasMore"`
	NextOffset int  `json:"nextOffset,omitempty"`
}

PaginatedResponse represents a paginated response

type Persona

type Persona struct {
	PersonaID         string    `json:"personaId"`
	Name              string    `json:"name"`
	LastUsedAt        time.Time `json:"lastUsedAt"`
	LastModifiedAt    time.Time `json:"lastModifiedAt"`
	Status            string    `json:"status"`
	TrainingStatus    string    `json:"trainingStatus"`
	PersonaType       string    `json:"personaType"`
	VoiceEvolution    bool      `json:"voiceEvolution"`
	PromptDescription string    `json:"personaPromptDescription,omitempty"`
	IsBuiltIn         bool      `json:"isBuiltIn,omitempty"`
}

Persona represents a writing persona

type PersonaListResponse

type PersonaListResponse struct {
	Personas []Persona `json:"personas"`
}

PersonaListResponse represents the response from listing personas

type PersonasClient

type PersonasClient struct {
	// contains filtered or unexported fields
}

PersonasClient handles persona-related API operations

func NewPersonasClient

func NewPersonasClient(client *Client) *PersonasClient

NewPersonasClient creates a new personas client

func (*PersonasClient) AssociateFiles

func (p *PersonasClient) AssociateFiles(ctx context.Context, personaID string, fileIDs []string) error

AssociateFiles associates files with a persona

func (*PersonasClient) Create

func (p *PersonasClient) Create(ctx context.Context, persona *Persona) (*Persona, error)

Create creates a new persona

func (*PersonasClient) Delete

func (p *PersonasClient) Delete(ctx context.Context, personaID string) error

Delete deletes a persona

func (*PersonasClient) DisassociateFiles

func (p *PersonasClient) DisassociateFiles(ctx context.Context, personaID string, fileIDs []string) error

DisassociateFiles removes file associations from a persona

func (*PersonasClient) Get

func (p *PersonasClient) Get(ctx context.Context, personaID string) (*Persona, error)

Get retrieves a specific persona by ID

func (*PersonasClient) List

func (p *PersonasClient) List(ctx context.Context) ([]Persona, error)

List retrieves all personas

func (*PersonasClient) ListBuiltIn added in v1.0.7

func (p *PersonasClient) ListBuiltIn(ctx context.Context) ([]Persona, error)

ListBuiltIn retrieves all built-in personas

func (*PersonasClient) ListFiles

func (p *PersonasClient) ListFiles(ctx context.Context, personaID string) ([]TrainingFile, error)

ListFiles retrieves files associated with a persona

func (*PersonasClient) Update

func (p *PersonasClient) Update(ctx context.Context, personaID string, persona *Persona) (*Persona, error)

Update updates an existing persona

type RateLimitError

type RateLimitError struct {
	ErrorResponse
	RemainingRequests int
	ResetTime         time.Time
	RetryAfterSeconds int
}

RateLimitError represents a rate limiting error with retry information

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type ToneCloneClient

type ToneCloneClient struct {
	*Client

	// Resource clients
	Personas  *PersonasClient
	Generate  *GenerateClient
	Training  *TrainingClient
	Knowledge *KnowledgeClient
}

ToneCloneClient provides access to all ToneClone API resources

func NewToneCloneClient

func NewToneCloneClient(apiKey string, options ...ClientOption) *ToneCloneClient

NewToneCloneClient creates a new ToneClone API client with all resource clients

func NewToneCloneClientFromConfig

func NewToneCloneClientFromConfig(baseURL, apiKey string, timeout time.Duration) *ToneCloneClient

NewToneCloneClientFromConfig creates a client from configuration

func (*ToneCloneClient) Ping

func (tc *ToneCloneClient) Ping(ctx context.Context) error

Ping tests the connection to the API

func (*ToneCloneClient) ValidateConnection

func (tc *ToneCloneClient) ValidateConnection(ctx context.Context) error

ValidateConnection validates that the client can connect and authenticate

func (*ToneCloneClient) WhoAmI

func (tc *ToneCloneClient) WhoAmI(ctx context.Context) (*User, error)

WhoAmI returns information about the authenticated user

type TrainingClient

type TrainingClient struct {
	// contains filtered or unexported fields
}

TrainingClient handles training-related API operations

func NewTrainingClient

func NewTrainingClient(client *Client) *TrainingClient

NewTrainingClient creates a new training client

func (*TrainingClient) CreateJob

func (t *TrainingClient) CreateJob(ctx context.Context, personaID string, fileIDs []string) (*TrainingJob, error)

CreateJob creates a new training job

func (*TrainingClient) CreatePersonaTrainingJob

func (t *TrainingClient) CreatePersonaTrainingJob(ctx context.Context, personaID string) (*TrainingJob, error)

CreatePersonaTrainingJob creates a training job for a persona using all associated files

func (*TrainingClient) DeleteFile

func (t *TrainingClient) DeleteFile(ctx context.Context, fileID string) error

DeleteFile deletes a training file

func (*TrainingClient) GetFile

func (t *TrainingClient) GetFile(ctx context.Context, fileID string) (*TrainingFile, error)

GetFile retrieves a specific training file by ID

func (*TrainingClient) GetJob

func (t *TrainingClient) GetJob(ctx context.Context, jobID string) (*TrainingJob, error)

GetJob retrieves a specific training job by ID

func (*TrainingClient) ListFiles

func (t *TrainingClient) ListFiles(ctx context.Context) ([]TrainingFile, error)

ListFiles retrieves all training files for the user

func (*TrainingClient) ListJobs

func (t *TrainingClient) ListJobs(ctx context.Context) ([]TrainingJob, error)

ListJobs retrieves all training jobs for the user

func (*TrainingClient) UploadFile

func (t *TrainingClient) UploadFile(ctx context.Context, file io.Reader, filename string) (*TrainingFile, error)

UploadFile uploads a binary file

func (*TrainingClient) UploadFileBatch

func (t *TrainingClient) UploadFileBatch(ctx context.Context, files []FileUpload, personaID, source string) (*BatchUploadResponse, error)

UploadFileBatch uploads multiple files in a single request

func (*TrainingClient) UploadText

func (t *TrainingClient) UploadText(ctx context.Context, request *UploadTextRequest) (*TrainingFile, error)

UploadText uploads text content

type TrainingFile

type TrainingFile struct {
	PK              string    `json:"PK"`
	SK              string    `json:"SK"`
	UserID          string    `json:"userId"`
	FileID          string    `json:"fileId"`
	FileName        string    `json:"filename"`
	FileType        string    `json:"fileType"`
	FileSize        int64     `json:"size"`
	CreatedAt       time.Time `json:"createdAt"`
	ModifiedAt      time.Time `json:"modifiedAt"`
	S3Key           string    `json:"s3Key"`
	ContentType     string    `json:"contentType"`
	Source          string    `json:"source"`
	UsedForTraining bool      `json:"usedForTraining"`
	PersonaID       string    `json:"personaId,omitempty"`
}

TrainingFile represents a training file

type TrainingFileListResponse

type TrainingFileListResponse struct {
	Files []TrainingFile `json:"files"`
}

TrainingFileListResponse represents the response from listing training files

type TrainingJob

type TrainingJob struct {
	JobID           string    `json:"jobId"`
	PersonaID       string    `json:"personaId"`
	FileIDs         []string  `json:"fileIds"`
	TotalFiles      int       `json:"totalFiles"`
	FilesProcessed  int       `json:"filesProcessed"`
	Status          string    `json:"status"`
	CreatedAt       time.Time `json:"createdAt"`
	UpdatedAt       time.Time `json:"updatedAt"`
	OpenAIJobID     string    `json:"openAIJobID,omitempty"`
	OpenAIJobStatus string    `json:"openAIJobStatus,omitempty"`
	BaseModel       string    `json:"baseModel,omitempty"`
}

TrainingJob represents a training job

type UploadTextRequest

type UploadTextRequest struct {
	Content  string `json:"content"`
	Filename string `json:"filename"`
	Source   string `json:"source"`
}

UploadTextRequest represents a text upload request

type User

type User struct {
	UserID    string    `json:"userId"`
	Email     string    `json:"email"`
	Name      string    `json:"name,omitempty"`
	CreatedAt time.Time `json:"createdAt"`
	Plan      string    `json:"plan,omitempty"`
}

User represents user information

type WritingSession

type WritingSession struct {
	SessionID       string    `json:"sessionId"`
	Title           string    `json:"title,omitempty"`
	Content         string    `json:"content,omitempty"`
	PersonaID       string    `json:"personaId,omitempty"`
	KnowledgeCardID string    `json:"knowledgeCardId,omitempty"`
	CreatedAt       time.Time `json:"createdAt"`
	LastModifiedAt  time.Time `json:"lastModifiedAt"`
	Status          string    `json:"status"`
}

WritingSession represents a writing session

type WritingSessionListResponse

type WritingSessionListResponse struct {
	Sessions []WritingSession `json:"sessions"`
}

WritingSessionListResponse represents the response from listing writing sessions

Jump to

Keyboard shortcuts

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