-
Notifications
You must be signed in to change notification settings - Fork 513
Expand file tree
/
Copy pathqwen_provider.go
More file actions
94 lines (86 loc) · 2.56 KB
/
Copy pathqwen_provider.go
File metadata and controls
94 lines (86 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package parser
import (
"context"
"path/filepath"
"strings"
)
// Qwen stores each chat as a JSONL transcript under a per-project
// directory. It is a directory-of-files provider: discovery, watching,
// change classification, lookup, and fingerprinting come from
// JSONLSourceSet, and the ParseFile option makes that source set a full
// SourceSet so it rides the generic factory.
func newQwenProviderFactory(def AgentDef) ProviderFactory {
return newSourceSetFactory(
def,
qwenProviderCapabilities(),
func(cfg ProviderConfig) SourceSet { return newQwenSourceSet(cfg.Roots) },
)
}
func newQwenSourceSet(roots []string) JSONLSourceSet {
return newJSONLSourceSet(AgentQwen, roots,
withRecursive(),
withSymlinkFollowing(),
withIncludePath(isQwenSourcePath),
withProjectHint(qwenProjectHintFromPath),
withSessionIDFromPath(qwenSessionIDFromPath),
withParseFile(qwenParseFile),
)
}
func qwenParseFile(
_ context.Context, path string, req ParseRequest,
) ([]ParseResult, []string, error) {
sess, msgs, err := parseQwenSession(path, req.Source.ProjectHint, req.Machine)
if err != nil {
return nil, nil, err
}
if sess == nil {
return nil, nil, nil
}
if req.Fingerprint.Hash != "" {
sess.File.Hash = req.Fingerprint.Hash
}
return []ParseResult{{Session: *sess, Messages: msgs}}, nil, nil
}
func isQwenSourcePath(root, path string) bool {
rel, err := filepath.Rel(root, path)
if err != nil {
return false
}
parts := strings.Split(rel, string(filepath.Separator))
return len(parts) == 3 &&
parts[0] != "" && parts[0] != "." && parts[0] != ".." &&
parts[1] == "chats" &&
parts[2] != "" && parts[2] != "." && parts[2] != ".." &&
strings.HasSuffix(parts[2], ".jsonl")
}
func qwenProjectHintFromPath(root, path string) string {
rel, err := filepath.Rel(root, path)
if err != nil {
return ""
}
parts := strings.Split(rel, string(filepath.Separator))
if len(parts) != 3 {
return ""
}
return GetProjectName(parts[0])
}
func qwenSessionIDFromPath(root, path string) string {
if !isQwenSourcePath(root, path) {
return ""
}
return strings.TrimSuffix(filepath.Base(path), ".jsonl")
}
func qwenProviderCapabilities() Capabilities {
return Capabilities{
Source: jsonlFileProviderSourceCapabilities(),
Content: ContentCapabilities{
FirstMessage: CapabilitySupported,
Cwd: CapabilitySupported,
Thinking: CapabilitySupported,
ToolCalls: CapabilitySupported,
ToolResults: CapabilitySupported,
PerMessageTokenUsage: CapabilitySupported,
Model: CapabilitySupported,
},
}
}