fleet-memory/hindsight-clients/go/model_create_webhook_request.go
Nicolò Boschi abbf874d84
feat: webhook system with retain.completed event, UI, and docs (#487)
* doc: update cookbook

* fix(cookbook): preserve tag keys during sync, strip local .md links

- Fix extract_tags_from_readme/notebook to return dict[str,str] preserving
  sdk/topic keys instead of bare values, preventing topics like
  "Customer Service" from being misclassified as SDK
- Add strip_local_md_links() to remove relative .md references that
  would cause broken link errors in Docusaurus build

* ci: run test-doc-examples independently without waiting for test-rust-cli

Build the CLI directly in the job instead of downloading the artifact,
so test-doc-examples can start at the beginning in parallel with all other jobs.

* feat: webhook system with task-owned retry, retain.completed event, and UI

- New webhook system: register per-bank webhooks with HMAC signing, configurable
  HTTP method/timeout/headers/params (http_config JSONB), and PATCH support
- Webhook deliveries run as async_operations (webhook_delivery type) with
  task-owned retry via RetryTaskAt exception and exponential backoff
  (60s / 5m / 30m / 2h / 8h, max 6 attempts)
- New retain.completed event fires per-document for both sync and async retain
- Delivery debug info (status code, response body) stored in result_metadata
- Control plane UI: webhooks tab per bank with create/edit/delete and a
  deliveries table with cursor pagination and expandable response details
- 28 webhook tests covering HMAC signing, delivery retries, CRUD endpoints,
  PATCH update, and retain.completed queuing
- Docs page at developer/api/webhooks documenting event payloads and delivery
- OpenAPI spec and all client SDKs (Python, TypeScript, Rust, Go) regenerated

* fix: update tests for task-owned retry model and guard _webhook_manager attribute

- test_worker.py: test_executor_exception_triggers_retry now raises RetryTaskAt
  (plain exceptions are immediate failures in the new system); rename
  test_executor_exception_marks_failed_after_max_retries to
  test_executor_exception_marks_failed_immediately to reflect new semantics
- test_batch_api.py: remove max_retries kwarg from WorkerPoller constructor
- memory_engine.py: use getattr for _webhook_manager in _fire_retain_webhook
  to avoid AttributeError when engine is created without __init__ (tests)

* fix: remove max_retries from benchmark WorkerPoller call

* fix(webhooks): transactional outbox, observations_deleted tracking, sidebar

- Queue webhook delivery rows atomically with the primary operation using the
  transactional outbox pattern — prevents lost events on process crash:
  - Retain (sync + async): outbox_callback passed into orchestrator.retain_batch
    and called inside the DB transaction, replacing the post-commit fire call
  - Consolidation: new _mark_operation_completed_and_fire_webhook combines the
    status UPDATE and webhook INSERT in one transaction
  - Added fire_event_with_conn() to WebhookManager for in-connection delivery

- Track observations_deleted count in consolidation stats and expose it in the
  consolidation.completed webhook payload (was always None)

- Add Webhooks page to docs sidebar

- Document at-least-once delivery guarantee with operation_id dedup guidance

* fix(ui): add retain.completed to available webhook event types

* feat(ui): add delete confirmation dialog for webhooks

* fix(webhooks): include operation_id in task_payload so delivery is marked completed

The task_payload JSON was missing the operation_id field, causing execute_task
to see operation_id=None and skip _mark_operation_completed — leaving every
delivery row stuck in 'pending' forever.

Added a test that inserts a real async_operations row and verifies the status
transitions to 'completed' after a successful execute_task call.

* style: fix prettier formatting in webhooks-view
2026-03-04 14:17:01 +01:00

320 lines
8.5 KiB
Go

/*
Hindsight HTTP API
HTTP API for Hindsight
API version: 0.4.15
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hindsight
import (
"encoding/json"
"bytes"
"fmt"
)
// checks if the CreateWebhookRequest type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &CreateWebhookRequest{}
// CreateWebhookRequest Request model for registering a webhook.
type CreateWebhookRequest struct {
// HTTP(S) endpoint URL to deliver events to
Url string `json:"url"`
Secret NullableString `json:"secret,omitempty"`
// List of event types to deliver. Currently supported: 'consolidation.completed'
EventTypes []string `json:"event_types,omitempty"`
// Whether this webhook is active
Enabled *bool `json:"enabled,omitempty"`
// HTTP delivery configuration (method, timeout, headers, params)
HttpConfig *WebhookHttpConfig `json:"http_config,omitempty"`
}
type _CreateWebhookRequest CreateWebhookRequest
// NewCreateWebhookRequest instantiates a new CreateWebhookRequest object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewCreateWebhookRequest(url string) *CreateWebhookRequest {
this := CreateWebhookRequest{}
this.Url = url
var enabled bool = true
this.Enabled = &enabled
return &this
}
// NewCreateWebhookRequestWithDefaults instantiates a new CreateWebhookRequest object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewCreateWebhookRequestWithDefaults() *CreateWebhookRequest {
this := CreateWebhookRequest{}
var enabled bool = true
this.Enabled = &enabled
return &this
}
// GetUrl returns the Url field value
func (o *CreateWebhookRequest) GetUrl() string {
if o == nil {
var ret string
return ret
}
return o.Url
}
// GetUrlOk returns a tuple with the Url field value
// and a boolean to check if the value has been set.
func (o *CreateWebhookRequest) GetUrlOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Url, true
}
// SetUrl sets field value
func (o *CreateWebhookRequest) SetUrl(v string) {
o.Url = v
}
// GetSecret returns the Secret field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *CreateWebhookRequest) GetSecret() string {
if o == nil || IsNil(o.Secret.Get()) {
var ret string
return ret
}
return *o.Secret.Get()
}
// GetSecretOk returns a tuple with the Secret field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *CreateWebhookRequest) GetSecretOk() (*string, bool) {
if o == nil {
return nil, false
}
return o.Secret.Get(), o.Secret.IsSet()
}
// HasSecret returns a boolean if a field has been set.
func (o *CreateWebhookRequest) HasSecret() bool {
if o != nil && o.Secret.IsSet() {
return true
}
return false
}
// SetSecret gets a reference to the given NullableString and assigns it to the Secret field.
func (o *CreateWebhookRequest) SetSecret(v string) {
o.Secret.Set(&v)
}
// SetSecretNil sets the value for Secret to be an explicit nil
func (o *CreateWebhookRequest) SetSecretNil() {
o.Secret.Set(nil)
}
// UnsetSecret ensures that no value is present for Secret, not even an explicit nil
func (o *CreateWebhookRequest) UnsetSecret() {
o.Secret.Unset()
}
// GetEventTypes returns the EventTypes field value if set, zero value otherwise.
func (o *CreateWebhookRequest) GetEventTypes() []string {
if o == nil || IsNil(o.EventTypes) {
var ret []string
return ret
}
return o.EventTypes
}
// GetEventTypesOk returns a tuple with the EventTypes field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *CreateWebhookRequest) GetEventTypesOk() ([]string, bool) {
if o == nil || IsNil(o.EventTypes) {
return nil, false
}
return o.EventTypes, true
}
// HasEventTypes returns a boolean if a field has been set.
func (o *CreateWebhookRequest) HasEventTypes() bool {
if o != nil && !IsNil(o.EventTypes) {
return true
}
return false
}
// SetEventTypes gets a reference to the given []string and assigns it to the EventTypes field.
func (o *CreateWebhookRequest) SetEventTypes(v []string) {
o.EventTypes = v
}
// GetEnabled returns the Enabled field value if set, zero value otherwise.
func (o *CreateWebhookRequest) GetEnabled() bool {
if o == nil || IsNil(o.Enabled) {
var ret bool
return ret
}
return *o.Enabled
}
// GetEnabledOk returns a tuple with the Enabled field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *CreateWebhookRequest) GetEnabledOk() (*bool, bool) {
if o == nil || IsNil(o.Enabled) {
return nil, false
}
return o.Enabled, true
}
// HasEnabled returns a boolean if a field has been set.
func (o *CreateWebhookRequest) HasEnabled() bool {
if o != nil && !IsNil(o.Enabled) {
return true
}
return false
}
// SetEnabled gets a reference to the given bool and assigns it to the Enabled field.
func (o *CreateWebhookRequest) SetEnabled(v bool) {
o.Enabled = &v
}
// GetHttpConfig returns the HttpConfig field value if set, zero value otherwise.
func (o *CreateWebhookRequest) GetHttpConfig() WebhookHttpConfig {
if o == nil || IsNil(o.HttpConfig) {
var ret WebhookHttpConfig
return ret
}
return *o.HttpConfig
}
// GetHttpConfigOk returns a tuple with the HttpConfig field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *CreateWebhookRequest) GetHttpConfigOk() (*WebhookHttpConfig, bool) {
if o == nil || IsNil(o.HttpConfig) {
return nil, false
}
return o.HttpConfig, true
}
// HasHttpConfig returns a boolean if a field has been set.
func (o *CreateWebhookRequest) HasHttpConfig() bool {
if o != nil && !IsNil(o.HttpConfig) {
return true
}
return false
}
// SetHttpConfig gets a reference to the given WebhookHttpConfig and assigns it to the HttpConfig field.
func (o *CreateWebhookRequest) SetHttpConfig(v WebhookHttpConfig) {
o.HttpConfig = &v
}
func (o CreateWebhookRequest) MarshalJSON() ([]byte, error) {
toSerialize,err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}
func (o CreateWebhookRequest) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{}
toSerialize["url"] = o.Url
if o.Secret.IsSet() {
toSerialize["secret"] = o.Secret.Get()
}
if !IsNil(o.EventTypes) {
toSerialize["event_types"] = o.EventTypes
}
if !IsNil(o.Enabled) {
toSerialize["enabled"] = o.Enabled
}
if !IsNil(o.HttpConfig) {
toSerialize["http_config"] = o.HttpConfig
}
return toSerialize, nil
}
func (o *CreateWebhookRequest) UnmarshalJSON(data []byte) (err error) {
// This validates that all required properties are included in the JSON object
// by unmarshalling the object into a generic map with string keys and checking
// that every required field exists as a key in the generic map.
requiredProperties := []string{
"url",
}
allProperties := make(map[string]interface{})
err = json.Unmarshal(data, &allProperties)
if err != nil {
return err;
}
for _, requiredProperty := range(requiredProperties) {
if _, exists := allProperties[requiredProperty]; !exists {
return fmt.Errorf("no value given for required property %v", requiredProperty)
}
}
varCreateWebhookRequest := _CreateWebhookRequest{}
decoder := json.NewDecoder(bytes.NewReader(data))
decoder.DisallowUnknownFields()
err = decoder.Decode(&varCreateWebhookRequest)
if err != nil {
return err
}
*o = CreateWebhookRequest(varCreateWebhookRequest)
return err
}
type NullableCreateWebhookRequest struct {
value *CreateWebhookRequest
isSet bool
}
func (v NullableCreateWebhookRequest) Get() *CreateWebhookRequest {
return v.value
}
func (v *NullableCreateWebhookRequest) Set(val *CreateWebhookRequest) {
v.value = val
v.isSet = true
}
func (v NullableCreateWebhookRequest) IsSet() bool {
return v.isSet
}
func (v *NullableCreateWebhookRequest) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableCreateWebhookRequest(val *CreateWebhookRequest) *NullableCreateWebhookRequest {
return &NullableCreateWebhookRequest{value: val, isSet: true}
}
func (v NullableCreateWebhookRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableCreateWebhookRequest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}