Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.18.0
0.19.0
13 changes: 13 additions & 0 deletions arkruntime/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
80 changes: 80 additions & 0 deletions arkruntime/ark_apis_agent_archive_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
79 changes: 79 additions & 0 deletions arkruntime/ark_apis_environment_archive_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
81 changes: 81 additions & 0 deletions arkruntime/ark_apis_session_archive_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
13 changes: 13 additions & 0 deletions arkruntime/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions arkruntime/model/agent/multiagent_contract_shim_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2026 ByteDance Ltd. and/or its affiliates.
// SPDX-License-Identifier: Apache-2.0

package agent

import (
Expand Down
Loading
Loading