content

package
v0.0.0-...-791efaf Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 15 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDataURI

func BuildDataURI(mimeType, base64Data string) string

BuildDataURI constructs a data URI from the given MIME type and base64 data.

func ExtractMIMETypeFromURIOrURL

func ExtractMIMETypeFromURIOrURL(s string) string

ExtractMIMETypeFromURIOrURL tries to obtain a MIME type from either a data URI (preferred) or a regular URL path extension as a fallback.

func GuessMIMETypeFromURL

func GuessMIMETypeFromURL(rawURL string) string

GuessMIMETypeFromURL attempts to infer a MIME type from a URL's path extension using the local MIME database. Falls back to a small set of common image/audio/video extensions when necessary. Returns an empty string if no guess can be made.

func ImageToDataURI

func ImageToDataURI(path string, highQuality bool) (name, dataURI string, err error)

ImageToDataURI reads an image from the given path, resizes it if necessary based on the quality setting, encodes it as base64, and returns its filename and a data URI string.

func IsImageMIME

func IsImageMIME(m string) bool

IsImageMIME returns true if the provided MIME type looks like an image type.

func ParseDataURI

func ParseDataURI(uri string) (mimeType string, base64Data string, ok bool)

ParseDataURI parses a data URI and returns its MIME type and base64 data. It returns ok=false if the provided string is not a data URI or does not match the expected `data:<mime>;base64,<payload>` shape.

Types

type AudioURL

type AudioURL struct {
	URL      string            `json:"audio_url"`
	MimeType string            `json:"mime_type,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

func (*AudioURL) GetMetadata

func (au *AudioURL) GetMetadata() map[string]string

func (*AudioURL) Type

func (au *AudioURL) Type() Type

type CacheHint

type CacheHint struct {
	// Duration: "short", "long"
	Duration string `json:"duration,omitempty"`
}

func (*CacheHint) Type

func (c *CacheHint) Type() Type

type Content

type Content []Item

func FromAny

func FromAny(value any) (Content, error)

FromAny marshals the given value to JSON and returns a new JSON content item with the marshalled JSON data.

func FromRawJSON

func FromRawJSON(data json.RawMessage) Content

FromRawJSON returns a new JSON content item with the given raw JSON data.

func FromText

func FromText(text string) Content

FromText returns a new content item with the given text.

func FromTextAndImage

func FromTextAndImage(text, imageURL string) Content

FromTextAndImage returns a new content item with the given text and image URL.

func Textf

func Textf(format string, args ...any) Content

Textf returns a new content item with the provided formatted text.

func (*Content) AddImage

func (c *Content) AddImage(imageURL string)

AddImage adds an image URL to the content.

func (*Content) Append

func (c *Content) Append(text string)

Append adds the text to the last content item if it's a text item, otherwise it adds a new text item to the end of the list.

func (*Content) AppendThought

func (c *Content) AppendThought(text string)

AppendThought adds the given text to the last content item if it's a thought, otherwise it adds a new thought item to the end of the list.

func (*Content) AppendThoughtWithID

func (c *Content) AppendThoughtWithID(id, text string, summary bool) *Thought

AppendThoughtWithID finds an existing thought with the given ID and appends text to it, or creates a new thought with the given ID if none exists. Returns the thought that was updated or created. This is useful for streaming APIs that provide thought IDs upfront.

func (Content) AsString

func (c Content) AsString() (string, bool)

AsString returns the text content and true if the Content contains exactly one Text item. Otherwise, it returns an empty string and false.

func (Content) MarshalJSON

func (c Content) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Content.

func (*Content) SetThoughtSignature

func (c *Content) SetThoughtSignature(signature string)

SetThoughtSignature sets the signature for the last thought item. Panics if there is no thought item.

func (*Content) SetThoughtSummary

func (c *Content) SetThoughtSummary(text, signature string)

SetThoughtSummary will replace the last content item if it's a thought, otherwise it adds a new thought item to the end of the list.

func (*Content) UnmarshalJSON

func (c *Content) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Content.

type ImageURL

type ImageURL struct {
	URL string `json:"image_url"`
	// MimeType, if omitted, will be inferred from data URIs / URL path extensions.
	MimeType string `json:"mime_type,omitempty"`
	// Metadata holds provider-specific metadata that should be forwarded unchanged.
	Metadata map[string]string `json:"metadata,omitempty"`
}

func (*ImageURL) GetMetadata

func (iu *ImageURL) GetMetadata() map[string]string

func (*ImageURL) Type

func (iu *ImageURL) Type() Type

type Item

type Item interface {
	Type() Type
}

type JSON

type JSON struct {
	Data json.RawMessage `json:"data"`
}

func (*JSON) Type

func (j *JSON) Type() Type

type MetadataCarrier

type MetadataCarrier interface {
	GetMetadata() map[string]string
}

MetadataCarrier is implemented by content items that can carry provider-specific metadata through the pipeline. Keys are prefixed with the provider name, e.g. "openai:item_id".

type Text

type Text struct {
	Text string `json:"text"`
}

func (*Text) Type

func (t *Text) Type() Type

type Thought

type Thought struct {
	ID        string `json:"id,omitempty"`
	Text      string `json:"text,omitempty"`
	Encrypted []byte `json:"encrypted,omitempty"`
	Signature string `json:"signature,omitempty"`
	// Metadata holds protocol-specific metadata that should be forwarded unchanged.
	// Keys are prefixed with the protocol/provider name, e.g. "openai:format".
	Metadata map[string]string `json:"metadata,omitempty"`
	// Summary is true if the thought is a complete summary of the thinking
	// session, as opposed to the actual thinking stream.
	Summary bool `json:"summary"`
}

func (*Thought) GetMetadata

func (t *Thought) GetMetadata() map[string]string

func (*Thought) Type

func (t *Thought) Type() Type

type Type

type Type string
const (
	TypeText      Type = "text"
	TypeImageURL  Type = "image_url"
	TypeAudioURL  Type = "audio_url"
	TypeVideoURL  Type = "video_url"
	TypeJSON      Type = "json"
	TypeThought   Type = "thought"
	TypeCacheHint Type = "cache_hint"
)

type VideoURL

type VideoURL struct {
	URL      string            `json:"video_url"`
	MimeType string            `json:"mime_type,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

func (*VideoURL) GetMetadata

func (vu *VideoURL) GetMetadata() map[string]string

func (*VideoURL) Type

func (vu *VideoURL) Type() Type

Jump to

Keyboard shortcuts

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