From c3287a517da3be0ac4beb14284163ad5702a79e0 Mon Sep 17 00:00:00 2001 From: "ark-hand[bot]" Date: Tue, 3 Nov 2026 06:07:52 +0000 Subject: [PATCH] chore: sync from ark-apis 593e5d2797 Auto-generated SDK sync from ark-apis at 593e5d2797988920a10e575157f8e2a5db420fc6. Generated files are overwritten by the sync pipeline and should not be edited by hand. Sync-Source-Commit: 0540c7082c4e6fd8e1aa5c7e7957292a5ee30349 Ark-APIs-Commit: 593e5d2797988920a10e575157f8e2a5db420fc6 Release-Version: 0.19.0 --- VERSION | 2 +- arkruntime/agents.go | 13 + arkruntime/ark_apis_agent_archive_test.go | 80 ++ .../ark_apis_environment_archive_test.go | 79 ++ arkruntime/ark_apis_session_archive_test.go | 81 ++ arkruntime/environments.go | 13 + .../agent/multiagent_contract_shim_test.go | 3 + arkruntime/model/agent/oas_json_gen.go | 689 ++++++++++++++++-- arkruntime/model/agent/oas_parameters_gen.go | 8 + arkruntime/model/agent/oas_schemas_gen.go | 449 ++++++++++-- arkruntime/model/agent/oas_validators_gen.go | 230 ++++++ arkruntime/model/environment/oas_json_gen.go | 47 +- .../model/environment/oas_parameters_gen.go | 8 + .../model/environment/oas_schemas_gen.go | 12 + arkruntime/model/session/oas_json_gen.go | 602 ++++++++++++++- .../model/session/oas_parameters_gen.go | 10 + arkruntime/model/session/oas_schemas_gen.go | 371 +++++++++- .../model/session/oas_validators_gen.go | 195 +++++ arkruntime/sessions.go | 13 + 19 files changed, 2768 insertions(+), 137 deletions(-) create mode 100644 arkruntime/ark_apis_agent_archive_test.go create mode 100644 arkruntime/ark_apis_environment_archive_test.go create mode 100644 arkruntime/ark_apis_session_archive_test.go diff --git a/VERSION b/VERSION index 6633391..1cf0537 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.18.0 +0.19.0 diff --git a/arkruntime/agents.go b/arkruntime/agents.go index 86fa75c..8a22191 100644 --- a/arkruntime/agents.go +++ b/arkruntime/agents.go @@ -45,6 +45,19 @@ func (c *Client) GetAgent(ctx context.Context, agentID string, setters ...reques return &wrap.Agent, nil } +func (c *Client) ArchiveAgent(ctx context.Context, agentID string, setters ...requestOption) (*agent.Agent, error) { + if agentID == "" { + return nil, errors.New("missing required agent_id") + } + u := c.fullURL(fmt.Sprintf("%s/%s/archive", agentsPrefix, agent.PathEscape(agentID))) + opts := append(setters, withBody(nil)) + wrap := &agent.AgentResponse{} + if err := c.Do(ctx, http.MethodPost, u, "", "", wrap, opts...); err != nil { + return nil, err + } + return &wrap.Agent, nil +} + // ListAgents lists Agents with optional query filters. func (c *Client) ListAgents( ctx context.Context, diff --git a/arkruntime/ark_apis_agent_archive_test.go b/arkruntime/ark_apis_agent_archive_test.go new file mode 100644 index 0000000..8c3adc2 --- /dev/null +++ b/arkruntime/ark_apis_agent_archive_test.go @@ -0,0 +1,80 @@ +// Copyright (c) 2026 ByteDance Ltd. and/or its affiliates. +// SPDX-License-Identifier: Apache-2.0 + +package arkruntime + +import ( + "context" + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "testing" + + "github.com/volcengine/ark-runtime-go/arkruntime/model/agent" +) + +func TestArkApisAgentArchive(t *testing.T) { + const resourceID = "resource/1" + const archivedAt = "2026-10-29T00:00:00Z" + var query string + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + body, _ := io.ReadAll(r.Body) + if len(body) != 0 { + t.Errorf("expected no request body, got %s", body) + } + if r.Method == http.MethodPost { + if r.URL.EscapedPath() != "/agents/resource%2F1/archive" { + t.Errorf("path: %s", r.URL.EscapedPath()) + } + // Build synthetic response data explicitly, independently of SDK codecs. + response := map[string]interface{}{ + "id": resourceID, + "type": "agent", + "archived_at": archivedAt, + "created_at": archivedAt, + "updated_at": archivedAt, + "name": "archive test", + "version": 1, + } + if err := json.NewEncoder(w).Encode(response); err != nil { + t.Error(err) + } + } else { + if r.Method != http.MethodGet || r.URL.Path != "/agents" { + t.Errorf("unexpected list request: %s %s", r.Method, r.URL) + } + query = r.URL.Query().Get("include_archived") + io.WriteString(w, `{"data": [], "total": 0}`) + } + })) + defer server.Close() + client := NewClientWithApiKey("test", WithBaseUrl(server.URL)) + result, err := client.ArchiveAgent(context.Background(), resourceID) + if err != nil { + t.Fatal(err) + } + if result.ID != resourceID || result.ArchivedAt.Value != archivedAt { + t.Fatalf("result: %+v", result) + } + if _, err := client.ArchiveAgent(context.Background(), ""); err == nil { + t.Fatal("missing ID accepted") + } + for _, tc := range []struct { + params *agent.AgentsListParams + want string + }{ + {nil, ""}, + {&agent.AgentsListParams{}, ""}, + {&agent.AgentsListParams{IncludeArchived: agent.NewOptBool(false)}, "false"}, + {&agent.AgentsListParams{IncludeArchived: agent.NewOptBool(true)}, "true"}, + } { + if _, err := client.ListAgents(context.Background(), tc.params); err != nil { + t.Fatal(err) + } + if query != tc.want { + t.Fatalf("query: %q; want %q", query, tc.want) + } + } +} diff --git a/arkruntime/ark_apis_environment_archive_test.go b/arkruntime/ark_apis_environment_archive_test.go new file mode 100644 index 0000000..9ad9ce2 --- /dev/null +++ b/arkruntime/ark_apis_environment_archive_test.go @@ -0,0 +1,79 @@ +// Copyright (c) 2026 ByteDance Ltd. and/or its affiliates. +// SPDX-License-Identifier: Apache-2.0 + +package arkruntime + +import ( + "context" + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "testing" + + "github.com/volcengine/ark-runtime-go/arkruntime/model/environment" +) + +func TestArkApisEnvironmentArchive(t *testing.T) { + const resourceID = "resource/1" + const archivedAt = "2026-10-29T00:00:00Z" + var query string + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + body, _ := io.ReadAll(r.Body) + if len(body) != 0 { + t.Errorf("expected no request body, got %s", body) + } + if r.Method == http.MethodPost { + if r.URL.EscapedPath() != "/environments/resource%2F1/archive" { + t.Errorf("path: %s", r.URL.EscapedPath()) + } + // Build synthetic response data explicitly, independently of SDK codecs. + response := map[string]interface{}{ + "id": resourceID, + "type": "environment", + "archived_at": archivedAt, + "created_at": archivedAt, + "updated_at": archivedAt, + "name": "archive test", + } + if err := json.NewEncoder(w).Encode(response); err != nil { + t.Error(err) + } + } else { + if r.Method != http.MethodGet || r.URL.Path != "/environments" { + t.Errorf("unexpected list request: %s %s", r.Method, r.URL) + } + query = r.URL.Query().Get("include_archived") + io.WriteString(w, `{"data": []}`) + } + })) + defer server.Close() + client := NewClientWithApiKey("test", WithBaseUrl(server.URL)) + result, err := client.ArchiveEnvironment(context.Background(), resourceID) + if err != nil { + t.Fatal(err) + } + if result.ID != resourceID || result.ArchivedAt.Value != archivedAt { + t.Fatalf("result: %+v", result) + } + if _, err := client.ArchiveEnvironment(context.Background(), ""); err == nil { + t.Fatal("missing ID accepted") + } + for _, tc := range []struct { + params *environment.EnvironmentsListParams + want string + }{ + {nil, ""}, + {&environment.EnvironmentsListParams{}, ""}, + {&environment.EnvironmentsListParams{IncludeArchived: environment.NewOptBool(false)}, "false"}, + {&environment.EnvironmentsListParams{IncludeArchived: environment.NewOptBool(true)}, "true"}, + } { + if _, err := client.ListEnvironments(context.Background(), tc.params); err != nil { + t.Fatal(err) + } + if query != tc.want { + t.Fatalf("query: %q; want %q", query, tc.want) + } + } +} diff --git a/arkruntime/ark_apis_session_archive_test.go b/arkruntime/ark_apis_session_archive_test.go new file mode 100644 index 0000000..45c0b5b --- /dev/null +++ b/arkruntime/ark_apis_session_archive_test.go @@ -0,0 +1,81 @@ +// Copyright (c) 2026 ByteDance Ltd. and/or its affiliates. +// SPDX-License-Identifier: Apache-2.0 + +package arkruntime + +import ( + "context" + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "testing" + + "github.com/volcengine/ark-runtime-go/arkruntime/model/session" +) + +func TestArkApisSessionArchive(t *testing.T) { + const resourceID = "resource/1" + const archivedAt = "2026-10-29T00:00:00Z" + var query string + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + body, _ := io.ReadAll(r.Body) + if len(body) != 0 { + t.Errorf("expected no request body, got %s", body) + } + if r.Method == http.MethodPost { + if r.URL.EscapedPath() != "/sessions/resource%2F1/archive" { + t.Errorf("path: %s", r.URL.EscapedPath()) + } + // Build synthetic response data explicitly, independently of SDK codecs. + response := map[string]interface{}{ + "id": resourceID, + "type": "session", + "archived_at": archivedAt, + "created_at": archivedAt, + "updated_at": archivedAt, + "status": "terminated", + "environment_id": "env-1", + "agent": map[string]interface{}{}, + } + if err := json.NewEncoder(w).Encode(response); err != nil { + t.Error(err) + } + } else { + if r.Method != http.MethodGet || r.URL.Path != "/sessions" { + t.Errorf("unexpected list request: %s %s", r.Method, r.URL) + } + query = r.URL.Query().Get("include_archived") + io.WriteString(w, `{"data": []}`) + } + })) + defer server.Close() + client := NewClientWithApiKey("test", WithBaseUrl(server.URL)) + result, err := client.ArchiveSession(context.Background(), resourceID) + if err != nil { + t.Fatal(err) + } + if result.ID != resourceID || result.ArchivedAt.Value != archivedAt { + t.Fatalf("result: %+v", result) + } + if _, err := client.ArchiveSession(context.Background(), ""); err == nil { + t.Fatal("missing ID accepted") + } + for _, tc := range []struct { + params *session.SessionsListParams + want string + }{ + {nil, ""}, + {&session.SessionsListParams{}, ""}, + {&session.SessionsListParams{IncludeArchived: session.NewOptBool(false)}, "false"}, + {&session.SessionsListParams{IncludeArchived: session.NewOptBool(true)}, "true"}, + } { + if _, err := client.ListSessions(context.Background(), tc.params); err != nil { + t.Fatal(err) + } + if query != tc.want { + t.Fatalf("query: %q; want %q", query, tc.want) + } + } +} diff --git a/arkruntime/environments.go b/arkruntime/environments.go index a3a5ada..226b9fc 100644 --- a/arkruntime/environments.go +++ b/arkruntime/environments.go @@ -49,6 +49,19 @@ func (c *Client) GetEnvironment( return &wrap.Environment, nil } +func (c *Client) ArchiveEnvironment(ctx context.Context, environmentID string, setters ...requestOption) (*environment.Environment, error) { + if environmentID == "" { + return nil, errors.New("missing required environment_id") + } + u := c.fullURL(fmt.Sprintf("%s/%s/archive", environmentsPrefix, environment.PathEscape(environmentID))) + opts := append(setters, withBody(nil)) + wrap := &environment.EnvironmentResponse{} + if err := c.Do(ctx, http.MethodPost, u, "", "", wrap, opts...); err != nil { + return nil, err + } + return &wrap.Environment, nil +} + // ListEnvironments lists Environments with optional query filters. func (c *Client) ListEnvironments( ctx context.Context, diff --git a/arkruntime/model/agent/multiagent_contract_shim_test.go b/arkruntime/model/agent/multiagent_contract_shim_test.go index 3a6c043..24bd10a 100644 --- a/arkruntime/model/agent/multiagent_contract_shim_test.go +++ b/arkruntime/model/agent/multiagent_contract_shim_test.go @@ -1,3 +1,6 @@ +// Copyright (c) 2026 ByteDance Ltd. and/or its affiliates. +// SPDX-License-Identifier: Apache-2.0 + package agent import ( diff --git a/arkruntime/model/agent/oas_json_gen.go b/arkruntime/model/agent/oas_json_gen.go index 5e5d0cc..6d50765 100644 --- a/arkruntime/model/agent/oas_json_gen.go +++ b/arkruntime/model/agent/oas_json_gen.go @@ -115,6 +115,18 @@ func (s *Agent) encodeFields(e *jx.Encoder) { s.DisplayName.Encode(e) } } + { + if s.ContextManagement != nil { + e.FieldStart("context_management") + s.ContextManagement.Encode(e) + } + } + { + if s.ArchivedAt.Set { + e.FieldStart("archived_at") + s.ArchivedAt.Encode(e) + } + } { e.FieldStart("created_at") e.Str(s.CreatedAt) @@ -125,7 +137,7 @@ func (s *Agent) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfAgent = [16]string{ +var jsonFieldsNameOfAgent = [18]string{ 0: "id", 1: "type", 2: "name", @@ -140,8 +152,10 @@ var jsonFieldsNameOfAgent = [16]string{ 11: "metadata", 12: "tags", 13: "display_name", - 14: "created_at", - 15: "updated_at", + 14: "context_management", + 15: "archived_at", + 16: "created_at", + 17: "updated_at", } // Decode decodes Agent from json. @@ -149,7 +163,7 @@ func (s *Agent) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode Agent to nil") } - var requiredBitSet [2]uint8 + var requiredBitSet [3]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { @@ -327,8 +341,27 @@ func (s *Agent) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"display_name\"") } + case "context_management": + if err := func() error { + if err := s.ContextManagement.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"context_management\"") + } + case "archived_at": + if err := func() error { + s.ArchivedAt.Reset() + if err := s.ArchivedAt.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"archived_at\"") + } case "created_at": - requiredBitSet[1] |= 1 << 6 + requiredBitSet[2] |= 1 << 0 if err := func() error { v, err := d.Str() s.CreatedAt = string(v) @@ -340,7 +373,7 @@ func (s *Agent) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"created_at\"") } case "updated_at": - requiredBitSet[1] |= 1 << 7 + requiredBitSet[2] |= 1 << 1 if err := func() error { v, err := d.Str() s.UpdatedAt = string(v) @@ -360,9 +393,10 @@ func (s *Agent) Decode(d *jx.Decoder) error { } // Validate required fields. var failures []validate.FieldError - for i, mask := range [2]uint8{ + for i, mask := range [3]uint8{ 0b00010111, - 0b11000000, + 0b00000000, + 0b00000011, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. @@ -543,6 +577,12 @@ func (s *AgentRef) encodeFields(e *jx.Encoder) { e.ArrEnd() } } + { + if s.ContextManagement != nil { + e.FieldStart("context_management") + s.ContextManagement.Encode(e) + } + } { if s.DisplayName.Set { e.FieldStart("display_name") @@ -551,7 +591,7 @@ func (s *AgentRef) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfAgentRef = [11]string{ +var jsonFieldsNameOfAgentRef = [12]string{ 0: "type", 1: "id", 2: "version", @@ -562,7 +602,8 @@ var jsonFieldsNameOfAgentRef = [11]string{ 7: "tools", 8: "mcp_servers", 9: "skills", - 10: "display_name", + 10: "context_management", + 11: "display_name", } // Decode decodes AgentRef from json. @@ -695,6 +736,15 @@ func (s *AgentRef) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"skills\"") } + case "context_management": + if err := func() error { + if err := s.ContextManagement.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"context_management\"") + } case "display_name": if err := func() error { s.DisplayName.Reset() @@ -985,6 +1035,362 @@ func (s *AgentType) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes CompactThreshold as json. +func (s CompactThreshold) Encode(e *jx.Encoder) { + unwrapped := int64(s) + + e.Int64(unwrapped) +} + +// Decode decodes CompactThreshold from json. +func (s *CompactThreshold) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CompactThreshold to nil") + } + var unwrapped int64 + if err := func() error { + v, err := d.Int64() + unwrapped = int64(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = CompactThreshold(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s CompactThreshold) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CompactThreshold) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes ContextManagementInstructions as json. +func (s ContextManagementInstructions) Encode(e *jx.Encoder) { + unwrapped := string(s) + + e.Str(unwrapped) +} + +// Decode decodes ContextManagementInstructions from json. +func (s *ContextManagementInstructions) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ContextManagementInstructions to nil") + } + var unwrapped string + if err := func() error { + v, err := d.Str() + unwrapped = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = ContextManagementInstructions(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s ContextManagementInstructions) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ContextManagementInstructions) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes ContextManagementPolicies as json. +func (s ContextManagementPolicies) Encode(e *jx.Encoder) { + unwrapped := []ContextManagementPolicy(s) + if unwrapped == nil { + e.ArrEmpty() + return + } + if unwrapped != nil { + e.ArrStart() + for _, elem := range unwrapped { + elem.Encode(e) + } + e.ArrEnd() + } +} + +// Decode decodes ContextManagementPolicies from json. +func (s *ContextManagementPolicies) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ContextManagementPolicies to nil") + } + var unwrapped []ContextManagementPolicy + if err := func() error { + unwrapped = make([]ContextManagementPolicy, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem ContextManagementPolicy + if err := elem.Decode(d); err != nil { + return err + } + unwrapped = append(unwrapped, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = ContextManagementPolicies(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s ContextManagementPolicies) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ContextManagementPolicies) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes ContextManagementPoliciesItem as json. +func (s ContextManagementPoliciesItem) Encode(e *jx.Encoder) { + unwrapped := []ContextManagementPolicy(s) + if unwrapped == nil { + e.ArrEmpty() + return + } + if unwrapped != nil { + e.ArrStart() + for _, elem := range unwrapped { + elem.Encode(e) + } + e.ArrEnd() + } +} + +// Decode decodes ContextManagementPoliciesItem from json. +func (s *ContextManagementPoliciesItem) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ContextManagementPoliciesItem to nil") + } + var unwrapped []ContextManagementPolicy + if err := func() error { + unwrapped = make([]ContextManagementPolicy, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem ContextManagementPolicy + if err := elem.Decode(d); err != nil { + return err + } + unwrapped = append(unwrapped, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = ContextManagementPoliciesItem(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s ContextManagementPoliciesItem) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ContextManagementPoliciesItem) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *ContextManagementPolicy) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *ContextManagementPolicy) encodeFields(e *jx.Encoder) { + { + e.FieldStart("type") + s.Type.Encode(e) + } + { + if s.CompactThreshold.Set { + e.FieldStart("compact_threshold") + s.CompactThreshold.Encode(e) + } + } + { + if s.Instructions.Set { + e.FieldStart("instructions") + s.Instructions.Encode(e) + } + } +} + +var jsonFieldsNameOfContextManagementPolicy = [3]string{ + 0: "type", + 1: "compact_threshold", + 2: "instructions", +} + +// Decode decodes ContextManagementPolicy from json. +func (s *ContextManagementPolicy) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ContextManagementPolicy to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "type": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + if err := s.Type.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"type\"") + } + case "compact_threshold": + if err := func() error { + s.CompactThreshold.Reset() + if err := s.CompactThreshold.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"compact_threshold\"") + } + case "instructions": + if err := func() error { + s.Instructions.Reset() + if err := s.Instructions.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"instructions\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode ContextManagementPolicy") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfContextManagementPolicy) { + name = jsonFieldsNameOfContextManagementPolicy[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *ContextManagementPolicy) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ContextManagementPolicy) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes ContextManagementType as json. +func (s ContextManagementType) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes ContextManagementType from json. +func (s *ContextManagementType) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ContextManagementType to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch ContextManagementType(v) { + case ContextManagementTypeCompaction: + *s = ContextManagementTypeCompaction + default: + *s = ContextManagementType(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s ContextManagementType) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ContextManagementType) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode implements json.Marshaler. func (s *CreateAgentRequest) Encode(e *jx.Encoder) { e.ObjStart() @@ -1072,9 +1478,15 @@ func (s *CreateAgentRequest) encodeFields(e *jx.Encoder) { e.ArrEnd() } } + { + if s.ContextManagement.Set { + e.FieldStart("context_management") + s.ContextManagement.Encode(e) + } + } } -var jsonFieldsNameOfCreateAgentRequest = [11]string{ +var jsonFieldsNameOfCreateAgentRequest = [12]string{ 0: "name", 1: "model", 2: "description", @@ -1086,6 +1498,7 @@ var jsonFieldsNameOfCreateAgentRequest = [11]string{ 8: "multiagent", 9: "metadata", 10: "tags", + 11: "context_management", } // Decode decodes CreateAgentRequest from json. @@ -1237,6 +1650,16 @@ func (s *CreateAgentRequest) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"tags\"") } + case "context_management": + if err := func() error { + s.ContextManagement.Reset() + if err := s.ContextManagement.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"context_management\"") + } default: return d.Skip() } @@ -2659,11 +3082,16 @@ func (s *MultiagentPatch) Decode(d *jx.Decoder) error { }); err != nil { return errors.Wrap(err, "decode MultiagentPatch") } + // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000001, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) @@ -2678,6 +3106,7 @@ func (s *MultiagentPatch) Decode(d *jx.Decoder) error { Name: name, Error: validate.ErrFieldRequired, }) + // Reset bit. result &^= 1 << bitIdx } } @@ -3243,8 +3672,41 @@ func (s *OptMultiagentConfig) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes MultiagentPatch as json. -func (o OptMultiagentPatch) Encode(e *jx.Encoder) { +// Encode encodes MultiagentSubagentsConfig as json. +func (o OptMultiagentSubagentsConfig) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes MultiagentSubagentsConfig from json. +func (o *OptMultiagentSubagentsConfig) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptMultiagentSubagentsConfig to nil") + } + o.Set = true + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptMultiagentSubagentsConfig) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptMultiagentSubagentsConfig) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes []AgentRef as json. +func (o OptNilAgentRefArray) Encode(e *jx.Encoder) { if !o.Set { return } @@ -3252,20 +3714,24 @@ func (o OptMultiagentPatch) Encode(e *jx.Encoder) { e.Null() return } - o.Value.Encode(e) + e.ArrStart() + for _, elem := range o.Value { + elem.Encode(e) + } + e.ArrEnd() } -// Decode decodes MultiagentPatch from json. -func (o *OptMultiagentPatch) Decode(d *jx.Decoder) error { +// Decode decodes []AgentRef from json. +func (o *OptNilAgentRefArray) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptMultiagentPatch to nil") + return errors.New("invalid: unable to decode OptNilAgentRefArray to nil") } if d.Next() == jx.Null { if err := d.Null(); err != nil { return err } - var v MultiagentPatch + var v []AgentRef o.Value = v o.Set = true o.Null = true @@ -3273,39 +3739,63 @@ func (o *OptMultiagentPatch) Decode(d *jx.Decoder) error { } o.Set = true o.Null = false - if err := o.Value.Decode(d); err != nil { + o.Value = make([]AgentRef, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem AgentRef + if err := elem.Decode(d); err != nil { + return err + } + o.Value = append(o.Value, elem) + return nil + }); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptMultiagentPatch) MarshalJSON() ([]byte, error) { +func (s OptNilAgentRefArray) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptMultiagentPatch) UnmarshalJSON(data []byte) error { +func (s *OptNilAgentRefArray) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes MultiagentSubagentsConfig as json. -func (o OptMultiagentSubagentsConfig) Encode(e *jx.Encoder) { +// Encode encodes CompactThreshold as json. +func (o OptNilCompactThreshold) Encode(e *jx.Encoder) { if !o.Set { return } + if o.Null { + e.Null() + return + } o.Value.Encode(e) } -// Decode decodes MultiagentSubagentsConfig from json. -func (o *OptMultiagentSubagentsConfig) Decode(d *jx.Decoder) error { +// Decode decodes CompactThreshold from json. +func (o *OptNilCompactThreshold) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptMultiagentSubagentsConfig to nil") + return errors.New("invalid: unable to decode OptNilCompactThreshold to nil") + } + if d.Next() == jx.Null { + if err := d.Null(); err != nil { + return err + } + + var v CompactThreshold + o.Value = v + o.Set = true + o.Null = true + return nil } o.Set = true + o.Null = false if err := o.Value.Decode(d); err != nil { return err } @@ -3313,20 +3803,20 @@ func (o *OptMultiagentSubagentsConfig) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OptMultiagentSubagentsConfig) MarshalJSON() ([]byte, error) { +func (s OptNilCompactThreshold) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptMultiagentSubagentsConfig) UnmarshalJSON(data []byte) error { +func (s *OptNilCompactThreshold) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes []AgentRef as json. -func (o OptNilAgentRefArray) Encode(e *jx.Encoder) { +// Encode encodes ContextManagementInstructions as json. +func (o OptNilContextManagementInstructions) Encode(e *jx.Encoder) { if !o.Set { return } @@ -3334,24 +3824,20 @@ func (o OptNilAgentRefArray) Encode(e *jx.Encoder) { e.Null() return } - e.ArrStart() - for _, elem := range o.Value { - elem.Encode(e) - } - e.ArrEnd() + o.Value.Encode(e) } -// Decode decodes []AgentRef from json. -func (o *OptNilAgentRefArray) Decode(d *jx.Decoder) error { +// Decode decodes ContextManagementInstructions from json. +func (o *OptNilContextManagementInstructions) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptNilAgentRefArray to nil") + return errors.New("invalid: unable to decode OptNilContextManagementInstructions to nil") } if d.Next() == jx.Null { if err := d.Null(); err != nil { return err } - var v []AgentRef + var v ContextManagementInstructions o.Value = v o.Set = true o.Null = true @@ -3359,29 +3845,70 @@ func (o *OptNilAgentRefArray) Decode(d *jx.Decoder) error { } o.Set = true o.Null = false - o.Value = make([]AgentRef, 0) - if err := d.Arr(func(d *jx.Decoder) error { - var elem AgentRef - if err := elem.Decode(d); err != nil { + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptNilContextManagementInstructions) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptNilContextManagementInstructions) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes ContextManagementPolicies as json. +func (o OptNilContextManagementPolicies) Encode(e *jx.Encoder) { + if !o.Set { + return + } + if o.Null { + e.Null() + return + } + o.Value.Encode(e) +} + +// Decode decodes ContextManagementPolicies from json. +func (o *OptNilContextManagementPolicies) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptNilContextManagementPolicies to nil") + } + if d.Next() == jx.Null { + if err := d.Null(); err != nil { return err } - o.Value = append(o.Value, elem) + + var v ContextManagementPolicies + o.Value = v + o.Set = true + o.Null = true return nil - }); err != nil { + } + o.Set = true + o.Null = false + if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptNilAgentRefArray) MarshalJSON() ([]byte, error) { +func (s OptNilContextManagementPolicies) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptNilAgentRefArray) UnmarshalJSON(data []byte) error { +func (s *OptNilContextManagementPolicies) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } @@ -3435,6 +3962,55 @@ func (s *OptNilMultiagentInlineAgentsConfig) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes MultiagentPatch as json. +func (o OptNilMultiagentPatch) Encode(e *jx.Encoder) { + if !o.Set { + return + } + if o.Null { + e.Null() + return + } + o.Value.Encode(e) +} + +// Decode decodes MultiagentPatch from json. +func (o *OptNilMultiagentPatch) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptNilMultiagentPatch to nil") + } + if d.Next() == jx.Null { + if err := d.Null(); err != nil { + return err + } + + var v MultiagentPatch + o.Value = v + o.Set = true + o.Null = true + return nil + } + o.Set = true + o.Null = false + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptNilMultiagentPatch) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptNilMultiagentPatch) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes MultiagentSubagentsConfig as json. func (o OptNilMultiagentSubagentsConfig) Encode(e *jx.Encoder) { if !o.Set { @@ -4552,9 +5128,15 @@ func (s *UpdateAgentRequest) encodeFields(e *jx.Encoder) { e.ArrEnd() } } + { + if s.ContextManagement.Set { + e.FieldStart("context_management") + s.ContextManagement.Encode(e) + } + } } -var jsonFieldsNameOfUpdateAgentRequest = [12]string{ +var jsonFieldsNameOfUpdateAgentRequest = [13]string{ 0: "version", 1: "name", 2: "display_name", @@ -4567,6 +5149,7 @@ var jsonFieldsNameOfUpdateAgentRequest = [12]string{ 9: "multiagent", 10: "metadata", 11: "tags", + 12: "context_management", } // Decode decodes UpdateAgentRequest from json. @@ -4728,6 +5311,16 @@ func (s *UpdateAgentRequest) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"tags\"") } + case "context_management": + if err := func() error { + s.ContextManagement.Reset() + if err := s.ContextManagement.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"context_management\"") + } default: return d.Skip() } diff --git a/arkruntime/model/agent/oas_parameters_gen.go b/arkruntime/model/agent/oas_parameters_gen.go index f640ee0..184d0d9 100644 --- a/arkruntime/model/agent/oas_parameters_gen.go +++ b/arkruntime/model/agent/oas_parameters_gen.go @@ -5,8 +5,16 @@ package agent +// AgentsArchiveParams is parameters of Agents_archive operation. +type AgentsArchiveParams struct { + AgentId string +} + // AgentsListParams is parameters of Agents_list operation. type AgentsListParams struct { + // 是否包含已归档资源。省略或 false 时排除已归档,true + // 时同时返回未归档与已归档资源。. + IncludeArchived OptBool `json:",omitempty,omitzero" query:"include_archived"` // 单页最大条数。. Limit OptInt32 `json:",omitempty,omitzero" query:"limit"` // 数字页码,从 1 开始;首页可留空。. diff --git a/arkruntime/model/agent/oas_schemas_gen.go b/arkruntime/model/agent/oas_schemas_gen.go index ac39b20..b96f78b 100644 --- a/arkruntime/model/agent/oas_schemas_gen.go +++ b/arkruntime/model/agent/oas_schemas_gen.go @@ -42,6 +42,10 @@ type Agent struct { Tags []Tag `json:"tags"` // 展示名。. DisplayName OptString `json:"display_name"` + // 上下文管理策略。服务端可能在公开响应中补展示默认;该默认不代表用户已显式配置。. + ContextManagement ContextManagementPolicies `json:"context_management"` + // 首次归档时间(RFC 3339),只读;未归档时省略。归档作用于资源 ID。. + ArchivedAt OptString `json:"archived_at"` // RFC 3339 时间。. CreatedAt string `json:"created_at"` // RFC 3339 时间。. @@ -118,6 +122,16 @@ func (s *Agent) GetDisplayName() OptString { return s.DisplayName } +// GetContextManagement returns the value of ContextManagement. +func (s *Agent) GetContextManagement() ContextManagementPolicies { + return s.ContextManagement +} + +// GetArchivedAt returns the value of ArchivedAt. +func (s *Agent) GetArchivedAt() OptString { + return s.ArchivedAt +} + // GetCreatedAt returns the value of CreatedAt. func (s *Agent) GetCreatedAt() string { return s.CreatedAt @@ -198,6 +212,16 @@ func (s *Agent) SetDisplayName(val OptString) { s.DisplayName = val } +// SetContextManagement sets the value of ContextManagement. +func (s *Agent) SetContextManagement(val ContextManagementPolicies) { + s.ContextManagement = val +} + +// SetArchivedAt sets the value of ArchivedAt. +func (s *Agent) SetArchivedAt(val OptString) { + s.ArchivedAt = val +} + // SetCreatedAt sets the value of CreatedAt. func (s *Agent) SetCreatedAt(val string) { s.CreatedAt = val @@ -243,6 +267,8 @@ type AgentRef struct { McpServers []MCPServer `json:"mcp_servers"` // Session 响应中冻结的成员 Agent skills。. Skills []AgentSkillRef `json:"skills"` + // Session 响应中冻结的成员 Agent 上下文管理策略。. + ContextManagement ContextManagementPoliciesItem `json:"context_management"` // Session 响应中冻结的成员 Agent 展示名。. DisplayName OptString `json:"display_name"` } @@ -297,6 +323,11 @@ func (s *AgentRef) GetSkills() []AgentSkillRef { return s.Skills } +// GetContextManagement returns the value of ContextManagement. +func (s *AgentRef) GetContextManagement() ContextManagementPoliciesItem { + return s.ContextManagement +} + // GetDisplayName returns the value of DisplayName. func (s *AgentRef) GetDisplayName() OptString { return s.DisplayName @@ -352,6 +383,11 @@ func (s *AgentRef) SetSkills(val []AgentSkillRef) { s.Skills = val } +// SetContextManagement sets the value of ContextManagement. +func (s *AgentRef) SetContextManagement(val ContextManagementPoliciesItem) { + s.ContextManagement = val +} + // SetDisplayName sets the value of DisplayName. func (s *AgentRef) SetDisplayName(val OptString) { s.DisplayName = val @@ -488,7 +524,94 @@ func (s *AgentType) UnmarshalText(data []byte) error { } } -// 创建 Agent 的请求体。. +type CompactThreshold int64 + +type ContextManagementInstructions string + +type ContextManagementPolicies []ContextManagementPolicy + +type ContextManagementPoliciesItem []ContextManagementPolicy + +// Agent 上下文管理策略。当前最多配置一条 compaction 策略。. +// Ref: #/components/schemas/ContextManagementPolicy +type ContextManagementPolicy struct { + // 策略类型,当前固定为 `compaction`。. + Type ContextManagementType `json:"type"` + // 触发压缩的上下文 token 阈值;省略时由运行时使用默认值。. + CompactThreshold OptNilCompactThreshold `json:"compact_threshold"` + // 自定义摘要指令;省略时由运行时使用内置提示词。. + Instructions OptNilContextManagementInstructions `json:"instructions"` +} + +// GetType returns the value of Type. +func (s *ContextManagementPolicy) GetType() ContextManagementType { + return s.Type +} + +// GetCompactThreshold returns the value of CompactThreshold. +func (s *ContextManagementPolicy) GetCompactThreshold() OptNilCompactThreshold { + return s.CompactThreshold +} + +// GetInstructions returns the value of Instructions. +func (s *ContextManagementPolicy) GetInstructions() OptNilContextManagementInstructions { + return s.Instructions +} + +// SetType sets the value of Type. +func (s *ContextManagementPolicy) SetType(val ContextManagementType) { + s.Type = val +} + +// SetCompactThreshold sets the value of CompactThreshold. +func (s *ContextManagementPolicy) SetCompactThreshold(val OptNilCompactThreshold) { + s.CompactThreshold = val +} + +// SetInstructions sets the value of Instructions. +func (s *ContextManagementPolicy) SetInstructions(val OptNilContextManagementInstructions) { + s.Instructions = val +} + +// Agent 上下文管理策略类型。. +// Ref: #/components/schemas/ContextManagementType +type ContextManagementType string + +const ( + ContextManagementTypeCompaction ContextManagementType = "compaction" +) + +// AllValues returns all ContextManagementType values. +func (ContextManagementType) AllValues() []ContextManagementType { + return []ContextManagementType{ + ContextManagementTypeCompaction, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s ContextManagementType) MarshalText() ([]byte, error) { + switch s { + case ContextManagementTypeCompaction: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *ContextManagementType) UnmarshalText(data []byte) error { + switch ContextManagementType(data) { + case ContextManagementTypeCompaction: + *s = ContextManagementTypeCompaction + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + +// 创建 Agent 的请求体。 +// multiagent_20261001 必须携带非 null 的 subagents;该条件由服务端校验, +// 并通过 dependentSchemas 写入公开契约。. // Ref: #/components/schemas/CreateAgentRequest type CreateAgentRequest struct { // 人类可读名称。. @@ -513,6 +636,10 @@ type CreateAgentRequest struct { Metadata OptCreateAgentRequestMetadata `json:"metadata"` // 资源标签。. Tags []Tag `json:"tags"` + // 上下文管理策略,最多一条 compaction。省略、null 或 [] + // 均表示不配置自定义策略; + // SDK 不会自动填入服务端公开响应中的展示默认阈值。. + ContextManagement OptNilContextManagementPolicies `json:"context_management"` } // GetName returns the value of Name. @@ -570,6 +697,11 @@ func (s *CreateAgentRequest) GetTags() []Tag { return s.Tags } +// GetContextManagement returns the value of ContextManagement. +func (s *CreateAgentRequest) GetContextManagement() OptNilContextManagementPolicies { + return s.ContextManagement +} + // SetName sets the value of Name. func (s *CreateAgentRequest) SetName(val string) { s.Name = val @@ -625,6 +757,11 @@ func (s *CreateAgentRequest) SetTags(val []Tag) { s.Tags = val } +// SetContextManagement sets the value of ContextManagement. +func (s *CreateAgentRequest) SetContextManagement(val OptNilContextManagementPolicies) { + s.ContextManagement = val +} + // 用户自定义键值对元数据。. type CreateAgentRequestMetadata map[string]string @@ -1041,7 +1178,7 @@ type MultiagentConfig struct { // 拓扑类型。. Type MultiagentType `json:"type"` // Coordinator 的下属 Agent 数组,0–20 项;深度限制为 1。 - // `multiagent_20261001` 不支持该字段。. + // `multiagent_20261001` 不使用该字段;服务端响应仍可能回显 `[]`。. Agents []AgentRef `json:"agents"` // `multiagent_20261001` 的子代理配置。 // Create 时必须提供。该属性不接受显式 `null`。. @@ -1792,98 +1929,227 @@ func (o OptMultiagentConfig) Or(d MultiagentConfig) MultiagentConfig { return d } -// NewOptMultiagentPatch returns new OptMultiagentPatch with value set to v. -func NewOptMultiagentPatch(v MultiagentPatch) OptMultiagentPatch { - return OptMultiagentPatch{ +// NewOptMultiagentSubagentsConfig returns new OptMultiagentSubagentsConfig with value set to v. +func NewOptMultiagentSubagentsConfig(v MultiagentSubagentsConfig) OptMultiagentSubagentsConfig { + return OptMultiagentSubagentsConfig{ Value: v, Set: true, } } -// OptMultiagentPatch is optional MultiagentPatch. -type OptMultiagentPatch struct { - Value MultiagentPatch +// OptMultiagentSubagentsConfig is optional MultiagentSubagentsConfig. +type OptMultiagentSubagentsConfig struct { + Value MultiagentSubagentsConfig + Set bool +} + +// IsSet returns true if OptMultiagentSubagentsConfig was set. +func (o OptMultiagentSubagentsConfig) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptMultiagentSubagentsConfig) Reset() { + var v MultiagentSubagentsConfig + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptMultiagentSubagentsConfig) SetTo(v MultiagentSubagentsConfig) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptMultiagentSubagentsConfig) Get() (v MultiagentSubagentsConfig, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptMultiagentSubagentsConfig) Or(d MultiagentSubagentsConfig) MultiagentSubagentsConfig { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptNilAgentRefArray returns new OptNilAgentRefArray with value set to v. +func NewOptNilAgentRefArray(v []AgentRef) OptNilAgentRefArray { + return OptNilAgentRefArray{ + Value: v, + Set: true, + } +} + +// OptNilAgentRefArray is optional nullable []AgentRef. +type OptNilAgentRefArray struct { + Value []AgentRef Set bool Null bool } -// IsSet returns true if OptMultiagentPatch was set. -func (o OptMultiagentPatch) IsSet() bool { return o.Set } +// IsSet returns true if OptNilAgentRefArray was set. +func (o OptNilAgentRefArray) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptNilAgentRefArray) Reset() { + var v []AgentRef + o.Value = v + o.Set = false + o.Null = false +} + +// SetTo sets value to v. +func (o *OptNilAgentRefArray) SetTo(v []AgentRef) { + o.Set = true + o.Null = false + o.Value = v +} + +// IsNull returns true if value is Null. +func (o OptNilAgentRefArray) IsNull() bool { return o.Null } + +// SetToNull sets value to null. +func (o *OptNilAgentRefArray) SetToNull() { + o.Set = true + o.Null = true + var v []AgentRef + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptNilAgentRefArray) Get() (v []AgentRef, ok bool) { + if o.Null { + return v, false + } + if !o.Set { + return v, false + } + return o.Value, true +} -// IsNull returns true if MultiagentPatch is set to null. -func (o OptMultiagentPatch) IsNull() bool { return o.Null } +// Or returns value if set, or given parameter if does not. +func (o OptNilAgentRefArray) Or(d []AgentRef) []AgentRef { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptNilCompactThreshold returns new OptNilCompactThreshold with value set to v. +func NewOptNilCompactThreshold(v CompactThreshold) OptNilCompactThreshold { + return OptNilCompactThreshold{ + Value: v, + Set: true, + } +} + +// OptNilCompactThreshold is optional nullable CompactThreshold. +type OptNilCompactThreshold struct { + Value CompactThreshold + Set bool + Null bool +} + +// IsSet returns true if OptNilCompactThreshold was set. +func (o OptNilCompactThreshold) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptMultiagentPatch) Reset() { - var v MultiagentPatch +func (o *OptNilCompactThreshold) Reset() { + var v CompactThreshold o.Value = v o.Set = false o.Null = false } // SetTo sets value to v. -func (o *OptMultiagentPatch) SetTo(v MultiagentPatch) { +func (o *OptNilCompactThreshold) SetTo(v CompactThreshold) { o.Set = true o.Null = false o.Value = v } +// IsNull returns true if value is Null. +func (o OptNilCompactThreshold) IsNull() bool { return o.Null } + // SetToNull sets value to null. -func (o *OptMultiagentPatch) SetToNull() { - var v MultiagentPatch +func (o *OptNilCompactThreshold) SetToNull() { o.Set = true o.Null = true + var v CompactThreshold o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptMultiagentPatch) Get() (v MultiagentPatch, ok bool) { - if !o.Set || o.Null { +func (o OptNilCompactThreshold) Get() (v CompactThreshold, ok bool) { + if o.Null { + return v, false + } + if !o.Set { return v, false } return o.Value, true } // Or returns value if set, or given parameter if does not. -func (o OptMultiagentPatch) Or(d MultiagentPatch) MultiagentPatch { +func (o OptNilCompactThreshold) Or(d CompactThreshold) CompactThreshold { if v, ok := o.Get(); ok { return v } return d } -// NewOptMultiagentSubagentsConfig returns new OptMultiagentSubagentsConfig with value set to v. -func NewOptMultiagentSubagentsConfig(v MultiagentSubagentsConfig) OptMultiagentSubagentsConfig { - return OptMultiagentSubagentsConfig{ +// NewOptNilContextManagementInstructions returns new OptNilContextManagementInstructions with value set to v. +func NewOptNilContextManagementInstructions(v ContextManagementInstructions) OptNilContextManagementInstructions { + return OptNilContextManagementInstructions{ Value: v, Set: true, } } -// OptMultiagentSubagentsConfig is optional MultiagentSubagentsConfig. -type OptMultiagentSubagentsConfig struct { - Value MultiagentSubagentsConfig +// OptNilContextManagementInstructions is optional nullable ContextManagementInstructions. +type OptNilContextManagementInstructions struct { + Value ContextManagementInstructions Set bool + Null bool } -// IsSet returns true if OptMultiagentSubagentsConfig was set. -func (o OptMultiagentSubagentsConfig) IsSet() bool { return o.Set } +// IsSet returns true if OptNilContextManagementInstructions was set. +func (o OptNilContextManagementInstructions) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptMultiagentSubagentsConfig) Reset() { - var v MultiagentSubagentsConfig +func (o *OptNilContextManagementInstructions) Reset() { + var v ContextManagementInstructions o.Value = v o.Set = false + o.Null = false } // SetTo sets value to v. -func (o *OptMultiagentSubagentsConfig) SetTo(v MultiagentSubagentsConfig) { +func (o *OptNilContextManagementInstructions) SetTo(v ContextManagementInstructions) { o.Set = true + o.Null = false + o.Value = v +} + +// IsNull returns true if value is Null. +func (o OptNilContextManagementInstructions) IsNull() bool { return o.Null } + +// SetToNull sets value to null. +func (o *OptNilContextManagementInstructions) SetToNull() { + o.Set = true + o.Null = true + var v ContextManagementInstructions o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptMultiagentSubagentsConfig) Get() (v MultiagentSubagentsConfig, ok bool) { +func (o OptNilContextManagementInstructions) Get() (v ContextManagementInstructions, ok bool) { + if o.Null { + return v, false + } if !o.Set { return v, false } @@ -1891,59 +2157,59 @@ func (o OptMultiagentSubagentsConfig) Get() (v MultiagentSubagentsConfig, ok boo } // Or returns value if set, or given parameter if does not. -func (o OptMultiagentSubagentsConfig) Or(d MultiagentSubagentsConfig) MultiagentSubagentsConfig { +func (o OptNilContextManagementInstructions) Or(d ContextManagementInstructions) ContextManagementInstructions { if v, ok := o.Get(); ok { return v } return d } -// NewOptNilAgentRefArray returns new OptNilAgentRefArray with value set to v. -func NewOptNilAgentRefArray(v []AgentRef) OptNilAgentRefArray { - return OptNilAgentRefArray{ +// NewOptNilContextManagementPolicies returns new OptNilContextManagementPolicies with value set to v. +func NewOptNilContextManagementPolicies(v ContextManagementPolicies) OptNilContextManagementPolicies { + return OptNilContextManagementPolicies{ Value: v, Set: true, } } -// OptNilAgentRefArray is optional nullable []AgentRef. -type OptNilAgentRefArray struct { - Value []AgentRef +// OptNilContextManagementPolicies is optional nullable ContextManagementPolicies. +type OptNilContextManagementPolicies struct { + Value ContextManagementPolicies Set bool Null bool } -// IsSet returns true if OptNilAgentRefArray was set. -func (o OptNilAgentRefArray) IsSet() bool { return o.Set } +// IsSet returns true if OptNilContextManagementPolicies was set. +func (o OptNilContextManagementPolicies) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilAgentRefArray) Reset() { - var v []AgentRef +func (o *OptNilContextManagementPolicies) Reset() { + var v ContextManagementPolicies o.Value = v o.Set = false o.Null = false } // SetTo sets value to v. -func (o *OptNilAgentRefArray) SetTo(v []AgentRef) { +func (o *OptNilContextManagementPolicies) SetTo(v ContextManagementPolicies) { o.Set = true o.Null = false o.Value = v } // IsNull returns true if value is Null. -func (o OptNilAgentRefArray) IsNull() bool { return o.Null } +func (o OptNilContextManagementPolicies) IsNull() bool { return o.Null } // SetToNull sets value to null. -func (o *OptNilAgentRefArray) SetToNull() { +func (o *OptNilContextManagementPolicies) SetToNull() { o.Set = true o.Null = true - var v []AgentRef + var v ContextManagementPolicies o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilAgentRefArray) Get() (v []AgentRef, ok bool) { +func (o OptNilContextManagementPolicies) Get() (v ContextManagementPolicies, ok bool) { if o.Null { return v, false } @@ -1954,7 +2220,7 @@ func (o OptNilAgentRefArray) Get() (v []AgentRef, ok bool) { } // Or returns value if set, or given parameter if does not. -func (o OptNilAgentRefArray) Or(d []AgentRef) []AgentRef { +func (o OptNilContextManagementPolicies) Or(d ContextManagementPolicies) ContextManagementPolicies { if v, ok := o.Get(); ok { return v } @@ -2024,6 +2290,69 @@ func (o OptNilMultiagentInlineAgentsConfig) Or(d MultiagentInlineAgentsConfig) M return d } +// NewOptNilMultiagentPatch returns new OptNilMultiagentPatch with value set to v. +func NewOptNilMultiagentPatch(v MultiagentPatch) OptNilMultiagentPatch { + return OptNilMultiagentPatch{ + Value: v, + Set: true, + } +} + +// OptNilMultiagentPatch is optional nullable MultiagentPatch. +type OptNilMultiagentPatch struct { + Value MultiagentPatch + Set bool + Null bool +} + +// IsSet returns true if OptNilMultiagentPatch was set. +func (o OptNilMultiagentPatch) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptNilMultiagentPatch) Reset() { + var v MultiagentPatch + o.Value = v + o.Set = false + o.Null = false +} + +// SetTo sets value to v. +func (o *OptNilMultiagentPatch) SetTo(v MultiagentPatch) { + o.Set = true + o.Null = false + o.Value = v +} + +// IsNull returns true if value is Null. +func (o OptNilMultiagentPatch) IsNull() bool { return o.Null } + +// SetToNull sets value to null. +func (o *OptNilMultiagentPatch) SetToNull() { + o.Set = true + o.Null = true + var v MultiagentPatch + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptNilMultiagentPatch) Get() (v MultiagentPatch, ok bool) { + if o.Null { + return v, false + } + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptNilMultiagentPatch) Or(d MultiagentPatch) MultiagentPatch { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptNilMultiagentSubagentsConfig returns new OptNilMultiagentSubagentsConfig with value set to v. func NewOptNilMultiagentSubagentsConfig(v MultiagentSubagentsConfig) OptNilMultiagentSubagentsConfig { return OptNilMultiagentSubagentsConfig{ @@ -2667,7 +2996,8 @@ func (s *ToolItem) SetInputSchema(val OptCustomToolInputSchema) { // 更新 Agent 的请求体。语义: // - 省略 = 保留 -// - 空字符串/null = 清空(仅 description / system / 数组类) +// - 空字符串/null = 清空(仅 description / system / 既有数组类;context_management 的 +// null 表示保留) // - `name` / `model` 不可清空 // - `metadata` 走 patch // - `mcp_servers` / `tools` / `skills` 整体替换 @@ -2704,11 +3034,14 @@ type UpdateAgentRequest struct { // 发送;不能表达时 // 必须使用 raw HTTP/request-body escape hatch。需要补齐的 typed patch API // 由各 SDK 独立交付,不在本契约 MR 中新增。. - Multiagent OptMultiagentPatch `json:"multiagent"` + Multiagent OptNilMultiagentPatch `json:"multiagent"` // 用户自定义键值对元数据(patch)。. Metadata OptUpdateAgentRequestMetadata `json:"metadata"` // 资源标签(整体替换)。. Tags []Tag `json:"tags"` + // 上下文管理策略(整体替换),最多一条 compaction。省略或 null 表示保留; + // 显式 [] 表示清除自定义策略,随后由运行时使用默认行为。. + ContextManagement OptNilContextManagementPolicies `json:"context_management"` } // GetVersion returns the value of Version. @@ -2757,7 +3090,7 @@ func (s *UpdateAgentRequest) GetSkills() []AgentSkillRef { } // GetMultiagent returns the value of Multiagent. -func (s *UpdateAgentRequest) GetMultiagent() OptMultiagentPatch { +func (s *UpdateAgentRequest) GetMultiagent() OptNilMultiagentPatch { return s.Multiagent } @@ -2771,6 +3104,11 @@ func (s *UpdateAgentRequest) GetTags() []Tag { return s.Tags } +// GetContextManagement returns the value of ContextManagement. +func (s *UpdateAgentRequest) GetContextManagement() OptNilContextManagementPolicies { + return s.ContextManagement +} + // SetVersion sets the value of Version. func (s *UpdateAgentRequest) SetVersion(val int32) { s.Version = val @@ -2817,7 +3155,7 @@ func (s *UpdateAgentRequest) SetSkills(val []AgentSkillRef) { } // SetMultiagent sets the value of Multiagent. -func (s *UpdateAgentRequest) SetMultiagent(val OptMultiagentPatch) { +func (s *UpdateAgentRequest) SetMultiagent(val OptNilMultiagentPatch) { s.Multiagent = val } @@ -2831,6 +3169,11 @@ func (s *UpdateAgentRequest) SetTags(val []Tag) { s.Tags = val } +// SetContextManagement sets the value of ContextManagement. +func (s *UpdateAgentRequest) SetContextManagement(val OptNilContextManagementPolicies) { + s.ContextManagement = val +} + // 用户自定义键值对元数据(patch)。. type UpdateAgentRequestMetadata map[string]string diff --git a/arkruntime/model/agent/oas_validators_gen.go b/arkruntime/model/agent/oas_validators_gen.go index c12cefd..e144340 100644 --- a/arkruntime/model/agent/oas_validators_gen.go +++ b/arkruntime/model/agent/oas_validators_gen.go @@ -140,6 +140,17 @@ func (s *Agent) Validate() error { Error: err, }) } + if err := func() error { + if err := s.ContextManagement.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "context_management", + Error: err, + }) + } if len(failures) > 0 { return &validate.Error{Fields: failures} } @@ -256,6 +267,17 @@ func (s *AgentRef) Validate() error { Error: err, }) } + if err := func() error { + if err := s.ContextManagement.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "context_management", + Error: err, + }) + } if len(failures) > 0 { return &validate.Error{Fields: failures} } @@ -305,6 +327,178 @@ func (s AgentType) Validate() error { } } +func (s CompactThreshold) Validate() error { + alias := (int64)(s) + if err := (validate.Int{ + MinSet: true, + Min: 50000, + MaxSet: false, + Max: 0, + MinExclusive: false, + MaxExclusive: false, + MultipleOfSet: false, + MultipleOf: 0, + Pattern: nil, + }).Validate(int64(alias)); err != nil { + return errors.Wrap(err, "int") + } + return nil +} + +func (s ContextManagementInstructions) Validate() error { + alias := (string)(s) + if err := (validate.String{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 100000, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(alias)); err != nil { + return errors.Wrap(err, "string") + } + return nil +} + +func (s ContextManagementPolicies) Validate() error { + alias := ([]ContextManagementPolicy)(s) + if alias == nil { + return nil // optional + } + if err := (validate.Array{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 1, + MaxLengthSet: true, + }).ValidateLength(len(alias)); err != nil { + return errors.Wrap(err, "array") + } + var failures []validate.FieldError + for i, elem := range alias { + if err := func() error { + if err := elem.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: fmt.Sprintf("[%d]", i), + Error: err, + }) + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s ContextManagementPoliciesItem) Validate() error { + alias := ([]ContextManagementPolicy)(s) + if alias == nil { + return nil // optional + } + if err := (validate.Array{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 1, + MaxLengthSet: true, + }).ValidateLength(len(alias)); err != nil { + return errors.Wrap(err, "array") + } + var failures []validate.FieldError + for i, elem := range alias { + if err := func() error { + if err := elem.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: fmt.Sprintf("[%d]", i), + Error: err, + }) + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *ContextManagementPolicy) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := s.Type.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "type", + Error: err, + }) + } + if err := func() error { + if value, ok := s.CompactThreshold.Get(); ok { + if err := func() error { + if err := value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "compact_threshold", + Error: err, + }) + } + if err := func() error { + if value, ok := s.Instructions.Get(); ok { + if err := func() error { + if err := value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "instructions", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s ContextManagementType) Validate() error { + switch s { + case "compaction": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + func (s *CreateAgentRequest) Validate() error { if s == nil { return validate.ErrNilPointer @@ -415,6 +609,24 @@ func (s *CreateAgentRequest) Validate() error { Error: err, }) } + if err := func() error { + if value, ok := s.ContextManagement.Get(); ok { + if err := func() error { + if err := value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "context_management", + Error: err, + }) + } if len(failures) > 0 { return &validate.Error{Fields: failures} } @@ -1066,6 +1278,24 @@ func (s *UpdateAgentRequest) Validate() error { Error: err, }) } + if err := func() error { + if value, ok := s.ContextManagement.Get(); ok { + if err := func() error { + if err := value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "context_management", + Error: err, + }) + } if len(failures) > 0 { return &validate.Error{Fields: failures} } diff --git a/arkruntime/model/environment/oas_json_gen.go b/arkruntime/model/environment/oas_json_gen.go index afcc108..a3bafd8 100644 --- a/arkruntime/model/environment/oas_json_gen.go +++ b/arkruntime/model/environment/oas_json_gen.go @@ -667,6 +667,12 @@ func (s *Environment) encodeFields(e *jx.Encoder) { s.Scope.Encode(e) } } + { + if s.ArchivedAt.Set { + e.FieldStart("archived_at") + s.ArchivedAt.Encode(e) + } + } { e.FieldStart("created_at") e.Str(s.CreatedAt) @@ -687,17 +693,18 @@ func (s *Environment) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfEnvironment = [10]string{ - 0: "id", - 1: "type", - 2: "name", - 3: "description", - 4: "config", - 5: "metadata", - 6: "scope", - 7: "created_at", - 8: "updated_at", - 9: "overridden_fields", +var jsonFieldsNameOfEnvironment = [11]string{ + 0: "id", + 1: "type", + 2: "name", + 3: "description", + 4: "config", + 5: "metadata", + 6: "scope", + 7: "archived_at", + 8: "created_at", + 9: "updated_at", + 10: "overridden_fields", } // Decode decodes Environment from json. @@ -783,8 +790,18 @@ func (s *Environment) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"scope\"") } + case "archived_at": + if err := func() error { + s.ArchivedAt.Reset() + if err := s.ArchivedAt.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"archived_at\"") + } case "created_at": - requiredBitSet[0] |= 1 << 7 + requiredBitSet[1] |= 1 << 0 if err := func() error { v, err := d.Str() s.CreatedAt = string(v) @@ -796,7 +813,7 @@ func (s *Environment) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"created_at\"") } case "updated_at": - requiredBitSet[1] |= 1 << 0 + requiredBitSet[1] |= 1 << 1 if err := func() error { v, err := d.Str() s.UpdatedAt = string(v) @@ -836,8 +853,8 @@ func (s *Environment) Decode(d *jx.Decoder) error { // Validate required fields. var failures []validate.FieldError for i, mask := range [2]uint8{ - 0b10000111, - 0b00000001, + 0b00000111, + 0b00000011, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. diff --git a/arkruntime/model/environment/oas_parameters_gen.go b/arkruntime/model/environment/oas_parameters_gen.go index ccdd33c..c83e2a6 100644 --- a/arkruntime/model/environment/oas_parameters_gen.go +++ b/arkruntime/model/environment/oas_parameters_gen.go @@ -48,8 +48,16 @@ type EnvironmentWorkStopParams struct { WorkId string } +// EnvironmentsArchiveParams is parameters of Environments_archive operation. +type EnvironmentsArchiveParams struct { + EnvironmentId string +} + // EnvironmentsListParams is parameters of Environments_list operation. type EnvironmentsListParams struct { + // 是否包含已归档资源。省略或 false 时排除已归档,true + // 时同时返回未归档与已归档资源。. + IncludeArchived OptBool `json:",omitempty,omitzero" query:"include_archived"` // 下一页 cursor(opaque)。从上一次响应的 `next_page` 中取。 // 首次请求可省略。. Page OptString `json:",omitempty,omitzero" query:"page"` diff --git a/arkruntime/model/environment/oas_schemas_gen.go b/arkruntime/model/environment/oas_schemas_gen.go index 339918f..bfd0137 100644 --- a/arkruntime/model/environment/oas_schemas_gen.go +++ b/arkruntime/model/environment/oas_schemas_gen.go @@ -264,6 +264,8 @@ type Environment struct { Metadata OptEnvironmentMetadata `json:"metadata"` // 一期未启用;仅协议占位。. Scope OptEnvironmentScope `json:"scope"` + // 首次归档时间(RFC 3339),只读;未归档时省略。归档作用于资源 ID。. + ArchivedAt OptString `json:"archived_at"` // RFC 3339 时间。. CreatedAt string `json:"created_at"` // RFC 3339 时间。. @@ -307,6 +309,11 @@ func (s *Environment) GetScope() OptEnvironmentScope { return s.Scope } +// GetArchivedAt returns the value of ArchivedAt. +func (s *Environment) GetArchivedAt() OptString { + return s.ArchivedAt +} + // GetCreatedAt returns the value of CreatedAt. func (s *Environment) GetCreatedAt() string { return s.CreatedAt @@ -357,6 +364,11 @@ func (s *Environment) SetScope(val OptEnvironmentScope) { s.Scope = val } +// SetArchivedAt sets the value of ArchivedAt. +func (s *Environment) SetArchivedAt(val OptString) { + s.ArchivedAt = val +} + // SetCreatedAt sets the value of CreatedAt. func (s *Environment) SetCreatedAt(val string) { s.CreatedAt = val diff --git a/arkruntime/model/session/oas_json_gen.go b/arkruntime/model/session/oas_json_gen.go index cd0e670..43e3a99 100644 --- a/arkruntime/model/session/oas_json_gen.go +++ b/arkruntime/model/session/oas_json_gen.go @@ -14,6 +14,302 @@ import ( "github.com/volcengine/ark-runtime-go/arkruntime/internal/validate" ) +// Encode encodes AgentCompactThreshold as json. +func (s AgentCompactThreshold) Encode(e *jx.Encoder) { + unwrapped := int64(s) + + e.Int64(unwrapped) +} + +// Decode decodes AgentCompactThreshold from json. +func (s *AgentCompactThreshold) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode AgentCompactThreshold to nil") + } + var unwrapped int64 + if err := func() error { + v, err := d.Int64() + unwrapped = int64(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = AgentCompactThreshold(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s AgentCompactThreshold) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *AgentCompactThreshold) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes AgentContextManagementInstructions as json. +func (s AgentContextManagementInstructions) Encode(e *jx.Encoder) { + unwrapped := string(s) + + e.Str(unwrapped) +} + +// Decode decodes AgentContextManagementInstructions from json. +func (s *AgentContextManagementInstructions) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode AgentContextManagementInstructions to nil") + } + var unwrapped string + if err := func() error { + v, err := d.Str() + unwrapped = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = AgentContextManagementInstructions(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s AgentContextManagementInstructions) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *AgentContextManagementInstructions) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes AgentContextManagementPolicies as json. +func (s AgentContextManagementPolicies) Encode(e *jx.Encoder) { + unwrapped := []AgentContextManagementPolicy(s) + + e.ArrStart() + for _, elem := range unwrapped { + elem.Encode(e) + } + e.ArrEnd() +} + +// Decode decodes AgentContextManagementPolicies from json. +func (s *AgentContextManagementPolicies) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode AgentContextManagementPolicies to nil") + } + var unwrapped []AgentContextManagementPolicy + if err := func() error { + unwrapped = make([]AgentContextManagementPolicy, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem AgentContextManagementPolicy + if err := elem.Decode(d); err != nil { + return err + } + unwrapped = append(unwrapped, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = AgentContextManagementPolicies(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s AgentContextManagementPolicies) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *AgentContextManagementPolicies) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *AgentContextManagementPolicy) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *AgentContextManagementPolicy) encodeFields(e *jx.Encoder) { + { + e.FieldStart("type") + s.Type.Encode(e) + } + { + if s.CompactThreshold.Set { + e.FieldStart("compact_threshold") + s.CompactThreshold.Encode(e) + } + } + { + if s.Instructions.Set { + e.FieldStart("instructions") + s.Instructions.Encode(e) + } + } +} + +var jsonFieldsNameOfAgentContextManagementPolicy = [3]string{ + 0: "type", + 1: "compact_threshold", + 2: "instructions", +} + +// Decode decodes AgentContextManagementPolicy from json. +func (s *AgentContextManagementPolicy) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode AgentContextManagementPolicy to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "type": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + if err := s.Type.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"type\"") + } + case "compact_threshold": + if err := func() error { + s.CompactThreshold.Reset() + if err := s.CompactThreshold.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"compact_threshold\"") + } + case "instructions": + if err := func() error { + s.Instructions.Reset() + if err := s.Instructions.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"instructions\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode AgentContextManagementPolicy") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfAgentContextManagementPolicy) { + name = jsonFieldsNameOfAgentContextManagementPolicy[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *AgentContextManagementPolicy) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *AgentContextManagementPolicy) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes AgentContextManagementPolicyType as json. +func (s AgentContextManagementPolicyType) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes AgentContextManagementPolicyType from json. +func (s *AgentContextManagementPolicyType) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode AgentContextManagementPolicyType to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch AgentContextManagementPolicyType(v) { + case AgentContextManagementPolicyTypeCompaction: + *s = AgentContextManagementPolicyTypeCompaction + default: + *s = AgentContextManagementPolicyType(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s AgentContextManagementPolicyType) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *AgentContextManagementPolicyType) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes AgentIdentifier as json. func (s AgentIdentifier) Encode(e *jx.Encoder) { switch s.Type { @@ -129,6 +425,12 @@ func (s *AgentRef) encodeFields(e *jx.Encoder) { s.Multiagent.Encode(e) } } + { + if s.ContextManagement.Set { + e.FieldStart("context_management") + s.ContextManagement.Encode(e) + } + } { if s.DisplayName.Set { e.FieldStart("display_name") @@ -143,17 +445,18 @@ func (s *AgentRef) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfAgentRef = [10]string{ - 0: "type", - 1: "id", - 2: "version", - 3: "system", - 4: "tools", - 5: "mcp_servers", - 6: "skills", - 7: "multiagent", - 8: "display_name", - 9: "model", +var jsonFieldsNameOfAgentRef = [11]string{ + 0: "type", + 1: "id", + 2: "version", + 3: "system", + 4: "tools", + 5: "mcp_servers", + 6: "skills", + 7: "multiagent", + 8: "context_management", + 9: "display_name", + 10: "model", } // Decode decodes AgentRef from json. @@ -268,6 +571,16 @@ func (s *AgentRef) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"multiagent\"") } + case "context_management": + if err := func() error { + s.ContextManagement.Reset() + if err := s.ContextManagement.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"context_management\"") + } case "display_name": if err := func() error { s.DisplayName.Reset() @@ -9124,6 +9437,46 @@ func (s *ManagedAgentsVideoBlockType) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes MemoryStoreInstructions as json. +func (s MemoryStoreInstructions) Encode(e *jx.Encoder) { + unwrapped := string(s) + + e.Str(unwrapped) +} + +// Decode decodes MemoryStoreInstructions from json. +func (s *MemoryStoreInstructions) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode MemoryStoreInstructions to nil") + } + var unwrapped string + if err := func() error { + v, err := d.Str() + unwrapped = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = MemoryStoreInstructions(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s MemoryStoreInstructions) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *MemoryStoreInstructions) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode implements json.Marshaler. func (s *ModelOverrides) Encode(e *jx.Encoder) { e.ObjStart() @@ -10538,6 +10891,202 @@ func (s *OptModelUpgradesHeaders) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes AgentCompactThreshold as json. +func (o OptNilAgentCompactThreshold) Encode(e *jx.Encoder) { + if !o.Set { + return + } + if o.Null { + e.Null() + return + } + o.Value.Encode(e) +} + +// Decode decodes AgentCompactThreshold from json. +func (o *OptNilAgentCompactThreshold) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptNilAgentCompactThreshold to nil") + } + if d.Next() == jx.Null { + if err := d.Null(); err != nil { + return err + } + + var v AgentCompactThreshold + o.Value = v + o.Set = true + o.Null = true + return nil + } + o.Set = true + o.Null = false + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptNilAgentCompactThreshold) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptNilAgentCompactThreshold) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes AgentContextManagementInstructions as json. +func (o OptNilAgentContextManagementInstructions) Encode(e *jx.Encoder) { + if !o.Set { + return + } + if o.Null { + e.Null() + return + } + o.Value.Encode(e) +} + +// Decode decodes AgentContextManagementInstructions from json. +func (o *OptNilAgentContextManagementInstructions) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptNilAgentContextManagementInstructions to nil") + } + if d.Next() == jx.Null { + if err := d.Null(); err != nil { + return err + } + + var v AgentContextManagementInstructions + o.Value = v + o.Set = true + o.Null = true + return nil + } + o.Set = true + o.Null = false + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptNilAgentContextManagementInstructions) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptNilAgentContextManagementInstructions) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes AgentContextManagementPolicies as json. +func (o OptNilAgentContextManagementPolicies) Encode(e *jx.Encoder) { + if !o.Set { + return + } + if o.Null { + e.Null() + return + } + o.Value.Encode(e) +} + +// Decode decodes AgentContextManagementPolicies from json. +func (o *OptNilAgentContextManagementPolicies) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptNilAgentContextManagementPolicies to nil") + } + if d.Next() == jx.Null { + if err := d.Null(); err != nil { + return err + } + + var v AgentContextManagementPolicies + o.Value = v + o.Set = true + o.Null = true + return nil + } + o.Set = true + o.Null = false + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptNilAgentContextManagementPolicies) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptNilAgentContextManagementPolicies) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes MemoryStoreInstructions as json. +func (o OptNilMemoryStoreInstructions) Encode(e *jx.Encoder) { + if !o.Set { + return + } + if o.Null { + e.Null() + return + } + o.Value.Encode(e) +} + +// Decode decodes MemoryStoreInstructions from json. +func (o *OptNilMemoryStoreInstructions) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptNilMemoryStoreInstructions to nil") + } + if d.Next() == jx.Null { + if err := d.Null(); err != nil { + return err + } + + var v MemoryStoreInstructions + o.Value = v + o.Set = true + o.Null = true + return nil + } + o.Set = true + o.Null = false + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptNilMemoryStoreInstructions) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptNilMemoryStoreInstructions) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes SessionEnvironment as json. func (o OptNilSessionEnvironment) Encode(e *jx.Encoder) { if !o.Set { @@ -12543,6 +13092,12 @@ func (s *SessionResource) encodeFields(e *jx.Encoder) { s.Access.Encode(e) } } + { + if s.Instructions.Set { + e.FieldStart("instructions") + s.Instructions.Encode(e) + } + } { if s.MountPath.Set { e.FieldStart("mount_path") @@ -12581,18 +13136,19 @@ func (s *SessionResource) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfSessionResource = [11]string{ +var jsonFieldsNameOfSessionResource = [12]string{ 0: "id", 1: "type", 2: "file_id", 3: "memory_store_id", 4: "access", - 5: "mount_path", - 6: "created_at", - 7: "updated_at", - 8: "tos_bucket", - 9: "tos_key", - 10: "tos_region", + 5: "instructions", + 6: "mount_path", + 7: "created_at", + 8: "updated_at", + 9: "tos_bucket", + 10: "tos_key", + 11: "tos_region", } // Decode decodes SessionResource from json. @@ -12654,6 +13210,16 @@ func (s *SessionResource) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"access\"") } + case "instructions": + if err := func() error { + s.Instructions.Reset() + if err := s.Instructions.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"instructions\"") + } case "mount_path": if err := func() error { s.MountPath.Reset() diff --git a/arkruntime/model/session/oas_parameters_gen.go b/arkruntime/model/session/oas_parameters_gen.go index 99e39da..23a2301 100644 --- a/arkruntime/model/session/oas_parameters_gen.go +++ b/arkruntime/model/session/oas_parameters_gen.go @@ -132,8 +132,18 @@ type SessionUpgradesCreateParams struct { SessionId string } +// SessionsArchiveParams is parameters of Sessions_archive operation. +type SessionsArchiveParams struct { + SessionId string +} + // SessionsListParams is parameters of Sessions_list operation. type SessionsListParams struct { + // 是否包含已归档会话。省略或 false 时排除 archived_at 非空或 status=terminated + // 的会话; + // true 时包含这些会话,其他筛选条件仍生效。查询 terminated 会话需同时传 + // true。. + IncludeArchived OptBool `json:",omitempty,omitzero" query:"include_archived"` // 按 agent_id 精确过滤。. AgentID OptString `json:",omitempty,omitzero" query:"agent_id"` // 按 agent_version 精确过滤(配合 agent_id)。. diff --git a/arkruntime/model/session/oas_schemas_gen.go b/arkruntime/model/session/oas_schemas_gen.go index 81b0f9d..8900afb 100644 --- a/arkruntime/model/session/oas_schemas_gen.go +++ b/arkruntime/model/session/oas_schemas_gen.go @@ -10,6 +10,88 @@ import ( "github.com/go-faster/jx" ) +type AgentCompactThreshold int64 + +type AgentContextManagementInstructions string + +type AgentContextManagementPolicies []AgentContextManagementPolicy + +// Session 创建期可覆写的 Agent 上下文管理策略。. +// Ref: #/components/schemas/AgentContextManagementPolicy +type AgentContextManagementPolicy struct { + // 策略类型,当前固定为 `compaction`。. + Type AgentContextManagementPolicyType `json:"type"` + // 触发压缩的上下文 token 阈值;省略时由运行时使用默认值。. + CompactThreshold OptNilAgentCompactThreshold `json:"compact_threshold"` + // 自定义摘要指令;省略时由运行时使用内置提示词。. + Instructions OptNilAgentContextManagementInstructions `json:"instructions"` +} + +// GetType returns the value of Type. +func (s *AgentContextManagementPolicy) GetType() AgentContextManagementPolicyType { + return s.Type +} + +// GetCompactThreshold returns the value of CompactThreshold. +func (s *AgentContextManagementPolicy) GetCompactThreshold() OptNilAgentCompactThreshold { + return s.CompactThreshold +} + +// GetInstructions returns the value of Instructions. +func (s *AgentContextManagementPolicy) GetInstructions() OptNilAgentContextManagementInstructions { + return s.Instructions +} + +// SetType sets the value of Type. +func (s *AgentContextManagementPolicy) SetType(val AgentContextManagementPolicyType) { + s.Type = val +} + +// SetCompactThreshold sets the value of CompactThreshold. +func (s *AgentContextManagementPolicy) SetCompactThreshold(val OptNilAgentCompactThreshold) { + s.CompactThreshold = val +} + +// SetInstructions sets the value of Instructions. +func (s *AgentContextManagementPolicy) SetInstructions(val OptNilAgentContextManagementInstructions) { + s.Instructions = val +} + +// 策略类型,当前固定为 `compaction`。. +type AgentContextManagementPolicyType string + +const ( + AgentContextManagementPolicyTypeCompaction AgentContextManagementPolicyType = "compaction" +) + +// AllValues returns all AgentContextManagementPolicyType values. +func (AgentContextManagementPolicyType) AllValues() []AgentContextManagementPolicyType { + return []AgentContextManagementPolicyType{ + AgentContextManagementPolicyTypeCompaction, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s AgentContextManagementPolicyType) MarshalText() ([]byte, error) { + switch s { + case AgentContextManagementPolicyTypeCompaction: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *AgentContextManagementPolicyType) UnmarshalText(data []byte) error { + switch AgentContextManagementPolicyType(data) { + case AgentContextManagementPolicyTypeCompaction: + *s = AgentContextManagementPolicyTypeCompaction + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + // Agent 标识:字符串 (agent_id) 或 AgentRef 对象。 // 由 TypeSpec union → OpenAPI `oneOf` → ogen sum type。. // Ref: #/components/schemas/AgentIdentifier @@ -97,6 +179,10 @@ type AgentRef struct { Skills []AgentRefSkillsItem `json:"skills"` // 多 Agent 配置覆写。. Multiagent OptAgentRefMultiagent `json:"multiagent"` + // 上下文管理策略覆写(整体替换)。省略或 null 表示继承;显式 [] + // 表示清除 + // 自定义策略,随后由运行时使用默认行为。. + ContextManagement OptNilAgentContextManagementPolicies `json:"context_management"` // Session 响应中冻结的 Agent 展示名。. DisplayName OptString `json:"display_name"` // 模型运行参数覆写。. @@ -143,6 +229,11 @@ func (s *AgentRef) GetMultiagent() OptAgentRefMultiagent { return s.Multiagent } +// GetContextManagement returns the value of ContextManagement. +func (s *AgentRef) GetContextManagement() OptNilAgentContextManagementPolicies { + return s.ContextManagement +} + // GetDisplayName returns the value of DisplayName. func (s *AgentRef) GetDisplayName() OptString { return s.DisplayName @@ -193,6 +284,11 @@ func (s *AgentRef) SetMultiagent(val OptAgentRefMultiagent) { s.Multiagent = val } +// SetContextManagement sets the value of ContextManagement. +func (s *AgentRef) SetContextManagement(val OptNilAgentContextManagementPolicies) { + s.ContextManagement = val +} + // SetDisplayName sets the value of DisplayName. func (s *AgentRef) SetDisplayName(val OptString) { s.DisplayName = val @@ -4034,6 +4130,8 @@ func (s *ManagedAgentsVideoBlockType) UnmarshalText(data []byte) error { } } +type MemoryStoreInstructions string + // Session 创建时允许临时覆写的模型运行参数与接入配置。 // 内部字段省略表示继承 base Agent 的对应值。. // Ref: #/components/schemas/ModelOverrides @@ -4230,12 +4328,13 @@ type ModelUpgrades struct { // 目标模型提供方。 // 切到非 `ark` provider 时,`base_url` 与 `token_limits` 必填(可继承 // 当前 Session 快照中已有的值,否则返回 400);`ark` provider 不允许 - // 指定 `token_limits`。. + // 指定 `token_limits` 或非空 `base_url`。. Provider OptString `json:"provider"` // 目标模型接入协议;取值须命中服务端维护的接入协议白名单,非法值返回 // 400。. Protocol OptString `json:"protocol"` - // 自定义模型接入点 base URL。配合非 `ark` 的 `provider` 使用。. + // 自定义模型接入点 base URL。配合非 `ark` 的 `provider` 使用; + // `ark` provider 指定非空值时返回 400。. BaseURL OptString `json:"base_url"` // 模型静态请求 header(整组覆写)。 // 仅用于非认证类静态 header;认证 header 必须由 SendEvent 请求上的 @@ -5556,6 +5655,258 @@ func (o OptModelUpgradesHeaders) Or(d ModelUpgradesHeaders) ModelUpgradesHeaders return d } +// NewOptNilAgentCompactThreshold returns new OptNilAgentCompactThreshold with value set to v. +func NewOptNilAgentCompactThreshold(v AgentCompactThreshold) OptNilAgentCompactThreshold { + return OptNilAgentCompactThreshold{ + Value: v, + Set: true, + } +} + +// OptNilAgentCompactThreshold is optional nullable AgentCompactThreshold. +type OptNilAgentCompactThreshold struct { + Value AgentCompactThreshold + Set bool + Null bool +} + +// IsSet returns true if OptNilAgentCompactThreshold was set. +func (o OptNilAgentCompactThreshold) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptNilAgentCompactThreshold) Reset() { + var v AgentCompactThreshold + o.Value = v + o.Set = false + o.Null = false +} + +// SetTo sets value to v. +func (o *OptNilAgentCompactThreshold) SetTo(v AgentCompactThreshold) { + o.Set = true + o.Null = false + o.Value = v +} + +// IsNull returns true if value is Null. +func (o OptNilAgentCompactThreshold) IsNull() bool { return o.Null } + +// SetToNull sets value to null. +func (o *OptNilAgentCompactThreshold) SetToNull() { + o.Set = true + o.Null = true + var v AgentCompactThreshold + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptNilAgentCompactThreshold) Get() (v AgentCompactThreshold, ok bool) { + if o.Null { + return v, false + } + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptNilAgentCompactThreshold) Or(d AgentCompactThreshold) AgentCompactThreshold { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptNilAgentContextManagementInstructions returns new OptNilAgentContextManagementInstructions with value set to v. +func NewOptNilAgentContextManagementInstructions(v AgentContextManagementInstructions) OptNilAgentContextManagementInstructions { + return OptNilAgentContextManagementInstructions{ + Value: v, + Set: true, + } +} + +// OptNilAgentContextManagementInstructions is optional nullable AgentContextManagementInstructions. +type OptNilAgentContextManagementInstructions struct { + Value AgentContextManagementInstructions + Set bool + Null bool +} + +// IsSet returns true if OptNilAgentContextManagementInstructions was set. +func (o OptNilAgentContextManagementInstructions) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptNilAgentContextManagementInstructions) Reset() { + var v AgentContextManagementInstructions + o.Value = v + o.Set = false + o.Null = false +} + +// SetTo sets value to v. +func (o *OptNilAgentContextManagementInstructions) SetTo(v AgentContextManagementInstructions) { + o.Set = true + o.Null = false + o.Value = v +} + +// IsNull returns true if value is Null. +func (o OptNilAgentContextManagementInstructions) IsNull() bool { return o.Null } + +// SetToNull sets value to null. +func (o *OptNilAgentContextManagementInstructions) SetToNull() { + o.Set = true + o.Null = true + var v AgentContextManagementInstructions + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptNilAgentContextManagementInstructions) Get() (v AgentContextManagementInstructions, ok bool) { + if o.Null { + return v, false + } + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptNilAgentContextManagementInstructions) Or(d AgentContextManagementInstructions) AgentContextManagementInstructions { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptNilAgentContextManagementPolicies returns new OptNilAgentContextManagementPolicies with value set to v. +func NewOptNilAgentContextManagementPolicies(v AgentContextManagementPolicies) OptNilAgentContextManagementPolicies { + return OptNilAgentContextManagementPolicies{ + Value: v, + Set: true, + } +} + +// OptNilAgentContextManagementPolicies is optional nullable AgentContextManagementPolicies. +type OptNilAgentContextManagementPolicies struct { + Value AgentContextManagementPolicies + Set bool + Null bool +} + +// IsSet returns true if OptNilAgentContextManagementPolicies was set. +func (o OptNilAgentContextManagementPolicies) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptNilAgentContextManagementPolicies) Reset() { + var v AgentContextManagementPolicies + o.Value = v + o.Set = false + o.Null = false +} + +// SetTo sets value to v. +func (o *OptNilAgentContextManagementPolicies) SetTo(v AgentContextManagementPolicies) { + o.Set = true + o.Null = false + o.Value = v +} + +// IsNull returns true if value is Null. +func (o OptNilAgentContextManagementPolicies) IsNull() bool { return o.Null } + +// SetToNull sets value to null. +func (o *OptNilAgentContextManagementPolicies) SetToNull() { + o.Set = true + o.Null = true + var v AgentContextManagementPolicies + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptNilAgentContextManagementPolicies) Get() (v AgentContextManagementPolicies, ok bool) { + if o.Null { + return v, false + } + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptNilAgentContextManagementPolicies) Or(d AgentContextManagementPolicies) AgentContextManagementPolicies { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptNilMemoryStoreInstructions returns new OptNilMemoryStoreInstructions with value set to v. +func NewOptNilMemoryStoreInstructions(v MemoryStoreInstructions) OptNilMemoryStoreInstructions { + return OptNilMemoryStoreInstructions{ + Value: v, + Set: true, + } +} + +// OptNilMemoryStoreInstructions is optional nullable MemoryStoreInstructions. +type OptNilMemoryStoreInstructions struct { + Value MemoryStoreInstructions + Set bool + Null bool +} + +// IsSet returns true if OptNilMemoryStoreInstructions was set. +func (o OptNilMemoryStoreInstructions) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptNilMemoryStoreInstructions) Reset() { + var v MemoryStoreInstructions + o.Value = v + o.Set = false + o.Null = false +} + +// SetTo sets value to v. +func (o *OptNilMemoryStoreInstructions) SetTo(v MemoryStoreInstructions) { + o.Set = true + o.Null = false + o.Value = v +} + +// IsNull returns true if value is Null. +func (o OptNilMemoryStoreInstructions) IsNull() bool { return o.Null } + +// SetToNull sets value to null. +func (o *OptNilMemoryStoreInstructions) SetToNull() { + o.Set = true + o.Null = true + var v MemoryStoreInstructions + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptNilMemoryStoreInstructions) Get() (v MemoryStoreInstructions, ok bool) { + if o.Null { + return v, false + } + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptNilMemoryStoreInstructions) Or(d MemoryStoreInstructions) MemoryStoreInstructions { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptNilSessionEnvironment returns new OptNilSessionEnvironment with value set to v. func NewOptNilSessionEnvironment(v SessionEnvironment) OptNilSessionEnvironment { return OptNilSessionEnvironment{ @@ -6685,6 +7036,12 @@ type SessionResource struct { MemoryStoreID OptString `json:"memory_store_id"` // `memory_store` 类型:访问权限。. Access OptSessionResourceAccess `json:"access"` + // `memory_store` 类型:会话使用该记忆库时遵循的指导,最长 4096 个 Unicode + // 字符。 + // 创建会话时可指定;省略、null + // 或空字符串均表示无使用指导,响应中省略空值。 + // 不适用于其他资源类型;与 Agent 上下文压缩策略的摘要指令不同。. + Instructions OptNilMemoryStoreInstructions `json:"instructions"` // 在 sandbox 中的挂载路径。. MountPath OptString `json:"mount_path"` // RFC 3339 时间。. @@ -6724,6 +7081,11 @@ func (s *SessionResource) GetAccess() OptSessionResourceAccess { return s.Access } +// GetInstructions returns the value of Instructions. +func (s *SessionResource) GetInstructions() OptNilMemoryStoreInstructions { + return s.Instructions +} + // GetMountPath returns the value of MountPath. func (s *SessionResource) GetMountPath() OptString { return s.MountPath @@ -6779,6 +7141,11 @@ func (s *SessionResource) SetAccess(val OptSessionResourceAccess) { s.Access = val } +// SetInstructions sets the value of Instructions. +func (s *SessionResource) SetInstructions(val OptNilMemoryStoreInstructions) { + s.Instructions = val +} + // SetMountPath sets the value of MountPath. func (s *SessionResource) SetMountPath(val OptString) { s.MountPath = val diff --git a/arkruntime/model/session/oas_validators_gen.go b/arkruntime/model/session/oas_validators_gen.go index 60588bd..4d98afa 100644 --- a/arkruntime/model/session/oas_validators_gen.go +++ b/arkruntime/model/session/oas_validators_gen.go @@ -12,6 +12,145 @@ import ( "github.com/volcengine/ark-runtime-go/arkruntime/internal/validate" ) +func (s AgentCompactThreshold) Validate() error { + alias := (int64)(s) + if err := (validate.Int{ + MinSet: true, + Min: 50000, + MaxSet: false, + Max: 0, + MinExclusive: false, + MaxExclusive: false, + MultipleOfSet: false, + MultipleOf: 0, + Pattern: nil, + }).Validate(int64(alias)); err != nil { + return errors.Wrap(err, "int") + } + return nil +} + +func (s AgentContextManagementInstructions) Validate() error { + alias := (string)(s) + if err := (validate.String{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 100000, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(alias)); err != nil { + return errors.Wrap(err, "string") + } + return nil +} + +func (s AgentContextManagementPolicies) Validate() error { + alias := ([]AgentContextManagementPolicy)(s) + if alias == nil { + return errors.New("nil is invalid value") + } + if err := (validate.Array{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 1, + MaxLengthSet: true, + }).ValidateLength(len(alias)); err != nil { + return errors.Wrap(err, "array") + } + var failures []validate.FieldError + for i, elem := range alias { + if err := func() error { + if err := elem.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: fmt.Sprintf("[%d]", i), + Error: err, + }) + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *AgentContextManagementPolicy) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := s.Type.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "type", + Error: err, + }) + } + if err := func() error { + if value, ok := s.CompactThreshold.Get(); ok { + if err := func() error { + if err := value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "compact_threshold", + Error: err, + }) + } + if err := func() error { + if value, ok := s.Instructions.Get(); ok { + if err := func() error { + if err := value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "instructions", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s AgentContextManagementPolicyType) Validate() error { + switch s { + case "compaction": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + func (s AgentIdentifier) Validate() error { switch s.Type { case StringAgentIdentifier: @@ -32,6 +171,24 @@ func (s *AgentRef) Validate() error { } var failures []validate.FieldError + if err := func() error { + if value, ok := s.ContextManagement.Get(); ok { + if err := func() error { + if err := value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "context_management", + Error: err, + }) + } if err := func() error { if value, ok := s.Model.Get(); ok { if err := func() error { @@ -1722,6 +1879,26 @@ func (s ManagedAgentsVideoBlockType) Validate() error { } } +func (s MemoryStoreInstructions) Validate() error { + alias := (string)(s) + if err := (validate.String{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 4096, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(alias)); err != nil { + return errors.Wrap(err, "string") + } + return nil +} + func (s *ModelOverrides) Validate() error { if s == nil { return validate.ErrNilPointer @@ -2190,6 +2367,24 @@ func (s *SessionResource) Validate() error { Error: err, }) } + if err := func() error { + if value, ok := s.Instructions.Get(); ok { + if err := func() error { + if err := value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "instructions", + Error: err, + }) + } if len(failures) > 0 { return &validate.Error{Fields: failures} } diff --git a/arkruntime/sessions.go b/arkruntime/sessions.go index 830067a..884eb36 100644 --- a/arkruntime/sessions.go +++ b/arkruntime/sessions.go @@ -52,6 +52,19 @@ func (c *Client) GetSession( return &wrap.Session, nil } +func (c *Client) ArchiveSession(ctx context.Context, sessionID string, setters ...requestOption) (*session.Session, error) { + if sessionID == "" { + return nil, errors.New("missing required session_id") + } + u := c.fullURL(fmt.Sprintf("%s/%s/archive", sessionsPrefix, session.PathEscape(sessionID))) + opts := append(setters, withBody(nil)) + wrap := &session.SessionResponse{} + if err := c.Do(ctx, http.MethodPost, u, "", "", wrap, opts...); err != nil { + return nil, err + } + return &wrap.Session, nil +} + // ListSessions lists Sessions with optional filters. func (c *Client) ListSessions( ctx context.Context,