| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385 |
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
- package opencode
- import (
- "context"
- "errors"
- "fmt"
- "net/http"
- "reflect"
- "github.com/sst/opencode-sdk-go/internal/apijson"
- "github.com/sst/opencode-sdk-go/internal/param"
- "github.com/sst/opencode-sdk-go/internal/requestconfig"
- "github.com/sst/opencode-sdk-go/option"
- "github.com/sst/opencode-sdk-go/shared"
- "github.com/tidwall/gjson"
- )
- // SessionService contains methods and other services that help with interacting
- // with the opencode API.
- //
- // Note, unlike clients, this service does not read variables from the environment
- // automatically. You should not instantiate this service directly, and instead use
- // the [NewSessionService] method instead.
- type SessionService struct {
- Options []option.RequestOption
- }
- // NewSessionService generates a new service that applies the given options to each
- // request. These options are applied after the parent client's options (if there
- // is one), and before any request-specific options.
- func NewSessionService(opts ...option.RequestOption) (r *SessionService) {
- r = &SessionService{}
- r.Options = opts
- return
- }
- // Create a new session
- func (r *SessionService) New(ctx context.Context, opts ...option.RequestOption) (res *Session, err error) {
- opts = append(r.Options[:], opts...)
- path := "session"
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
- return
- }
- // List all sessions
- func (r *SessionService) List(ctx context.Context, opts ...option.RequestOption) (res *[]Session, err error) {
- opts = append(r.Options[:], opts...)
- path := "session"
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
- return
- }
- // Delete a session and all its data
- func (r *SessionService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (res *bool, err error) {
- opts = append(r.Options[:], opts...)
- if id == "" {
- err = errors.New("missing required id parameter")
- return
- }
- path := fmt.Sprintf("session/%s", id)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
- return
- }
- // Abort a session
- func (r *SessionService) Abort(ctx context.Context, id string, opts ...option.RequestOption) (res *bool, err error) {
- opts = append(r.Options[:], opts...)
- if id == "" {
- err = errors.New("missing required id parameter")
- return
- }
- path := fmt.Sprintf("session/%s/abort", id)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
- return
- }
- // Create and send a new message to a session
- func (r *SessionService) Chat(ctx context.Context, id string, body SessionChatParams, opts ...option.RequestOption) (res *Message, err error) {
- opts = append(r.Options[:], opts...)
- if id == "" {
- err = errors.New("missing required id parameter")
- return
- }
- path := fmt.Sprintf("session/%s/message", id)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
- }
- // Analyze the app and create an AGENTS.md file
- func (r *SessionService) Init(ctx context.Context, id string, body SessionInitParams, opts ...option.RequestOption) (res *bool, err error) {
- opts = append(r.Options[:], opts...)
- if id == "" {
- err = errors.New("missing required id parameter")
- return
- }
- path := fmt.Sprintf("session/%s/init", id)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
- }
- // List messages for a session
- func (r *SessionService) Messages(ctx context.Context, id string, opts ...option.RequestOption) (res *[]Message, err error) {
- opts = append(r.Options[:], opts...)
- if id == "" {
- err = errors.New("missing required id parameter")
- return
- }
- path := fmt.Sprintf("session/%s/message", id)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
- return
- }
- // Share a session
- func (r *SessionService) Share(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) {
- opts = append(r.Options[:], opts...)
- if id == "" {
- err = errors.New("missing required id parameter")
- return
- }
- path := fmt.Sprintf("session/%s/share", id)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
- return
- }
- // Summarize the session
- func (r *SessionService) Summarize(ctx context.Context, id string, body SessionSummarizeParams, opts ...option.RequestOption) (res *bool, err error) {
- opts = append(r.Options[:], opts...)
- if id == "" {
- err = errors.New("missing required id parameter")
- return
- }
- path := fmt.Sprintf("session/%s/summarize", id)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
- return
- }
- // Unshare the session
- func (r *SessionService) Unshare(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) {
- opts = append(r.Options[:], opts...)
- if id == "" {
- err = errors.New("missing required id parameter")
- return
- }
- path := fmt.Sprintf("session/%s/share", id)
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
- return
- }
- type FilePart struct {
- MediaType string `json:"mediaType,required"`
- Type FilePartType `json:"type,required"`
- URL string `json:"url,required"`
- Filename string `json:"filename"`
- JSON filePartJSON `json:"-"`
- }
- // filePartJSON contains the JSON metadata for the struct [FilePart]
- type filePartJSON struct {
- MediaType apijson.Field
- Type apijson.Field
- URL apijson.Field
- Filename apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *FilePart) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r filePartJSON) RawJSON() string {
- return r.raw
- }
- func (r FilePart) implementsMessagePart() {}
- type FilePartType string
- const (
- FilePartTypeFile FilePartType = "file"
- )
- func (r FilePartType) IsKnown() bool {
- switch r {
- case FilePartTypeFile:
- return true
- }
- return false
- }
- type FilePartParam struct {
- MediaType param.Field[string] `json:"mediaType,required"`
- Type param.Field[FilePartType] `json:"type,required"`
- URL param.Field[string] `json:"url,required"`
- Filename param.Field[string] `json:"filename"`
- }
- func (r FilePartParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- func (r FilePartParam) implementsMessagePartUnionParam() {}
- type Message struct {
- ID string `json:"id,required"`
- Metadata MessageMetadata `json:"metadata,required"`
- Parts []MessagePart `json:"parts,required"`
- Role MessageRole `json:"role,required"`
- JSON messageJSON `json:"-"`
- }
- // messageJSON contains the JSON metadata for the struct [Message]
- type messageJSON struct {
- ID apijson.Field
- Metadata apijson.Field
- Parts apijson.Field
- Role apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *Message) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r messageJSON) RawJSON() string {
- return r.raw
- }
- type MessageMetadata struct {
- SessionID string `json:"sessionID,required"`
- Time MessageMetadataTime `json:"time,required"`
- Tool map[string]MessageMetadataTool `json:"tool,required"`
- Assistant MessageMetadataAssistant `json:"assistant"`
- Error MessageMetadataError `json:"error"`
- Snapshot string `json:"snapshot"`
- JSON messageMetadataJSON `json:"-"`
- }
- // messageMetadataJSON contains the JSON metadata for the struct [MessageMetadata]
- type messageMetadataJSON struct {
- SessionID apijson.Field
- Time apijson.Field
- Tool apijson.Field
- Assistant apijson.Field
- Error apijson.Field
- Snapshot apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *MessageMetadata) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r messageMetadataJSON) RawJSON() string {
- return r.raw
- }
- type MessageMetadataTime struct {
- Created float64 `json:"created,required"`
- Completed float64 `json:"completed"`
- JSON messageMetadataTimeJSON `json:"-"`
- }
- // messageMetadataTimeJSON contains the JSON metadata for the struct
- // [MessageMetadataTime]
- type messageMetadataTimeJSON struct {
- Created apijson.Field
- Completed apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *MessageMetadataTime) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r messageMetadataTimeJSON) RawJSON() string {
- return r.raw
- }
- type MessageMetadataTool struct {
- Time MessageMetadataToolTime `json:"time,required"`
- Title string `json:"title,required"`
- Snapshot string `json:"snapshot"`
- ExtraFields map[string]interface{} `json:"-,extras"`
- JSON messageMetadataToolJSON `json:"-"`
- }
- // messageMetadataToolJSON contains the JSON metadata for the struct
- // [MessageMetadataTool]
- type messageMetadataToolJSON struct {
- Time apijson.Field
- Title apijson.Field
- Snapshot apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *MessageMetadataTool) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r messageMetadataToolJSON) RawJSON() string {
- return r.raw
- }
- type MessageMetadataToolTime struct {
- End float64 `json:"end,required"`
- Start float64 `json:"start,required"`
- JSON messageMetadataToolTimeJSON `json:"-"`
- }
- // messageMetadataToolTimeJSON contains the JSON metadata for the struct
- // [MessageMetadataToolTime]
- type messageMetadataToolTimeJSON struct {
- End apijson.Field
- Start apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *MessageMetadataToolTime) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r messageMetadataToolTimeJSON) RawJSON() string {
- return r.raw
- }
- type MessageMetadataAssistant struct {
- Cost float64 `json:"cost,required"`
- ModelID string `json:"modelID,required"`
- Path MessageMetadataAssistantPath `json:"path,required"`
- ProviderID string `json:"providerID,required"`
- System []string `json:"system,required"`
- Tokens MessageMetadataAssistantTokens `json:"tokens,required"`
- Summary bool `json:"summary"`
- JSON messageMetadataAssistantJSON `json:"-"`
- }
- // messageMetadataAssistantJSON contains the JSON metadata for the struct
- // [MessageMetadataAssistant]
- type messageMetadataAssistantJSON struct {
- Cost apijson.Field
- ModelID apijson.Field
- Path apijson.Field
- ProviderID apijson.Field
- System apijson.Field
- Tokens apijson.Field
- Summary apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *MessageMetadataAssistant) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r messageMetadataAssistantJSON) RawJSON() string {
- return r.raw
- }
- type MessageMetadataAssistantPath struct {
- Cwd string `json:"cwd,required"`
- Root string `json:"root,required"`
- JSON messageMetadataAssistantPathJSON `json:"-"`
- }
- // messageMetadataAssistantPathJSON contains the JSON metadata for the struct
- // [MessageMetadataAssistantPath]
- type messageMetadataAssistantPathJSON struct {
- Cwd apijson.Field
- Root apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *MessageMetadataAssistantPath) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r messageMetadataAssistantPathJSON) RawJSON() string {
- return r.raw
- }
- type MessageMetadataAssistantTokens struct {
- Cache MessageMetadataAssistantTokensCache `json:"cache,required"`
- Input float64 `json:"input,required"`
- Output float64 `json:"output,required"`
- Reasoning float64 `json:"reasoning,required"`
- JSON messageMetadataAssistantTokensJSON `json:"-"`
- }
- // messageMetadataAssistantTokensJSON contains the JSON metadata for the struct
- // [MessageMetadataAssistantTokens]
- type messageMetadataAssistantTokensJSON struct {
- Cache apijson.Field
- Input apijson.Field
- Output apijson.Field
- Reasoning apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *MessageMetadataAssistantTokens) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r messageMetadataAssistantTokensJSON) RawJSON() string {
- return r.raw
- }
- type MessageMetadataAssistantTokensCache struct {
- Read float64 `json:"read,required"`
- Write float64 `json:"write,required"`
- JSON messageMetadataAssistantTokensCacheJSON `json:"-"`
- }
- // messageMetadataAssistantTokensCacheJSON contains the JSON metadata for the
- // struct [MessageMetadataAssistantTokensCache]
- type messageMetadataAssistantTokensCacheJSON struct {
- Read apijson.Field
- Write apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *MessageMetadataAssistantTokensCache) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r messageMetadataAssistantTokensCacheJSON) RawJSON() string {
- return r.raw
- }
- type MessageMetadataError struct {
- // This field can have the runtime type of [shared.ProviderAuthErrorData],
- // [shared.UnknownErrorData], [interface{}].
- Data interface{} `json:"data,required"`
- Name MessageMetadataErrorName `json:"name,required"`
- JSON messageMetadataErrorJSON `json:"-"`
- union MessageMetadataErrorUnion
- }
- // messageMetadataErrorJSON contains the JSON metadata for the struct
- // [MessageMetadataError]
- type messageMetadataErrorJSON struct {
- Data apijson.Field
- Name apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r messageMetadataErrorJSON) RawJSON() string {
- return r.raw
- }
- func (r *MessageMetadataError) UnmarshalJSON(data []byte) (err error) {
- *r = MessageMetadataError{}
- err = apijson.UnmarshalRoot(data, &r.union)
- if err != nil {
- return err
- }
- return apijson.Port(r.union, &r)
- }
- // AsUnion returns a [MessageMetadataErrorUnion] interface which you can cast to
- // the specific types for more type safety.
- //
- // Possible runtime types of the union are [shared.ProviderAuthError],
- // [shared.UnknownError], [MessageMetadataErrorMessageOutputLengthError].
- func (r MessageMetadataError) AsUnion() MessageMetadataErrorUnion {
- return r.union
- }
- // Union satisfied by [shared.ProviderAuthError], [shared.UnknownError] or
- // [MessageMetadataErrorMessageOutputLengthError].
- type MessageMetadataErrorUnion interface {
- ImplementsMessageMetadataError()
- }
- func init() {
- apijson.RegisterUnion(
- reflect.TypeOf((*MessageMetadataErrorUnion)(nil)).Elem(),
- "name",
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(shared.ProviderAuthError{}),
- DiscriminatorValue: "ProviderAuthError",
- },
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(shared.UnknownError{}),
- DiscriminatorValue: "UnknownError",
- },
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(MessageMetadataErrorMessageOutputLengthError{}),
- DiscriminatorValue: "MessageOutputLengthError",
- },
- )
- }
- type MessageMetadataErrorMessageOutputLengthError struct {
- Data interface{} `json:"data,required"`
- Name MessageMetadataErrorMessageOutputLengthErrorName `json:"name,required"`
- JSON messageMetadataErrorMessageOutputLengthErrorJSON `json:"-"`
- }
- // messageMetadataErrorMessageOutputLengthErrorJSON contains the JSON metadata for
- // the struct [MessageMetadataErrorMessageOutputLengthError]
- type messageMetadataErrorMessageOutputLengthErrorJSON struct {
- Data apijson.Field
- Name apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *MessageMetadataErrorMessageOutputLengthError) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r messageMetadataErrorMessageOutputLengthErrorJSON) RawJSON() string {
- return r.raw
- }
- func (r MessageMetadataErrorMessageOutputLengthError) ImplementsMessageMetadataError() {}
- type MessageMetadataErrorMessageOutputLengthErrorName string
- const (
- MessageMetadataErrorMessageOutputLengthErrorNameMessageOutputLengthError MessageMetadataErrorMessageOutputLengthErrorName = "MessageOutputLengthError"
- )
- func (r MessageMetadataErrorMessageOutputLengthErrorName) IsKnown() bool {
- switch r {
- case MessageMetadataErrorMessageOutputLengthErrorNameMessageOutputLengthError:
- return true
- }
- return false
- }
- type MessageMetadataErrorName string
- const (
- MessageMetadataErrorNameProviderAuthError MessageMetadataErrorName = "ProviderAuthError"
- MessageMetadataErrorNameUnknownError MessageMetadataErrorName = "UnknownError"
- MessageMetadataErrorNameMessageOutputLengthError MessageMetadataErrorName = "MessageOutputLengthError"
- )
- func (r MessageMetadataErrorName) IsKnown() bool {
- switch r {
- case MessageMetadataErrorNameProviderAuthError, MessageMetadataErrorNameUnknownError, MessageMetadataErrorNameMessageOutputLengthError:
- return true
- }
- return false
- }
- type MessageRole string
- const (
- MessageRoleUser MessageRole = "user"
- MessageRoleAssistant MessageRole = "assistant"
- )
- func (r MessageRole) IsKnown() bool {
- switch r {
- case MessageRoleUser, MessageRoleAssistant:
- return true
- }
- return false
- }
- type MessagePart struct {
- Type MessagePartType `json:"type,required"`
- Filename string `json:"filename"`
- MediaType string `json:"mediaType"`
- // This field can have the runtime type of [map[string]interface{}].
- ProviderMetadata interface{} `json:"providerMetadata"`
- SourceID string `json:"sourceId"`
- Text string `json:"text"`
- Title string `json:"title"`
- // This field can have the runtime type of [ToolInvocationPartToolInvocation].
- ToolInvocation interface{} `json:"toolInvocation"`
- URL string `json:"url"`
- JSON messagePartJSON `json:"-"`
- union MessagePartUnion
- }
- // messagePartJSON contains the JSON metadata for the struct [MessagePart]
- type messagePartJSON struct {
- Type apijson.Field
- Filename apijson.Field
- MediaType apijson.Field
- ProviderMetadata apijson.Field
- SourceID apijson.Field
- Text apijson.Field
- Title apijson.Field
- ToolInvocation apijson.Field
- URL apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r messagePartJSON) RawJSON() string {
- return r.raw
- }
- func (r *MessagePart) UnmarshalJSON(data []byte) (err error) {
- *r = MessagePart{}
- err = apijson.UnmarshalRoot(data, &r.union)
- if err != nil {
- return err
- }
- return apijson.Port(r.union, &r)
- }
- // AsUnion returns a [MessagePartUnion] interface which you can cast to the
- // specific types for more type safety.
- //
- // Possible runtime types of the union are [TextPart], [ReasoningPart],
- // [ToolInvocationPart], [SourceURLPart], [FilePart], [StepStartPart].
- func (r MessagePart) AsUnion() MessagePartUnion {
- return r.union
- }
- // Union satisfied by [TextPart], [ReasoningPart], [ToolInvocationPart],
- // [SourceURLPart], [FilePart] or [StepStartPart].
- type MessagePartUnion interface {
- implementsMessagePart()
- }
- func init() {
- apijson.RegisterUnion(
- reflect.TypeOf((*MessagePartUnion)(nil)).Elem(),
- "type",
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(TextPart{}),
- DiscriminatorValue: "text",
- },
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(ReasoningPart{}),
- DiscriminatorValue: "reasoning",
- },
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(ToolInvocationPart{}),
- DiscriminatorValue: "tool-invocation",
- },
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(SourceURLPart{}),
- DiscriminatorValue: "source-url",
- },
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(FilePart{}),
- DiscriminatorValue: "file",
- },
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(StepStartPart{}),
- DiscriminatorValue: "step-start",
- },
- )
- }
- type MessagePartType string
- const (
- MessagePartTypeText MessagePartType = "text"
- MessagePartTypeReasoning MessagePartType = "reasoning"
- MessagePartTypeToolInvocation MessagePartType = "tool-invocation"
- MessagePartTypeSourceURL MessagePartType = "source-url"
- MessagePartTypeFile MessagePartType = "file"
- MessagePartTypeStepStart MessagePartType = "step-start"
- )
- func (r MessagePartType) IsKnown() bool {
- switch r {
- case MessagePartTypeText, MessagePartTypeReasoning, MessagePartTypeToolInvocation, MessagePartTypeSourceURL, MessagePartTypeFile, MessagePartTypeStepStart:
- return true
- }
- return false
- }
- type MessagePartParam struct {
- Type param.Field[MessagePartType] `json:"type,required"`
- Filename param.Field[string] `json:"filename"`
- MediaType param.Field[string] `json:"mediaType"`
- ProviderMetadata param.Field[interface{}] `json:"providerMetadata"`
- SourceID param.Field[string] `json:"sourceId"`
- Text param.Field[string] `json:"text"`
- Title param.Field[string] `json:"title"`
- ToolInvocation param.Field[interface{}] `json:"toolInvocation"`
- URL param.Field[string] `json:"url"`
- }
- func (r MessagePartParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- func (r MessagePartParam) implementsMessagePartUnionParam() {}
- // Satisfied by [TextPartParam], [ReasoningPartParam], [ToolInvocationPartParam],
- // [SourceURLPartParam], [FilePartParam], [StepStartPartParam], [MessagePartParam].
- type MessagePartUnionParam interface {
- implementsMessagePartUnionParam()
- }
- type ReasoningPart struct {
- Text string `json:"text,required"`
- Type ReasoningPartType `json:"type,required"`
- ProviderMetadata map[string]interface{} `json:"providerMetadata"`
- JSON reasoningPartJSON `json:"-"`
- }
- // reasoningPartJSON contains the JSON metadata for the struct [ReasoningPart]
- type reasoningPartJSON struct {
- Text apijson.Field
- Type apijson.Field
- ProviderMetadata apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ReasoningPart) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r reasoningPartJSON) RawJSON() string {
- return r.raw
- }
- func (r ReasoningPart) implementsMessagePart() {}
- type ReasoningPartType string
- const (
- ReasoningPartTypeReasoning ReasoningPartType = "reasoning"
- )
- func (r ReasoningPartType) IsKnown() bool {
- switch r {
- case ReasoningPartTypeReasoning:
- return true
- }
- return false
- }
- type ReasoningPartParam struct {
- Text param.Field[string] `json:"text,required"`
- Type param.Field[ReasoningPartType] `json:"type,required"`
- ProviderMetadata param.Field[map[string]interface{}] `json:"providerMetadata"`
- }
- func (r ReasoningPartParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- func (r ReasoningPartParam) implementsMessagePartUnionParam() {}
- type Session struct {
- ID string `json:"id,required"`
- Time SessionTime `json:"time,required"`
- Title string `json:"title,required"`
- Version string `json:"version,required"`
- ParentID string `json:"parentID"`
- Revert SessionRevert `json:"revert"`
- Share SessionShare `json:"share"`
- JSON sessionJSON `json:"-"`
- }
- // sessionJSON contains the JSON metadata for the struct [Session]
- type sessionJSON struct {
- ID apijson.Field
- Time apijson.Field
- Title apijson.Field
- Version apijson.Field
- ParentID apijson.Field
- Revert apijson.Field
- Share apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *Session) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r sessionJSON) RawJSON() string {
- return r.raw
- }
- type SessionTime struct {
- Created float64 `json:"created,required"`
- Updated float64 `json:"updated,required"`
- JSON sessionTimeJSON `json:"-"`
- }
- // sessionTimeJSON contains the JSON metadata for the struct [SessionTime]
- type sessionTimeJSON struct {
- Created apijson.Field
- Updated apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *SessionTime) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r sessionTimeJSON) RawJSON() string {
- return r.raw
- }
- type SessionRevert struct {
- MessageID string `json:"messageID,required"`
- Part float64 `json:"part,required"`
- Snapshot string `json:"snapshot"`
- JSON sessionRevertJSON `json:"-"`
- }
- // sessionRevertJSON contains the JSON metadata for the struct [SessionRevert]
- type sessionRevertJSON struct {
- MessageID apijson.Field
- Part apijson.Field
- Snapshot apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *SessionRevert) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r sessionRevertJSON) RawJSON() string {
- return r.raw
- }
- type SessionShare struct {
- URL string `json:"url,required"`
- JSON sessionShareJSON `json:"-"`
- }
- // sessionShareJSON contains the JSON metadata for the struct [SessionShare]
- type sessionShareJSON struct {
- URL apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *SessionShare) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r sessionShareJSON) RawJSON() string {
- return r.raw
- }
- type SourceURLPart struct {
- SourceID string `json:"sourceId,required"`
- Type SourceURLPartType `json:"type,required"`
- URL string `json:"url,required"`
- ProviderMetadata map[string]interface{} `json:"providerMetadata"`
- Title string `json:"title"`
- JSON sourceURLPartJSON `json:"-"`
- }
- // sourceURLPartJSON contains the JSON metadata for the struct [SourceURLPart]
- type sourceURLPartJSON struct {
- SourceID apijson.Field
- Type apijson.Field
- URL apijson.Field
- ProviderMetadata apijson.Field
- Title apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *SourceURLPart) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r sourceURLPartJSON) RawJSON() string {
- return r.raw
- }
- func (r SourceURLPart) implementsMessagePart() {}
- type SourceURLPartType string
- const (
- SourceURLPartTypeSourceURL SourceURLPartType = "source-url"
- )
- func (r SourceURLPartType) IsKnown() bool {
- switch r {
- case SourceURLPartTypeSourceURL:
- return true
- }
- return false
- }
- type SourceURLPartParam struct {
- SourceID param.Field[string] `json:"sourceId,required"`
- Type param.Field[SourceURLPartType] `json:"type,required"`
- URL param.Field[string] `json:"url,required"`
- ProviderMetadata param.Field[map[string]interface{}] `json:"providerMetadata"`
- Title param.Field[string] `json:"title"`
- }
- func (r SourceURLPartParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- func (r SourceURLPartParam) implementsMessagePartUnionParam() {}
- type StepStartPart struct {
- Type StepStartPartType `json:"type,required"`
- JSON stepStartPartJSON `json:"-"`
- }
- // stepStartPartJSON contains the JSON metadata for the struct [StepStartPart]
- type stepStartPartJSON struct {
- Type apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *StepStartPart) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r stepStartPartJSON) RawJSON() string {
- return r.raw
- }
- func (r StepStartPart) implementsMessagePart() {}
- type StepStartPartType string
- const (
- StepStartPartTypeStepStart StepStartPartType = "step-start"
- )
- func (r StepStartPartType) IsKnown() bool {
- switch r {
- case StepStartPartTypeStepStart:
- return true
- }
- return false
- }
- type StepStartPartParam struct {
- Type param.Field[StepStartPartType] `json:"type,required"`
- }
- func (r StepStartPartParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- func (r StepStartPartParam) implementsMessagePartUnionParam() {}
- type TextPart struct {
- Text string `json:"text,required"`
- Type TextPartType `json:"type,required"`
- JSON textPartJSON `json:"-"`
- }
- // textPartJSON contains the JSON metadata for the struct [TextPart]
- type textPartJSON struct {
- Text apijson.Field
- Type apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *TextPart) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r textPartJSON) RawJSON() string {
- return r.raw
- }
- func (r TextPart) implementsMessagePart() {}
- type TextPartType string
- const (
- TextPartTypeText TextPartType = "text"
- )
- func (r TextPartType) IsKnown() bool {
- switch r {
- case TextPartTypeText:
- return true
- }
- return false
- }
- type TextPartParam struct {
- Text param.Field[string] `json:"text,required"`
- Type param.Field[TextPartType] `json:"type,required"`
- }
- func (r TextPartParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- func (r TextPartParam) implementsMessagePartUnionParam() {}
- type ToolCall struct {
- State ToolCallState `json:"state,required"`
- ToolCallID string `json:"toolCallId,required"`
- ToolName string `json:"toolName,required"`
- Args interface{} `json:"args"`
- Step float64 `json:"step"`
- JSON toolCallJSON `json:"-"`
- }
- // toolCallJSON contains the JSON metadata for the struct [ToolCall]
- type toolCallJSON struct {
- State apijson.Field
- ToolCallID apijson.Field
- ToolName apijson.Field
- Args apijson.Field
- Step apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ToolCall) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r toolCallJSON) RawJSON() string {
- return r.raw
- }
- func (r ToolCall) implementsToolInvocationPartToolInvocation() {}
- type ToolCallState string
- const (
- ToolCallStateCall ToolCallState = "call"
- )
- func (r ToolCallState) IsKnown() bool {
- switch r {
- case ToolCallStateCall:
- return true
- }
- return false
- }
- type ToolCallParam struct {
- State param.Field[ToolCallState] `json:"state,required"`
- ToolCallID param.Field[string] `json:"toolCallId,required"`
- ToolName param.Field[string] `json:"toolName,required"`
- Args param.Field[interface{}] `json:"args"`
- Step param.Field[float64] `json:"step"`
- }
- func (r ToolCallParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- func (r ToolCallParam) implementsToolInvocationPartToolInvocationUnionParam() {}
- type ToolInvocationPart struct {
- ToolInvocation ToolInvocationPartToolInvocation `json:"toolInvocation,required"`
- Type ToolInvocationPartType `json:"type,required"`
- JSON toolInvocationPartJSON `json:"-"`
- }
- // toolInvocationPartJSON contains the JSON metadata for the struct
- // [ToolInvocationPart]
- type toolInvocationPartJSON struct {
- ToolInvocation apijson.Field
- Type apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ToolInvocationPart) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r toolInvocationPartJSON) RawJSON() string {
- return r.raw
- }
- func (r ToolInvocationPart) implementsMessagePart() {}
- type ToolInvocationPartToolInvocation struct {
- State ToolInvocationPartToolInvocationState `json:"state,required"`
- ToolCallID string `json:"toolCallId,required"`
- ToolName string `json:"toolName,required"`
- // This field can have the runtime type of [interface{}].
- Args interface{} `json:"args"`
- Result string `json:"result"`
- Step float64 `json:"step"`
- JSON toolInvocationPartToolInvocationJSON `json:"-"`
- union ToolInvocationPartToolInvocationUnion
- }
- // toolInvocationPartToolInvocationJSON contains the JSON metadata for the struct
- // [ToolInvocationPartToolInvocation]
- type toolInvocationPartToolInvocationJSON struct {
- State apijson.Field
- ToolCallID apijson.Field
- ToolName apijson.Field
- Args apijson.Field
- Result apijson.Field
- Step apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r toolInvocationPartToolInvocationJSON) RawJSON() string {
- return r.raw
- }
- func (r *ToolInvocationPartToolInvocation) UnmarshalJSON(data []byte) (err error) {
- *r = ToolInvocationPartToolInvocation{}
- err = apijson.UnmarshalRoot(data, &r.union)
- if err != nil {
- return err
- }
- return apijson.Port(r.union, &r)
- }
- // AsUnion returns a [ToolInvocationPartToolInvocationUnion] interface which you
- // can cast to the specific types for more type safety.
- //
- // Possible runtime types of the union are [ToolCall], [ToolPartialCall],
- // [ToolResult].
- func (r ToolInvocationPartToolInvocation) AsUnion() ToolInvocationPartToolInvocationUnion {
- return r.union
- }
- // Union satisfied by [ToolCall], [ToolPartialCall] or [ToolResult].
- type ToolInvocationPartToolInvocationUnion interface {
- implementsToolInvocationPartToolInvocation()
- }
- func init() {
- apijson.RegisterUnion(
- reflect.TypeOf((*ToolInvocationPartToolInvocationUnion)(nil)).Elem(),
- "state",
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(ToolCall{}),
- DiscriminatorValue: "call",
- },
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(ToolPartialCall{}),
- DiscriminatorValue: "partial-call",
- },
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(ToolResult{}),
- DiscriminatorValue: "result",
- },
- )
- }
- type ToolInvocationPartToolInvocationState string
- const (
- ToolInvocationPartToolInvocationStateCall ToolInvocationPartToolInvocationState = "call"
- ToolInvocationPartToolInvocationStatePartialCall ToolInvocationPartToolInvocationState = "partial-call"
- ToolInvocationPartToolInvocationStateResult ToolInvocationPartToolInvocationState = "result"
- )
- func (r ToolInvocationPartToolInvocationState) IsKnown() bool {
- switch r {
- case ToolInvocationPartToolInvocationStateCall, ToolInvocationPartToolInvocationStatePartialCall, ToolInvocationPartToolInvocationStateResult:
- return true
- }
- return false
- }
- type ToolInvocationPartType string
- const (
- ToolInvocationPartTypeToolInvocation ToolInvocationPartType = "tool-invocation"
- )
- func (r ToolInvocationPartType) IsKnown() bool {
- switch r {
- case ToolInvocationPartTypeToolInvocation:
- return true
- }
- return false
- }
- type ToolInvocationPartParam struct {
- ToolInvocation param.Field[ToolInvocationPartToolInvocationUnionParam] `json:"toolInvocation,required"`
- Type param.Field[ToolInvocationPartType] `json:"type,required"`
- }
- func (r ToolInvocationPartParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- func (r ToolInvocationPartParam) implementsMessagePartUnionParam() {}
- type ToolInvocationPartToolInvocationParam struct {
- State param.Field[ToolInvocationPartToolInvocationState] `json:"state,required"`
- ToolCallID param.Field[string] `json:"toolCallId,required"`
- ToolName param.Field[string] `json:"toolName,required"`
- Args param.Field[interface{}] `json:"args"`
- Result param.Field[string] `json:"result"`
- Step param.Field[float64] `json:"step"`
- }
- func (r ToolInvocationPartToolInvocationParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- func (r ToolInvocationPartToolInvocationParam) implementsToolInvocationPartToolInvocationUnionParam() {
- }
- // Satisfied by [ToolCallParam], [ToolPartialCallParam], [ToolResultParam],
- // [ToolInvocationPartToolInvocationParam].
- type ToolInvocationPartToolInvocationUnionParam interface {
- implementsToolInvocationPartToolInvocationUnionParam()
- }
- type ToolPartialCall struct {
- State ToolPartialCallState `json:"state,required"`
- ToolCallID string `json:"toolCallId,required"`
- ToolName string `json:"toolName,required"`
- Args interface{} `json:"args"`
- Step float64 `json:"step"`
- JSON toolPartialCallJSON `json:"-"`
- }
- // toolPartialCallJSON contains the JSON metadata for the struct [ToolPartialCall]
- type toolPartialCallJSON struct {
- State apijson.Field
- ToolCallID apijson.Field
- ToolName apijson.Field
- Args apijson.Field
- Step apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ToolPartialCall) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r toolPartialCallJSON) RawJSON() string {
- return r.raw
- }
- func (r ToolPartialCall) implementsToolInvocationPartToolInvocation() {}
- type ToolPartialCallState string
- const (
- ToolPartialCallStatePartialCall ToolPartialCallState = "partial-call"
- )
- func (r ToolPartialCallState) IsKnown() bool {
- switch r {
- case ToolPartialCallStatePartialCall:
- return true
- }
- return false
- }
- type ToolPartialCallParam struct {
- State param.Field[ToolPartialCallState] `json:"state,required"`
- ToolCallID param.Field[string] `json:"toolCallId,required"`
- ToolName param.Field[string] `json:"toolName,required"`
- Args param.Field[interface{}] `json:"args"`
- Step param.Field[float64] `json:"step"`
- }
- func (r ToolPartialCallParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- func (r ToolPartialCallParam) implementsToolInvocationPartToolInvocationUnionParam() {}
- type ToolResult struct {
- Result string `json:"result,required"`
- State ToolResultState `json:"state,required"`
- ToolCallID string `json:"toolCallId,required"`
- ToolName string `json:"toolName,required"`
- Args interface{} `json:"args"`
- Step float64 `json:"step"`
- JSON toolResultJSON `json:"-"`
- }
- // toolResultJSON contains the JSON metadata for the struct [ToolResult]
- type toolResultJSON struct {
- Result apijson.Field
- State apijson.Field
- ToolCallID apijson.Field
- ToolName apijson.Field
- Args apijson.Field
- Step apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ToolResult) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r toolResultJSON) RawJSON() string {
- return r.raw
- }
- func (r ToolResult) implementsToolInvocationPartToolInvocation() {}
- type ToolResultState string
- const (
- ToolResultStateResult ToolResultState = "result"
- )
- func (r ToolResultState) IsKnown() bool {
- switch r {
- case ToolResultStateResult:
- return true
- }
- return false
- }
- type ToolResultParam struct {
- Result param.Field[string] `json:"result,required"`
- State param.Field[ToolResultState] `json:"state,required"`
- ToolCallID param.Field[string] `json:"toolCallId,required"`
- ToolName param.Field[string] `json:"toolName,required"`
- Args param.Field[interface{}] `json:"args"`
- Step param.Field[float64] `json:"step"`
- }
- func (r ToolResultParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- func (r ToolResultParam) implementsToolInvocationPartToolInvocationUnionParam() {}
- type SessionChatParams struct {
- ModelID param.Field[string] `json:"modelID,required"`
- Parts param.Field[[]MessagePartUnionParam] `json:"parts,required"`
- ProviderID param.Field[string] `json:"providerID,required"`
- }
- func (r SessionChatParams) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- type SessionInitParams struct {
- ModelID param.Field[string] `json:"modelID,required"`
- ProviderID param.Field[string] `json:"providerID,required"`
- }
- func (r SessionInitParams) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
- type SessionSummarizeParams struct {
- ModelID param.Field[string] `json:"modelID,required"`
- ProviderID param.Field[string] `json:"providerID,required"`
- }
- func (r SessionSummarizeParams) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
- }
|