Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix(datasource): support Yuque team token in connector

liuwei435e0c6599c54de
diff --git a/internal/datasource/connector/yuque/connector.go b/internal/datasource/connector/yuque/connector.go
index dfb17a243..04605758e 100644
--- a/internal/datasource/connector/yuque/connector.go
+++ b/internal/datasource/connector/yuque/connector.go
@@ -54,37 +54,53 @@ func (c *Connector) ListResources(ctx context.Context, config *types.DataSourceC
return nil, fmt.Errorf("get current user: %w", err)
}
- // Personal repos come first and win over team representations of the same repo
- // (first-write-wins dedup) — owner-side metadata is more authoritative.
repos := make(map[int64]v2Repo)
- personal, err := cli.ListUserRepos(ctx, me.Login)
- if err != nil {
- return nil, fmt.Errorf("list personal repos: %w", err)
- }
- for _, r := range personal {
- if _, ok := repos[r.ID]; !ok {
+ // Team token: /api/v2/user returns type="Group" — the token represents a team,
+ // not a personal user. In this case, directly list the team's own repos instead
+ // of going through the personal-repos + user-groups flow.
+ if me.Type == "Group" {
+ logger.Infof(ctx, "[Yuque] detected team token (type=Group, login=%s), listing team repos directly", me.Login)
+ teamRepos, err := cli.ListGroupRepos(ctx, me.Login)
+ if err != nil {
+ return nil, fmt.Errorf("list team repos: %w", err)
+ }
+ for _, r := range teamRepos {
repos[r.ID] = r
}
- }
-
- groups, err := cli.ListUserGroups(ctx, me.ID)
- if err != nil {
- return nil, fmt.Errorf("list user groups: %w", err)
- }
- for _, g := range groups {
- teamRepos, err := cli.ListGroupRepos(ctx, g.Login)
+ } else {
+ // Personal token flow: list user's own repos + repos from joined groups.
+ personal, err := cli.ListUserRepos(ctx, me.Login)
if err != nil {
- // Skip this group but continue others (e.g., 403 on a restricted group).
- // Log so operators can distinguish partial failures from empty groups.
- logger.Warnf(ctx, "[Yuque] skip group %s: %v", g.Login, err)
- continue
+ return nil, fmt.Errorf("list personal repos: %w", err)
}
- for _, r := range teamRepos {
+ for _, r := range personal {
if _, ok := repos[r.ID]; !ok {
repos[r.ID] = r
}
}
+
+ groups, err := cli.ListUserGroups(ctx, me.ID)
+ if err != nil {
+ // Yuque returns 404 when the user has not joined any groups (teams),
+ // instead of an empty list. Treat this as "no groups" and continue
+ // — personal repos were already fetched above.
+ logger.Warnf(ctx, "[Yuque] list user groups failed (treating as empty): %v", err)
+ groups = nil
+ }
+ for _, g := range groups {
+ teamRepos, err := cli.ListGroupRepos(ctx, g.Login)
+ if err != nil {
+ // Skip this group but continue others (e.g., 403 on a restricted group).
+ logger.Warnf(ctx, "[Yuque] skip group %s: %v", g.Login, err)
+ continue
+ }
+ for _, r := range teamRepos {
+ if _, ok := repos[r.ID]; !ok {
+ repos[r.ID] = r
+ }
+ }
+ }
}
out := make([]types.Resource, 0, len(repos))
@@ -178,6 +194,12 @@ func (c *Connector) walk(
}
}
+ // Rate-limit: pause between GetDocDetail calls to avoid hitting
+ // Yuque's API rate limit (typically ~100 req/5min for personal tokens).
+ if err := sleepCtx(ctx, 300*time.Millisecond); err != nil {
+ return nil, nil, err
+ }
+
detail, err := cli.GetDocDetail(ctx, d.ID)
if err != nil {
// Record failure but continue (placeholder item with error metadata).
diff --git a/internal/datasource/connector/yuque/types.go b/internal/datasource/connector/yuque/types.go
index 3ec19f2e6..f24ec5715 100644
--- a/internal/datasource/connector/yuque/types.go
+++ b/internal/datasource/connector/yuque/types.go
@@ -128,6 +128,7 @@ type v2UserResponse struct {
type v2User struct {
ID int64 `json:"id"`
+ Type string `json:"type"` // "User" for personal token, "Group" for team token
Login string `json:"login"`
Name string `json:"name"`
}