@lingyao037/openclaw-lingyao-cli 0.6.0 → 0.8.0

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/index.d.ts CHANGED
@@ -608,6 +608,10 @@ declare class LingyaoWSClient {
608
608
  * 发送事件
609
609
  */
610
610
  private emitEvent;
611
+ /**
612
+ * 更新 WebSocket 连接使用的 token
613
+ */
614
+ updateToken(token: string): void;
611
615
  /**
612
616
  * 断开连接
613
617
  */
@@ -961,13 +965,14 @@ declare function validateConfig(config: unknown): LingyaoConfig;
961
965
  */
962
966
  declare function getDefaultConfig(): LingyaoConfig;
963
967
 
964
- declare const _default: {
968
+ declare const entry: {
965
969
  id: string;
966
970
  name: string;
967
971
  description: string;
968
972
  configSchema: openclaw_plugin_sdk.OpenClawPluginConfigSchema;
969
973
  register: NonNullable<openclaw_plugin_sdk_core.OpenClawPluginDefinition["register"]>;
970
974
  } & Pick<openclaw_plugin_sdk_core.OpenClawPluginDefinition, "kind">;
975
+ declare const register: (api: openclaw_plugin_sdk.OpenClawPluginApi) => void | Promise<void>;
971
976
 
972
977
  /** @deprecated Use the default export (OpenClaw SDK entry) instead. */
973
978
  declare function createPlugin(runtime: LingyaoRuntime, config?: Partial<LingyaoConfig>): Promise<LingyaoChannel>;
@@ -986,4 +991,4 @@ declare const pluginMetadata: {
986
991
  defaultConfig: LingyaoConfig;
987
992
  };
988
993
 
989
- export { type AgentMessage, DeviceInfo, DeviceToken, HealthStatus, LingyaoChannel, LingyaoConfig, LingyaoMessage, LingyaoRuntime, NotifyPayload, SyncRequest, SyncResponse, createPlugin, _default as default, getDefaultConfig, pluginMetadata, validateConfig };
994
+ export { type AgentMessage, DeviceInfo, DeviceToken, HealthStatus, LingyaoChannel, LingyaoConfig, LingyaoMessage, LingyaoRuntime, NotifyPayload, SyncRequest, SyncResponse, createPlugin, entry as default, getDefaultConfig, pluginMetadata, register, validateConfig };
package/dist/index.js CHANGED
@@ -763,6 +763,10 @@ var LingyaoWSClient = class {
763
763
  this.connectionId = null;
764
764
  this.stopHeartbeat();
765
765
  this.emitEvent({ type: "disconnected", code, reason });
766
+ if (code === 1008) {
767
+ this.logger.error("WebSocket closed with 1008 (Invalid Token). Stopping reconnect loop.");
768
+ return;
769
+ }
766
770
  if (code !== 1e3) {
767
771
  this.scheduleReconnect();
768
772
  }
@@ -957,6 +961,12 @@ var LingyaoWSClient = class {
957
961
  this.config.eventHandler(event);
958
962
  }
959
963
  }
964
+ /**
965
+ * 更新 WebSocket 连接使用的 token
966
+ */
967
+ updateToken(token) {
968
+ this.config.token = token;
969
+ }
960
970
  /**
961
971
  * 断开连接
962
972
  */
@@ -2820,6 +2830,12 @@ var MultiAccountOrchestrator = class {
2820
2830
  code: event.code,
2821
2831
  reason: event.reason
2822
2832
  });
2833
+ if (event.code === 1008) {
2834
+ this.runtime.logger.warn(`[${state.accountId}] Token invalid (1008). Forcing re-registration...`);
2835
+ this.handleInvalidToken(state).catch((err) => {
2836
+ this.runtime.logger.error(`[${state.accountId}] Failed to re-register after 1008`, err);
2837
+ });
2838
+ }
2823
2839
  break;
2824
2840
  case "error":
2825
2841
  this.runtime.logger.error(`[${state.accountId}] WS error`, event.error);
@@ -2852,6 +2868,28 @@ var MultiAccountOrchestrator = class {
2852
2868
  this.runtime.logger.error(`[${state.accountId}] Failed to auto-bind device: ${deviceId}`, error);
2853
2869
  }
2854
2870
  }
2871
+ /**
2872
+ * Handle invalid token by re-registering the gateway and reconnecting WS
2873
+ */
2874
+ async handleInvalidToken(state) {
2875
+ if (!state.httpClient || !state.wsClient) {
2876
+ return;
2877
+ }
2878
+ try {
2879
+ this.runtime.logger.info(`[${state.accountId}] Requesting new gateway token...`);
2880
+ const response = await state.httpClient.register({
2881
+ websocket: true,
2882
+ compression: false,
2883
+ maxMessageSize: 1048576
2884
+ });
2885
+ this.runtime.logger.info(`[${state.accountId}] Obtained new token. Reconnecting WS...`);
2886
+ state.wsClient.updateToken(response.gatewayToken);
2887
+ await state.wsClient.connect();
2888
+ } catch (error) {
2889
+ this.runtime.logger.error(`[${state.accountId}] Failed to handle invalid token`, error);
2890
+ state.errorHandler.handleError(error);
2891
+ }
2892
+ }
2855
2893
  };
2856
2894
 
2857
2895
  // src/channel.ts
@@ -3506,7 +3544,7 @@ function buildPlugin() {
3506
3544
  messaging: messagingAdapter
3507
3545
  };
3508
3546
  }
3509
- var index_default = defineChannelPluginEntry({
3547
+ var entry = defineChannelPluginEntry({
3510
3548
  id: "lingyao",
3511
3549
  name: "Lingyao",
3512
3550
  description: "Lingyao Channel Plugin - bidirectional sync via lingyao.live server relay",
@@ -3556,6 +3594,8 @@ var index_default = defineChannelPluginEntry({
3556
3594
  statusAdapter = createStatusAdapter(getOrchestrator, adapted);
3557
3595
  }
3558
3596
  });
3597
+ var register = entry.register;
3598
+ var index_default = entry;
3559
3599
  async function createPlugin(runtime, config = {}) {
3560
3600
  const fullConfig = { ...getDefaultConfig(), ...config };
3561
3601
  const validatedConfig = validateConfig(fullConfig);
@@ -3584,6 +3624,7 @@ export {
3584
3624
  index_default as default,
3585
3625
  getDefaultConfig,
3586
3626
  pluginMetadata,
3627
+ register,
3587
3628
  validateConfig
3588
3629
  };
3589
3630
  //# sourceMappingURL=index.js.map