feat(clients): openrouter: whole public API, spec-checked call table, chat model, demo

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 07:46:42 +02:00
co-authored by Claude Sonnet 5.5
parent 2e0270c043
commit 9a24bedc7c
54 changed files with 7109 additions and 3 deletions
+54
View File
@@ -0,0 +1,54 @@
#pragma once
// Stream parsers for the two non-chat inference skins: the Responses API
// (POST /responses, "beta") and the Anthropic-compatible Messages API
// (POST /messages). Event type names come from the spec schemas
// StreamEvents and MessagesStreamEvents. Each parser folds the events into a
// StreamSummary (text, reasoning, usage, terminal status or error) without
// touching the network.
#include <map>
#include <optional>
#include <string>
#include "clients/body/json.h"
#include "llm/chat_types.h"
#include "llm/sse.h"
#include "openrouter/errors.h"
namespace molo::openrouter {
struct StreamSummary {
std::string id;
std::string model;
std::string text;
std::string reasoning;
std::string status; // responses: completed incomplete failed; messages: stop_reason
std::optional<llm::Usage> usage;
std::optional<ErrorBody> error;
std::map<std::string, int> event_counts; // by event type
std::size_t events = 0;
};
class ResponsesStreamParser {
public:
// Returns the text delta this event carried ("" when none).
std::string feed(const llm::SseEvent& event);
const StreamSummary& summary() const { return summary_; }
void throw_if_errored() const;
private:
StreamSummary summary_;
};
class MessagesStreamParser {
public:
std::string feed(const llm::SseEvent& event);
const StreamSummary& summary() const { return summary_; }
void throw_if_errored() const;
private:
StreamSummary summary_;
};
} // namespace molo::openrouter