Add service status and usage dashboard, refresh externally published edits

This commit is contained in:
2026-10-09 20:20:44 +01:00
parent 67ac79765f
commit a50e8648f6
31 changed files with 1283 additions and 42 deletions
+31 -7
View File
@@ -32,18 +32,23 @@ type OpenCodeClient struct {
}
type openCodeError struct {
operation string
status int
cause error
operation string
status int
cause error
diagnostic string
}
func (e *openCodeError) Unwrap() error { return e.cause }
func (e *openCodeError) Error() string {
if e.status > 0 {
return fmt.Sprintf("OpenCode %s failed (HTTP %d)", e.operation, e.status)
detail := ""
if e.diagnostic != "" {
detail = ": " + e.diagnostic
}
return fmt.Sprintf("OpenCode %s command failed", e.operation)
if e.status > 0 {
return fmt.Sprintf("OpenCode %s failed (HTTP %d)%s", e.operation, e.status, detail)
}
return fmt.Sprintf("OpenCode %s command failed%s", e.operation, detail)
}
func (e *openCodeError) Retryable() bool {
return e.status == 429 || e.status == 502 || e.status == 503 || e.status == 504
@@ -104,7 +109,7 @@ func (c OpenCodeClient) call(ctx context.Context, method, path string, body any)
status, _ = strconv.Atoi(match[1])
}
// Do not embed provider responses, prompts, credentials, or CLI logs in errors.
return nil, &openCodeError{operation: method + " " + path, status: status}
return nil, &openCodeError{operation: method + " " + path, status: status, diagnostic: safeCommandDiagnostic(err, stdout.Bytes())}
}
if stdout.overflow {
return nil, fmt.Errorf("OpenCode response exceeds 1 MiB limit")
@@ -112,6 +117,25 @@ func (c OpenCodeClient) call(ctx context.Context, method, path string, body any)
return stdout.Bytes(), nil
}
func safeCommandDiagnostic(err error, data []byte) string {
var exit *exec.ExitError
detail := "could not execute CLI"
if errors.As(err, &exit) {
detail = fmt.Sprintf("CLI exit code %d", exit.ExitCode())
}
var response struct {
Tag string `json:"_tag"`
}
if json.Unmarshal(data, &response) == nil {
// Never copy provider messages, arbitrary stderr or response bodies.
reasons := map[string]string{"SessionNotFoundError": "session not found on the selected OpenCode service", "LocationNotFoundError": "session location not found", "ServiceUnavailableError": "OpenCode service unavailable", "UnauthorizedError": "OpenCode service authentication failed", "InvalidRequestError": "OpenCode rejected the request", "SessionBusyError": "OpenCode session is busy"}
if reason := reasons[response.Tag]; reason != "" {
detail += "; " + reason
}
}
return detail
}
func (c OpenCodeClient) Generate(ctx context.Context, config ModelConfig, prompt string) (text string, err error) {
if c.command == nil {
connection, err := opencode.Open(ctx, opencode.Executable(), c.Directory, c.Backend)