Skip to content

Commit b362c70

Browse files
JAORMXdmjb
andauthored
Add proxy_mode field to Workload API output (#1846)
- Add ProxyMode field to core.Workload struct - Load proxy_mode from RunConfig for container workloads - Include proxy_mode in remote workload creation - Output proxy_mode in thv list --format json This allows clients to see whether a workload uses SSE or streamable-http proxy mode, which is important for proper client configuration. Signed-off-by: Juan Antonio Osorio <[email protected]> Co-authored-by: Don Browne <[email protected]>
1 parent b640a5f commit b362c70

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

docs/server/docs.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/server/swagger.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/server/swagger.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/core/workload.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type Workload struct {
2727
ToolType string `json:"tool_type"`
2828
// TransportType is the type of transport used for this workload.
2929
TransportType types.TransportType `json:"transport_type"`
30+
// ProxyMode is the proxy mode for stdio transport (sse or streamable-http).
31+
ProxyMode string `json:"proxy_mode,omitempty"`
3032
// Status is the current status of the workload.
3133
Status runtime.WorkloadStatus `json:"status"`
3234
// StatusContext provides additional context about the workload's status.

pkg/workloads/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@ func (d *defaultManager) getRemoteWorkloadsFromState(
11601160
URL: runConfig.RemoteURL,
11611161
Port: runConfig.Port,
11621162
TransportType: transportType,
1163+
ProxyMode: string(runConfig.ProxyMode),
11631164
ToolType: "remote",
11641165
Group: runConfig.Group,
11651166
CreatedAt: workloadStatus.CreatedAt,

pkg/workloads/types/types.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import (
1414
"github.com/stacklok/toolhive/pkg/transport/types"
1515
)
1616

17-
// minimalRunConfig represents just the group field from a run configuration
17+
// minimalRunConfig represents just the fields we need from a run configuration
1818
type minimalRunConfig struct {
19-
Group string `json:"group,omitempty" yaml:"group,omitempty"`
19+
Group string `json:"group,omitempty" yaml:"group,omitempty"`
20+
ProxyMode string `json:"proxy_mode,omitempty" yaml:"proxy_mode,omitempty"`
2021
}
2122

22-
// loadGroupFromRunConfig attempts to load group information from the runconfig
23-
// Returns empty string if runconfig doesn't exist or doesn't have group info
24-
func loadGroupFromRunConfig(ctx context.Context, name string) (string, error) {
23+
// loadRunConfigFields attempts to load specific fields from the runconfig
24+
// Returns empty struct if runconfig doesn't exist
25+
func loadRunConfigFields(ctx context.Context, name string) (*minimalRunConfig, error) {
2526
// Try to load the runconfig
2627
runConfig, err := state.LoadRunConfig(ctx, name, func(r io.Reader) (*minimalRunConfig, error) {
2728
var config minimalRunConfig
@@ -33,13 +34,13 @@ func loadGroupFromRunConfig(ctx context.Context, name string) (string, error) {
3334
})
3435
if err != nil {
3536
if errors.IsRunConfigNotFound(err) {
36-
return "", nil
37+
return &minimalRunConfig{}, nil
3738
}
38-
return "", err
39+
return nil, err
3940
}
4041

41-
// Return the group from the runconfig
42-
return runConfig.Group, nil
42+
// Return the runconfig
43+
return runConfig, nil
4344
}
4445

4546
// WorkloadFromContainerInfo creates a Workload struct from the runtime container info.
@@ -89,7 +90,7 @@ func WorkloadFromContainerInfo(container *runtime.ContainerInfo) (core.Workload,
8990
}
9091

9192
ctx := context.Background()
92-
groupName, err := loadGroupFromRunConfig(ctx, name)
93+
runConfig, err := loadRunConfigFields(ctx, name)
9394
if err != nil {
9495
return core.Workload{}, err
9596
}
@@ -101,11 +102,12 @@ func WorkloadFromContainerInfo(container *runtime.ContainerInfo) (core.Workload,
101102
URL: url,
102103
ToolType: toolType,
103104
TransportType: tType,
105+
ProxyMode: runConfig.ProxyMode,
104106
Status: container.State,
105107
StatusContext: container.Status,
106108
CreatedAt: container.Created,
107109
Port: port,
108110
Labels: userLabels,
109-
Group: groupName,
111+
Group: runConfig.Group,
110112
}, nil
111113
}

0 commit comments

Comments
 (0)