@alfe.ai/openclaw-chat 0.0.13 → 0.0.14
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.
- package/dist/plugin2.js +29 -28
- package/package.json +1 -1
package/dist/plugin2.js
CHANGED
|
@@ -464,22 +464,21 @@ const plugin = {
|
|
|
464
464
|
description: "Chat conversation channel — web widget and mobile app share unified chat sessions",
|
|
465
465
|
version: "0.0.8",
|
|
466
466
|
activate(api) {
|
|
467
|
-
if (globalThis.__alfeChatPluginActivated) {
|
|
468
|
-
api.logger.debug("Chat plugin already activated, skipping re-init");
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
globalThis.__alfeChatPluginActivated = true;
|
|
472
467
|
const log = api.logger;
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
pluginRuntime = api.runtime ?? null;
|
|
468
|
+
const alreadyActivated = globalThis.__alfeChatPluginActivated === true;
|
|
469
|
+
globalThis.__alfeChatPluginActivated = true;
|
|
476
470
|
const alfeChannel = createAlfeChannelPlugin();
|
|
477
471
|
api.registerChannel(alfeChannel);
|
|
478
472
|
log.info(`Registered channel: ${alfeChannel.id}`);
|
|
473
|
+
if (!alreadyActivated) {
|
|
474
|
+
log.info("Chat plugin registering...");
|
|
475
|
+
resolveOpenClawSdk(log);
|
|
476
|
+
pluginRuntime = api.runtime ?? null;
|
|
477
|
+
}
|
|
479
478
|
const pluginConfig = (((api.config ?? {}).plugins?.entries)?.["@alfe.ai/openclaw-chat"] ?? {}).config ?? {};
|
|
480
|
-
connectingPromise = (
|
|
479
|
+
if (!alreadyActivated) connectingPromise = Promise.resolve().then(() => {
|
|
481
480
|
try {
|
|
482
|
-
const { apiKey, chatWsUrl } =
|
|
481
|
+
const { apiKey, chatWsUrl } = resolveAlfeChat({
|
|
483
482
|
apiKey: pluginConfig.apiKey,
|
|
484
483
|
chatWsUrl: pluginConfig.chatWsUrl
|
|
485
484
|
});
|
|
@@ -505,7 +504,7 @@ const plugin = {
|
|
|
505
504
|
} catch (err) {
|
|
506
505
|
log.error(`Failed to initialize chat service: ${err instanceof Error ? err.message : String(err)}`);
|
|
507
506
|
}
|
|
508
|
-
})
|
|
507
|
+
});
|
|
509
508
|
if (typeof api.registerGatewayMethod === "function") {
|
|
510
509
|
api.registerGatewayMethod("sessions.list", async (...args) => {
|
|
511
510
|
const params = args[0];
|
|
@@ -536,23 +535,25 @@ const plugin = {
|
|
|
536
535
|
});
|
|
537
536
|
log.info("Registered gateway RPC methods: sessions.list, sessions.get");
|
|
538
537
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
538
|
+
if (!alreadyActivated) {
|
|
539
|
+
api.on("session_start", async (...eventArgs) => {
|
|
540
|
+
const key = eventArgs[0].sessionKey;
|
|
541
|
+
if (!key || isAlfeSessionKey(key)) return;
|
|
542
|
+
log.info(`Chat session starting: ${key}`);
|
|
543
|
+
await createSession(key, "", "alfe");
|
|
544
|
+
}, { priority: 50 });
|
|
545
|
+
api.on("message", async (...eventArgs) => {
|
|
546
|
+
const event = eventArgs[0];
|
|
547
|
+
const key = event.sessionKey;
|
|
548
|
+
if (!key || isAlfeSessionKey(key)) return;
|
|
549
|
+
await addMessage(key, event.role, event.content);
|
|
550
|
+
});
|
|
551
|
+
api.on("session_end", (...eventArgs) => {
|
|
552
|
+
const key = eventArgs[0].sessionKey;
|
|
553
|
+
if (!key || !isAlfeSessionKey(key)) return;
|
|
554
|
+
log.info(`Chat session ending: ${key}`);
|
|
555
|
+
});
|
|
556
|
+
}
|
|
556
557
|
log.info("Chat plugin registered");
|
|
557
558
|
},
|
|
558
559
|
async deactivate(api) {
|