mirror of
https://github.com/anomalyco/opencode-sdk-go.git
synced 2026-04-28 04:29:49 +00:00
feat(api): api update
This commit is contained in:
parent
3ba9a4c3e0
commit
2ed0800b2c
5 changed files with 92 additions and 39 deletions
83
session.go
83
session.go
|
|
@ -829,16 +829,19 @@ func (r MessageRole) IsKnown() bool {
|
|||
}
|
||||
|
||||
type Part struct {
|
||||
ID string `json:"id,required"`
|
||||
MessageID string `json:"messageID,required"`
|
||||
SessionID string `json:"sessionID,required"`
|
||||
Type PartType `json:"type,required"`
|
||||
CallID string `json:"callID"`
|
||||
Cost float64 `json:"cost"`
|
||||
Filename string `json:"filename"`
|
||||
Mime string `json:"mime"`
|
||||
Snapshot string `json:"snapshot"`
|
||||
Source FilePartSource `json:"source"`
|
||||
ID string `json:"id,required"`
|
||||
MessageID string `json:"messageID,required"`
|
||||
SessionID string `json:"sessionID,required"`
|
||||
Type PartType `json:"type,required"`
|
||||
CallID string `json:"callID"`
|
||||
Cost float64 `json:"cost"`
|
||||
Filename string `json:"filename"`
|
||||
// This field can have the runtime type of [[]string].
|
||||
Files interface{} `json:"files"`
|
||||
Hash string `json:"hash"`
|
||||
Mime string `json:"mime"`
|
||||
Snapshot string `json:"snapshot"`
|
||||
Source FilePartSource `json:"source"`
|
||||
// This field can have the runtime type of [ToolPartState].
|
||||
State interface{} `json:"state"`
|
||||
Synthetic bool `json:"synthetic"`
|
||||
|
|
@ -862,6 +865,8 @@ type partJSON struct {
|
|||
CallID apijson.Field
|
||||
Cost apijson.Field
|
||||
Filename apijson.Field
|
||||
Files apijson.Field
|
||||
Hash apijson.Field
|
||||
Mime apijson.Field
|
||||
Snapshot apijson.Field
|
||||
Source apijson.Field
|
||||
|
|
@ -893,13 +898,13 @@ func (r *Part) UnmarshalJSON(data []byte) (err error) {
|
|||
// for more type safety.
|
||||
//
|
||||
// Possible runtime types of the union are [TextPart], [FilePart], [ToolPart],
|
||||
// [StepStartPart], [StepFinishPart], [SnapshotPart].
|
||||
// [StepStartPart], [StepFinishPart], [SnapshotPart], [PartPatchPart].
|
||||
func (r Part) AsUnion() PartUnion {
|
||||
return r.union
|
||||
}
|
||||
|
||||
// Union satisfied by [TextPart], [FilePart], [ToolPart], [StepStartPart],
|
||||
// [StepFinishPart] or [SnapshotPart].
|
||||
// [StepFinishPart], [SnapshotPart] or [PartPatchPart].
|
||||
type PartUnion interface {
|
||||
implementsPart()
|
||||
}
|
||||
|
|
@ -938,9 +943,60 @@ func init() {
|
|||
Type: reflect.TypeOf(SnapshotPart{}),
|
||||
DiscriminatorValue: "snapshot",
|
||||
},
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.JSON,
|
||||
Type: reflect.TypeOf(PartPatchPart{}),
|
||||
DiscriminatorValue: "patch",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
type PartPatchPart struct {
|
||||
ID string `json:"id,required"`
|
||||
Files []string `json:"files,required"`
|
||||
Hash string `json:"hash,required"`
|
||||
MessageID string `json:"messageID,required"`
|
||||
SessionID string `json:"sessionID,required"`
|
||||
Type PartPatchPartType `json:"type,required"`
|
||||
JSON partPatchPartJSON `json:"-"`
|
||||
}
|
||||
|
||||
// partPatchPartJSON contains the JSON metadata for the struct [PartPatchPart]
|
||||
type partPatchPartJSON struct {
|
||||
ID apijson.Field
|
||||
Files apijson.Field
|
||||
Hash apijson.Field
|
||||
MessageID apijson.Field
|
||||
SessionID apijson.Field
|
||||
Type apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
}
|
||||
|
||||
func (r *PartPatchPart) UnmarshalJSON(data []byte) (err error) {
|
||||
return apijson.UnmarshalRoot(data, r)
|
||||
}
|
||||
|
||||
func (r partPatchPartJSON) RawJSON() string {
|
||||
return r.raw
|
||||
}
|
||||
|
||||
func (r PartPatchPart) implementsPart() {}
|
||||
|
||||
type PartPatchPartType string
|
||||
|
||||
const (
|
||||
PartPatchPartTypePatch PartPatchPartType = "patch"
|
||||
)
|
||||
|
||||
func (r PartPatchPartType) IsKnown() bool {
|
||||
switch r {
|
||||
case PartPatchPartTypePatch:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type PartType string
|
||||
|
||||
const (
|
||||
|
|
@ -950,11 +1006,12 @@ const (
|
|||
PartTypeStepStart PartType = "step-start"
|
||||
PartTypeStepFinish PartType = "step-finish"
|
||||
PartTypeSnapshot PartType = "snapshot"
|
||||
PartTypePatch PartType = "patch"
|
||||
)
|
||||
|
||||
func (r PartType) IsKnown() bool {
|
||||
switch r {
|
||||
case PartTypeText, PartTypeFile, PartTypeTool, PartTypeStepStart, PartTypeStepFinish, PartTypeSnapshot:
|
||||
case PartTypeText, PartTypeFile, PartTypeTool, PartTypeStepStart, PartTypeStepFinish, PartTypeSnapshot, PartTypePatch:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue