win 21325afb33
Some checks failed
CI / test (push) Failing after 10s
CI / frontend (push) Failing after 8s
CI / golangci-lint (push) Failing after 5s
Security Scan / backend-security (push) Failing after 5s
Security Scan / frontend-security (push) Failing after 4s
feat(windsurf): 补全ops日志记录与endpoint派生,对齐其他平台
- windsurf_gateway_service: 添加上游延迟/TTFT/错误上下文记录
- endpoint: DeriveUpstreamEndpoint 添加 PlatformWindsurf 分支
- ops_error_logger: guessPlatformFromPath 添加 /windsurf/ 识别
2026-04-23 20:46:27 +08:00

93 lines
2.8 KiB
Go

// Package windsurf is a minimal Go client for the Windsurf LanguageServerService (local gRPC)
// and upstream Connect-RPC JSON endpoints.
//
// Portions of this file derive from https://github.com/seven7763/windsurf-tools (MIT, 2025 shaoyu521).
// See ./LICENSE for full attribution.
package windsurf
import (
"encoding/hex"
)
// ── Constants ──────────────────────────────────────────────────────────────
const (
DefaultBaseURL = "https://server.self-serve.windsurf.com"
AppName = "windsurf"
AppVersion = "1.48.2"
ExtensionVersion = "1.9600.41"
IDEVersion = ExtensionVersion
RuntimeOS = "linux"
HardwareArch = "x86_64"
ClientVersion = "2.0.63"
UserAgent = "connect-go/1.18.1 (go1.26.1)"
)
// ── Protobuf wire encoding ─────────────────────────────────────────────────
func writeVarint(value uint64) []byte {
var parts []byte
for value > 0x7F {
parts = append(parts, byte(value&0x7F)|0x80)
value >>= 7
}
parts = append(parts, byte(value))
return parts
}
func encodeBytesField(fieldNum uint64, data []byte) []byte {
tag := writeVarint((fieldNum << 3) | 2)
length := writeVarint(uint64(len(data)))
out := make([]byte, 0, len(tag)+len(length)+len(data))
out = append(out, tag...)
out = append(out, length...)
out = append(out, data...)
return out
}
func encodeStringField(fieldNum uint64, s string) []byte {
return encodeBytesField(fieldNum, []byte(s))
}
func encodeVarintField(fieldNum uint64, value uint64) []byte {
tag := writeVarint((fieldNum << 3) | 0)
val := writeVarint(value)
out := make([]byte, 0, len(tag)+len(val))
out = append(out, tag...)
out = append(out, val...)
return out
}
// ReadVarint reads a varint from data starting at pos.
func ReadVarint(data []byte, pos int) (val uint64, newPos int, ok bool) {
var shift uint
for pos < len(data) {
b := data[pos]
pos++
val |= uint64(b&0x7F) << shift
shift += 7
if (b & 0x80) == 0 {
return val, pos, true
}
if shift >= 64 {
return 0, pos, false
}
}
return 0, pos, false
}
// ── UUID ───────────────────────────────────────────────────────────────────
func generateUUID() string {
var buf [16]byte
_, _ = readRandom(buf[:])
buf[6] = (buf[6] & 0x0f) | 0x40
buf[8] = (buf[8] & 0x3f) | 0x80
return hex.EncodeToString(buf[0:4]) + "-" +
hex.EncodeToString(buf[4:6]) + "-" +
hex.EncodeToString(buf[6:8]) + "-" +
hex.EncodeToString(buf[8:10]) + "-" +
hex.EncodeToString(buf[10:16])
}