@alfe.ai/openclaw-chat 0.0.8 → 0.0.9

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/plugin.d.ts CHANGED
@@ -236,7 +236,7 @@ declare const plugin: {
236
236
  description: string;
237
237
  version: string;
238
238
  activate(api: PluginApi): void;
239
- deactivate(api: PluginApi): void;
239
+ deactivate(api: PluginApi): Promise<void>;
240
240
  };
241
241
  //#endregion
242
242
  export { AlfeResolvedAccount as a, AlfePluginConfig as i, createAlfeChannelPlugin as n, AlfeChannelConfig as r, plugin as t };
package/dist/plugin2.js CHANGED
@@ -324,6 +324,7 @@ function resolveOpenClawSdk(log) {
324
324
  }
325
325
  let pluginRuntime = null;
326
326
  let chatClient = null;
327
+ let connectingPromise = null;
327
328
  async function handleAgentRequest(request, log) {
328
329
  const runtime = pluginRuntime;
329
330
  if (!runtime) {
@@ -400,6 +401,50 @@ async function handleAgentRequest(request, log) {
400
401
  unsubscribe();
401
402
  }
402
403
  }
404
+ async function handleSessionsList(request, log) {
405
+ try {
406
+ const params = request.params;
407
+ const sessions = await listSessions({
408
+ agentId: params.agentId,
409
+ channel: params.channel,
410
+ tenantId: params.tenantId
411
+ });
412
+ chatClient?.sendResponse(request.id, true, { sessions });
413
+ } catch (err) {
414
+ const errMsg = err instanceof Error ? err.message : String(err);
415
+ log.error(`sessions.list failed: ${errMsg}`);
416
+ chatClient?.sendResponse(request.id, false, { message: errMsg });
417
+ }
418
+ }
419
+ async function handleSessionsGet(request, log) {
420
+ try {
421
+ const params = request.params;
422
+ const session = await getSession(params.sessionId);
423
+ if (!session) {
424
+ chatClient?.sendResponse(request.id, true, {
425
+ ok: false,
426
+ error: "Session not found"
427
+ });
428
+ return;
429
+ }
430
+ chatClient?.sendResponse(request.id, true, {
431
+ sessionId: session.sessionId,
432
+ agentId: session.agentId,
433
+ channel: session.channel,
434
+ createdAt: session.createdAt,
435
+ messages: session.messages.map((m) => ({
436
+ id: `msg-${String(m.timestamp)}`,
437
+ role: m.role,
438
+ content: m.content,
439
+ timestamp: m.timestamp
440
+ }))
441
+ });
442
+ } catch (err) {
443
+ const errMsg = err instanceof Error ? err.message : String(err);
444
+ log.error(`sessions.get failed: ${errMsg}`);
445
+ chatClient?.sendResponse(request.id, false, { message: errMsg });
446
+ }
447
+ }
403
448
  const plugin = {
404
449
  id: "@alfe.ai/openclaw-chat",
405
450
  name: "Alfe Chat Plugin",
@@ -419,7 +464,7 @@ const plugin = {
419
464
  api.registerChannel(alfeChannel);
420
465
  log.info(`Registered channel: ${alfeChannel.id}`);
421
466
  const pluginConfig = (((api.config ?? {}).plugins?.entries)?.["@alfe.ai/openclaw-chat"] ?? {}).config ?? {};
422
- (async () => {
467
+ connectingPromise = (async () => {
423
468
  try {
424
469
  const { apiKey, chatWsUrl } = await resolveAlfeChat({
425
470
  apiKey: pluginConfig.apiKey,
@@ -432,6 +477,9 @@ const plugin = {
432
477
  apiKey,
433
478
  onRequest: (request) => {
434
479
  if (request.method === "agent") handleAgentRequest(request, log);
480
+ else if (request.method === "sessions.list") handleSessionsList(request, log);
481
+ else if (request.method === "sessions.get") handleSessionsGet(request, log);
482
+ else chatClient?.sendResponse(request.id, false, { message: `Unknown method: ${request.method}` });
435
483
  },
436
484
  onConnectionChange: (connected) => {
437
485
  log.info(`Chat service connection: ${connected ? "connected" : "disconnected"}`);
@@ -495,10 +543,16 @@ const plugin = {
495
543
  });
496
544
  log.info("Alfe Chat plugin registered");
497
545
  },
498
- deactivate(api) {
546
+ async deactivate(api) {
499
547
  globalThis.__alfeChatPluginActivated = false;
500
548
  const log = api.logger;
501
549
  log.info("Alfe Chat plugin deactivating...");
550
+ if (connectingPromise) {
551
+ await connectingPromise.catch((err) => {
552
+ api.logger.debug(`Connection attempt failed: ${err instanceof Error ? err.message : String(err)}`);
553
+ });
554
+ connectingPromise = null;
555
+ }
502
556
  if (chatClient) {
503
557
  chatClient.stop();
504
558
  chatClient = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfe.ai/openclaw-chat",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "OpenClaw chat plugin for Alfe — web widget and mobile app channels",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin.js",