Skip to content

update to new api#26

Merged
jazzz merged 1 commit into
masterfrom
update_api
May 7, 2026
Merged

update to new api#26
jazzz merged 1 commit into
masterfrom
update_api

Conversation

@iurimatias
Copy link
Copy Markdown
Member

@iurimatias iurimatias commented May 7, 2026

Update Module to latest version of API

This PR removed QT type dependencies, and migrates to a JSON based approach for EventData

update to new api

re-add old commnets

remove emitSafe
Copilot AI review requested due to automatic review settings May 7, 2026 15:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the chat module from a Qt plugin/interface-based implementation to a “universal” pure C++ implementation that reports results via named events with JSON payloads.

Changes:

  • Replaced the Qt ChatModulePlugin + ChatModuleInterface design with a pure C++ ChatModuleImpl that emits JSON strings via an emitEvent callback.
  • Updated unit tests to exercise ChatModuleImpl and adjusted test include paths for stubs.
  • Updated module metadata/build inputs for the new universal/codegen setup and removed the old interface header from the build.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/test_chat_module.cpp Updates tests to use ChatModuleImpl and wire emitEvent in test setup.
tests/CMakeLists.txt Adjusts stub include path for the new header include layout.
src/chat_module_plugin.h Replaces Qt plugin interface with ChatModuleImpl API + JSON event contract docs.
src/chat_module_plugin.cpp Implements JSON-emitting callbacks and replaces Qt types/logging with std + nlohmann::json.
src/chat_module_interface.h Removes the legacy Qt plugin interface.
metadata.json Declares universal interface/codegen header and adds Nix package metadata.
CMakeLists.txt Removes the deleted interface header from module sources.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/chat_module_plugin.h
#include <string>

extern "C" {
#include "lib/liblogoschat.h"
Comment thread src/chat_module_plugin.h
/// Wired automatically by the generated glue layer.
/// Call this to emit named events to other modules / the host application.
/// Data is a JSON-encoded string (object or array).
std::function<void(const std::string& eventName, const std::string& data)> emitEvent;
Comment on lines +24 to 30
ChatModuleImpl::~ChatModuleImpl()
{
// Clean up Chat context if it exists
if (chatCtx) {
chat_destroy(chatCtx, destroy_callback, this);
chatCtx = nullptr;
}

// Clean up resources
if (logosAPI) {
delete logosAPI;
logosAPI = nullptr;
}
}

void ChatModulePlugin::initLogos(LogosAPI* logosAPIInstance) {
if (logosAPI) {
delete logosAPI;
}
logosAPI = logosAPIInstance;
}

void ChatModulePlugin::emitEvent(const QString& eventName, const QVariantList& data) {
if (!logosAPI) {
qWarning() << "ChatModulePlugin: LogosAPI not available, cannot emit" << eventName;
return;
}

LogosAPIClient* client = logosAPI->getClient("chat_module");
if (!client) {
qWarning() << "ChatModulePlugin: Failed to get chat_module client for event" << eventName;
return;
}

client->onEventResponse(this, eventName, data);
}
Comment on lines +5 to +14
#include <nlohmann/json.hpp>

static std::string isoTimestamp()
{
auto now = std::chrono::system_clock::now();
auto tt = std::chrono::system_clock::to_time_t(now);
struct tm buf;
gmtime_r(&tt, &buf);
char out[32];
strftime(out, sizeof(out), "%Y-%m-%dT%H:%M:%SZ", &buf);

plugin->emitEvent("chatGetIdResult", eventData);
nlohmann::json ev;
ev["clientId"] = message;
Copy link
Copy Markdown
Collaborator

@jazzz jazzz May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clientId is the preferred value. Ignore Copilot

Copy link
Copy Markdown
Collaborator

@jazzz jazzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. No blocker from my end.


plugin->emitEvent("chatGetIdResult", eventData);
nlohmann::json ev;
ev["clientId"] = message;
Copy link
Copy Markdown
Collaborator

@jazzz jazzz May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clientId is the preferred value. Ignore Copilot

Comment on lines +49 to +52
ev["success"] = (callerRet == RET_OK);
ev["statusCode"] = callerRet;
ev["message"] = message;
ev["timestamp"] = isoTimestamp();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[?] Is this schema doc'd anywhere?

Comment on lines -2 to -9
#include <QDebug>
#include <QCoreApplication>
#include <QVariantList>
#include <QDateTime>
#include <QJsonDocument>
#include <QJsonObject>

ChatModulePlugin::ChatModulePlugin() : chatCtx(nullptr)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@jazzz jazzz merged commit a0d251f into master May 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants