Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions protocol/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ const (
// KindTask is the kind of the task.
KindTask = "task"
// KindTaskStatusUpdate is the kind of the task status update event.
KindTaskStatusUpdate = "status_update"
KindTaskStatusUpdate = "status-update"
// KindTaskArtifactUpdate is the kind of the task artifact update event.
KindTaskArtifactUpdate = "artifact_update"
KindTaskArtifactUpdate = "artifact-update"
// KindData is the kind of the data.
KindData = "data"
// KindFile is the kind of the file.
Expand Down Expand Up @@ -661,11 +661,12 @@ func NewTaskStatusUpdateEvent(taskID, contextID string, status TaskStatus, final
ContextID: contextID,
Kind: KindTaskStatusUpdate,
Status: status,
Final: &final,
}
}

// NewTaskArtifactUpdateEvent creates a new TaskArtifactUpdateEvent.
func NewTaskArtifactUpdateEvent(taskID, contextID string, artifact Artifact, final bool) TaskArtifactUpdateEvent {
func NewTaskArtifactUpdateEvent(taskID, contextID string, artifact Artifact) TaskArtifactUpdateEvent {
return TaskArtifactUpdateEvent{
TaskID: taskID,
ContextID: contextID,
Expand Down Expand Up @@ -806,7 +807,7 @@ type StreamingMessageEvent struct {
}

// UnmarshalJSON implements custom unmarshalling logic for StreamingMessageEvent
func (r *StreamingMessageEvent) UnmarshalJSON(data []byte) error {
func (r StreamingMessageEvent) UnmarshalJSON(data []byte) error {
// First, try to detect if this is wrapped in a Result field
type StreamingMessageEventRaw struct {
Result json.RawMessage `json:"Result"`
Expand Down Expand Up @@ -864,12 +865,16 @@ func (r *StreamingMessageEvent) UnmarshalJSON(data []byte) error {
}

// MarshalJSON implements custom marshalling logic for StreamingMessageResult
func (r *StreamingMessageEvent) MarshalJSON() ([]byte, error) {
func (r StreamingMessageEvent) MarshalJSON() ([]byte, error) {
switch r.Result.GetKind() {
case KindMessage:
return json.Marshal(r.Result)
case KindTask:
return json.Marshal(r.Result)
case KindTaskStatusUpdate:
return json.Marshal(r.Result)
case KindTaskArtifactUpdate:
return json.Marshal(r.Result)
default:
return nil, fmt.Errorf("unsupported result kind: %s", r.Result.GetKind())
}
Expand Down
Loading