-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_document.go
More file actions
55 lines (48 loc) · 1.39 KB
/
Copy pathget_document.go
File metadata and controls
55 lines (48 loc) · 1.39 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
package tools
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
)
func init() {
_ = RegisterTool(&ToolDefinition{
Name: "get_document",
Description: "Fetch the current content of a ZenithScience document by its ID. Returns the full document JSON including sections and metadata.",
Parameters: map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
"document_id": map[string]interface{}{
"type": "string",
"description": "The unique document ID to fetch.",
},
},
"required": []string{"document_id"},
},
Function: getDocument,
})
}
func getDocument(_ context.Context, params map[string]interface{}) (map[string]interface{}, error) {
docID, ok := params["document_id"].(string)
if !ok || docID == "" {
return nil, fmt.Errorf("document_id is required")
}
home, err := os.UserHomeDir()
if err != nil {
return nil, fmt.Errorf("cannot determine home directory: %w", err)
}
docPath := filepath.Join(home, ".zen-sci", "documents", docID+".json")
data, err := os.ReadFile(docPath)
if err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("document not found: %s", docID)
}
return nil, fmt.Errorf("failed to read document: %w", err)
}
var doc map[string]interface{}
if err := json.Unmarshal(data, &doc); err != nil {
return nil, fmt.Errorf("document file is corrupt: %w", err)
}
return doc, nil
}