api

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const OAuthClient = "oauth"

OAuthClient marks a saved profile whose credentials are an OAuth bearer from `treecli connect`. Such profiles reach the backend only through /mcp.

Variables

This section is empty.

Functions

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 ResolveThreadUser added in v0.2.7

func ResolveThreadUser(backendURL, accessToken, client, uid, user string) (string, error)

ResolveThreadUser accepts IDs, usernames (optionally @-prefixed), and me. The server resolves me from the authenticated session, even for old profiles.

func SafeCredentialResponseBody added in v0.2.13

func SafeCredentialResponseBody(raw []byte, credentials ...string) string

SafeCredentialResponseBody also removes active credential values from freeform upstream errors, where key-based JSON redaction cannot identify them.

func SafeResponseBody

func SafeResponseBody(raw []byte) string

func SetOAuthRefresher added in v0.2.13

func SetOAuthRefresher(refresh func(stale string) (string, error))

SetOAuthRefresher installs the hook that trades an expired bearer for a fresh one (and persists it). The CLI owns credential storage; this package never does.

func SharedOperation added in v0.2.13

func SharedOperation(backendURL, accessToken, clientID, uid, tool string, arguments map[string]interface{}) (json.RawMessage, error)

SharedOperation is the sole RPC envelope used by legacy CLI adapters and MCP. The backend owns operation validation, authorization and business decisions.

func UploadSharedFile added in v0.2.13

func UploadSharedFile(backendURL, token, client, uid, path, purpose string) (map[string]interface{}, error)

UploadSharedFile keeps file selection and storage transport local, while the shared server operations own registration, validation and reference ownership.

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 {
	ReplyToAnswerID              string              `json:"reply_to_answer_id"`
	ID                           string              `json:"id"`
	SpaceID                      string              `json:"space_id"`
	QuestID                      string              `json:"quest_id"`
	UserID                       string              `json:"user_id"`
	Content                      string              `json:"content"`
	DeltaJSON                    json.RawMessage     `json:"delta_json,omitempty"`
	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 BsvUpvalue added in v0.2.6

type BsvUpvalue struct {
	ID         string                 `json:"id"`
	TxID       string                 `json:"tx_id"`
	Amount     string                 `json:"amount"`
	Fee        string                 `json:"fee"`
	CreatedAt  string                 `json:"created_at"`
	FromUserID string                 `json:"from_user_id"`
	ToUserID   string                 `json:"to_user_id"`
	IsBoost    bool                   `json:"is_boost"`
	Metadata   map[string]interface{} `json:"metadata"`
	Status     string                 `json:"status"`
	FromUser   User                   `json:"from_user"`
	ToUser     User                   `json:"to_user"`
	BsvTx      *BsvUpvalueTx          `json:"bsv_tx"`
	Answer     BsvUpvalueAnswer       `json:"answer"`
}

type BsvUpvalueAnswer added in v0.2.6

type BsvUpvalueAnswer struct {
	ID          string       `json:"id"`
	ChildQuests []ChildQuest `json:"child_quests"`
}

type BsvUpvalueTx added in v0.2.6

type BsvUpvalueTx struct {
	ID            string `json:"id"`
	TxID          string `json:"tx_id"`
	Status        string `json:"status"`
	Confirmations int    `json:"confirmations"`
	Confirmed     bool   `json:"confirmed"`
}

type ChildQuest

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

type Client added in v0.2.13

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

Client binds explicit credentials to one origin. It never reads CLI configuration. Bearer support here does not grant access to any server endpoint or scope.

func NewOAuthClient added in v0.2.13

func NewOAuthClient(origin, bearer string) (*Client, error)

func NewTokenClient added in v0.2.13

func NewTokenClient(origin, accessToken, clientID, uid string) (*Client, error)

func (*Client) CallTool added in v0.2.13

func (c *Client) CallTool(ctx context.Context, name string, args map[string]interface{}) (ToolResult, error)

func (*Client) DoJSON added in v0.2.13

func (c *Client) DoJSON(ctx context.Context, method, path string, query url.Values, body, out interface{}) error

DoJSON is a transport primitive for typed operations, not an MCP tool. Callers select the endpoint; model-supplied arbitrary methods/paths must not be exposed.

func (*Client) ListTools added in v0.2.13

func (c *Client) ListTools(ctx context.Context) (ToolList, error)

type CreateAnswerResponse

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

type CreateQuestResponse

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

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 DecodeGeneration added in v0.2.13

func DecodeGeneration(raw json.RawMessage) (GenerationResponse, error)

DecodeGeneration adapts response naming only; billing and media decisions stay server-side.

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 HTTPError added in v0.2.10

type HTTPError struct {
	StatusCode int
	Body       string
}

HTTPError preserves the response status and safe response body for callers that need to distinguish a rejected request from an ambiguous transport failure.

func (*HTTPError) Error added in v0.2.10

func (e *HTTPError) Error() string

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 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 {
	SideQuest               bool     `json:"side_quest"`
	ID                      string   `json:"id"`
	TeamID                  string   `json:"team_id"`
	Public                  *bool    `json:"public"`
	Private                 *bool    `json:"private"`
	IsClip                  *bool    `json:"is_clip"`
	ThreadType              string   `json:"thread_type"`
	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 ResolvedMediaLink struct {
	MediaLink    string
	RawMediaLink string
}
func ResolveAnswerMediaLinks(answer Answer, fallbackBase string) []ResolvedMediaLink

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 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 ThreadListOptions added in v0.2.7

type ThreadListOptions struct {
	User  string
	Scope string
	Page  int
	Limit int
}

ThreadListOptions describes an authored, creation-ordered collection.

type ThreadPagination added in v0.2.7

type ThreadPagination struct {
	Page     int  `json:"page"`
	Limit    int  `json:"limit"`
	NextPage *int `json:"next_page"`
	HasMore  bool `json:"has_more"`
}

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 ThreadsResponse added in v0.2.7

type ThreadsResponse struct {
	Threads    []Quest           `json:"threads"`
	Pagination *ThreadPagination `json:"pagination,omitempty"`
	Raw        json.RawMessage   `json:"-"`
}

func ListThreads added in v0.2.7

func ListThreads(backendURL, accessToken, client, uid string, options ThreadListOptions) (ThreadsResponse, error)

func ThreadsForAnswer added in v0.2.7

func ThreadsForAnswer(backendURL, accessToken, client, uid, answerID string) (ThreadsResponse, error)

ThreadsForAnswer preserves complete thread payloads and server-side visibility.

type ToolDefinition added in v0.2.13

type ToolDefinition map[string]interface{}

ToolDefinition preserves the backend-owned schema and annotations without a second model/option registry in the CLI.

type ToolList added in v0.2.13

type ToolList struct {
	Tools []ToolDefinition `json:"tools"`
}

type ToolResult added in v0.2.13

type ToolResult struct {
	Content           []map[string]interface{} `json:"content"`
	StructuredContent interface{}              `json:"structuredContent,omitempty"`
	IsError           bool                     `json:"isError,omitempty"`
}

type URL

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

type UpvalueHistoryResponse added in v0.2.6

type UpvalueHistoryResponse struct {
	Upvalues []BsvUpvalue    `json:"upvalues"`
	Page     int             `json:"page"`
	PerPage  int             `json:"per_page"`
	HasMore  bool            `json:"has_more"`
	Raw      json.RawMessage `json:"-"`
}

func GetUpvalueHistory added in v0.2.6

func GetUpvalueHistory(
	backendURL string,
	accessToken string,
	client string,
	uid string,
	page int,
	perPage int,
) (UpvalueHistoryResponse, error)

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