Change API naming to KI

It is just the catchy thing to do.
This commit is contained in:
Χγφτ Kompanion 2025-10-18 14:16:16 +02:00
parent ee37ed47bb
commit dadb0af954
30 changed files with 95 additions and 94 deletions

View File

@ -2,5 +2,5 @@ add_subdirectory(cli)
add_subdirectory(dal)
add_subdirectory(gui)
add_subdirectory(KompanionAI)
add_subdirectory(KI)
add_subdirectory(mcp)

View File

@ -1,11 +1,10 @@
set(KOMPANION_AI_SRCS
set(KOM_KI_SRCS
Client/KIClient.cpp
Provider/OllamaProvider.cpp
Completion/KIReply.cpp
)
set(KOMPANION_AI_HDRS
set(KOM_KI_HDRS
Client/KIClient.h
Provider/KIProvider.h
Provider/KICapabilities.h
@ -20,14 +19,14 @@ set(KOMPANION_AI_HDRS
Policy/KIPolicy.h
)
add_library(kom_ai STATIC ${KOMPANION_AI_SRCS} ${KOMPANION_AI_HDRS})
add_library(kom_ki STATIC ${KOM_KI_SRCS} ${KOM_KI_HDRS})
target_include_directories(kom_ai PUBLIC
target_include_directories(kom_ki PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${Qt6Core_INCLUDE_DIRS}
)
target_link_libraries(kom_ai PUBLIC
target_link_libraries(kom_ki PUBLIC
Qt6::Core
Qt6::Network
)
)

View File

@ -1,7 +1,7 @@
#include "KIClient.h"
namespace KompanionAI {
namespace KI {
KIClient::KIClient(QObject *parent) : QObject(parent)
{
@ -58,4 +58,4 @@ void KIClient::cancel(quint64 requestId)
}
}
} // namespace KompanionAI
} // namespace KI

View File

@ -9,7 +9,7 @@
#include "../Completion/KIChatOptions.h"
#include "../Embedding/KIEmbedding.h"
namespace KompanionAI {
namespace KI {
class KIClient : public QObject
{
@ -39,6 +39,6 @@ private:
QString m_defaultModel;
};
} // namespace KompanionAI
} // namespace KI
#endif // KIANICLIENT_H

View File

@ -7,7 +7,7 @@
#include "../Tool/KITool.h"
#include "../Policy/KIPolicy.h"
namespace KompanionAI {
namespace KI {
class KIChatOptions
{
@ -33,6 +33,6 @@ public:
bool operator!=(const KIChatOptions& other) const = default;
};
} // namespace KompanionAI
} // namespace KI
#endif // KIANICHATOPTIONS_H

View File

@ -4,7 +4,7 @@
#include <QObject>
#include <QString>
namespace KompanionAI {
namespace KI {
class KIError
{
@ -33,6 +33,6 @@ public:
bool operator!=(const KIError& other) const = default;
};
} // namespace KompanionAI
} // namespace KI
#endif // KIANIERROR_H

View File

@ -2,7 +2,7 @@
#include <QJsonDocument>
#include <QJsonObject>
namespace KompanionAI {
namespace KI {
QString KIReply::text() const
{
@ -48,4 +48,4 @@ void KIReply::processIncomingData(const QByteArray& newData)
}
}
} // namespace KompanionAI
} // namespace KI

View File

@ -8,7 +8,7 @@
#include "../Tool/KITool.h"
#include "KIError.h"
namespace KompanionAI {
namespace KI {
class KIReply : public QObject
{
@ -52,6 +52,6 @@ protected:
QString m_accumulatedText; // Added for accumulating text
};
} // namespace KompanionAI
} // namespace KI
#endif // KIANIREPLY_H

View File

@ -6,7 +6,7 @@
#include <QString>
#include <QVector>
namespace KompanionAI {
namespace KI {
class KIEmbedOptions
{
@ -34,6 +34,6 @@ public:
bool operator!=(const KIEmbeddingResult& other) const = default;
};
} // namespace KompanionAI
} // namespace KI
#endif // KIANIEMBEDDING_H

View File

@ -7,7 +7,7 @@
#include <QList>
#include <QVariantMap>
namespace KompanionAI {
namespace KI {
class KIMessagePart
{
@ -37,6 +37,6 @@ class KIMessage
bool operator!=(const KIMessage& other) const = default;
};
} // namespace KompanionAI
} // namespace KI
#endif // KIANIMESSAGE_H

View File

@ -6,7 +6,7 @@
#include <QList>
#include "KIMessage.h"
namespace KompanionAI {
namespace KI {
class KIThread
{
@ -20,6 +20,6 @@ public:
bool operator!=(const KIThread& other) const = default;
};
} // namespace KompanionAI
} // namespace KI
#endif // KIANITHREAD_H

View File

@ -5,7 +5,7 @@
#include <QString>
#include <QStringList>
namespace KompanionAI {
namespace KI {
class KIPolicy
{
@ -23,6 +23,6 @@ public:
bool operator!=(const KIPolicy& other) const = default;
};
} // namespace KompanionAI
} // namespace KI
#endif // KIANIPOLICY_H

View File

@ -3,7 +3,7 @@
#include <QObject>
namespace KompanionAI {
namespace KI {
class KICapabilities : public QObject
{
@ -37,6 +37,6 @@ private:
bool m_images = false;
};
} // namespace KompanionAI
} // namespace KI
#endif // KIANICAPABILITIES_H

View File

@ -9,7 +9,7 @@
#include "../Embedding/KIEmbedding.h"
#include "KICapabilities.h"
namespace KompanionAI {
namespace KI {
class KIChatOptions; // Forward declaration
class KIEmbedOptions; // Forward declaration
@ -36,6 +36,6 @@ signals:
void modelsChanged();
};
} // namespace KompanionAI
} // namespace KI
#endif // KIANIPROVIDER_H

View File

@ -6,7 +6,7 @@
#include "../Completion/KIChatOptions.h" // Added
#include "../Completion/KIError.h" // Added
namespace KompanionAI {
namespace KI {
OllamaProvider::OllamaProvider(QObject *parent) : KIProvider(parent)
{
@ -153,4 +153,4 @@ void OllamaProvider::cancel(quint64 requestId)
// TODO: Implement cancellation logic
}
} // namespace KompanionAI
} // namespace KI

View File

@ -10,7 +10,7 @@
#include "../Message/KIThread.h" // Included full definition for KIThread
#include "KICapabilities.h"
namespace KompanionAI {
namespace KI {
class OllamaProvider : public KIProvider
{
@ -36,6 +36,6 @@ private:
KICapabilities* m_caps;
};
} // namespace KompanionAI
} // namespace KI
#endif // OLLAMAPROVIDER_H

View File

@ -8,7 +8,7 @@
#include <QVariant>
#include <QVariantMap>
namespace KompanionAI {
namespace KI {
class KIToolParam
{
@ -70,6 +70,6 @@ public:
bool operator!=(const KIToolResult& other) const = default;
};
} // namespace KompanionAI
} // namespace KI
#endif // KIANITOOL_H

View File

@ -7,6 +7,6 @@ Qt6::Core
Qt6::Sql
KF6::ConfigCore
kom_dal
kom_ai
kom_ki
)
install(TARGETS kompanion RUNTIME ${KF_INSTALL_TARGETS_DEFAULT_ARGS})

View File

@ -5,7 +5,7 @@
#include <utility>
#include <optional>
namespace kom {
namespace ki {
class IDatabase {
public:
virtual ~IDatabase() = default;

View File

@ -4,7 +4,7 @@
#include <optional>
#include <cstdint>
namespace kom {
namespace ki {
struct MemoryItem {
std::string id;
std::string namespace_id;

View File

@ -18,7 +18,7 @@
#include <numeric>
#include <stdexcept>
namespace kom {
namespace ki {
namespace {
@ -1101,4 +1101,4 @@ std::vector<std::string> PgDal::parsePgTextArray(const QString& value) {
return tags;
}
} // namespace kom
} // namespace ki

View File

@ -14,7 +14,7 @@
#include <unordered_set>
#include <vector>
namespace kom {
namespace ki {
struct NamespaceRow {
std::string id;
@ -177,4 +177,4 @@ private:
std::unordered_map<std::string, EmbeddingRow> embeddings_;
};
} // namespace kom
} // namespace ki

View File

@ -11,7 +11,7 @@ target_link_libraries(kompanion_gui PRIVATE
Qt6::McpServer
Qt6::McpCommon
kom_dal
kom_ai
kom_ki
)
install(TARGETS kompanion_gui RUNTIME DESTINATION bin)

View File

@ -10,12 +10,12 @@
#include <QApplication>
#include <QFutureWatcher>
#include <KompanionAI/Client/KIClient.h>
#include <KompanionAI/Provider/OllamaProvider.h>
#include <KompanionAI/Message/KIMessage.h>
#include <KompanionAI/Message/KIThread.h>
#include <KompanionAI/Completion/KIReply.h>
#include <KompanionAI/Completion/KIChatOptions.h>
#include <Client/KIClient.h>
#include <Provider/OllamaProvider.h>
#include <Message/KIMessage.h>
#include <Message/KIThread.h>
#include <Completion/KIReply.h>
#include <Completion/KIChatOptions.h>
class MainWindow : public KParts::MainWindow
@ -42,9 +42,9 @@ public:
connect(sendButton, &QPushButton::clicked, this, &MainWindow::sendMessage);
// Setup KompanionAI
m_ollamaProvider = new KompanionAI::OllamaProvider(this);
m_kompanionClient = new KompanionAI::KIClient(this);
// Setup KI
m_ollamaProvider = new KI::OllamaProvider(this);
m_kompanionClient = new KI::KIClient(this);
m_kompanionClient->setProvider(m_ollamaProvider);
m_kompanionClient->setDefaultModel("llama2"); // Or some other default
}
@ -62,29 +62,29 @@ private slots:
// Append user message to chat view
insertText(QString("User: %1\n").arg(message));
// Send message to KompanionAI
KompanionAI::KIThread thread;
KompanionAI::KIMessage kimessage;
// Send message to KI
KI::KIThread thread;
KI::KIMessage kimessage;
kimessage.role = "user";
KompanionAI::KIMessagePart part;
KI::KIMessagePart part;
part.mime = "text/plain";
part.text = message;
kimessage.parts.append(part);
thread.messages.append(kimessage);
KompanionAI::KIChatOptions opts;
KI::KIChatOptions opts;
opts.model = m_kompanionClient->defaultModel();
QFuture<KompanionAI::KIReply*> future = m_kompanionClient->chat(thread, opts);
QFuture<KI::KIReply*> future = m_kompanionClient->chat(thread, opts);
QFutureWatcher<KompanionAI::KIReply*> *watcher = new QFutureWatcher<KompanionAI::KIReply*>(this);
connect(watcher, &QFutureWatcher<KompanionAI::KIReply*>::finished, this, [this, watcher]() {
KompanionAI::KIReply* reply = watcher->result();
connect(reply, &KompanionAI::KIReply::tokensAdded, this, [this](const QString& delta) {
QFutureWatcher<KI::KIReply*> *watcher = new QFutureWatcher<KI::KIReply*>(this);
connect(watcher, &QFutureWatcher<KI::KIReply*>::finished, this, [this, watcher]() {
KI::KIReply* reply = watcher->result();
connect(reply, &KI::KIReply::tokensAdded, this, [this](const QString& delta) {
insertText(delta);
});
connect(reply, &KompanionAI::KIReply::finished, this, [this, reply]() {
connect(reply, &KI::KIReply::finished, this, [this, reply]() {
insertText("\n");
reply->deleteLater();
});
@ -105,8 +105,8 @@ private:
KTextEditor::Document *m_document;
QLineEdit *m_chatInput;
KompanionAI::KIClient* m_kompanionClient;
KompanionAI::OllamaProvider* m_ollamaProvider;
KI::KIClient* m_kompanionClient;
KI::OllamaProvider* m_ollamaProvider;
};
int main(int argc, char *argv[])
@ -117,4 +117,4 @@ int main(int argc, char *argv[])
window.show();
return app.exec();
}
}

View File

@ -200,7 +200,7 @@ int main(int argc, char **argv)
std::cerr << "[kom_mcp] PG_DSN not set; DAL will fall back to stubbed mode. Configure Database/PgDsn to enable persistence.\n";
}
kom::PgDal dal;
ki::PgDal dal;
if (effectiveDsn) {
if (!dal.connect(*effectiveDsn)) {
std::cerr << "[kom_mcp] Failed to connect to database; DAL will fall back to stubbed mode.\n";

View File

@ -1,3 +1,5 @@
find_package(Qt6 REQUIRED COMPONENTS Core)
add_library(kom_mcp STATIC
KompanionQtServer.cpp
)
@ -10,7 +12,7 @@ qt_add_resources(kom_mcp kompanion_mcp_resources
target_link_libraries(kom_mcp PRIVATE
kom_dal
kom_ai
kom_ki
KF6::ConfigCore
Qt6::Core
Qt6::Network
@ -26,4 +28,4 @@ target_compile_definitions(kom_mcp PRIVATE
)
install(FILES ToolSchemas.json DESTINATION ${KDE_INSTALL_DATADIR}/kompanion/mcp)
install(FILES ToolSchemas.json DESTINATION ${KDE_INSTALL_DATADIR}/kompanion/mcp)

View File

@ -19,8 +19,8 @@
namespace Handlers {
namespace detail {
inline kom::PgDal& database() {
static kom::PgDal instance;
inline ki::PgDal& database() {
static ki::PgDal instance;
static bool connected = [] {
const char* env = std::getenv("PG_DSN");
const std::string dsn = (env && *env) ? std::string(env) : std::string();
@ -385,7 +385,7 @@ inline std::string upsert_memory(const std::string& reqJson) {
return detail::error_response("bad_request", "items array must contain at least one entry");
}
kom::PgDal& dal = detail::database();
ki::PgDal& dal = detail::database();
const bool hasTx = dal.begin();
std::vector<std::string> ids;
ids.reserve(items.size());
@ -394,7 +394,7 @@ inline std::string upsert_memory(const std::string& reqJson) {
try {
#endif
for (auto& parsed : items) {
kom::ItemRow row;
ki::ItemRow row;
row.id = parsed.id;
row.namespace_id = nsRow->id;
row.content_json = parsed.rawJson;
@ -406,18 +406,18 @@ inline std::string upsert_memory(const std::string& reqJson) {
ids.push_back(itemId);
if (!parsed.embedding.empty()) {
kom::ChunkRow chunk;
ki::ChunkRow chunk;
chunk.item_id = itemId;
chunk.ord = 0;
chunk.text = parsed.text;
auto chunkIds = dal.upsertChunks(std::vector<kom::ChunkRow>{chunk});
auto chunkIds = dal.upsertChunks(std::vector<ki::ChunkRow>{chunk});
kom::EmbeddingRow emb;
ki::EmbeddingRow emb;
emb.chunk_id = chunkIds.front();
emb.model = "stub-model";
emb.dim = static_cast<int>(parsed.embedding.size());
emb.vector = parsed.embedding;
dal.upsertEmbeddings(std::vector<kom::EmbeddingRow>{emb});
dal.upsertEmbeddings(std::vector<ki::EmbeddingRow>{emb});
}
}
#if defined(__cpp_exceptions)
@ -466,7 +466,7 @@ inline std::string search_memory(const std::string& reqJson) {
}
}
kom::PgDal& dal = detail::database();
ki::PgDal& dal = detail::database();
std::unordered_set<std::string> seen;
std::vector<detail::SearchMatch> matches;
@ -520,8 +520,8 @@ inline std::string save_context(const std::string& reqJson) {
auto tags = detail::parse_string_array(reqJson, "tags");
auto ttlOpt = detail::extract_int_field(reqJson, "ttl_seconds");
kom::PgDal& dal = detail::database();
kom::ItemRow row;
ki::PgDal& dal = detail::database();
ki::ItemRow row;
row.namespace_id = nsRow->id;
if (!key.empty()) {
row.key = key;
@ -600,7 +600,7 @@ inline std::string recall_context(const std::string& reqJson) {
sinceOpt = since;
}
kom::PgDal& dal = detail::database();
ki::PgDal& dal = detail::database();
auto rows = dal.fetchContext(nsRow->id, keyOpt, tags, sinceOpt, limit);
std::ostringstream os;

View File

@ -38,7 +38,7 @@ QString normaliseToolName(const QString &defaultNamespace, const QString &rawNam
}
} // namespace
KompanionQtServer::KompanionQtServer(const QString &backend, KomMcpServer *logic, kom::PgDal* dal, QObject *parent)
KompanionQtServer::KompanionQtServer(const QString &backend, KomMcpServer *logic, ki::PgDal* dal, QObject *parent)
: QMcpServer(backend, parent)
, m_logic(logic)
, m_dal(dal)

View File

@ -5,7 +5,7 @@
#include <QtCore/QObject>
class KomMcpServer;
namespace kom {
namespace ki {
class PgDal;
}
class QMcpTool;
@ -14,12 +14,12 @@ class KompanionQtServer : public QMcpServer
{
Q_OBJECT
public:
explicit KompanionQtServer(const QString &backend, KomMcpServer *logic, kom::PgDal* dal, QObject *parent = nullptr);
explicit KompanionQtServer(const QString &backend, KomMcpServer *logic, ki::PgDal* dal, QObject *parent = nullptr);
private:
QList<QMcpTool> loadToolsFromSchema() const;
KomMcpServer *m_logic;
kom::PgDal* m_dal;
ki::PgDal* m_dal;
QList<QMcpTool> m_tools;
};

View File

@ -5,31 +5,31 @@
#include <vector>
static void contract_pgdal_basic() {
kom::PgDal dal;
ki::PgDal dal;
dal.connect("stub://memory");
auto ns = dal.ensureNamespace("tests");
static_cast<void>(ns);
kom::ItemRow item;
ki::ItemRow item;
item.namespace_id = "tests";
item.text = std::string("example");
item.tags = {"alpha", "beta"};
item.id = dal.upsertItem(item);
kom::ChunkRow chunk;
ki::ChunkRow chunk;
chunk.item_id = item.id;
chunk.text = "chunk-text";
auto chunkIds = dal.upsertChunks(std::vector<kom::ChunkRow>{chunk});
auto chunkIds = dal.upsertChunks(std::vector<ki::ChunkRow>{chunk});
if (!chunkIds.empty()) {
chunk.id = chunkIds.front();
}
kom::EmbeddingRow embedding;
ki::EmbeddingRow embedding;
embedding.chunk_id = chunk.id;
embedding.model = "stub-model";
embedding.dim = 3;
embedding.vector = {0.1f, 0.2f, 0.3f};
dal.upsertEmbeddings(std::vector<kom::EmbeddingRow>{embedding});
dal.upsertEmbeddings(std::vector<ki::EmbeddingRow>{embedding});
static_cast<void>(dal.searchText("tests", "chunk", 5));
static_cast<void>(dal.searchVector("tests", embedding.vector, 5));