completion-kit 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7a3fda7b41271efa8b169adff5bc72e3f347fa67641aa26ab2d52f84ad4d0526
|
|
4
|
+
data.tar.gz: fd9fcca6cc6ac22e32a3f8ba7f917fd8b0ccb30a270f45aa63fb7fc3ee59343b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '02917101ab65551a18974c80b382ba508b5f0a80f67182bf630998aacfebc4584f85d03d9fc0c59d6de7b89c1881391340cd81c3cd1631bca6b545067f57a513'
|
|
7
|
+
data.tar.gz: 255c33ab87a13e1e4ed5387c8cff70c952cf0c68c3d3829ddc4c401208bc1d94019f121fd0cfbd7ec425a4669f3420b96b988ade2bba50f0113f5e714957295e
|
|
@@ -45,7 +45,10 @@ module CompletionKit
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def dataset_params
|
|
48
|
-
params.permit(:name, :csv_data, tag_names: [])
|
|
48
|
+
permitted = params.permit(:name, :csv_data, tag_names: [])
|
|
49
|
+
upload = params[:file]
|
|
50
|
+
permitted[:csv_data] = upload.read.to_s.force_encoding("UTF-8") if upload.respond_to?(:read)
|
|
51
|
+
permitted
|
|
49
52
|
end
|
|
50
53
|
end
|
|
51
54
|
end
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
require "faraday"
|
|
2
|
+
|
|
1
3
|
module CompletionKit
|
|
2
4
|
module McpTools
|
|
3
5
|
module Datasets
|
|
4
6
|
extend Base
|
|
5
7
|
|
|
8
|
+
MAX_CSV_BYTES = 10 * 1024 * 1024
|
|
9
|
+
|
|
6
10
|
TOOLS = {
|
|
7
11
|
"datasets_list" => {
|
|
8
12
|
description: "List all datasets",
|
|
@@ -36,6 +40,19 @@ module CompletionKit
|
|
|
36
40
|
description: "Delete a dataset",
|
|
37
41
|
inputSchema: {type: "object", properties: {id: {type: "integer"}}, required: ["id"]},
|
|
38
42
|
handler: :delete
|
|
43
|
+
},
|
|
44
|
+
"datasets_create_from_url" => {
|
|
45
|
+
description: "Create a dataset by downloading CSV from a URL instead of inlining it. Use this for large datasets: pass a public http(s) URL and the server fetches the CSV directly, so the data never has to pass through the tool-call arguments. The URL is SSRF-checked and the download is capped at 10MB.",
|
|
46
|
+
inputSchema: {
|
|
47
|
+
type: "object",
|
|
48
|
+
properties: {
|
|
49
|
+
name: {type: "string"},
|
|
50
|
+
url: {type: "string", description: "Public http(s) URL of the CSV file to download."},
|
|
51
|
+
tag_names: {type: "array", items: {type: "string"}}
|
|
52
|
+
},
|
|
53
|
+
required: ["name", "url"]
|
|
54
|
+
},
|
|
55
|
+
handler: :create_from_url
|
|
39
56
|
}
|
|
40
57
|
}.freeze
|
|
41
58
|
|
|
@@ -71,6 +88,35 @@ module CompletionKit
|
|
|
71
88
|
Dataset.find(args["id"]).destroy!
|
|
72
89
|
text_result("Dataset #{args["id"]} deleted")
|
|
73
90
|
end
|
|
91
|
+
|
|
92
|
+
def self.create_from_url(args)
|
|
93
|
+
issues = ProviderEndpoint.validate(args["url"])
|
|
94
|
+
return error_result("URL is not allowed (#{issues.join(", ")}).") if issues.any?
|
|
95
|
+
|
|
96
|
+
response = csv_connection.get(args["url"])
|
|
97
|
+
return error_result("Could not download CSV (HTTP #{response.status}).") unless response.success?
|
|
98
|
+
|
|
99
|
+
body = response.body.to_s
|
|
100
|
+
return error_result("CSV is larger than the #{MAX_CSV_BYTES / (1024 * 1024)}MB limit.") if body.bytesize > MAX_CSV_BYTES
|
|
101
|
+
|
|
102
|
+
dataset = Dataset.new(name: args["name"], csv_data: body.dup.force_encoding("UTF-8"))
|
|
103
|
+
dataset.tag_names = args["tag_names"] if args.key?("tag_names")
|
|
104
|
+
if dataset.save
|
|
105
|
+
text_result(dataset.reload.as_json)
|
|
106
|
+
else
|
|
107
|
+
error_result(dataset.errors.full_messages.join(", "))
|
|
108
|
+
end
|
|
109
|
+
rescue Faraday::Error => e
|
|
110
|
+
error_result("Could not download CSV: #{e.message}")
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def self.csv_connection
|
|
114
|
+
Faraday.new do |f|
|
|
115
|
+
f.options.timeout = 30
|
|
116
|
+
f.options.open_timeout = 5
|
|
117
|
+
f.adapter Faraday.default_adapter
|
|
118
|
+
end
|
|
119
|
+
end
|
|
74
120
|
end
|
|
75
121
|
end
|
|
76
122
|
end
|