@@ -52,6 +52,7 @@ func DiffDocumentsTool() agent.Tool {
|
||||
if labelA == "" {
|
||||
labelA = "document_a"
|
||||
}
|
||||
|
||||
labelB := p.LabelB
|
||||
if labelB == "" {
|
||||
labelB = "document_b"
|
||||
@@ -80,6 +81,7 @@ func DiffDocumentsTool() agent.Tool {
|
||||
if len(output) > maxDiffOutput {
|
||||
output = output[:maxDiffOutput] + "\n[... diff truncated]"
|
||||
}
|
||||
|
||||
result.UnifiedDiff = output
|
||||
}
|
||||
|
||||
@@ -114,6 +116,7 @@ func computeDiff(linesA, linesB []string, labelA, labelB string) diffOutput {
|
||||
for i := range dp {
|
||||
dp[i] = make([]int, n+1)
|
||||
}
|
||||
|
||||
for i := m - 1; i >= 0; i-- {
|
||||
for j := n - 1; j >= 0; j-- {
|
||||
if linesA[i] == linesB[j] {
|
||||
@@ -131,6 +134,7 @@ func computeDiff(linesA, linesB []string, labelA, labelB string) diffOutput {
|
||||
fmt.Fprintf(&sb, "--- %s\n+++ %s\n", labelA, labelB)
|
||||
|
||||
var added, removed int
|
||||
|
||||
i, j := 0, 0
|
||||
for i < m || j < n {
|
||||
if i < m && j < n && linesA[i] == linesB[j] {
|
||||
@@ -139,10 +143,12 @@ func computeDiff(linesA, linesB []string, labelA, labelB string) diffOutput {
|
||||
j++
|
||||
} else if j < n && (i >= m || dp[i][j+1] >= dp[i+1][j]) {
|
||||
sb.WriteString("+ " + linesB[j] + "\n")
|
||||
|
||||
added++
|
||||
j++
|
||||
} else if i < m {
|
||||
sb.WriteString("- " + linesA[i] + "\n")
|
||||
|
||||
removed++
|
||||
i++
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ func FirecrawlSearchTool(apiKey string) agent.Tool {
|
||||
if maxResults <= 0 {
|
||||
maxResults = 5
|
||||
}
|
||||
|
||||
if maxResults > 10 {
|
||||
maxResults = 10
|
||||
}
|
||||
@@ -111,6 +112,7 @@ func firecrawlSearch(
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", "Bearer "+apiKey)
|
||||
|
||||
@@ -118,6 +120,7 @@ func firecrawlSearch(
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot execute search request: %w", err)
|
||||
}
|
||||
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
|
||||
@@ -91,6 +91,7 @@ func CheckGovernmentDBTool(apiKey string) agent.Tool {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, e := range entries {
|
||||
*s.target = append(
|
||||
*s.target,
|
||||
|
||||
@@ -28,6 +28,7 @@ type userAgentTransport struct {
|
||||
func (t *userAgentTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
r2 := r.Clone(r.Context())
|
||||
r2.Header.Set("User-Agent", "Probo-Agent/1.0")
|
||||
|
||||
return t.next.RoundTrip(r2)
|
||||
}
|
||||
|
||||
@@ -35,5 +36,6 @@ func newHTTPClient() *http.Client {
|
||||
client := httpclient.DefaultPooledClient()
|
||||
client.Timeout = 15 * time.Second
|
||||
client.Transport = &userAgentTransport{next: client.Transport}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ func CheckWaybackTool() agent.Tool {
|
||||
|
||||
// Check availability.
|
||||
availURL := "https://archive.org/wayback/available?url=" + url.QueryEscape(p.URL)
|
||||
|
||||
body, err := httpGet(ctx, client, availURL)
|
||||
if err != nil {
|
||||
result.ErrorDetail = fmt.Sprintf("cannot check Wayback Machine availability: %s", err)
|
||||
@@ -118,6 +119,7 @@ func httpGet(ctx context.Context, client *http.Client, rawURL string) ([]byte, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
||||
Reference in New Issue
Block a user