api

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClipLink(
	backendURL string,
	accessToken string,
	client string,
	uid string,
	url string,
	image []byte,
	video []byte,
	file []byte,
	title string,
	content string,
	destination map[string]interface{},
) (map[string]interface{}, error)

func DetectFileContentType

func DetectFileContentType(filePath string, data []byte) string

DetectFileContentType returns a stable media MIME type for local upload paths.

func DownloadMedia

func DownloadMedia(mediaURL, backendURL, accessToken, client, uid string) ([]byte, error)

DownloadMedia fetches a generated media URL. Treechat auth headers are sent only to same-origin API URLs so signed storage/CDN URLs never receive credentials.

func PrettyJSON

func PrettyJSON(raw []byte) (string, error)

func ResolveFinalURL

func ResolveFinalURL(rawURL string, fallbackBase string) string

func SafeResponseBody

func SafeResponseBody(raw []byte) string

Types

type AIModelRef

type AIModelRef struct {
	ID               string `json:"id"`
	Name             string `json:"name"`
	HumanName        string `json:"human_name"`
	DisplayName      string `json:"display_name"`
	Description      string `json:"description"`
	DescriptionShort string `json:"description_short"`
	Provider         string `json:"provider"`
	ModelType        string `json:"model_type"`
	ActionTagName    string `json:"action_tag_name"`
}

type AIModelsResponse

type AIModelsResponse []AIModelRef

func ListAIModels

func ListAIModels(backendURL, accessToken, client, uid string) (AIModelsResponse, error)

type AIRun

type AIRun struct {
	ID         string        `json:"id"`
	Status     string        `json:"status"`
	OutputURLs []AIRunOutput `json:"output_urls"`
}

type AIRunOutput

type AIRunOutput struct {
	URL      string            `json:"url"`
	URLs     map[string]string `json:"urls"`
	Variants map[string]string `json:"variants"`
}

type Answer

type Answer struct {
	ID                           string              `json:"id"`
	SpaceID                      string              `json:"space_id"`
	QuestID                      string              `json:"quest_id"`
	UserID                       string              `json:"user_id"`
	Content                      string              `json:"content"`
	DisplayContent               string              `json:"display_content"`
	Path                         string              `json:"path"`
	CreatedAt                    string              `json:"created_at"`
	UpdatedAt                    string              `json:"updated_at"`
	MessageType                  string              `json:"message_type"`
	IsPost                       bool                `json:"is_post"`
	IsDraft                      bool                `json:"is_draft"`
	IsSystem                     bool                `json:"is_system"`
	IsClip                       bool                `json:"is_clip"`
	Deleted                      bool                `json:"deleted"`
	RecordingURL                 *string             `json:"recording_url"`
	MP4RecordingURL              *string             `json:"mp4_recording_url"`
	RecordingThumbnailURL        *string             `json:"recording_thumbnail_url"`
	RecordingType                *string             `json:"recording_type"`
	OriginalRecordingType        *string             `json:"original_recording_type"`
	RecordingInfo                json.RawMessage     `json:"recording_info"`
	AnswerImageURL               *string             `json:"answer_image_url"`
	ImagesV2                     []AnswerImageV2     `json:"images_v2"`
	ImageURLs                    []AnswerImageURL    `json:"image_urls"`
	FileURLs                     []AnswerFileURL     `json:"file_urls"`
	AIRuns                       []AIRun             `json:"ai_runs"`
	IsGeneratingImage            bool                `json:"is_generating_image"`
	ImageGenerationFailed        bool                `json:"image_generation_failed"`
	ImageGenerationFailureReason *string             `json:"image_generation_failure_reason"`
	User                         *User               `json:"user"`
	URL                          *URL                `json:"url"`
	ChildQuests                  []ChildQuest        `json:"child_quests"`
	BsvAttachments               []BsvAttachment     `json:"bsv_attachments"`
	ImageBsvOrdinal              *BsvOrdinal         `json:"image_bsv_ordinal"`
	VideoBsvOrdinal              *BsvOrdinal         `json:"video_bsv_ordinal"`
	PollOpen                     bool                `json:"poll_open"`
	PollTotalVotes               int                 `json:"poll_total_votes"`
	PollUserVoteOptionID         *string             `json:"poll_user_vote_option_id"`
	PollResultsVisible           bool                `json:"poll_results_visible"`
	PollOptionsPayload           []PollOptionPayload `json:"poll_options_payload"`
}

func (Answer) CanonicalMediaURLs

func (answer Answer) CanonicalMediaURLs(fallbackBase string) []string

func (Answer) GenerationFailureReason

func (answer Answer) GenerationFailureReason() string

func (Answer) GenerationStatus

func (answer Answer) GenerationStatus() string

func (Answer) MediaURLs

func (answer Answer) MediaURLs() []string

func (Answer) ToASCII

func (answer Answer) ToASCII() string

type AnswerFileURL

type AnswerFileURL struct {
	URL          string            `json:"url"`
	Name         string            `json:"name"`
	ID           interface{}       `json:"id"`
	ContentType  string            `json:"content_type"`
	PreviewURLs  map[string]string `json:"preview_urls"`
	PreviewURL   *string           `json:"preview_url"`
	AttachmentID string            `json:"attachment_id"`
}

type AnswerImageURL

type AnswerImageURL struct {
	ImageURL         string            `json:"image_url"`
	AttachmentID     string            `json:"attachment_id"`
	ImageByteSize    *int64            `json:"image_byte_size"`
	ImageWidth       *int              `json:"image_width"`
	ImageHeight      *int              `json:"image_height"`
	ImageContentType string            `json:"image_content_type"`
	ImageFilename    string            `json:"image_filename"`
	PreviewURLs      map[string]string `json:"preview_urls"`
	PreviewURL       *string           `json:"preview_url"`
}

type AnswerImageV2

type AnswerImageV2 struct {
	AttachmentID     string            `json:"attachment_id"`
	BlobID           string            `json:"blob_id"`
	AttachedAt       string            `json:"attached_at"`
	BlobCreatedAt    string            `json:"blob_created_at"`
	Access           string            `json:"access"`
	ImageByteSize    *int64            `json:"image_byte_size"`
	ImageWidth       *int              `json:"image_width"`
	ImageHeight      *int              `json:"image_height"`
	ImageContentType string            `json:"image_content_type"`
	ImageFilename    string            `json:"image_filename"`
	URLs             map[string]string `json:"urls"`
	PreviewURL       *string           `json:"preview_url"`
}

type AnswerResponse

type AnswerResponse struct {
	Answer Answer          `json:"answer"`
	Raw    json.RawMessage `json:"-"`
}

func GetAnswer

func GetAnswer(backendURL, answerID, accessToken, client, uid string) (AnswerResponse, error)

type BsvAttachment

type BsvAttachment struct {
	ID            string `json:"id"`
	Size          *int64 `json:"size"`
	MimeType      string `json:"mime_type"`
	AttachmentID  string `json:"attachment_id"`
	AttachmentURL string `json:"attachment_url"`
}

type BsvOrdinal

type BsvOrdinal struct {
	ID                string `json:"id"`
	Origin            string `json:"origin"`
	InscriptionID     string `json:"inscription_id"`
	InscriptionNumber *int64 `json:"inscription_number"`
	ContentType       string `json:"content_type"`
	QuestID           string `json:"quest_id"`
	AnswerID          string `json:"answer_id"`
}

type ChildQuest

type ChildQuest struct {
	ID       string `json:"id"`
	ParentID string `json:"parent_id"`
	Path     string `json:"path"`
}

type CreateAnswerRequest

type CreateAnswerRequest struct {
	AnswerID           string
	ChildQuestID       string
	QuestID            string
	SpaceID            string
	UserID             string
	Content            string
	DeltaJSON          string
	ActionRequestsJSON string
	MessageType        string
	Uploads            []MultipartFile
}

type CreateAnswerResponse

type CreateAnswerResponse struct {
	Answer    Answer          `json:"answer"`
	Quest     *Quest          `json:"quest"`
	SideQuest *Quest          `json:"side_quest"`
	Raw       json.RawMessage `json:"-"`
}

func CreateAnswer

func CreateAnswer(
	backendURL string,
	accessToken string,
	client string,
	uid string,
	request CreateAnswerRequest,
) (CreateAnswerResponse, error)

type CreateClipQuestRequest

type CreateClipQuestRequest struct {
	URL         string
	Content     string
	DeltaJSON   string
	Image       []byte
	Video       []byte
	File        []byte
	Title       string
	Destination map[string]interface{}
}

type CreateQuestRequest

type CreateQuestRequest struct {
	QuestID            string
	ParentAnswerID     string
	SpaceID            string
	Content            string
	DeltaJSON          string
	ActionRequestsJSON string
	MessageType        string
	ThreadType         string
	TeamID             string
	Public             *bool
	Private            *bool
	Uploads            []MultipartFile
}

type CreateQuestResponse

type CreateQuestResponse struct {
	Quest Quest           `json:"quest"`
	Raw   json.RawMessage `json:"-"`
}

func CreateClipQuest

func CreateClipQuest(
	backendURL string,
	accessToken string,
	client string,
	uid string,
	request CreateClipQuestRequest,
) (CreateQuestResponse, error)

func CreateQuest

func CreateQuest(
	backendURL string,
	accessToken string,
	client string,
	uid string,
	request CreateQuestRequest,
) (CreateQuestResponse, error)

type GenerationActionInfo

type GenerationActionInfo struct {
	Action               string        `json:"action"`
	Tag                  string        `json:"tag,omitempty"`
	Provider             string        `json:"provider"`
	Kind                 string        `json:"kind"` // image | audio | video
	Async                bool          `json:"async"`
	AcceptsReference     bool          `json:"accepts_reference"`
	RequiresReference    bool          `json:"requires_reference"`
	ReferenceKinds       []string      `json:"reference_kinds,omitempty"`
	SupportsInstrumental bool          `json:"supports_instrumental"`
	Settings             []SettingInfo `json:"settings,omitempty"`
	DurationMin          int           `json:"duration_min,omitempty"`
	DurationMax          int           `json:"duration_max,omitempty"`
	Inputs               []string      `json:"inputs,omitempty"`
}

GenerationActionInfo describes one AI action available to the direct generation endpoint and what it accepts.

func ListGenerationActions

func ListGenerationActions(backendURL, accessToken, client, uid string) ([]GenerationActionInfo, error)

ListGenerationActions fetches the AI actions the direct generation endpoint supports and what each accepts. It prefers GET /api/v1/ai/generations/actions and falls back to /tags for older backends.

type GenerationMedia

type GenerationMedia struct {
	URL         string `json:"url"`
	ContentType string `json:"content_type,omitempty"`
	Kind        string `json:"kind,omitempty"`
}

GenerationMedia describes one generated media artifact.

type GenerationQuote

type GenerationQuote struct {
	AmountSats  int64   `json:"amount_sats"`
	AmountUSD   float64 `json:"amount_usd"`
	Action      string  `json:"action,omitempty"`
	Tag         string  `json:"tag"`
	Provider    string  `json:"provider,omitempty"`
	PaymentMode string  `json:"payment_mode,omitempty"`
}

GenerationQuote is the price for a generation, returned when quote=true (no media is produced).

type GenerationResponse

type GenerationResponse struct {
	ID           string                 `json:"id"`
	Status       string                 `json:"status"`
	Tag          string                 `json:"tag"`
	Action       string                 `json:"action,omitempty"`
	Source       string                 `json:"source"`
	Provider     string                 `json:"provider,omitempty"`
	PaymentMode  string                 `json:"payment_mode,omitempty"`
	MediaURLs    []string               `json:"media_urls"`
	MediaOutputs []GenerationMedia      `json:"media_outputs,omitempty"`
	AmountSats   int64                  `json:"amount_sats,omitempty"`
	AmountUSD    float64                `json:"amount_usd,omitempty"`
	Quote        *GenerationQuote       `json:"quote,omitempty"`
	Failure      map[string]interface{} `json:"failure,omitempty"`
	Error        string                 `json:"error,omitempty"`
	Raw          []byte                 `json:"-"`
}

GenerationResponse is the payload from the direct (post-less) generation endpoints.

func CreateGeneration

func CreateGeneration(
	backendURL string,
	accessToken string,
	client string,
	uid string,
	action string,
	prompt string,
	settings map[string]interface{},
	paymentMode string,
	quote bool,
	timeout time.Duration,
) (GenerationResponse, error)

CreateGeneration runs a direct AI generation that charges the user and returns media without ever creating a post. POST /api/v1/ai/generations.

func GetGeneration

func GetGeneration(backendURL, id, accessToken, client, uid string) (GenerationResponse, error)

GetGeneration polls a direct generation by id. GET /api/v1/ai/generations/:id.

type MessagesResponse

type MessagesResponse struct {
	Answers []Answer        `json:"answers"`
	Raw     json.RawMessage `json:"-"`
}

func GetMessages

func GetMessages(backendURL, accessToken, client, uid string, messageIDs []string) (MessagesResponse, error)

GetMessages fetches messages from the API and returns them

type MultipartFile

type MultipartFile struct {
	FieldName   string
	FileName    string
	ContentType string
	Content     []byte
}

type NotificationsCountResponse

type NotificationsCountResponse struct {
	NumNotifications *int            `json:"num_noti"`
	ClientVersion    int             `json:"client_version"`
	Raw              json.RawMessage `json:"-"`
}

func GetNotificationsCount

func GetNotificationsCount(
	backendURL string,
	accessToken string,
	client string,
	uid string,
	spaceID string,
) (NotificationsCountResponse, error)

type NotificationsResponse

type NotificationsResponse struct {
	Quests      []Quest         `json:"quests"`
	PinnedQuest *Quest          `json:"pinned_quest"`
	Raw         json.RawMessage `json:"-"`
}

func GetNotifications

func GetNotifications(
	backendURL string,
	accessToken string,
	client string,
	uid string,
	spaceID string,
	page int,
	unseenOnly bool,
	clear bool,
) (NotificationsResponse, error)

type PollOptionPayload

type PollOptionPayload struct {
	ID         string   `json:"id"`
	Label      string   `json:"label"`
	Position   int      `json:"position"`
	VotesCount *int     `json:"votes_count"`
	Percentage *float64 `json:"percentage"`
}

type Quest

type Quest struct {
	ID                      string   `json:"id"`
	SpaceID                 string   `json:"space_id"`
	UserID                  string   `json:"user_id"`
	Content                 string   `json:"content"`
	Path                    string   `json:"path"`
	QuestURL                string   `json:"quest_url"`
	ParentID                string   `json:"parent_id"`
	NotificationReasonLabel string   `json:"notification_reason_label"`
	SortedAnswerIDs         []string `json:"sorted_answer_ids"`
	MatchingAnswerIDs       []string `json:"matching_answer_ids"`
	Parent                  *Answer  `json:"parent"`
	SortedAnswers           []Answer `json:"sorted_answers"`
}

func (Quest) ToASCII

func (quest Quest) ToASCII() string

type ReferenceUploadResponse

type ReferenceUploadResponse struct {
	ID          string `json:"id"`
	URL         string `json:"url"`
	ContentType string `json:"content_type,omitempty"`
	Kind        string `json:"kind,omitempty"`
	Error       string `json:"error,omitempty"`
}

ReferenceUploadResponse is returned by the reference-upload endpoint.

func UploadReference

func UploadReference(backendURL, accessToken, client, uid, filePath string) (ReferenceUploadResponse, error)

UploadReference uploads a local file to use as a model reference and returns its presigned URL. POST /api/v1/ai/generations/references (multipart). The file is held on a direct AiRun; no charge.

type ResolvedMediaLink struct {
	MediaLink    string
	RawMediaLink string
}
func ResolveAnswerMediaLinks(answer Answer, fallbackBase string) []ResolvedMediaLink

type SettingInfo

type SettingInfo struct {
	Name          string      `json:"name"`
	Type          string      `json:"type,omitempty"`
	Description   string      `json:"description,omitempty"`
	Default       interface{} `json:"default,omitempty"`
	Min           int         `json:"min,omitempty"`
	Max           int         `json:"max,omitempty"`
	AllowedValues []int       `json:"allowed_values,omitempty"`
}

SettingInfo describes one backend-advertised direct generation setting.

type StripeAiBillingCheckoutResponse added in v0.2.2

type StripeAiBillingCheckoutResponse struct {
	URL string          `json:"url"`
	Raw json.RawMessage `json:"-"`
}

StripeAiBillingCheckoutResponse is returned by POST /api/v1/stripe_ai_billing/checkout.

func CreateStripeAiBillingCheckoutSession added in v0.2.2

func CreateStripeAiBillingCheckoutSession(backendURL, accessToken, client, uid string) (StripeAiBillingCheckoutResponse, error)

type StripeAiBillingStatusResponse added in v0.2.2

type StripeAiBillingStatusResponse struct {
	Stripe StripeAiBillingStripe `json:"stripe"`
	Usage  StripeAiBillingUsage  `json:"usage"`
	Raw    json.RawMessage       `json:"-"`
}

StripeAiBillingStatusResponse is returned by GET /api/v1/stripe_ai_billing/status.

func GetStripeAiBillingStatus added in v0.2.2

func GetStripeAiBillingStatus(backendURL, accessToken, client, uid string, refresh bool) (StripeAiBillingStatusResponse, error)

type StripeAiBillingStripe added in v0.2.2

type StripeAiBillingStripe struct {
	CustomerID         string `json:"customer_id"`
	SubscriptionID     string `json:"subscription_id"`
	SubscriptionStatus string `json:"subscription_status"`
	AIPaymentMode      string `json:"ai_payment_mode"`
	MeteredLockedAt    string `json:"metered_locked_at"`
	MeteredLockReason  string `json:"metered_lock_reason"`
	RefreshedAt        string `json:"refreshed_at"`
}

type StripeAiBillingSyncResponse added in v0.2.2

type StripeAiBillingSyncResponse struct {
	OK  bool            `json:"ok"`
	Raw json.RawMessage `json:"-"`
}

StripeAiBillingSyncResponse is returned by GET /api/v1/stripe_ai_billing/sync.

func SyncStripeAiBillingCheckoutSession added in v0.2.2

func SyncStripeAiBillingCheckoutSession(backendURL, accessToken, client, uid, sessionID string) (StripeAiBillingSyncResponse, error)

type StripeAiBillingUsEvent added in v0.2.2

type StripeAiBillingUsEvent struct {
	ID              int64  `json:"id"`
	AmountCents     int64  `json:"amount_cents"`
	Status          string `json:"status"`
	OccurredAt      string `json:"occurred_at"`
	StripeInvoiceID string `json:"stripe_invoice_id"`
	LastError       string `json:"last_error"`
}

type StripeAiBillingUsage added in v0.2.2

type StripeAiBillingUsage struct {
	UnpaidTotalCents    int64                    `json:"unpaid_total_cents"`
	TotalsCentsByStatus map[string]int64         `json:"totals_cents_by_status"`
	Events              []StripeAiBillingUsEvent `json:"events"`
}

type StripeAiPaymentModeResponse added in v0.2.2

type StripeAiPaymentModeResponse struct {
	OK            bool            `json:"ok"`
	AIPaymentMode string          `json:"ai_payment_mode"`
	Raw           json.RawMessage `json:"-"`
}

StripeAiPaymentModeResponse is returned by POST /api/v1/stripe_ai_billing/mode.

func SetStripeAiPaymentMode added in v0.2.2

func SetStripeAiPaymentMode(backendURL, accessToken, client, uid, mode string) (StripeAiPaymentModeResponse, error)

type TagInfo

type TagInfo = GenerationActionInfo

TagInfo is kept as a source-compatible alias for older callers.

func ListGenerationTags

func ListGenerationTags(backendURL, accessToken, client, uid string) ([]TagInfo, error)

ListGenerationTags is kept as a compatibility wrapper for older callers.

type TeamRef

type TeamRef struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	ShortName string `json:"short_name"`
	Path      string `json:"path"`
	URL       string `json:"url"`
}

type TeamsResponse

type TeamsResponse struct {
	Teams []TeamRef       `json:"teams"`
	Raw   json.RawMessage `json:"-"`
}

func ListPublicTeams

func ListPublicTeams(
	backendURL string,
	accessToken string,
	client string,
	uid string,
	spaceID string,
) (TeamsResponse, error)

func ListTeams

func ListTeams(
	backendURL string,
	accessToken string,
	client string,
	uid string,
	spaceID string,
	publicOnly bool,
) (TeamsResponse, error)

type ThreadResponse

type ThreadResponse struct {
	Quest Quest           `json:"quest"`
	Raw   json.RawMessage `json:"-"`
}

func GetThread

func GetThread(backendURL, threadID, accessToken, client, uid string) (ThreadResponse, error)

type URL

type URL struct {
	Address string `json:"address"`
	Title   string `json:"title"`
}

type UpvaluedContentLeaderboardItem

type UpvaluedContentLeaderboardItem struct {
	AnswerID      string `json:"answer_id"`
	QuestID       string `json:"quest_id"`
	QuestURL      string `json:"quest_url"`
	User          User   `json:"user"`
	TotalSats     int64  `json:"total_sats"`
	UpvalueCount  int    `json:"upvalue_count"`
	LastUpvalueAt string `json:"last_upvalue_at"`
	Answer        Answer `json:"answer"`
	Quest         Quest  `json:"quest"`
}

type UpvaluedContentLeaderboardResponse

type UpvaluedContentLeaderboardResponse struct {
	Period struct {
		StartDate string `json:"start_date"`
		EndDate   string `json:"end_date"`
	} `json:"period"`
	Limit int                              `json:"limit"`
	Items []UpvaluedContentLeaderboardItem `json:"items"`
	Raw   json.RawMessage                  `json:"-"`
}

func GetUpvaluedContentLeaderboard

func GetUpvaluedContentLeaderboard(
	backendURL string,
	accessToken string,
	client string,
	uid string,
	startDate string,
	endDate string,
	limit int,
) (UpvaluedContentLeaderboardResponse, error)

type User

type User struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Path string `json:"path"`
}

Jump to

Keyboard shortcuts

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