mirror of
https://github.com/Heretek-AI/openclaw.git
synced 2026-07-21 05:46:16 -04:00
a9ae1a6778
Matrix Protocol: - docker-compose.matrix.yml: Dendrite homeserver + PostgreSQL + Nginx TLS - src/channels/plugins/matrix-channel.ts: OpenClaw plugin implementation - docs/matrix-triad-setup.md: Setup guide with auth scheme (@tm1-4:triad.local) MCP Server Integration: - docs/mcp-triad-integration.md: SearXNG, Playwright, GitHub MCP configs - docs/mcp-curiosity-mapping.md: Gap-to-capability mapping Node Sync Architecture: - src/services/node-sync-service.ts: WebSocket peer sync + presence detection - src/services/node-sync-service.test.ts: Unit tests - docs/node-sync-architecture.md: Architecture docs Triad Resilience: - scripts/triad-corruption-check.mjs: SQLite + log + config + git integrity - docs/triad-resilience.md: Recovery procedures - .secure/deployment-logs/README.md: Schema v2 - skills/triad-heartbeat/SKILL.md: Corruption check integration NPM Publish Workflow: - scripts/npm-publish.mjs: version, changelog, validate, publish, rollback - .github/workflows/npm-publish.yml: GitHub Actions with provenance - docs/npm-publish-guide.md: Complete documentation All deliverables tested in Docker before production.
120 lines
2.5 KiB
Go
Executable File
120 lines
2.5 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
workflowVersion = 15
|
|
docsI18nEngineName = "pi"
|
|
envDocsI18nProvider = "OPENCLAW_DOCS_I18N_PROVIDER"
|
|
envDocsI18nModel = "OPENCLAW_DOCS_I18N_MODEL"
|
|
defaultOpenAIModel = "gpt-5.4"
|
|
defaultAnthropicModel = "claude-opus-4-6"
|
|
defaultFallbackProvider = "openai"
|
|
defaultFallbackModelName = defaultOpenAIModel
|
|
)
|
|
|
|
func cacheNamespace() string {
|
|
return fmt.Sprintf(
|
|
"wf=%d|engine=%s|provider=%s|model=%s",
|
|
workflowVersion,
|
|
docsI18nEngineName,
|
|
docsPiProvider(),
|
|
docsPiModel(),
|
|
)
|
|
}
|
|
|
|
func cacheKey(namespace, srcLang, tgtLang, segmentID, textHash string) string {
|
|
raw := fmt.Sprintf("%s|%s|%s|%s|%s", namespace, srcLang, tgtLang, segmentID, textHash)
|
|
hash := sha256.Sum256([]byte(raw))
|
|
return hex.EncodeToString(hash[:])
|
|
}
|
|
|
|
func hashText(text string) string {
|
|
normalized := normalizeText(text)
|
|
hash := sha256.Sum256([]byte(normalized))
|
|
return hex.EncodeToString(hash[:])
|
|
}
|
|
|
|
func hashBytes(data []byte) string {
|
|
hash := sha256.Sum256(data)
|
|
return hex.EncodeToString(hash[:])
|
|
}
|
|
|
|
func normalizeText(text string) string {
|
|
return strings.Join(strings.Fields(strings.TrimSpace(text)), " ")
|
|
}
|
|
|
|
func docsPiProvider() string {
|
|
if value := strings.TrimSpace(os.Getenv(envDocsI18nProvider)); value != "" {
|
|
return value
|
|
}
|
|
if strings.TrimSpace(os.Getenv("OPENAI_API_KEY")) != "" {
|
|
return "openai"
|
|
}
|
|
if strings.TrimSpace(os.Getenv("ANTHROPIC_API_KEY")) != "" {
|
|
return "anthropic"
|
|
}
|
|
return defaultFallbackProvider
|
|
}
|
|
|
|
func docsPiModel() string {
|
|
if value := strings.TrimSpace(os.Getenv(envDocsI18nModel)); value != "" {
|
|
return value
|
|
}
|
|
switch docsPiProvider() {
|
|
case "anthropic":
|
|
return defaultAnthropicModel
|
|
case "openai":
|
|
return defaultOpenAIModel
|
|
default:
|
|
return defaultFallbackModelName
|
|
}
|
|
}
|
|
|
|
func segmentID(relPath, textHash string) string {
|
|
shortHash := textHash
|
|
if len(shortHash) > 16 {
|
|
shortHash = shortHash[:16]
|
|
}
|
|
return fmt.Sprintf("%s:%s", relPath, shortHash)
|
|
}
|
|
|
|
func splitWhitespace(text string) (string, string, string) {
|
|
if text == "" {
|
|
return "", "", ""
|
|
}
|
|
start := 0
|
|
for start < len(text) && isWhitespace(text[start]) {
|
|
start++
|
|
}
|
|
end := len(text)
|
|
for end > start && isWhitespace(text[end-1]) {
|
|
end--
|
|
}
|
|
return text[:start], text[start:end], text[end:]
|
|
}
|
|
|
|
func isWhitespace(b byte) bool {
|
|
switch b {
|
|
case ' ', '\t', '\n', '\r':
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func fatal(err error) {
|
|
if err == nil {
|
|
return
|
|
}
|
|
_, _ = io.WriteString(os.Stderr, err.Error()+"\n")
|
|
os.Exit(1)
|
|
}
|