legionio 1.4.50 → 1.4.51
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/legion/cli/trace_command.rb +32 -0
- data/lib/legion/trace_search.rb +92 -0
- data/lib/legion/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a711d9a3b6b942849185b3ec8eb16e4ecaa8b054c4c157799140f23d0bfc5f9
|
|
4
|
+
data.tar.gz: 64f138151ce16a625846a982fe66ab03d3e6403aba144509a62218a34c75fbae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9acd3652f07de505bfa8b3262c20b65715668eb7a2a012dcb1a222a27cf0b94d91facef2bd961468ee93cab3f89e5b06f100a6bf32eaf8dd2368da5c3979a675
|
|
7
|
+
data.tar.gz: ebd3a23ee70a99b2e86d709c931221262656f3eb3be4f638c20e4f8c24f7f8ad08c9dd0d54928be0f3f781725380ea298a13f93da05771a19b71fdd452333f7b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Legion Changelog
|
|
2
2
|
|
|
3
|
+
## [1.4.51] - 2026-03-17
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `Legion::TraceSearch`: natural language to safe JSON filter translation via legion-llm structured output
|
|
7
|
+
- `legion trace search "query"`: CLI command for NL trace search
|
|
8
|
+
- Column allowlist enforcement for query safety (no eval, JSON-only filter DSL)
|
|
9
|
+
- Schema-aware prompt for metering_records table
|
|
10
|
+
|
|
3
11
|
## [1.4.50] - 2026-03-17
|
|
4
12
|
|
|
5
13
|
### Added
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module CLI
|
|
7
|
+
class TraceCommand < Thor
|
|
8
|
+
namespace 'trace'
|
|
9
|
+
|
|
10
|
+
desc 'search QUERY', 'Search traces with natural language'
|
|
11
|
+
option :limit, type: :numeric, default: 50
|
|
12
|
+
def search(*query_parts)
|
|
13
|
+
require 'legion/trace_search'
|
|
14
|
+
query = query_parts.join(' ')
|
|
15
|
+
say "Searching: #{query}", :yellow
|
|
16
|
+
|
|
17
|
+
result = Legion::TraceSearch.search(query, limit: options[:limit])
|
|
18
|
+
if result[:error]
|
|
19
|
+
say "Error: #{result[:error]}", :red
|
|
20
|
+
return
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
say "Found #{result[:count]} results", :green
|
|
24
|
+
result[:results].first(20).each do |r|
|
|
25
|
+
say " #{r[:created_at]} #{r[:extension]}.#{r[:runner_function]} #{r[:status]} $#{r[:cost_usd] || 0}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
default_task :search
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module TraceSearch
|
|
5
|
+
SCHEMA_CONTEXT = <<~PROMPT
|
|
6
|
+
You translate natural language queries into JSON filter objects for the metering_records table.
|
|
7
|
+
|
|
8
|
+
Columns: id (integer), worker_id (string), event_type (string), extension (string),
|
|
9
|
+
runner_function (string), status (string: success/failure), tokens_in (integer),
|
|
10
|
+
tokens_out (integer), cost_usd (float), wall_clock_ms (integer), created_at (datetime)
|
|
11
|
+
|
|
12
|
+
Return ONLY a valid JSON object with these possible keys:
|
|
13
|
+
- "where": hash of column => value filters (e.g. {"status": "failure"})
|
|
14
|
+
- "order": column name to sort by (prefix with "-" for descending, e.g. "-cost_usd")
|
|
15
|
+
- "limit": integer limit (default 50)
|
|
16
|
+
- "date_from": ISO date string for created_at >= filter
|
|
17
|
+
- "date_to": ISO date string for created_at <= filter
|
|
18
|
+
|
|
19
|
+
Examples:
|
|
20
|
+
- "failed tasks" => {"where": {"status": "failure"}}
|
|
21
|
+
- "most expensive calls" => {"order": "-cost_usd", "limit": 20}
|
|
22
|
+
- "tasks by worker-1 today" => {"where": {"worker_id": "worker-1"}, "date_from": "2026-03-16"}
|
|
23
|
+
|
|
24
|
+
Return ONLY the JSON object, no explanation.
|
|
25
|
+
PROMPT
|
|
26
|
+
|
|
27
|
+
FILTER_SCHEMA = {
|
|
28
|
+
type: 'object',
|
|
29
|
+
properties: {
|
|
30
|
+
where: { type: 'object' },
|
|
31
|
+
order: { type: 'string' },
|
|
32
|
+
limit: { type: 'integer' },
|
|
33
|
+
date_from: { type: 'string' },
|
|
34
|
+
date_to: { type: 'string' }
|
|
35
|
+
}
|
|
36
|
+
}.freeze
|
|
37
|
+
|
|
38
|
+
ALLOWED_COLUMNS = %w[
|
|
39
|
+
id worker_id event_type extension runner_function status
|
|
40
|
+
tokens_in tokens_out cost_usd wall_clock_ms created_at
|
|
41
|
+
].freeze
|
|
42
|
+
|
|
43
|
+
class << self
|
|
44
|
+
def search(query, limit: 50)
|
|
45
|
+
parsed = generate_filter(query)
|
|
46
|
+
return { results: [], error: 'no filter generated' } unless parsed
|
|
47
|
+
|
|
48
|
+
execute_filter(parsed, limit)
|
|
49
|
+
rescue StandardError => e
|
|
50
|
+
{ results: [], error: e.message }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def generate_filter(query)
|
|
54
|
+
return nil unless defined?(Legion::LLM) && Legion::LLM.respond_to?(:structured)
|
|
55
|
+
|
|
56
|
+
result = Legion::LLM.structured(
|
|
57
|
+
messages: [
|
|
58
|
+
{ role: 'system', content: SCHEMA_CONTEXT },
|
|
59
|
+
{ role: 'user', content: query }
|
|
60
|
+
],
|
|
61
|
+
schema: FILTER_SCHEMA
|
|
62
|
+
)
|
|
63
|
+
result[:data] if result[:valid]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def execute_filter(parsed, default_limit)
|
|
67
|
+
return { results: [], error: 'data unavailable' } unless defined?(Legion::Data) && Legion::Data.respond_to?(:connection) && Legion::Data.connection
|
|
68
|
+
|
|
69
|
+
ds = Legion::Data.connection[:metering_records]
|
|
70
|
+
|
|
71
|
+
if parsed[:where].is_a?(Hash)
|
|
72
|
+
safe_where = parsed[:where].select { |k, _| ALLOWED_COLUMNS.include?(k.to_s) }
|
|
73
|
+
ds = ds.where(safe_where.transform_keys(&:to_sym))
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
ds = ds.where { created_at >= parsed[:date_from] } if parsed[:date_from]
|
|
77
|
+
ds = ds.where { created_at <= parsed[:date_to] } if parsed[:date_to]
|
|
78
|
+
|
|
79
|
+
if parsed[:order].is_a?(String)
|
|
80
|
+
col = parsed[:order].delete_prefix('-')
|
|
81
|
+
if ALLOWED_COLUMNS.include?(col)
|
|
82
|
+
ds = parsed[:order].start_with?('-') ? ds.order(Sequel.desc(col.to_sym)) : ds.order(col.to_sym)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
limit = [parsed[:limit] || default_limit, 200].min
|
|
87
|
+
results = ds.limit(limit).all
|
|
88
|
+
{ results: results, count: results.size, filter: parsed }
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
data/lib/legion/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: legionio
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.4.
|
|
4
|
+
version: 1.4.51
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Esity
|
|
@@ -474,6 +474,7 @@ files:
|
|
|
474
474
|
- lib/legion/cli/telemetry_command.rb
|
|
475
475
|
- lib/legion/cli/templates/core.json.erb
|
|
476
476
|
- lib/legion/cli/theme.rb
|
|
477
|
+
- lib/legion/cli/trace_command.rb
|
|
477
478
|
- lib/legion/cli/trigger.rb
|
|
478
479
|
- lib/legion/cli/update_command.rb
|
|
479
480
|
- lib/legion/cli/version.rb
|
|
@@ -573,6 +574,7 @@ files:
|
|
|
573
574
|
- lib/legion/telemetry.rb
|
|
574
575
|
- lib/legion/tenant_context.rb
|
|
575
576
|
- lib/legion/tenants.rb
|
|
577
|
+
- lib/legion/trace_search.rb
|
|
576
578
|
- lib/legion/version.rb
|
|
577
579
|
- lib/legion/webhooks.rb
|
|
578
580
|
- scripts/rollout-ci-workflow.sh
|