summaryrefslogtreecommitdiffhomepage
path: root/packages/tui/sdk/session.go
diff options
context:
space:
mode:
authorDax <[email protected]>2025-07-07 15:53:43 -0400
committerGitHub <[email protected]>2025-07-07 15:53:43 -0400
commitf884766445bbf1fbce11f1db4bc6174e72d9baa5 (patch)
treee7d9e7b3d8efc8bed249f9d29e2d8fb838a275f2 /packages/tui/sdk/session.go
parent76b2e4539cb97bae5812ed2d832ce49d02e70c64 (diff)
downloadopencode-f884766445bbf1fbce11f1db4bc6174e72d9baa5.tar.gz
opencode-f884766445bbf1fbce11f1db4bc6174e72d9baa5.zip
v2 message format and upgrade to ai sdk v5 (#743)
Co-authored-by: GitHub Action <[email protected]> Co-authored-by: Liang-Shih Lin <[email protected]> Co-authored-by: Dominik Engelhardt <[email protected]> Co-authored-by: Jay V <[email protected]> Co-authored-by: adamdottv <[email protected]>
Diffstat (limited to 'packages/tui/sdk/session.go')
-rw-r--r--packages/tui/sdk/session.go1355
1 files changed, 700 insertions, 655 deletions
diff --git a/packages/tui/sdk/session.go b/packages/tui/sdk/session.go
index e8216a1fd..816ee7e31 100644
--- a/packages/tui/sdk/session.go
+++ b/packages/tui/sdk/session.go
@@ -77,7 +77,7 @@ func (r *SessionService) Abort(ctx context.Context, id string, opts ...option.Re
}
// 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) {
+func (r *SessionService) Chat(ctx context.Context, id string, body SessionChatParams, opts ...option.RequestOption) (res *AssistantMessage, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
@@ -148,256 +148,124 @@ func (r *SessionService) Unshare(ctx context.Context, id string, opts ...option.
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 {
+type AssistantMessage struct {
+ ID string `json:"id,required"`
+ Cost float64 `json:"cost,required"`
+ ModelID string `json:"modelID,required"`
+ Parts []AssistantMessagePart `json:"parts,required"`
+ Path AssistantMessagePath `json:"path,required"`
+ ProviderID string `json:"providerID,required"`
+ Role AssistantMessageRole `json:"role,required"`
+ SessionID string `json:"sessionID,required"`
+ System []string `json:"system,required"`
+ Time AssistantMessageTime `json:"time,required"`
+ Tokens AssistantMessageTokens `json:"tokens,required"`
+ Error AssistantMessageError `json:"error"`
+ Summary bool `json:"summary"`
+ JSON assistantMessageJSON `json:"-"`
+}
+
+// assistantMessageJSON contains the JSON metadata for the struct
+// [AssistantMessage]
+type assistantMessageJSON struct {
ID apijson.Field
- Metadata apijson.Field
+ Cost apijson.Field
+ ModelID apijson.Field
Parts apijson.Field
+ Path apijson.Field
+ ProviderID 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
+ System apijson.Field
Time apijson.Field
- Tool apijson.Field
- Assistant apijson.Field
+ Tokens 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
+ Summary apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
-func (r *MessageMetadataTime) UnmarshalJSON(data []byte) (err error) {
+func (r *AssistantMessage) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
-func (r messageMetadataTimeJSON) RawJSON() string {
+func (r assistantMessageJSON) 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 AssistantMessage) implementsMessage() {}
-func (r *MessageMetadataTool) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
+type AssistantMessagePath struct {
+ Cwd string `json:"cwd,required"`
+ Root string `json:"root,required"`
+ JSON assistantMessagePathJSON `json:"-"`
}
-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
+// assistantMessagePathJSON contains the JSON metadata for the struct
+// [AssistantMessagePath]
+type assistantMessagePathJSON struct {
+ Cwd apijson.Field
+ Root apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
-func (r *MessageMetadataToolTime) UnmarshalJSON(data []byte) (err error) {
+func (r *AssistantMessagePath) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
-func (r messageMetadataToolTimeJSON) RawJSON() string {
+func (r assistantMessagePathJSON) 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:"-"`
-}
+type AssistantMessageRole string
-// 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)
-}
+const (
+ AssistantMessageRoleAssistant AssistantMessageRole = "assistant"
+)
-func (r messageMetadataAssistantJSON) RawJSON() string {
- return r.raw
+func (r AssistantMessageRole) IsKnown() bool {
+ switch r {
+ case AssistantMessageRoleAssistant:
+ return true
+ }
+ return false
}
-type MessageMetadataAssistantPath struct {
- Cwd string `json:"cwd,required"`
- Root string `json:"root,required"`
- JSON messageMetadataAssistantPathJSON `json:"-"`
+type AssistantMessageTime struct {
+ Created float64 `json:"created,required"`
+ Completed float64 `json:"completed"`
+ JSON assistantMessageTimeJSON `json:"-"`
}
-// messageMetadataAssistantPathJSON contains the JSON metadata for the struct
-// [MessageMetadataAssistantPath]
-type messageMetadataAssistantPathJSON struct {
- Cwd apijson.Field
- Root apijson.Field
+// assistantMessageTimeJSON contains the JSON metadata for the struct
+// [AssistantMessageTime]
+type assistantMessageTimeJSON struct {
+ Created apijson.Field
+ Completed apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
-func (r *MessageMetadataAssistantPath) UnmarshalJSON(data []byte) (err error) {
+func (r *AssistantMessageTime) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
-func (r messageMetadataAssistantPathJSON) RawJSON() string {
+func (r assistantMessageTimeJSON) 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:"-"`
+type AssistantMessageTokens struct {
+ Cache AssistantMessageTokensCache `json:"cache,required"`
+ Input float64 `json:"input,required"`
+ Output float64 `json:"output,required"`
+ Reasoning float64 `json:"reasoning,required"`
+ JSON assistantMessageTokensJSON `json:"-"`
}
-// messageMetadataAssistantTokensJSON contains the JSON metadata for the struct
-// [MessageMetadataAssistantTokens]
-type messageMetadataAssistantTokensJSON struct {
+// assistantMessageTokensJSON contains the JSON metadata for the struct
+// [AssistantMessageTokens]
+type assistantMessageTokensJSON struct {
Cache apijson.Field
Input apijson.Field
Output apijson.Field
@@ -406,61 +274,61 @@ type messageMetadataAssistantTokensJSON struct {
ExtraFields map[string]apijson.Field
}
-func (r *MessageMetadataAssistantTokens) UnmarshalJSON(data []byte) (err error) {
+func (r *AssistantMessageTokens) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
-func (r messageMetadataAssistantTokensJSON) RawJSON() string {
+func (r assistantMessageTokensJSON) RawJSON() string {
return r.raw
}
-type MessageMetadataAssistantTokensCache struct {
- Read float64 `json:"read,required"`
- Write float64 `json:"write,required"`
- JSON messageMetadataAssistantTokensCacheJSON `json:"-"`
+type AssistantMessageTokensCache struct {
+ Read float64 `json:"read,required"`
+ Write float64 `json:"write,required"`
+ JSON assistantMessageTokensCacheJSON `json:"-"`
}
-// messageMetadataAssistantTokensCacheJSON contains the JSON metadata for the
-// struct [MessageMetadataAssistantTokensCache]
-type messageMetadataAssistantTokensCacheJSON struct {
+// assistantMessageTokensCacheJSON contains the JSON metadata for the struct
+// [AssistantMessageTokensCache]
+type assistantMessageTokensCacheJSON struct {
Read apijson.Field
Write apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
-func (r *MessageMetadataAssistantTokensCache) UnmarshalJSON(data []byte) (err error) {
+func (r *AssistantMessageTokensCache) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
-func (r messageMetadataAssistantTokensCacheJSON) RawJSON() string {
+func (r assistantMessageTokensCacheJSON) RawJSON() string {
return r.raw
}
-type MessageMetadataError struct {
+type AssistantMessageError 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
+ Data interface{} `json:"data,required"`
+ Name AssistantMessageErrorName `json:"name,required"`
+ JSON assistantMessageErrorJSON `json:"-"`
+ union AssistantMessageErrorUnion
}
-// messageMetadataErrorJSON contains the JSON metadata for the struct
-// [MessageMetadataError]
-type messageMetadataErrorJSON struct {
+// assistantMessageErrorJSON contains the JSON metadata for the struct
+// [AssistantMessageError]
+type assistantMessageErrorJSON struct {
Data apijson.Field
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
-func (r messageMetadataErrorJSON) RawJSON() string {
+func (r assistantMessageErrorJSON) RawJSON() string {
return r.raw
}
-func (r *MessageMetadataError) UnmarshalJSON(data []byte) (err error) {
- *r = MessageMetadataError{}
+func (r *AssistantMessageError) UnmarshalJSON(data []byte) (err error) {
+ *r = AssistantMessageError{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
@@ -468,24 +336,24 @@ func (r *MessageMetadataError) UnmarshalJSON(data []byte) (err error) {
return apijson.Port(r.union, &r)
}
-// AsUnion returns a [MessageMetadataErrorUnion] interface which you can cast to
+// AsUnion returns a [AssistantMessageErrorUnion] 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 {
+// [shared.UnknownError], [AssistantMessageErrorMessageOutputLengthError].
+func (r AssistantMessageError) AsUnion() AssistantMessageErrorUnion {
return r.union
}
// Union satisfied by [shared.ProviderAuthError], [shared.UnknownError] or
-// [MessageMetadataErrorMessageOutputLengthError].
-type MessageMetadataErrorUnion interface {
- ImplementsMessageMetadataError()
+// [AssistantMessageErrorMessageOutputLengthError].
+type AssistantMessageErrorUnion interface {
+ ImplementsAssistantMessageError()
}
func init() {
apijson.RegisterUnion(
- reflect.TypeOf((*MessageMetadataErrorUnion)(nil)).Elem(),
+ reflect.TypeOf((*AssistantMessageErrorUnion)(nil)).Elem(),
"name",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
@@ -499,119 +367,96 @@ func init() {
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(MessageMetadataErrorMessageOutputLengthError{}),
+ Type: reflect.TypeOf(AssistantMessageErrorMessageOutputLengthError{}),
DiscriminatorValue: "MessageOutputLengthError",
},
)
}
-type MessageMetadataErrorMessageOutputLengthError struct {
- Data interface{} `json:"data,required"`
- Name MessageMetadataErrorMessageOutputLengthErrorName `json:"name,required"`
- JSON messageMetadataErrorMessageOutputLengthErrorJSON `json:"-"`
+type AssistantMessageErrorMessageOutputLengthError struct {
+ Data interface{} `json:"data,required"`
+ Name AssistantMessageErrorMessageOutputLengthErrorName `json:"name,required"`
+ JSON assistantMessageErrorMessageOutputLengthErrorJSON `json:"-"`
}
-// messageMetadataErrorMessageOutputLengthErrorJSON contains the JSON metadata for
-// the struct [MessageMetadataErrorMessageOutputLengthError]
-type messageMetadataErrorMessageOutputLengthErrorJSON struct {
+// assistantMessageErrorMessageOutputLengthErrorJSON contains the JSON metadata for
+// the struct [AssistantMessageErrorMessageOutputLengthError]
+type assistantMessageErrorMessageOutputLengthErrorJSON struct {
Data apijson.Field
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
-func (r *MessageMetadataErrorMessageOutputLengthError) UnmarshalJSON(data []byte) (err error) {
+func (r *AssistantMessageErrorMessageOutputLengthError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
-func (r messageMetadataErrorMessageOutputLengthErrorJSON) RawJSON() string {
+func (r assistantMessageErrorMessageOutputLengthErrorJSON) RawJSON() string {
return r.raw
}
-func (r MessageMetadataErrorMessageOutputLengthError) ImplementsMessageMetadataError() {}
+func (r AssistantMessageErrorMessageOutputLengthError) ImplementsAssistantMessageError() {}
-type MessageMetadataErrorMessageOutputLengthErrorName string
+type AssistantMessageErrorMessageOutputLengthErrorName string
const (
- MessageMetadataErrorMessageOutputLengthErrorNameMessageOutputLengthError MessageMetadataErrorMessageOutputLengthErrorName = "MessageOutputLengthError"
+ AssistantMessageErrorMessageOutputLengthErrorNameMessageOutputLengthError AssistantMessageErrorMessageOutputLengthErrorName = "MessageOutputLengthError"
)
-func (r MessageMetadataErrorMessageOutputLengthErrorName) IsKnown() bool {
+func (r AssistantMessageErrorMessageOutputLengthErrorName) IsKnown() bool {
switch r {
- case MessageMetadataErrorMessageOutputLengthErrorNameMessageOutputLengthError:
+ case AssistantMessageErrorMessageOutputLengthErrorNameMessageOutputLengthError:
return true
}
return false
}
-type MessageMetadataErrorName string
+type AssistantMessageErrorName string
const (
- MessageMetadataErrorNameProviderAuthError MessageMetadataErrorName = "ProviderAuthError"
- MessageMetadataErrorNameUnknownError MessageMetadataErrorName = "UnknownError"
- MessageMetadataErrorNameMessageOutputLengthError MessageMetadataErrorName = "MessageOutputLengthError"
+ AssistantMessageErrorNameProviderAuthError AssistantMessageErrorName = "ProviderAuthError"
+ AssistantMessageErrorNameUnknownError AssistantMessageErrorName = "UnknownError"
+ AssistantMessageErrorNameMessageOutputLengthError AssistantMessageErrorName = "MessageOutputLengthError"
)
-func (r MessageMetadataErrorName) IsKnown() bool {
+func (r AssistantMessageErrorName) IsKnown() bool {
switch r {
- case MessageMetadataErrorNameProviderAuthError, MessageMetadataErrorNameUnknownError, MessageMetadataErrorNameMessageOutputLengthError:
+ case AssistantMessageErrorNameProviderAuthError, AssistantMessageErrorNameUnknownError, AssistantMessageErrorNameMessageOutputLengthError:
return true
}
return false
}
-type MessageRole string
-
-const (
- MessageRoleUser MessageRole = "user"
- MessageRoleAssistant MessageRole = "assistant"
-)
+type AssistantMessagePart struct {
+ Type AssistantMessagePartType `json:"type,required"`
+ ID string `json:"id"`
+ // This field can have the runtime type of [ToolPartState].
+ State interface{} `json:"state"`
+ Text string `json:"text"`
+ Tool string `json:"tool"`
+ JSON assistantMessagePartJSON `json:"-"`
+ union AssistantMessagePartUnion
+}
-func (r MessageRole) IsKnown() bool {
- switch r {
- case MessageRoleUser, MessageRoleAssistant:
- return true
- }
- return false
+// assistantMessagePartJSON contains the JSON metadata for the struct
+// [AssistantMessagePart]
+type assistantMessagePartJSON struct {
+ Type apijson.Field
+ ID apijson.Field
+ State apijson.Field
+ Text apijson.Field
+ Tool apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
}
-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 {
+func (r assistantMessagePartJSON) RawJSON() string {
return r.raw
}
-func (r *MessagePart) UnmarshalJSON(data []byte) (err error) {
- *r = MessagePart{}
+func (r *AssistantMessagePart) UnmarshalJSON(data []byte) (err error) {
+ *r = AssistantMessagePart{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
@@ -619,24 +464,22 @@ func (r *MessagePart) UnmarshalJSON(data []byte) (err error) {
return apijson.Port(r.union, &r)
}
-// AsUnion returns a [MessagePartUnion] interface which you can cast to the
-// specific types for more type safety.
+// AsUnion returns a [AssistantMessagePartUnion] 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 {
+// Possible runtime types of the union are [TextPart], [ToolPart], [StepStartPart].
+func (r AssistantMessagePart) AsUnion() AssistantMessagePartUnion {
return r.union
}
-// Union satisfied by [TextPart], [ReasoningPart], [ToolInvocationPart],
-// [SourceURLPart], [FilePart] or [StepStartPart].
-type MessagePartUnion interface {
- implementsMessagePart()
+// Union satisfied by [TextPart], [ToolPart] or [StepStartPart].
+type AssistantMessagePartUnion interface {
+ implementsAssistantMessagePart()
}
func init() {
apijson.RegisterUnion(
- reflect.TypeOf((*MessagePartUnion)(nil)).Elem(),
+ reflect.TypeOf((*AssistantMessagePartUnion)(nil)).Elem(),
"type",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
@@ -645,23 +488,8 @@ func init() {
},
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",
+ Type: reflect.TypeOf(ToolPart{}),
+ DiscriminatorValue: "tool",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
@@ -671,100 +499,179 @@ func init() {
)
}
-type MessagePartType string
+type AssistantMessagePartType string
const (
- MessagePartTypeText MessagePartType = "text"
- MessagePartTypeReasoning MessagePartType = "reasoning"
- MessagePartTypeToolInvocation MessagePartType = "tool-invocation"
- MessagePartTypeSourceURL MessagePartType = "source-url"
- MessagePartTypeFile MessagePartType = "file"
- MessagePartTypeStepStart MessagePartType = "step-start"
+ AssistantMessagePartTypeText AssistantMessagePartType = "text"
+ AssistantMessagePartTypeTool AssistantMessagePartType = "tool"
+ AssistantMessagePartTypeStepStart AssistantMessagePartType = "step-start"
)
-func (r MessagePartType) IsKnown() bool {
+func (r AssistantMessagePartType) IsKnown() bool {
switch r {
- case MessagePartTypeText, MessagePartTypeReasoning, MessagePartTypeToolInvocation, MessagePartTypeSourceURL, MessagePartTypeFile, MessagePartTypeStepStart:
+ case AssistantMessagePartTypeText, AssistantMessagePartTypeTool, AssistantMessagePartTypeStepStart:
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:"-"`
+type FilePart struct {
+ Mime string `json:"mime,required"`
+ Type FilePartType `json:"type,required"`
+ URL string `json:"url,required"`
+ Filename string `json:"filename"`
+ JSON filePartJSON `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
+// filePartJSON contains the JSON metadata for the struct [FilePart]
+type filePartJSON struct {
+ Mime apijson.Field
+ Type apijson.Field
+ URL apijson.Field
+ Filename apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
}
-func (r *ReasoningPart) UnmarshalJSON(data []byte) (err error) {
+func (r *FilePart) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
-func (r reasoningPartJSON) RawJSON() string {
+func (r filePartJSON) RawJSON() string {
return r.raw
}
-func (r ReasoningPart) implementsMessagePart() {}
+func (r FilePart) implementsUserMessagePart() {}
-type ReasoningPartType string
+type FilePartType string
const (
- ReasoningPartTypeReasoning ReasoningPartType = "reasoning"
+ FilePartTypeFile FilePartType = "file"
)
-func (r ReasoningPartType) IsKnown() bool {
+func (r FilePartType) IsKnown() bool {
switch r {
- case ReasoningPartTypeReasoning:
+ case FilePartTypeFile:
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"`
+type FilePartParam struct {
+ Mime param.Field[string] `json:"mime,required"`
+ Type param.Field[FilePartType] `json:"type,required"`
+ URL param.Field[string] `json:"url,required"`
+ Filename param.Field[string] `json:"filename"`
}
-func (r ReasoningPartParam) MarshalJSON() (data []byte, err error) {
+func (r FilePartParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
-func (r ReasoningPartParam) implementsMessagePartUnionParam() {}
+func (r FilePartParam) implementsUserMessagePartUnionParam() {}
+
+type Message struct {
+ ID string `json:"id,required"`
+ // This field can have the runtime type of [[]UserMessagePart],
+ // [[]AssistantMessagePart].
+ Parts interface{} `json:"parts,required"`
+ Role MessageRole `json:"role,required"`
+ SessionID string `json:"sessionID,required"`
+ // This field can have the runtime type of [UserMessageTime],
+ // [AssistantMessageTime].
+ Time interface{} `json:"time,required"`
+ Cost float64 `json:"cost"`
+ // This field can have the runtime type of [AssistantMessageError].
+ Error interface{} `json:"error"`
+ ModelID string `json:"modelID"`
+ // This field can have the runtime type of [AssistantMessagePath].
+ Path interface{} `json:"path"`
+ ProviderID string `json:"providerID"`
+ Summary bool `json:"summary"`
+ // This field can have the runtime type of [[]string].
+ System interface{} `json:"system"`
+ // This field can have the runtime type of [AssistantMessageTokens].
+ Tokens interface{} `json:"tokens"`
+ JSON messageJSON `json:"-"`
+ union MessageUnion
+}
+
+// messageJSON contains the JSON metadata for the struct [Message]
+type messageJSON struct {
+ ID apijson.Field
+ Parts apijson.Field
+ Role apijson.Field
+ SessionID apijson.Field
+ Time apijson.Field
+ Cost apijson.Field
+ Error apijson.Field
+ ModelID apijson.Field
+ Path apijson.Field
+ ProviderID apijson.Field
+ Summary apijson.Field
+ System apijson.Field
+ Tokens apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r messageJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r *Message) UnmarshalJSON(data []byte) (err error) {
+ *r = Message{}
+ err = apijson.UnmarshalRoot(data, &r.union)
+ if err != nil {
+ return err
+ }
+ return apijson.Port(r.union, &r)
+}
+
+// AsUnion returns a [MessageUnion] interface which you can cast to the specific
+// types for more type safety.
+//
+// Possible runtime types of the union are [UserMessage], [AssistantMessage].
+func (r Message) AsUnion() MessageUnion {
+ return r.union
+}
+
+// Union satisfied by [UserMessage] or [AssistantMessage].
+type MessageUnion interface {
+ implementsMessage()
+}
+
+func init() {
+ apijson.RegisterUnion(
+ reflect.TypeOf((*MessageUnion)(nil)).Elem(),
+ "role",
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(UserMessage{}),
+ DiscriminatorValue: "user",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(AssistantMessage{}),
+ DiscriminatorValue: "assistant",
+ },
+ )
+}
+
+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 Session struct {
ID string `json:"id,required"`
@@ -864,64 +771,6 @@ 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:"-"`
@@ -942,7 +791,7 @@ func (r stepStartPartJSON) RawJSON() string {
return r.raw
}
-func (r StepStartPart) implementsMessagePart() {}
+func (r StepStartPart) implementsAssistantMessagePart() {}
type StepStartPartType string
@@ -958,16 +807,6 @@ func (r StepStartPartType) IsKnown() bool {
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"`
@@ -990,7 +829,9 @@ func (r textPartJSON) RawJSON() string {
return r.raw
}
-func (r TextPart) implementsMessagePart() {}
+func (r TextPart) implementsAssistantMessagePart() {}
+
+func (r TextPart) implementsUserMessagePart() {}
type TextPartType string
@@ -1015,351 +856,555 @@ func (r TextPartParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
-func (r TextPartParam) implementsMessagePartUnionParam() {}
+func (r TextPartParam) implementsUserMessagePartUnionParam() {}
-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:"-"`
+type ToolPart struct {
+ ID string `json:"id,required"`
+ State ToolPartState `json:"state,required"`
+ Tool string `json:"tool,required"`
+ Type ToolPartType `json:"type,required"`
+ JSON toolPartJSON `json:"-"`
}
-// toolCallJSON contains the JSON metadata for the struct [ToolCall]
-type toolCallJSON struct {
+// toolPartJSON contains the JSON metadata for the struct [ToolPart]
+type toolPartJSON struct {
+ ID apijson.Field
State apijson.Field
- ToolCallID apijson.Field
- ToolName apijson.Field
- Args apijson.Field
- Step apijson.Field
+ Tool apijson.Field
+ Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
-func (r *ToolCall) UnmarshalJSON(data []byte) (err error) {
+func (r *ToolPart) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
-func (r toolCallJSON) RawJSON() string {
+func (r toolPartJSON) RawJSON() string {
return r.raw
}
-func (r ToolCall) implementsToolInvocationPartToolInvocation() {}
+func (r ToolPart) implementsAssistantMessagePart() {}
+
+type ToolPartState struct {
+ Status ToolPartStateStatus `json:"status,required"`
+ Error string `json:"error"`
+ // This field can have the runtime type of [interface{}].
+ Input interface{} `json:"input"`
+ // This field can have the runtime type of [map[string]interface{}].
+ Metadata interface{} `json:"metadata"`
+ Output string `json:"output"`
+ // This field can have the runtime type of [ToolStateRunningTime],
+ // [ToolStateCompletedTime], [ToolStateErrorTime].
+ Time interface{} `json:"time"`
+ Title string `json:"title"`
+ JSON toolPartStateJSON `json:"-"`
+ union ToolPartStateUnion
+}
+
+// toolPartStateJSON contains the JSON metadata for the struct [ToolPartState]
+type toolPartStateJSON struct {
+ Status apijson.Field
+ Error apijson.Field
+ Input apijson.Field
+ Metadata apijson.Field
+ Output apijson.Field
+ Time apijson.Field
+ Title apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r toolPartStateJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r *ToolPartState) UnmarshalJSON(data []byte) (err error) {
+ *r = ToolPartState{}
+ err = apijson.UnmarshalRoot(data, &r.union)
+ if err != nil {
+ return err
+ }
+ return apijson.Port(r.union, &r)
+}
+
+// AsUnion returns a [ToolPartStateUnion] interface which you can cast to the
+// specific types for more type safety.
+//
+// Possible runtime types of the union are [ToolStatePending], [ToolStateRunning],
+// [ToolStateCompleted], [ToolStateError].
+func (r ToolPartState) AsUnion() ToolPartStateUnion {
+ return r.union
+}
+
+// Union satisfied by [ToolStatePending], [ToolStateRunning], [ToolStateCompleted]
+// or [ToolStateError].
+type ToolPartStateUnion interface {
+ implementsToolPartState()
+}
+
+func init() {
+ apijson.RegisterUnion(
+ reflect.TypeOf((*ToolPartStateUnion)(nil)).Elem(),
+ "status",
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(ToolStatePending{}),
+ DiscriminatorValue: "pending",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(ToolStateRunning{}),
+ DiscriminatorValue: "running",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(ToolStateCompleted{}),
+ DiscriminatorValue: "completed",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(ToolStateError{}),
+ DiscriminatorValue: "error",
+ },
+ )
+}
-type ToolCallState string
+type ToolPartStateStatus string
const (
- ToolCallStateCall ToolCallState = "call"
+ ToolPartStateStatusPending ToolPartStateStatus = "pending"
+ ToolPartStateStatusRunning ToolPartStateStatus = "running"
+ ToolPartStateStatusCompleted ToolPartStateStatus = "completed"
+ ToolPartStateStatusError ToolPartStateStatus = "error"
)
-func (r ToolCallState) IsKnown() bool {
+func (r ToolPartStateStatus) IsKnown() bool {
switch r {
- case ToolCallStateCall:
+ case ToolPartStateStatusPending, ToolPartStateStatusRunning, ToolPartStateStatusCompleted, ToolPartStateStatusError:
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"`
-}
+type ToolPartType string
-func (r ToolCallParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
-}
+const (
+ ToolPartTypeTool ToolPartType = "tool"
+)
-func (r ToolCallParam) implementsToolInvocationPartToolInvocationUnionParam() {}
+func (r ToolPartType) IsKnown() bool {
+ switch r {
+ case ToolPartTypeTool:
+ return true
+ }
+ return false
+}
-type ToolInvocationPart struct {
- ToolInvocation ToolInvocationPartToolInvocation `json:"toolInvocation,required"`
- Type ToolInvocationPartType `json:"type,required"`
- JSON toolInvocationPartJSON `json:"-"`
+type ToolStateCompleted struct {
+ Metadata map[string]interface{} `json:"metadata,required"`
+ Output string `json:"output,required"`
+ Status ToolStateCompletedStatus `json:"status,required"`
+ Time ToolStateCompletedTime `json:"time,required"`
+ Title string `json:"title,required"`
+ Input interface{} `json:"input"`
+ JSON toolStateCompletedJSON `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
+// toolStateCompletedJSON contains the JSON metadata for the struct
+// [ToolStateCompleted]
+type toolStateCompletedJSON struct {
+ Metadata apijson.Field
+ Output apijson.Field
+ Status apijson.Field
+ Time apijson.Field
+ Title apijson.Field
+ Input apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
}
-func (r *ToolInvocationPart) UnmarshalJSON(data []byte) (err error) {
+func (r *ToolStateCompleted) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
-func (r toolInvocationPartJSON) RawJSON() string {
+func (r toolStateCompletedJSON) RawJSON() string {
return r.raw
}
-func (r ToolInvocationPart) implementsMessagePart() {}
+func (r ToolStateCompleted) implementsToolPartState() {}
-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
+type ToolStateCompletedStatus string
+
+const (
+ ToolStateCompletedStatusCompleted ToolStateCompletedStatus = "completed"
+)
+
+func (r ToolStateCompletedStatus) IsKnown() bool {
+ switch r {
+ case ToolStateCompletedStatusCompleted:
+ return true
+ }
+ return false
}
-// 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
+type ToolStateCompletedTime struct {
+ End float64 `json:"end,required"`
+ Start float64 `json:"start,required"`
+ JSON toolStateCompletedTimeJSON `json:"-"`
+}
+
+// toolStateCompletedTimeJSON contains the JSON metadata for the struct
+// [ToolStateCompletedTime]
+type toolStateCompletedTimeJSON struct {
+ End apijson.Field
+ Start apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
-func (r toolInvocationPartToolInvocationJSON) RawJSON() string {
+func (r *ToolStateCompletedTime) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r toolStateCompletedTimeJSON) 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)
+type ToolStateError struct {
+ Error string `json:"error,required"`
+ Status ToolStateErrorStatus `json:"status,required"`
+ Time ToolStateErrorTime `json:"time,required"`
+ Input interface{} `json:"input"`
+ JSON toolStateErrorJSON `json:"-"`
}
-// 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
+// toolStateErrorJSON contains the JSON metadata for the struct [ToolStateError]
+type toolStateErrorJSON struct {
+ Error apijson.Field
+ Status apijson.Field
+ Time apijson.Field
+ Input apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
}
-// Union satisfied by [ToolCall], [ToolPartialCall] or [ToolResult].
-type ToolInvocationPartToolInvocationUnion interface {
- implementsToolInvocationPartToolInvocation()
+func (r *ToolStateError) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
}
-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",
- },
- )
+func (r toolStateErrorJSON) RawJSON() string {
+ return r.raw
}
-type ToolInvocationPartToolInvocationState string
+func (r ToolStateError) implementsToolPartState() {}
+
+type ToolStateErrorStatus string
const (
- ToolInvocationPartToolInvocationStateCall ToolInvocationPartToolInvocationState = "call"
- ToolInvocationPartToolInvocationStatePartialCall ToolInvocationPartToolInvocationState = "partial-call"
- ToolInvocationPartToolInvocationStateResult ToolInvocationPartToolInvocationState = "result"
+ ToolStateErrorStatusError ToolStateErrorStatus = "error"
)
-func (r ToolInvocationPartToolInvocationState) IsKnown() bool {
+func (r ToolStateErrorStatus) IsKnown() bool {
switch r {
- case ToolInvocationPartToolInvocationStateCall, ToolInvocationPartToolInvocationStatePartialCall, ToolInvocationPartToolInvocationStateResult:
+ case ToolStateErrorStatusError:
return true
}
return false
}
-type ToolInvocationPartType string
+type ToolStateErrorTime struct {
+ End float64 `json:"end,required"`
+ Start float64 `json:"start,required"`
+ JSON toolStateErrorTimeJSON `json:"-"`
+}
+
+// toolStateErrorTimeJSON contains the JSON metadata for the struct
+// [ToolStateErrorTime]
+type toolStateErrorTimeJSON struct {
+ End apijson.Field
+ Start apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *ToolStateErrorTime) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r toolStateErrorTimeJSON) RawJSON() string {
+ return r.raw
+}
+
+type ToolStatePending struct {
+ Status ToolStatePendingStatus `json:"status,required"`
+ JSON toolStatePendingJSON `json:"-"`
+}
+
+// toolStatePendingJSON contains the JSON metadata for the struct
+// [ToolStatePending]
+type toolStatePendingJSON struct {
+ Status apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *ToolStatePending) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r toolStatePendingJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r ToolStatePending) implementsToolPartState() {}
+
+type ToolStatePendingStatus string
const (
- ToolInvocationPartTypeToolInvocation ToolInvocationPartType = "tool-invocation"
+ ToolStatePendingStatusPending ToolStatePendingStatus = "pending"
)
-func (r ToolInvocationPartType) IsKnown() bool {
+func (r ToolStatePendingStatus) IsKnown() bool {
switch r {
- case ToolInvocationPartTypeToolInvocation:
+ case ToolStatePendingStatusPending:
return true
}
return false
}
-type ToolInvocationPartParam struct {
- ToolInvocation param.Field[ToolInvocationPartToolInvocationUnionParam] `json:"toolInvocation,required"`
- Type param.Field[ToolInvocationPartType] `json:"type,required"`
+type ToolStateRunning struct {
+ Status ToolStateRunningStatus `json:"status,required"`
+ Time ToolStateRunningTime `json:"time,required"`
+ Input interface{} `json:"input"`
+ Metadata map[string]interface{} `json:"metadata"`
+ Title string `json:"title"`
+ JSON toolStateRunningJSON `json:"-"`
}
-func (r ToolInvocationPartParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
+// toolStateRunningJSON contains the JSON metadata for the struct
+// [ToolStateRunning]
+type toolStateRunningJSON struct {
+ Status apijson.Field
+ Time apijson.Field
+ Input apijson.Field
+ Metadata apijson.Field
+ Title apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
}
-func (r ToolInvocationPartParam) implementsMessagePartUnionParam() {}
+func (r *ToolStateRunning) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
-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 toolStateRunningJSON) RawJSON() string {
+ return r.raw
}
-func (r ToolInvocationPartToolInvocationParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
+func (r ToolStateRunning) implementsToolPartState() {}
+
+type ToolStateRunningStatus string
+
+const (
+ ToolStateRunningStatusRunning ToolStateRunningStatus = "running"
+)
+
+func (r ToolStateRunningStatus) IsKnown() bool {
+ switch r {
+ case ToolStateRunningStatusRunning:
+ return true
+ }
+ return false
}
-func (r ToolInvocationPartToolInvocationParam) implementsToolInvocationPartToolInvocationUnionParam() {
+type ToolStateRunningTime struct {
+ Start float64 `json:"start,required"`
+ JSON toolStateRunningTimeJSON `json:"-"`
}
-// Satisfied by [ToolCallParam], [ToolPartialCallParam], [ToolResultParam],
-// [ToolInvocationPartToolInvocationParam].
-type ToolInvocationPartToolInvocationUnionParam interface {
- implementsToolInvocationPartToolInvocationUnionParam()
+// toolStateRunningTimeJSON contains the JSON metadata for the struct
+// [ToolStateRunningTime]
+type toolStateRunningTimeJSON struct {
+ Start apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
}
-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:"-"`
+func (r *ToolStateRunningTime) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
}
-// 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
+func (r toolStateRunningTimeJSON) RawJSON() string {
+ return r.raw
+}
+
+type UserMessage struct {
+ ID string `json:"id,required"`
+ Parts []UserMessagePart `json:"parts,required"`
+ Role UserMessageRole `json:"role,required"`
+ SessionID string `json:"sessionID,required"`
+ Time UserMessageTime `json:"time,required"`
+ JSON userMessageJSON `json:"-"`
+}
+
+// userMessageJSON contains the JSON metadata for the struct [UserMessage]
+type userMessageJSON struct {
+ ID apijson.Field
+ Parts apijson.Field
+ Role apijson.Field
+ SessionID apijson.Field
+ Time apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
-func (r *ToolPartialCall) UnmarshalJSON(data []byte) (err error) {
+func (r *UserMessage) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
-func (r toolPartialCallJSON) RawJSON() string {
+func (r userMessageJSON) RawJSON() string {
return r.raw
}
-func (r ToolPartialCall) implementsToolInvocationPartToolInvocation() {}
+func (r UserMessage) implementsMessage() {}
-type ToolPartialCallState string
+type UserMessageRole string
const (
- ToolPartialCallStatePartialCall ToolPartialCallState = "partial-call"
+ UserMessageRoleUser UserMessageRole = "user"
)
-func (r ToolPartialCallState) IsKnown() bool {
+func (r UserMessageRole) IsKnown() bool {
switch r {
- case ToolPartialCallStatePartialCall:
+ case UserMessageRoleUser:
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"`
+type UserMessageTime struct {
+ Created float64 `json:"created,required"`
+ JSON userMessageTimeJSON `json:"-"`
}
-func (r ToolPartialCallParam) MarshalJSON() (data []byte, err error) {
- return apijson.MarshalRoot(r)
+// userMessageTimeJSON contains the JSON metadata for the struct [UserMessageTime]
+type userMessageTimeJSON struct {
+ Created apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *UserMessageTime) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
}
-func (r ToolPartialCallParam) implementsToolInvocationPartToolInvocationUnionParam() {}
+func (r userMessageTimeJSON) RawJSON() string {
+ return r.raw
+}
-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:"-"`
+type UserMessagePart struct {
+ Type UserMessagePartType `json:"type,required"`
+ Filename string `json:"filename"`
+ Mime string `json:"mime"`
+ Text string `json:"text"`
+ URL string `json:"url"`
+ JSON userMessagePartJSON `json:"-"`
+ union UserMessagePartUnion
}
-// 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
+// userMessagePartJSON contains the JSON metadata for the struct [UserMessagePart]
+type userMessagePartJSON struct {
+ Type apijson.Field
+ Filename apijson.Field
+ Mime apijson.Field
+ Text apijson.Field
+ URL apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
-func (r *ToolResult) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
+func (r userMessagePartJSON) RawJSON() string {
+ return r.raw
}
-func (r toolResultJSON) RawJSON() string {
- return r.raw
+func (r *UserMessagePart) UnmarshalJSON(data []byte) (err error) {
+ *r = UserMessagePart{}
+ err = apijson.UnmarshalRoot(data, &r.union)
+ if err != nil {
+ return err
+ }
+ return apijson.Port(r.union, &r)
}
-func (r ToolResult) implementsToolInvocationPartToolInvocation() {}
+// AsUnion returns a [UserMessagePartUnion] interface which you can cast to the
+// specific types for more type safety.
+//
+// Possible runtime types of the union are [TextPart], [FilePart].
+func (r UserMessagePart) AsUnion() UserMessagePartUnion {
+ return r.union
+}
-type ToolResultState string
+// Union satisfied by [TextPart] or [FilePart].
+type UserMessagePartUnion interface {
+ implementsUserMessagePart()
+}
+
+func init() {
+ apijson.RegisterUnion(
+ reflect.TypeOf((*UserMessagePartUnion)(nil)).Elem(),
+ "type",
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(TextPart{}),
+ DiscriminatorValue: "text",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(FilePart{}),
+ DiscriminatorValue: "file",
+ },
+ )
+}
+
+type UserMessagePartType string
const (
- ToolResultStateResult ToolResultState = "result"
+ UserMessagePartTypeText UserMessagePartType = "text"
+ UserMessagePartTypeFile UserMessagePartType = "file"
)
-func (r ToolResultState) IsKnown() bool {
+func (r UserMessagePartType) IsKnown() bool {
switch r {
- case ToolResultStateResult:
+ case UserMessagePartTypeText, UserMessagePartTypeFile:
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"`
+type UserMessagePartParam struct {
+ Type param.Field[UserMessagePartType] `json:"type,required"`
+ Filename param.Field[string] `json:"filename"`
+ Mime param.Field[string] `json:"mime"`
+ Text param.Field[string] `json:"text"`
+ URL param.Field[string] `json:"url"`
}
-func (r ToolResultParam) MarshalJSON() (data []byte, err error) {
+func (r UserMessagePartParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
-func (r ToolResultParam) implementsToolInvocationPartToolInvocationUnionParam() {}
+func (r UserMessagePartParam) implementsUserMessagePartUnionParam() {}
+
+// Satisfied by [TextPartParam], [FilePartParam], [UserMessagePartParam].
+type UserMessagePartUnionParam interface {
+ implementsUserMessagePartUnionParam()
+}
type SessionChatParams struct {
- ModelID param.Field[string] `json:"modelID,required"`
- Parts param.Field[[]MessagePartUnionParam] `json:"parts,required"`
- ProviderID param.Field[string] `json:"providerID,required"`
+ ModelID param.Field[string] `json:"modelID,required"`
+ Parts param.Field[[]UserMessagePartUnionParam] `json:"parts,required"`
+ ProviderID param.Field[string] `json:"providerID,required"`
}
func (r SessionChatParams) MarshalJSON() (data []byte, err error) {