openclaw-stepfun 0.2.2
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/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +18 -0
- package/dist/src/accounts.d.ts +22 -0
- package/dist/src/accounts.js +43 -0
- package/dist/src/bot.d.ts +16 -0
- package/dist/src/bot.js +100 -0
- package/dist/src/channel.d.ts +4 -0
- package/dist/src/channel.js +206 -0
- package/dist/src/client.d.ts +51 -0
- package/dist/src/client.js +206 -0
- package/dist/src/monitor.d.ts +19 -0
- package/dist/src/monitor.js +153 -0
- package/dist/src/proto/capy/botauth/auth_common_pb.d.ts +82 -0
- package/dist/src/proto/capy/botauth/auth_common_pb.js +35 -0
- package/dist/src/proto/capy/botauth/botauth_connect.d.ts +118 -0
- package/dist/src/proto/capy/botauth/botauth_connect.js +118 -0
- package/dist/src/proto/capy/botauth/botauth_pb.d.ts +1065 -0
- package/dist/src/proto/capy/botauth/botauth_pb.js +348 -0
- package/dist/src/proto/capy/botauth/public_connect.d.ts +62 -0
- package/dist/src/proto/capy/botauth/public_connect.js +62 -0
- package/dist/src/proto/capy/botauth/public_pb.d.ts +254 -0
- package/dist/src/proto/capy/botauth/public_pb.js +105 -0
- package/dist/src/proto/capy/botmsg/botmsg_connect.d.ts +72 -0
- package/dist/src/proto/capy/botmsg/botmsg_connect.js +72 -0
- package/dist/src/proto/capy/botmsg/botmsg_pb.d.ts +426 -0
- package/dist/src/proto/capy/botmsg/botmsg_pb.js +160 -0
- package/dist/src/proto/capy/botway/ctrl_connect.d.ts +61 -0
- package/dist/src/proto/capy/botway/ctrl_connect.js +61 -0
- package/dist/src/proto/capy/botway/ctrl_pb.d.ts +267 -0
- package/dist/src/proto/capy/botway/ctrl_pb.js +120 -0
- package/dist/src/proto/capy/botway/stream_connect.d.ts +26 -0
- package/dist/src/proto/capy/botway/stream_connect.js +26 -0
- package/dist/src/proto/capy/botway/stream_pb.d.ts +495 -0
- package/dist/src/proto/capy/botway/stream_pb.js +165 -0
- package/dist/src/reply-dispatcher.d.ts +17 -0
- package/dist/src/reply-dispatcher.js +234 -0
- package/dist/src/runtime.d.ts +4 -0
- package/dist/src/runtime.js +11 -0
- package/dist/src/send.d.ts +19 -0
- package/dist/src/send.js +66 -0
- package/dist/src/types.d.ts +65 -0
- package/dist/src/types.js +2 -0
- package/dist/src/websocket/cacheEvent.d.ts +17 -0
- package/dist/src/websocket/cacheEvent.js +61 -0
- package/dist/src/websocket/connect.d.ts +32 -0
- package/dist/src/websocket/connect.js +79 -0
- package/dist/src/websocket/constant.d.ts +8 -0
- package/dist/src/websocket/constant.js +10 -0
- package/dist/src/websocket/eventBus.d.ts +15 -0
- package/dist/src/websocket/eventBus.js +46 -0
- package/dist/src/websocket/index.d.ts +117 -0
- package/dist/src/websocket/index.js +637 -0
- package/dist/src/websocket/service.d.ts +36 -0
- package/dist/src/websocket/service.js +4 -0
- package/dist/src/websocket/stream.d.ts +10 -0
- package/dist/src/websocket/stream.js +24 -0
- package/dist/src/websocket/streamConnect.d.ts +40 -0
- package/dist/src/websocket/streamConnect.js +48 -0
- package/openclaw.plugin.json +23 -0
- package/package.json +69 -0
- package/scripts/setup.mjs +381 -0
- package/scripts/switch-env.mjs +98 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OpenClaw
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# OpenClaw Stepfun Plugin
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://www.npmjs.com/package/openclaw-stepfun)
|
|
5
|
+
|
|
6
|
+
OpenClaw Stepfun WebSocket Gateway Channel Plugin - 将阶跃星辰 Stepfun Bot API 集成到 OpenClaw 平台。
|
|
7
|
+
|
|
8
|
+
## 功能特性
|
|
9
|
+
|
|
10
|
+
- 🤖 支持 Stepfun Bot API 双向通信
|
|
11
|
+
- 🔄 自动重连和心跳保活
|
|
12
|
+
- 📡 WebSocket 实时消息推送
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
openclaw plugins install openclaw-stepfun
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
验证安装:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
openclaw plugins list
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 配置插件
|
|
27
|
+
|
|
28
|
+
打开 OpenClaw Web UI(默认地址:http://127.0.0.1:18789):
|
|
29
|
+
|
|
30
|
+
1. 进入 **Channels** 页面
|
|
31
|
+
2. 找到 **Stepfun Channels**
|
|
32
|
+
3. 填写 **App ID** 和 **App Token**
|
|
33
|
+
4. 点击 **Save** 保存配置
|
|
34
|
+
|
|
35
|
+
## 更新
|
|
36
|
+
|
|
37
|
+
更新插件到最新版本:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
openclaw plugins update openclaw-stepfun
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
更新完成后重启网关:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
openclaw gateway restart
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 环境要求
|
|
50
|
+
|
|
51
|
+
- OpenClaw >= 2026.2.0
|
|
52
|
+
- Node.js >= 18.0.0
|
|
53
|
+
|
|
54
|
+
## 许可证
|
|
55
|
+
|
|
56
|
+
[MIT](LICENSE)
|
|
57
|
+
|
|
58
|
+
## 相关链接
|
|
59
|
+
|
|
60
|
+
- [OpenClaw 官方文档](https://docs.openclaw.com)
|
|
61
|
+
- [Stepfun 开放平台](https://platform.stepfun.com)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
2
|
+
export { monitorStepfunProvider } from "./src/monitor.js";
|
|
3
|
+
export { sendMessageStepfun } from "./src/send.js";
|
|
4
|
+
export { stepfunPlugin } from "./src/channel.js";
|
|
5
|
+
declare const plugin: {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
configSchema: unknown;
|
|
10
|
+
register: (api: OpenClawPluginApi) => void;
|
|
11
|
+
};
|
|
12
|
+
export default plugin;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
|
|
2
|
+
import { stepfunPlugin } from "./src/channel.js";
|
|
3
|
+
import { setStepfunRuntime } from "./src/runtime.js";
|
|
4
|
+
export { monitorStepfunProvider } from "./src/monitor.js";
|
|
5
|
+
export { sendMessageStepfun } from "./src/send.js";
|
|
6
|
+
export { stepfunPlugin } from "./src/channel.js";
|
|
7
|
+
const plugin = {
|
|
8
|
+
id: "openclaw-stepfun",
|
|
9
|
+
name: "OpenClaw Stepfun",
|
|
10
|
+
description: "Stepfun WebSocket gateway channel plugin",
|
|
11
|
+
configSchema: emptyPluginConfigSchema(),
|
|
12
|
+
register(api) {
|
|
13
|
+
setStepfunRuntime(api.runtime);
|
|
14
|
+
api.registerChannel({ plugin: stepfunPlugin });
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export default plugin;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
2
|
+
import type { ResolvedStepfunAccount } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Resolve Stepfun account configuration.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveStepfunAccount(params: {
|
|
7
|
+
cfg: OpenClawConfig;
|
|
8
|
+
accountId?: string | null;
|
|
9
|
+
}): ResolvedStepfunAccount;
|
|
10
|
+
/**
|
|
11
|
+
* List all Stepfun account IDs.
|
|
12
|
+
*/
|
|
13
|
+
export declare function listStepfunAccountIds(cfg: OpenClawConfig): string[];
|
|
14
|
+
/**
|
|
15
|
+
* List enabled Stepfun accounts.
|
|
16
|
+
*/
|
|
17
|
+
export declare function listEnabledStepfunAccounts(cfg: OpenClawConfig): ResolvedStepfunAccount[];
|
|
18
|
+
/**
|
|
19
|
+
* Resolve default Stepfun account ID.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveDefaultStepfunAccountId(_cfg: OpenClawConfig): string;
|
|
22
|
+
//# sourceMappingURL=accounts.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve Stepfun account configuration.
|
|
4
|
+
*/
|
|
5
|
+
export function resolveStepfunAccount(params) {
|
|
6
|
+
const { cfg, accountId = DEFAULT_ACCOUNT_ID } = params;
|
|
7
|
+
const stepfunCfg = cfg.channels?.stepfun;
|
|
8
|
+
const enabled = stepfunCfg?.enabled ?? false;
|
|
9
|
+
// Account is configured if both appId and appToken are provided
|
|
10
|
+
const configured = Boolean(stepfunCfg?.appId && stepfunCfg?.appToken);
|
|
11
|
+
return {
|
|
12
|
+
accountId: accountId ?? DEFAULT_ACCOUNT_ID,
|
|
13
|
+
enabled,
|
|
14
|
+
configured,
|
|
15
|
+
config: stepfunCfg ?? {},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* List all Stepfun account IDs.
|
|
20
|
+
*/
|
|
21
|
+
export function listStepfunAccountIds(cfg) {
|
|
22
|
+
const stepfunCfg = cfg.channels?.stepfun;
|
|
23
|
+
if (!stepfunCfg) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
return [DEFAULT_ACCOUNT_ID];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* List enabled Stepfun accounts.
|
|
30
|
+
*/
|
|
31
|
+
export function listEnabledStepfunAccounts(cfg) {
|
|
32
|
+
const accountIds = listStepfunAccountIds(cfg);
|
|
33
|
+
return accountIds
|
|
34
|
+
.map((accountId) => resolveStepfunAccount({ cfg, accountId }))
|
|
35
|
+
.filter((account) => account.enabled && account.configured);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolve default Stepfun account ID.
|
|
39
|
+
*/
|
|
40
|
+
export function resolveDefaultStepfunAccountId(_cfg) {
|
|
41
|
+
return DEFAULT_ACCOUNT_ID;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { OpenClawConfig, RuntimeEnv } from "openclaw/plugin-sdk";
|
|
2
|
+
import type { StepfunInboundMessage, StepfunMessageContext } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parse incoming message from Stepfun gateway.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseStepfunMessage(message: StepfunInboundMessage): StepfunMessageContext;
|
|
7
|
+
/**
|
|
8
|
+
* Handle an inbound message from Stepfun gateway.
|
|
9
|
+
*/
|
|
10
|
+
export declare function handleStepfunMessage(params: {
|
|
11
|
+
cfg: OpenClawConfig;
|
|
12
|
+
message: StepfunInboundMessage;
|
|
13
|
+
runtime?: RuntimeEnv;
|
|
14
|
+
accountId?: string;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=bot.d.ts.map
|
package/dist/src/bot.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { resolveStepfunAccount } from "./accounts.js";
|
|
2
|
+
import { getStepfunRuntime } from "./runtime.js";
|
|
3
|
+
import { createStepfunReplyDispatcher } from "./reply-dispatcher.js";
|
|
4
|
+
/**
|
|
5
|
+
* Parse incoming message from Stepfun gateway.
|
|
6
|
+
*/
|
|
7
|
+
export function parseStepfunMessage(message) {
|
|
8
|
+
return {
|
|
9
|
+
chatSessionId: message.chatSessionId,
|
|
10
|
+
messageId: message.messageId,
|
|
11
|
+
userId: message.userId,
|
|
12
|
+
userName: message.userName,
|
|
13
|
+
content: message.content,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Handle an inbound message from Stepfun gateway.
|
|
18
|
+
*/
|
|
19
|
+
export async function handleStepfunMessage(params) {
|
|
20
|
+
const { cfg, message, runtime, accountId } = params;
|
|
21
|
+
const account = resolveStepfunAccount({ cfg, accountId });
|
|
22
|
+
const log = runtime?.log ?? console.log;
|
|
23
|
+
const error = runtime?.error ?? console.error;
|
|
24
|
+
const ctx = parseStepfunMessage(message);
|
|
25
|
+
log(`stepfun[${account.accountId}]: received message from ${ctx.userId} in chat session ${ctx.chatSessionId}`);
|
|
26
|
+
try {
|
|
27
|
+
const core = getStepfunRuntime();
|
|
28
|
+
// Build identifiers for OpenClaw
|
|
29
|
+
const stepfunFrom = `stepfun:${ctx.userId}`;
|
|
30
|
+
const stepfunTo = `stepfun:${ctx.chatSessionId}`;
|
|
31
|
+
// Resolve agent route
|
|
32
|
+
const route = core.channel.routing.resolveAgentRoute({
|
|
33
|
+
cfg,
|
|
34
|
+
channel: "stepfun",
|
|
35
|
+
accountId: account.accountId,
|
|
36
|
+
peer: {
|
|
37
|
+
kind: "direct",
|
|
38
|
+
id: `${ctx.chatSessionId}:${ctx.userId}`,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const preview = ctx.content.replace(/\s+/g, " ").slice(0, 160);
|
|
42
|
+
const inboundLabel = `Stepfun[${account.accountId}] message from ${ctx.userId}`;
|
|
43
|
+
core.system.enqueueSystemEvent(`${inboundLabel}: ${preview}`, {
|
|
44
|
+
sessionKey: route.sessionKey,
|
|
45
|
+
contextKey: `stepfun:message:${ctx.chatSessionId}:${ctx.messageId}`,
|
|
46
|
+
});
|
|
47
|
+
const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(cfg);
|
|
48
|
+
// Build message body with sender name
|
|
49
|
+
const speaker = ctx.userName ?? ctx.userId;
|
|
50
|
+
const messageBody = `${speaker}: ${ctx.content}`;
|
|
51
|
+
const body = core.channel.reply.formatAgentEnvelope({
|
|
52
|
+
channel: "Stepfun",
|
|
53
|
+
from: ctx.userId,
|
|
54
|
+
timestamp: new Date(),
|
|
55
|
+
envelope: envelopeOptions,
|
|
56
|
+
body: messageBody,
|
|
57
|
+
});
|
|
58
|
+
const ctxPayload = core.channel.reply.finalizeInboundContext({
|
|
59
|
+
Body: body,
|
|
60
|
+
RawBody: ctx.content,
|
|
61
|
+
CommandBody: ctx.content,
|
|
62
|
+
From: stepfunFrom,
|
|
63
|
+
To: stepfunTo,
|
|
64
|
+
SessionKey: route.sessionKey,
|
|
65
|
+
AccountId: route.accountId,
|
|
66
|
+
ChatType: "direct",
|
|
67
|
+
SenderName: ctx.userName ?? ctx.userId,
|
|
68
|
+
SenderId: ctx.userId,
|
|
69
|
+
Provider: "stepfun",
|
|
70
|
+
Surface: "stepfun",
|
|
71
|
+
MessageSid: ctx.messageId,
|
|
72
|
+
Timestamp: Date.now(),
|
|
73
|
+
WasMentioned: false,
|
|
74
|
+
CommandAuthorized: true,
|
|
75
|
+
OriginatingChannel: "stepfun",
|
|
76
|
+
OriginatingTo: stepfunTo,
|
|
77
|
+
});
|
|
78
|
+
// Create dispatcher that sends replies back to gateway
|
|
79
|
+
const agentId = route.agentId ?? "default";
|
|
80
|
+
const { dispatcher, replyOptions } = createStepfunReplyDispatcher({
|
|
81
|
+
cfg,
|
|
82
|
+
agentId,
|
|
83
|
+
runtime: { log, error },
|
|
84
|
+
chatSessionId: ctx.chatSessionId,
|
|
85
|
+
accountId: account.accountId,
|
|
86
|
+
});
|
|
87
|
+
log(`stepfun[${account.accountId}]: dispatching to agent (session=${route.sessionKey})`);
|
|
88
|
+
const { queuedFinal, counts } = await core.channel.reply.dispatchReplyFromConfig({
|
|
89
|
+
ctx: ctxPayload,
|
|
90
|
+
cfg,
|
|
91
|
+
dispatcher,
|
|
92
|
+
replyOptions,
|
|
93
|
+
});
|
|
94
|
+
log(`stepfun[${account.accountId}]: dispatch complete (queuedFinal=${queuedFinal}, replies=${counts.final})`);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
error(`stepfun[${account.accountId}]: failed to dispatch message: ${String(err)}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=bot.js.map
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk";
|
|
2
|
+
import { resolveStepfunAccount, listStepfunAccountIds, } from "./accounts.js";
|
|
3
|
+
const meta = {
|
|
4
|
+
id: "openclaw-stepfun",
|
|
5
|
+
label: "Stepfun",
|
|
6
|
+
selectionLabel: "Stepfun Gateway",
|
|
7
|
+
docsPath: "/channels/openclaw-stepfun",
|
|
8
|
+
docsLabel: "openclaw-stepfun",
|
|
9
|
+
blurb: "Stepfun WebSocket gateway integration.",
|
|
10
|
+
aliases: [],
|
|
11
|
+
order: 80,
|
|
12
|
+
};
|
|
13
|
+
export const stepfunPlugin = {
|
|
14
|
+
id: "stepfun",
|
|
15
|
+
meta: {
|
|
16
|
+
...meta,
|
|
17
|
+
},
|
|
18
|
+
capabilities: {
|
|
19
|
+
chatTypes: ["direct"],
|
|
20
|
+
media: false,
|
|
21
|
+
reactions: false,
|
|
22
|
+
threads: false,
|
|
23
|
+
polls: false,
|
|
24
|
+
nativeCommands: false,
|
|
25
|
+
blockStreaming: false,
|
|
26
|
+
},
|
|
27
|
+
agentPrompt: {
|
|
28
|
+
messageToolHints: () => [
|
|
29
|
+
"- Stepfun: messages are automatically sent to the WebSocket gateway",
|
|
30
|
+
"- Conversation context is maintained per chatSessionId",
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
reload: { configPrefixes: ["channels.stepfun"] },
|
|
34
|
+
configSchema: {
|
|
35
|
+
schema: {
|
|
36
|
+
type: "object",
|
|
37
|
+
additionalProperties: false,
|
|
38
|
+
properties: {
|
|
39
|
+
enabled: {
|
|
40
|
+
type: "boolean",
|
|
41
|
+
description: "Enable Stepfun channel",
|
|
42
|
+
default: false,
|
|
43
|
+
},
|
|
44
|
+
appId: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "App ID for bot authentication",
|
|
47
|
+
},
|
|
48
|
+
appToken: {
|
|
49
|
+
type: "string",
|
|
50
|
+
description: "App token for WebSocket connection authentication",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
config: {
|
|
56
|
+
listAccountIds: (cfg) => listStepfunAccountIds(cfg),
|
|
57
|
+
resolveAccount: (cfg, accountId) => resolveStepfunAccount({ cfg, accountId }),
|
|
58
|
+
defaultAccountId: () => DEFAULT_ACCOUNT_ID,
|
|
59
|
+
setAccountEnabled: ({ cfg, accountId, enabled }) => {
|
|
60
|
+
const isDefault = accountId === DEFAULT_ACCOUNT_ID;
|
|
61
|
+
if (isDefault) {
|
|
62
|
+
// Close WebSocket connection when disabling
|
|
63
|
+
if (!enabled) {
|
|
64
|
+
import("./client.js")
|
|
65
|
+
.then(({ closeStepfunWSClient }) => {
|
|
66
|
+
closeStepfunWSClient();
|
|
67
|
+
})
|
|
68
|
+
.catch(() => {
|
|
69
|
+
// Ignore import errors
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const stepfunConfig = cfg.channels?.stepfun ?? {};
|
|
73
|
+
return {
|
|
74
|
+
...cfg,
|
|
75
|
+
channels: {
|
|
76
|
+
...cfg.channels,
|
|
77
|
+
stepfun: {
|
|
78
|
+
...stepfunConfig,
|
|
79
|
+
enabled,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return cfg;
|
|
85
|
+
},
|
|
86
|
+
deleteAccount: ({ cfg, accountId }) => {
|
|
87
|
+
const isDefault = accountId === DEFAULT_ACCOUNT_ID;
|
|
88
|
+
if (isDefault) {
|
|
89
|
+
const next = { ...cfg };
|
|
90
|
+
const nextChannels = { ...cfg.channels };
|
|
91
|
+
delete nextChannels.stepfun;
|
|
92
|
+
if (Object.keys(nextChannels).length > 0) {
|
|
93
|
+
next.channels = nextChannels;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
delete next.channels;
|
|
97
|
+
}
|
|
98
|
+
return next;
|
|
99
|
+
}
|
|
100
|
+
return cfg;
|
|
101
|
+
},
|
|
102
|
+
isConfigured: (account) => account.configured,
|
|
103
|
+
describeAccount: (account) => ({
|
|
104
|
+
accountId: account.accountId,
|
|
105
|
+
enabled: account.enabled,
|
|
106
|
+
configured: account.configured,
|
|
107
|
+
name: account.name,
|
|
108
|
+
}),
|
|
109
|
+
},
|
|
110
|
+
security: {
|
|
111
|
+
collectWarnings: () => [],
|
|
112
|
+
},
|
|
113
|
+
setup: {
|
|
114
|
+
resolveAccountId: () => DEFAULT_ACCOUNT_ID,
|
|
115
|
+
applyAccountConfig: ({ cfg, accountId, input }) => {
|
|
116
|
+
const isDefault = !accountId || accountId === DEFAULT_ACCOUNT_ID;
|
|
117
|
+
if (isDefault) {
|
|
118
|
+
const stepfunConfig = (cfg.channels?.stepfun ?? {});
|
|
119
|
+
const setupInput = input;
|
|
120
|
+
return {
|
|
121
|
+
...cfg,
|
|
122
|
+
channels: {
|
|
123
|
+
...cfg.channels,
|
|
124
|
+
stepfun: {
|
|
125
|
+
...stepfunConfig,
|
|
126
|
+
enabled: true,
|
|
127
|
+
...(setupInput.appId ? { appId: setupInput.appId } : {}),
|
|
128
|
+
...(setupInput.appToken ? { appToken: setupInput.appToken } : {}),
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return cfg;
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
messaging: {
|
|
137
|
+
normalizeTarget: (target) => target,
|
|
138
|
+
targetResolver: {
|
|
139
|
+
looksLikeId: (id) => typeof id === "string" && id.length > 0,
|
|
140
|
+
hint: "<chatSessionId>",
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
directory: {
|
|
144
|
+
self: async () => null,
|
|
145
|
+
listPeers: async () => [],
|
|
146
|
+
listGroups: async () => [],
|
|
147
|
+
},
|
|
148
|
+
status: {
|
|
149
|
+
defaultRuntime: {
|
|
150
|
+
accountId: DEFAULT_ACCOUNT_ID,
|
|
151
|
+
running: false,
|
|
152
|
+
lastStartAt: null,
|
|
153
|
+
lastStopAt: null,
|
|
154
|
+
lastError: null,
|
|
155
|
+
port: null,
|
|
156
|
+
},
|
|
157
|
+
buildChannelSummary: ({ snapshot }) => ({
|
|
158
|
+
configured: snapshot.configured ?? false,
|
|
159
|
+
running: snapshot.running ?? false,
|
|
160
|
+
lastStartAt: snapshot.lastStartAt ?? null,
|
|
161
|
+
lastStopAt: snapshot.lastStopAt ?? null,
|
|
162
|
+
lastError: snapshot.lastError ?? null,
|
|
163
|
+
port: null,
|
|
164
|
+
}),
|
|
165
|
+
probeAccount: async ({ account, timeoutMs, cfg }) => {
|
|
166
|
+
return {
|
|
167
|
+
ok: account.configured,
|
|
168
|
+
message: account.configured ? "Configured" : "Not configured",
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
buildAccountSnapshot: ({ account, runtime }) => ({
|
|
172
|
+
accountId: account.accountId,
|
|
173
|
+
enabled: account.enabled,
|
|
174
|
+
configured: account.configured,
|
|
175
|
+
name: account.name,
|
|
176
|
+
running: runtime?.running ?? false,
|
|
177
|
+
lastStartAt: runtime?.lastStartAt ?? null,
|
|
178
|
+
lastStopAt: runtime?.lastStopAt ?? null,
|
|
179
|
+
lastError: runtime?.lastError ?? null,
|
|
180
|
+
port: null,
|
|
181
|
+
}),
|
|
182
|
+
},
|
|
183
|
+
gateway: {
|
|
184
|
+
startAccount: async (ctx) => {
|
|
185
|
+
const { monitorStepfunProvider } = await import("./monitor.js");
|
|
186
|
+
const account = resolveStepfunAccount({
|
|
187
|
+
cfg: ctx.cfg,
|
|
188
|
+
accountId: ctx.accountId,
|
|
189
|
+
});
|
|
190
|
+
ctx.setStatus({ accountId: ctx.accountId, port: null });
|
|
191
|
+
ctx.log?.info(`starting stepfun[${ctx.accountId}] (WebSocket gateway mode)`);
|
|
192
|
+
return monitorStepfunProvider({
|
|
193
|
+
config: ctx.cfg,
|
|
194
|
+
runtime: ctx.runtime,
|
|
195
|
+
abortSignal: ctx.abortSignal,
|
|
196
|
+
accountId: ctx.accountId,
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
stopAccount: async (ctx) => {
|
|
200
|
+
const { closeStepfunWSClient } = await import("./client.js");
|
|
201
|
+
ctx.log?.info(`stopping stepfun[${ctx.accountId}] (WebSocket gateway mode)`);
|
|
202
|
+
closeStepfunWSClient();
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=channel.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ResolvedStepfunAccount, StepfunOutboundMessage } from "./types.js";
|
|
2
|
+
import { _Socket } from "./websocket/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper class that adapts getSocket() to the StepfunWSClient interface.
|
|
5
|
+
* Maintains backward compatibility with existing code.
|
|
6
|
+
*/
|
|
7
|
+
declare class StepfunWSClientWrapper {
|
|
8
|
+
private socket;
|
|
9
|
+
private account;
|
|
10
|
+
private onMessage?;
|
|
11
|
+
private onError?;
|
|
12
|
+
private onClose?;
|
|
13
|
+
private isConnectedFlag;
|
|
14
|
+
constructor(socket: _Socket, account: ResolvedStepfunAccount);
|
|
15
|
+
private setupEventHandlers;
|
|
16
|
+
private convertToInboundMessage;
|
|
17
|
+
/**
|
|
18
|
+
* Connect to the gateway.
|
|
19
|
+
* Note: Errors are handled via onError callback, not thrown, to ensure
|
|
20
|
+
* the OpenClaw gateway is not affected by connection failures.
|
|
21
|
+
*/
|
|
22
|
+
connect(handlers: {
|
|
23
|
+
onMessage?: (data: unknown) => void;
|
|
24
|
+
onError?: (error: Error) => void;
|
|
25
|
+
onClose?: () => void;
|
|
26
|
+
}): void;
|
|
27
|
+
/**
|
|
28
|
+
* Send a message to the gateway.
|
|
29
|
+
* Converts JSON message to Protobuf format.
|
|
30
|
+
*/
|
|
31
|
+
send(data: StepfunOutboundMessage | Record<string, unknown>): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Close the connection.
|
|
34
|
+
*/
|
|
35
|
+
close(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Check if connected.
|
|
38
|
+
*/
|
|
39
|
+
isConnected(): boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get or create WebSocket client.
|
|
43
|
+
* If account config (appId or appToken) has changed, recreates the client with new credentials.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getStepfunWSClient(account: ResolvedStepfunAccount): StepfunWSClientWrapper;
|
|
46
|
+
/**
|
|
47
|
+
* Close and clear WebSocket client.
|
|
48
|
+
*/
|
|
49
|
+
export declare function closeStepfunWSClient(): void;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=client.d.ts.map
|