fix: add involves edge from task to agent:nomos at creation
Some checks failed
ci / build-test (push) Has been cancelled
ci / docker-build (push) Has been cancelled
ci / web (push) Has been cancelled
Desktop App / Build Linux (amd64) (push) Has been cancelled
Desktop App / Attach to Release (push) Has been cancelled

Plus sync vendor directory for Docker build compatibility.
This commit is contained in:
2026-08-11 22:03:12 +02:00
parent 7d6a3320d4
commit febc153b7f
3384 changed files with 945212 additions and 2 deletions

View File

@@ -0,0 +1,101 @@
package param
import (
"encoding/json"
"fmt"
"reflect"
"time"
shimjson "github.com/openai/openai-go/internal/encoding/json"
"github.com/tidwall/sjson"
)
// EncodedAsDate is not be stable and shouldn't be relied upon
type EncodedAsDate Opt[time.Time]
type forceOmit int
func (m EncodedAsDate) MarshalJSON() ([]byte, error) {
underlying := Opt[time.Time](m)
bytes := underlying.MarshalJSONWithTimeLayout("2006-01-02")
if len(bytes) > 0 {
return bytes, nil
}
return underlying.MarshalJSON()
}
// MarshalObject uses a shimmed 'encoding/json' from Go 1.24, to support the 'omitzero' tag
//
// Stability for the API of MarshalObject is not guaranteed.
func MarshalObject[T ParamStruct](f T, underlying any) ([]byte, error) {
return MarshalWithExtras(f, underlying, f.extraFields())
}
// MarshalWithExtras is used to marshal a struct with additional properties.
//
// Stability for the API of MarshalWithExtras is not guaranteed.
func MarshalWithExtras[T ParamStruct, R any](f T, underlying any, extras map[string]R) ([]byte, error) {
if f.null() {
return []byte("null"), nil
} else if len(extras) > 0 {
bytes, err := shimjson.Marshal(underlying)
if err != nil {
return nil, err
}
for k, v := range extras {
var a any = v
if a == Omit {
// Errors when handling ForceOmitted are ignored.
if b, e := sjson.DeleteBytes(bytes, k); e == nil {
bytes = b
}
continue
}
bytes, err = sjson.SetBytes(bytes, k, v)
if err != nil {
return nil, err
}
}
return bytes, nil
} else if ovr, ok := f.Overrides(); ok {
return shimjson.Marshal(ovr)
} else {
return shimjson.Marshal(underlying)
}
}
// MarshalUnion uses a shimmed 'encoding/json' from Go 1.24, to support the 'omitzero' tag
//
// Stability for the API of MarshalUnion is not guaranteed.
func MarshalUnion[T ParamStruct](metadata T, variants ...any) ([]byte, error) {
nPresent := 0
presentIdx := -1
for i, variant := range variants {
if !IsOmitted(variant) {
nPresent++
presentIdx = i
}
}
if nPresent == 0 || presentIdx == -1 {
if ovr, ok := metadata.Overrides(); ok {
return shimjson.Marshal(ovr)
}
return []byte(`null`), nil
} else if nPresent > 1 {
return nil, &json.MarshalerError{
Type: typeFor[T](),
Err: fmt.Errorf("expected union to have only one present variant, got %d", nPresent),
}
}
return shimjson.Marshal(variants[presentIdx])
}
// typeFor is shimmed from Go 1.23 "reflect" package
func typeFor[T any]() reflect.Type {
var v T
if t := reflect.TypeOf(v); t != nil {
return t // optimize for T being a non-interface kind
}
return reflect.TypeOf((*T)(nil)).Elem() // only for an interface kind
}

View File

@@ -0,0 +1,19 @@
package param
import "github.com/openai/openai-go/internal/encoding/json/sentinel"
// NullMap returns a non-nil map with a length of 0.
// When used with [MarshalObject] or [MarshalUnion], it will be marshaled as null.
//
// It is unspecified behavior to mutate the map returned by [NullMap].
func NullMap[MapT ~map[string]T, T any]() MapT {
return sentinel.NewNullSentinel(func() MapT { return make(MapT, 1) })
}
// NullSlice returns a non-nil slice with a length of 0.
// When used with [MarshalObject] or [MarshalUnion], it will be marshaled as null.
//
// It is unspecified behavior to mutate the slice returned by [NullSlice].
func NullSlice[SliceT ~[]T, T any]() SliceT {
return sentinel.NewNullSentinel(func() SliceT { return make(SliceT, 0, 1) })
}

View File

@@ -0,0 +1,121 @@
package param
import (
"encoding/json"
"fmt"
shimjson "github.com/openai/openai-go/internal/encoding/json"
"time"
)
func NewOpt[T comparable](v T) Opt[T] {
return Opt[T]{Value: v, status: included}
}
// Null creates optional field with the JSON value "null".
//
// To set a struct to null, use [NullStruct].
func Null[T comparable]() Opt[T] { return Opt[T]{status: null} }
type status int8
const (
omitted status = iota
null
included
)
// Opt represents an optional parameter of type T. Use
// the [Opt.Valid] method to confirm.
type Opt[T comparable] struct {
Value T
// indicates whether the field should be omitted, null, or valid
status status
opt
}
// Valid returns true if the value is not "null" or omitted.
//
// To check if explicitly null, use [Opt.Null].
func (o Opt[T]) Valid() bool {
var empty Opt[T]
return o.status == included || o != empty && o.status != null
}
func (o Opt[T]) Or(v T) T {
if o.Valid() {
return o.Value
}
return v
}
func (o Opt[T]) String() string {
if o.null() {
return "null"
}
if s, ok := any(o.Value).(fmt.Stringer); ok {
return s.String()
}
return fmt.Sprintf("%v", o.Value)
}
func (o Opt[T]) MarshalJSON() ([]byte, error) {
if !o.Valid() {
return []byte("null"), nil
}
return json.Marshal(o.Value)
}
func (o *Opt[T]) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
o.status = null
return nil
}
var value *T
if err := json.Unmarshal(data, &value); err != nil {
return err
}
if value == nil {
o.status = omitted
return nil
}
o.status = included
o.Value = *value
return nil
}
// MarshalJSONWithTimeLayout is necessary to bypass the internal caching performed
// by [json.Marshal]. Prefer to use [Opt.MarshalJSON] instead.
//
// This function requires that the generic type parameter of [Opt] is not [time.Time].
func (o Opt[T]) MarshalJSONWithTimeLayout(format string) []byte {
t, ok := any(o.Value).(time.Time)
if !ok || o.null() {
return nil
}
b, err := json.Marshal(t.Format(shimjson.TimeLayout(format)))
if err != nil {
return nil
}
return b
}
func (o Opt[T]) null() bool { return o.status == null }
func (o Opt[T]) isZero() bool { return o == Opt[T]{} }
// opt helps limit the [Optional] interface to only types in this package
type opt struct{}
func (opt) implOpt() {}
// This interface is useful for internal purposes.
type Optional interface {
Valid() bool
null() bool
isZero() bool
implOpt()
}

View File

@@ -0,0 +1,168 @@
package param
import (
"encoding/json"
"github.com/openai/openai-go/internal/encoding/json/sentinel"
"reflect"
)
// NullStruct is used to set a struct to the JSON value null.
// Check for null structs with [IsNull].
//
// Only the first type parameter should be provided,
// the type PtrT will be inferred.
//
// json.Marshal(param.NullStruct[MyStruct]()) -> 'null'
//
// To send null to an [Opt] field use [Null].
func NullStruct[T ParamStruct, PtrT InferPtr[T]]() T {
var t T
pt := PtrT(&t)
pt.setMetadata(nil)
return *pt
}
// Override replaces the value of a struct with any type.
//
// Only the first type parameter should be provided,
// the type PtrT will be inferred.
//
// It's often useful for providing raw JSON
//
// param.Override[MyStruct](json.RawMessage(`{"foo": "bar"}`))
//
// The public fields of the returned struct T will be unset.
//
// To override a specific field in a struct, use its [SetExtraFields] method.
func Override[T ParamStruct, PtrT InferPtr[T]](v any) T {
var t T
pt := PtrT(&t)
pt.setMetadata(v)
return *pt
}
// IsOmitted returns true if v is the zero value of its type.
//
// If IsOmitted is true, and the field uses a `json:"...,omitzero"` tag,
// the field will be omitted from the request.
//
// If v is set explicitly to the JSON value "null", IsOmitted returns false.
func IsOmitted(v any) bool {
if v == nil {
return false
}
if o, ok := v.(Optional); ok {
return o.isZero()
}
return reflect.ValueOf(v).IsZero()
}
// IsNull returns true if v was set to the JSON value null.
//
// To set a param to null use [NullStruct], [Null], [NullMap], or [NullSlice]
// depending on the type of v.
//
// IsNull returns false if the value is omitted.
func IsNull[T any](v T) bool {
if nullable, ok := any(v).(ParamNullable); ok {
return nullable.null()
}
switch reflect.TypeOf(v).Kind() {
case reflect.Slice, reflect.Map:
return sentinel.IsNull(v)
}
return false
}
// ParamNullable encapsulates all structs in parameters,
// and all [Opt] types in parameters.
type ParamNullable interface {
null() bool
}
// ParamStruct represents the set of all structs that are
// used in API parameters, by convention these usually end in
// "Params" or "Param".
type ParamStruct interface {
Overrides() (any, bool)
null() bool
extraFields() map[string]any
}
// This is an implementation detail and should never be explicitly set.
type InferPtr[T ParamStruct] interface {
setMetadata(any)
*T
}
// APIObject should be embedded in api object fields, preferably using an alias to make private
type APIObject struct{ metadata }
// APIUnion should be embedded in all api unions fields, preferably using an alias to make private
type APIUnion struct{ metadata }
// Overrides returns the value of the struct when it is created with
// [Override], the second argument helps differentiate an explicit null.
func (m metadata) Overrides() (any, bool) {
if _, ok := m.any.(metadataExtraFields); ok {
return nil, false
}
return m.any, m.any != nil
}
// ExtraFields returns the extra fields added to the JSON object.
func (m metadata) ExtraFields() map[string]any {
if extras, ok := m.any.(metadataExtraFields); ok {
return extras
}
return nil
}
// Omit can be used with [metadata.SetExtraFields] to ensure that a
// required field is omitted. This is useful as an escape hatch for
// when a required is unwanted for some unexpected reason.
const Omit forceOmit = -1
// SetExtraFields adds extra fields to the JSON object.
//
// SetExtraFields will override any existing fields with the same key.
// For security reasons, ensure this is only used with trusted input data.
//
// To intentionally omit a required field, use [Omit].
//
// foo.SetExtraFields(map[string]any{"bar": Omit})
//
// If the struct already contains the field ExtraFields, then this
// method will have no effect.
func (m *metadata) SetExtraFields(extraFields map[string]any) {
m.any = metadataExtraFields(extraFields)
}
// extraFields aliases [metadata.ExtraFields] to avoid name collisions.
func (m metadata) extraFields() map[string]any { return m.ExtraFields() }
func (m metadata) null() bool {
if _, ok := m.any.(metadataNull); ok {
return true
}
if msg, ok := m.any.(json.RawMessage); ok {
return string(msg) == "null"
}
return false
}
type metadata struct{ any }
type metadataNull struct{}
type metadataExtraFields map[string]any
func (m *metadata) setMetadata(override any) {
if override == nil {
m.any = metadataNull{}
return
}
m.any = override
}