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
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/legion/api/acp.rb', line 66
def self.registered(app)
app.helpers Legion::API::Helpers::Acp
app.get '/.well-known/agent.json' do
card = build_agent_card
content_type :json
Legion::JSON.dump(card)
end
app.post '/api/acp/tasks' do
body = parse_request_body
payload = (body[:input] || {}).transform_keys(&:to_sym)
result = Legion::Ingress.run(
payload: payload,
runner_class: body[:runner_class],
function: body[:function],
source: 'acp'
)
json_response({ task_id: result[:task_id], status: 'queued' }, status_code: 202)
end
app.get '/api/acp/tasks/:id' do
task = find_task(params[:id])
halt 404, json_error(404, 'Task not found') unless task
json_response({
task_id: task[:id],
status: translate_status(task[:status]),
output: { data: task[:result] },
created_at: task[:created_at]&.to_s,
completed_at: task[:completed_at]&.to_s
})
end
app.delete '/api/acp/tasks/:id' do
halt 501, json_error(501, 'Task cancellation not implemented')
end
end
|