Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(skills): explain unfederated skills.sh imports (#4196)
tsumon80ce846328d0
diff --git a/internal/application/service/tenant_skill_source.go b/internal/application/service/tenant_skill_source.goindex 776b94801..1bad4e77a 100644--- a/internal/application/service/tenant_skill_source.go+++ b/internal/application/service/tenant_skill_source.go@@ -23,6 +23,19 @@ import (// source so the handler can map the class to 400 without matching on text.var ErrSkillSourceInvalid = errors.New("skill source is invalid")+type skillSourceHTTPError struct {+ statusCode int+ message string+}++func (e *skillSourceHTTPError) Error() string {+ return fmt.Sprintf("%v: download returned HTTP %d: %s", ErrSkillSourceInvalid, e.statusCode, e.message)+}++func (e *skillSourceHTTPError) Unwrap() error {+ return ErrSkillSourceInvalid+}+const (defaultSkillRegistryOrigin = "https://clawhub.ai"skillSourceUserAgent = "WeKnora-SkillInstaller (+https://github.com/Tencent/WeKnora)"@@ -641,6 +654,14 @@ func fetchSkillSourceBytes(}body, contentType, err := getSkillURL(ctx, client, target)if err != nil {+ var statusErr *skillSourceHTTPError+ if src.Kind == skillSourceSkillsSh && errors.As(err, &statusErr) &&+ statusErr.statusCode == http.StatusNotFound {+ return fetchedSkillSource{}, fmt.Errorf(+ "%w: this skills.sh listing is not available through ClawHub federation "++ "(HTTP 404: %s); import it using the GitHub folder URL shown by skills.sh",+ ErrSkillSourceInvalid, statusErr.message)+ }return fetchedSkillSource{}, err}fetched := fetchedSkillSource{body: body, contentType: contentType, subdir: src.Subdir}@@ -832,8 +853,10 @@ func getSkillURL(if msg == "" {msg = resp.Status}- return nil, "", fmt.Errorf("%w: download returned HTTP %d: %s",- ErrSkillSourceInvalid, resp.StatusCode, truncateSkillError(msg))+ return nil, "", &skillSourceHTTPError{+ statusCode: resp.StatusCode,+ message: truncateSkillError(msg),+ }}body, err := io.ReadAll(io.LimitReader(resp.Body, maxBytes+1))if err != nil {diff --git a/internal/application/service/tenant_skill_source_test.go b/internal/application/service/tenant_skill_source_test.goindex e0703de88..0ed45a911 100644--- a/internal/application/service/tenant_skill_source_test.go+++ b/internal/application/service/tenant_skill_source_test.go@@ -372,6 +372,33 @@ func TestFetchSkillArchiveFromSkillsShInstallResolver(t *testing.T) {require.NotContains(t, bundle.Files, "README.md")}+func TestFetchSkillArchiveFromUnfederatedSkillsShExplainsGitHubSource(t *testing.T) {+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ http.NotFound(w, r)+ }))+ t.Cleanup(server.Close)+ allowLoopbackSkillFetch(t)++ _, err := fetchSkillArchive(t.Context(),+ server.URL+"/skills-sh/acedatacloud/skills/suno-music", server.Client())+ require.ErrorIs(t, err, ErrSkillSourceInvalid)+ require.ErrorContains(t, err, "not available through ClawHub")+ require.ErrorContains(t, err, "GitHub folder URL")+}++func TestFetchSkillArchiveFromOtherSourceKeepsHTTPError(t *testing.T) {+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ http.NotFound(w, r)+ }))+ t.Cleanup(server.Close)+ allowLoopbackSkillFetch(t)++ _, err := fetchSkillArchive(t.Context(), server.URL+"/demo.zip", server.Client())+ require.ErrorIs(t, err, ErrSkillSourceInvalid)+ require.ErrorContains(t, err, "download returned HTTP 404")+ require.NotContains(t, err.Error(), "ClawHub federation")+}+func TestFetchSkillArchiveFromRegistry(t *testing.T) {archive := zipBundle(t, map[string]string{"SKILL.md": validSkillMD})server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {