@cored-im/openclaw-plugin 0.1.5 → 0.1.10

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/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) 2026 Cored Limited
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { defineChannelPluginEntry, type PluginApi } from "openclaw/plugin-sdk/core";
4
+ import { defineChannelPluginEntry } from "openclaw/plugin-sdk/core";
5
5
  import { coredPlugin } from "./channel.js";
6
6
  import { listEnabledAccountConfigs, validateAccountConfig } from "./config.js";
7
7
  import {
@@ -9,64 +9,58 @@ import {
9
9
  destroyAllClients,
10
10
  clientCount,
11
11
  } from "./core/cored-client.js";
12
- import { processInboundMessage, type ExtendedPluginApi } from "./messaging/inbound.js";
12
+ import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core";
13
+ import { processInboundMessage } from "./messaging/inbound.js";
13
14
  import { makeDeliver, setTyping, clearTyping, readMessage } from "./messaging/outbound.js";
14
15
  import type { CoredAccountConfig, CoredMessageEvent } from "./types.js";
15
16
 
16
- // Extended PluginApi with config type for service registration
17
- interface ServicePluginApi extends ExtendedPluginApi {
18
- config: { channels?: Record<string, unknown> };
19
- }
20
-
21
17
  export default defineChannelPluginEntry({
22
18
  id: "cored",
23
19
  name: "Cored",
24
20
  description: "Connect OpenClaw with Cored",
25
21
  plugin: coredPlugin,
26
22
  registerFull(api) {
27
- const typedApi = api as ServicePluginApi;
28
-
29
- typedApi.registerService({
23
+ api.registerService({
30
24
  id: "cored-sdk",
31
25
  start: async () => {
32
26
  if (clientCount() > 0) return;
33
27
 
34
- const accounts = listEnabledAccountConfigs(typedApi.config);
28
+ const accounts = listEnabledAccountConfigs(api.config);
35
29
  if (accounts.length === 0) {
36
- typedApi.logger?.warn?.("[cored] no enabled account config found — service idle");
30
+ api.logger?.warn?.("[cored] no enabled account config found — service idle");
37
31
  return;
38
32
  }
39
33
 
40
34
  for (const account of accounts) {
41
35
  const errors = validateAccountConfig(account);
42
36
  if (errors.length > 0) {
43
- typedApi.logger?.warn?.(
37
+ api.logger?.warn?.(
44
38
  `[cored] skipping account=${account.accountId}: ${errors.map((e) => e.message).join("; ")}`,
45
39
  );
46
40
  continue;
47
41
  }
48
42
 
49
43
  try {
50
- await startAccount(typedApi, account);
51
- typedApi.logger?.info?.(
44
+ await startAccount(api, account);
45
+ api.logger?.info?.(
52
46
  `[cored] account=${account.accountId} connected (appId=${account.appId})`,
53
47
  );
54
48
  } catch (err) {
55
- typedApi.logger?.error?.(
49
+ api.logger?.error?.(
56
50
  `[cored] account=${account.accountId} failed to start: ${err instanceof Error ? err.message : String(err)}`,
57
51
  );
58
52
  }
59
53
  }
60
54
 
61
- typedApi.logger?.info?.(`[cored] service started with ${clientCount()} account(s)`);
55
+ api.logger?.info?.(`[cored] service started with ${clientCount()} account(s)`);
62
56
  },
63
57
  stop: async () => {
64
58
  await destroyAllClients();
65
- typedApi.logger?.info?.("[cored] service stopped — all clients disconnected");
59
+ api.logger?.info?.("[cored] service stopped — all clients disconnected");
66
60
  },
67
61
  });
68
62
 
69
- typedApi.logger?.info?.("[cored] plugin registered");
63
+ api.logger?.info?.("[cored] plugin registered");
70
64
  },
71
65
  });
72
66
 
@@ -74,7 +68,7 @@ export default defineChannelPluginEntry({
74
68
  * Start a single account — create client, subscribe to inbound events.
75
69
  */
76
70
  async function startAccount(
77
- api: ServicePluginApi,
71
+ api: OpenClawPluginApi,
78
72
  account: CoredAccountConfig,
79
73
  ): Promise<void> {
80
74
  const deliver = makeDeliver(account.accountId, (msg) => api.logger?.warn?.(msg));
@@ -97,7 +91,7 @@ async function startAccount(
97
91
  * Handle a single inbound message with typing indicator lifecycle.
98
92
  */
99
93
  async function handleInbound(
100
- api: ServicePluginApi,
94
+ api: OpenClawPluginApi,
101
95
  account: CoredAccountConfig,
102
96
  event: CoredMessageEvent,
103
97
  deliver: (chatId: string, text: string) => Promise<void>,
@@ -14,8 +14,8 @@ import {
14
14
  import type {
15
15
  CoredAccountConfig,
16
16
  CoredMessageEvent,
17
- PluginApi,
18
17
  } from "../types.js";
18
+ import type { InboundPluginApi } from "./inbound.js";
19
19
 
20
20
  // ---------------------------------------------------------------------------
21
21
  // Helpers
@@ -56,7 +56,7 @@ function makeEvent(
56
56
  };
57
57
  }
58
58
 
59
- function makeMockApi(): PluginApi {
59
+ function makeMockApi(): InboundPluginApi {
60
60
  return {
61
61
  registerChannel: vi.fn(),
62
62
  registerService: vi.fn(),
@@ -14,22 +14,25 @@ import type {
14
14
  CoredAccountConfig,
15
15
  CoredMessage,
16
16
  CoredMessageEvent,
17
- PluginApi,
18
17
  } from "../types.js";
19
18
 
20
- // Extended PluginApi with runtime surfaces used by this module
21
- export interface ExtendedPluginApi extends PluginApi {
19
+ // Plugin API surface used by this module.
20
+ // At runtime the full OpenClawPluginApi is provided by the gateway;
21
+ // we only declare the subset we access so the module stays decoupled
22
+ // and testable without importing the full SDK.
23
+ export interface InboundPluginApi {
24
+ config: Record<string, unknown>;
22
25
  runtime?: {
23
26
  channel?: {
24
27
  reply?: {
25
- dispatchReplyWithBufferedBlockDispatcher?: (opts: unknown) => Promise<void>;
28
+ dispatchReplyWithBufferedBlockDispatcher?: (...args: any[]) => any;
26
29
  };
27
30
  session?: {
28
- recordInboundSession?: (opts: unknown) => Promise<void>;
29
- resolveStorePath?: (store: unknown, opts: unknown) => string;
31
+ recordInboundSession?: (...args: any[]) => any;
32
+ resolveStorePath?: (...args: any[]) => string;
30
33
  };
31
34
  routing?: {
32
- resolveAgentRoute?: (opts: unknown) => unknown;
35
+ resolveAgentRoute?: (...args: any[]) => unknown;
33
36
  };
34
37
  };
35
38
  };
@@ -314,7 +317,7 @@ export interface InboundDispatchOptions {
314
317
  * Returns `true` if the message was dispatched, `false` if filtered.
315
318
  */
316
319
  export async function processInboundMessage(
317
- api: ExtendedPluginApi,
320
+ api: InboundPluginApi,
318
321
  account: CoredAccountConfig,
319
322
  event: CoredMessageEvent,
320
323
  opts: InboundDispatchOptions,
package/src/types.ts CHANGED
@@ -79,7 +79,3 @@ export type ConnectionState =
79
79
  | "connected"
80
80
  | "disconnecting";
81
81
 
82
- // --- OpenClaw Plugin API (re-export from SDK) ---
83
-
84
- // Re-export PluginApi from SDK for convenience
85
- export type { PluginApi } from "openclaw/plugin-sdk/core";
@@ -1,162 +0,0 @@
1
- // Copyright (c) 2026 Cored Limited
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /**
5
- * Type declarations for openclaw/plugin-sdk.
6
- *
7
- * These types provide the minimal interface needed for the channel plugin.
8
- * The actual implementation is provided by the OpenClaw runtime at plugin load time.
9
- */
10
-
11
- declare module "openclaw/plugin-sdk/core" {
12
- export interface OpenClawConfig {
13
- channels?: Record<string, unknown>;
14
- plugins?: {
15
- entries?: Record<string, { enabled?: boolean; config?: unknown }>;
16
- };
17
- }
18
-
19
- export interface ChannelPluginMeta {
20
- id: string;
21
- label: string;
22
- selectionLabel?: string;
23
- docsPath?: string;
24
- blurb?: string;
25
- aliases?: string[];
26
- }
27
-
28
- export interface ChannelPluginCapabilities {
29
- chatTypes?: readonly ("direct" | "group")[];
30
- }
31
-
32
- export interface ResolvedAccountResult {
33
- ok: true;
34
- to: string;
35
- }
36
-
37
- export interface ResolvedAccountError {
38
- ok: false;
39
- error: Error;
40
- }
41
-
42
- export type ResolvedAccount = ResolvedAccountResult | ResolvedAccountError;
43
-
44
- export interface OutboundAdapter {
45
- deliveryMode?: "direct" | "queue";
46
- resolveTarget?: (params: { to?: string }) => ResolvedAccount;
47
- sendText?: (params: {
48
- to: string;
49
- text: string;
50
- accountId?: string;
51
- }) => Promise<{ ok: boolean; error?: Error }>;
52
- }
53
-
54
- export interface AccountInspection {
55
- enabled: boolean;
56
- configured: boolean;
57
- tokenStatus: "available" | "missing" | "invalid";
58
- }
59
-
60
- export interface ChannelSetup {
61
- resolveAccount: (
62
- cfg: OpenClawConfig,
63
- accountId?: string | null,
64
- ) => unknown;
65
- inspectAccount?: (
66
- cfg: OpenClawConfig,
67
- accountId?: string | null,
68
- ) => AccountInspection;
69
- }
70
-
71
- export interface ChannelPluginBase {
72
- id: string;
73
- setup?: ChannelSetup;
74
- }
75
-
76
- export interface ChatChannelPlugin<TResolved = unknown> {
77
- base: ChannelPluginBase;
78
- meta?: ChannelPluginMeta;
79
- capabilities?: ChannelPluginCapabilities;
80
- config?: {
81
- listAccountIds?: (cfg: unknown) => string[];
82
- resolveAccount?: (cfg: unknown, accountId?: string) => unknown;
83
- };
84
- outbound?: OutboundAdapter;
85
- setupWizard?: unknown;
86
- }
87
-
88
- export interface PluginLogger {
89
- debug?: (msg: string) => void;
90
- info?: (msg: string) => void;
91
- warn?: (msg: string) => void;
92
- error?: (msg: string) => void;
93
- }
94
-
95
- export interface PluginApi {
96
- config: OpenClawConfig;
97
- logger?: PluginLogger;
98
- pluginConfig?: unknown;
99
- registrationMode: "full" | "setup-only" | "setup-runtime" | "cli-metadata";
100
- runtime?: unknown;
101
- registerChannel(options: { plugin: unknown }): void;
102
- registerService(service: {
103
- id: string;
104
- start: () => Promise<void>;
105
- stop: () => Promise<void>;
106
- }): void;
107
- registerTool(options: unknown): void;
108
- registerHook(events: string[], handler: unknown): void;
109
- registerHttpRoute(options: unknown): void;
110
- registerGatewayMethod(name: string, handler: unknown): void;
111
- registerCli(registrar: unknown, options?: unknown): void;
112
- registerCommand(options: unknown): void;
113
- }
114
-
115
- export type { PluginApi };
116
-
117
- export interface DefineChannelPluginEntryOptions<TPlugin> {
118
- id: string;
119
- name: string;
120
- description: string;
121
- plugin: TPlugin;
122
- configSchema?: unknown;
123
- setRuntime?: (runtime: unknown) => void;
124
- registerCliMetadata?: (api: PluginApi) => void;
125
- registerFull?: (api: PluginApi) => void;
126
- }
127
-
128
- export interface DefinedChannelPluginEntry<TPlugin> {
129
- plugin: TPlugin;
130
- }
131
-
132
- export interface DefineSetupPluginEntry<TPlugin> {
133
- plugin: TPlugin;
134
- }
135
-
136
- export function createChannelPluginBase(options: {
137
- id: string;
138
- setup: ChannelSetup;
139
- }): ChannelPluginBase;
140
-
141
- export function createChatChannelPlugin<TResolved>(options: {
142
- base: ChannelPluginBase;
143
- meta?: ChannelPluginMeta;
144
- capabilities?: ChannelPluginCapabilities;
145
- config?: {
146
- listAccountIds?: (cfg: unknown) => string[];
147
- resolveAccount?: (cfg: unknown, accountId?: string) => unknown;
148
- };
149
- outbound?: OutboundAdapter;
150
- setupWizard?: unknown;
151
- }): ChatChannelPlugin<TResolved>;
152
-
153
- export function defineChannelPluginEntry<TPlugin>(
154
- options: DefineChannelPluginEntryOptions<TPlugin>,
155
- ): DefinedChannelPluginEntry<TPlugin>;
156
-
157
- export function defineSetupPluginEntry<TPlugin>(
158
- plugin: TPlugin,
159
- ): DefineSetupPluginEntry<TPlugin>;
160
-
161
- export function buildChannelConfigSchema(schema: unknown): unknown;
162
- }