Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 24 additions & 11 deletions hosted_agent_triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ const (
HostedAgentTriggerExecutionStatusFailed HostedAgentTriggerExecutionStatus = "failed"
)

// HostedAgentTriggerExecutionStatusReason is why a non-terminal execution is
// held. The API may add reasons, so an unrecognized value stays an opaque
// string. Status itself stays running while one of these is set.
type HostedAgentTriggerExecutionStatusReason string

const (
// HostedAgentTriggerExecutionWaitingForBoundSession means a reuse firing is
// waiting for its bound session to pause. Status stays running.
HostedAgentTriggerExecutionWaitingForBoundSession HostedAgentTriggerExecutionStatusReason = "waiting_for_bound_session"
)

// HostedAgentWebhookSignatureScheme is how an external system authenticates a delivery.
type HostedAgentWebhookSignatureScheme string

Expand Down Expand Up @@ -272,17 +283,19 @@ type HostedAgentTriggerRotateSecretResponse struct {

// HostedAgentTriggerExecution is one row per firing.
type HostedAgentTriggerExecution struct {
ExecutionID string `json:"execution_id,omitempty"`
TriggerID string `json:"trigger_id,omitempty"`
Status HostedAgentTriggerExecutionStatus `json:"status,omitempty"`
SessionID string `json:"session_id,omitempty"`
RunID string `json:"run_id,omitempty"`
FailureReason string `json:"failure_reason,omitempty"`
CreatedAt Timestamp `json:"created_at,omitempty"`
UpdatedAt Timestamp `json:"updated_at,omitempty"`
Payload string `json:"payload,omitempty"`
OutputText string `json:"output_text,omitempty"`
OutputTruncated bool `json:"output_truncated,omitempty"`
ExecutionID string `json:"execution_id,omitempty"`
TriggerID string `json:"trigger_id,omitempty"`
Status HostedAgentTriggerExecutionStatus `json:"status,omitempty"`
SessionID string `json:"session_id,omitempty"`
RunID string `json:"run_id,omitempty"`
StatusReason HostedAgentTriggerExecutionStatusReason `json:"status_reason,omitempty"`
StatusMessage string `json:"status_message,omitempty"`
FailureReason string `json:"failure_reason,omitempty"`
CreatedAt Timestamp `json:"created_at,omitempty"`
UpdatedAt Timestamp `json:"updated_at,omitempty"`
Payload string `json:"payload,omitempty"`
OutputText string `json:"output_text,omitempty"`
OutputTruncated bool `json:"output_truncated,omitempty"`
}

// HostedAgentTriggerExecutionListOptions specifies optional execution list filters.
Expand Down
32 changes: 32 additions & 0 deletions hosted_agent_triggers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,38 @@ func TestHostedAgentTriggers_GetExecution(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode)
}

func TestHostedAgentTriggerExecution_DecodesWaitingDetail(t *testing.T) {
const raw = `{
"execution_id": "exec-wait",
"status": "running",
"status_reason": "waiting_for_bound_session",
"status_message": "Waiting for the bound session to pause."
}`

var exec HostedAgentTriggerExecution
require.NoError(t, json.Unmarshal([]byte(raw), &exec))
assert.Equal(t, HostedAgentTriggerExecutionStatusRunning, exec.Status)
assert.Equal(t, HostedAgentTriggerExecutionWaitingForBoundSession, exec.StatusReason)
assert.Equal(t, "Waiting for the bound session to pause.", exec.StatusMessage)

body, err := json.Marshal(&exec)
require.NoError(t, err)
var fields map[string]any
require.NoError(t, json.Unmarshal(body, &fields))
assert.Equal(t, "waiting_for_bound_session", fields["status_reason"])
assert.Equal(t, "Waiting for the bound session to pause.", fields["status_message"])

// An unknown reason stays opaque, and an execution with no detail omits both fields.
var unknown HostedAgentTriggerExecution
require.NoError(t, json.Unmarshal([]byte(`{"status_reason":"some_future_reason"}`), &unknown))
assert.Equal(t, HostedAgentTriggerExecutionStatusReason("some_future_reason"), unknown.StatusReason)

empty, err := json.Marshal(&HostedAgentTriggerExecution{ExecutionID: "exec-plain", Status: HostedAgentTriggerExecutionStatusRunning})
require.NoError(t, err)
assert.NotContains(t, string(empty), "status_reason")
assert.NotContains(t, string(empty), "status_message")
}

func TestHostedAgentTriggers_Cancel(t *testing.T) {
setup()
defer teardown()
Expand Down
3 changes: 3 additions & 0 deletions hosted_agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ const (
// Deprecated: Use HostedAgentSessionPauseReasonZeroBalance. Servers now return
// "zero_balance"; this constant is kept for backward compatibility with older API responses.
HostedAgentSessionPauseReasonLowBalance HostedAgentSessionPauseReason = "low_balance"
// HostedAgentSessionPauseReasonTrigger is a pause recorded after a reuse
// trigger firing, rather than one the customer requested.
HostedAgentSessionPauseReasonTrigger HostedAgentSessionPauseReason = "trigger"
)

// HostedAgentProviderAuthState tracks OAuth authorization for an external provider.
Expand Down
12 changes: 12 additions & 0 deletions hosted_agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,18 @@ func TestHostedAgentSession_DecodesPauseReason(t *testing.T) {
assert.Equal(t, HostedAgentSessionPauseReasonLowBalance, session.PauseReason)
}

func TestHostedAgentSession_DecodesTriggerPauseReason(t *testing.T) {
const sessionJSON = `{
"session_id": "sess-trigger",
"status": "SESSION_STATUS_PAUSED",
"pause_reason": "trigger"
}`

var session HostedAgentSession
require.NoError(t, json.Unmarshal([]byte(sessionJSON), &session))
assert.Equal(t, HostedAgentSessionPauseReasonTrigger, session.PauseReason)
}

// The API reserves the right to add reasons, so a value this client has no
// constant for still has to survive decoding intact.
func TestHostedAgentSession_KeepsUnknownPauseReasonVerbatim(t *testing.T) {
Expand Down
Loading