@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/dist/index.cjs +120 -115
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -9
- package/dist/index.d.ts +11 -9
- package/dist/index.js +120 -115
- package/dist/index.js.map +1 -1
- package/dist/setup-entry.cjs +110 -104
- package/dist/setup-entry.cjs.map +1 -1
- package/dist/setup-entry.d.cts +4 -9
- package/dist/setup-entry.d.ts +4 -9
- package/dist/setup-entry.js +110 -104
- package/dist/setup-entry.js.map +1 -1
- package/dist/types-C6n4PnbR.d.cts +14 -0
- package/dist/types-C6n4PnbR.d.ts +14 -0
- package/openclaw.plugin.json +2 -51
- package/package.json +3 -2
- package/src/channel.ts +129 -134
- package/src/index.ts +15 -21
- package/src/messaging/inbound.test.ts +2 -2
- package/src/messaging/inbound.ts +11 -8
- package/src/types.ts +0 -4
- package/src/typings/openclaw-plugin-sdk.d.ts +0 -162
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
|
|
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 {
|
|
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
|
-
|
|
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(
|
|
28
|
+
const accounts = listEnabledAccountConfigs(api.config);
|
|
35
29
|
if (accounts.length === 0) {
|
|
36
|
-
|
|
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
|
-
|
|
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(
|
|
51
|
-
|
|
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
|
-
|
|
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
|
-
|
|
55
|
+
api.logger?.info?.(`[cored] service started with ${clientCount()} account(s)`);
|
|
62
56
|
},
|
|
63
57
|
stop: async () => {
|
|
64
58
|
await destroyAllClients();
|
|
65
|
-
|
|
59
|
+
api.logger?.info?.("[cored] service stopped — all clients disconnected");
|
|
66
60
|
},
|
|
67
61
|
});
|
|
68
62
|
|
|
69
|
-
|
|
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:
|
|
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:
|
|
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():
|
|
59
|
+
function makeMockApi(): InboundPluginApi {
|
|
60
60
|
return {
|
|
61
61
|
registerChannel: vi.fn(),
|
|
62
62
|
registerService: vi.fn(),
|
package/src/messaging/inbound.ts
CHANGED
|
@@ -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
|
-
//
|
|
21
|
-
|
|
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?: (
|
|
28
|
+
dispatchReplyWithBufferedBlockDispatcher?: (...args: any[]) => any;
|
|
26
29
|
};
|
|
27
30
|
session?: {
|
|
28
|
-
recordInboundSession?: (
|
|
29
|
-
resolveStorePath?: (
|
|
31
|
+
recordInboundSession?: (...args: any[]) => any;
|
|
32
|
+
resolveStorePath?: (...args: any[]) => string;
|
|
30
33
|
};
|
|
31
34
|
routing?: {
|
|
32
|
-
resolveAgentRoute?: (
|
|
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:
|
|
320
|
+
api: InboundPluginApi,
|
|
318
321
|
account: CoredAccountConfig,
|
|
319
322
|
event: CoredMessageEvent,
|
|
320
323
|
opts: InboundDispatchOptions,
|
package/src/types.ts
CHANGED
|
@@ -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
|
-
}
|