@searchfe/openclaw-baiduapp 0.1.0-beta.9 → 0.1.1
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 +9 -41
- package/dist/index.js +49 -166
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
2
|
|
|
3
|
-
type BaiduAppDmPolicy = 'open' | 'pairing' | 'allowlist' | 'disabled';
|
|
4
3
|
interface BaiduAppAccountConfig {
|
|
5
4
|
name?: string;
|
|
6
5
|
enabled?: boolean;
|
|
@@ -11,8 +10,6 @@ interface BaiduAppAccountConfig {
|
|
|
11
10
|
appSecret?: string;
|
|
12
11
|
apiBase?: string;
|
|
13
12
|
welcomeText?: string;
|
|
14
|
-
dmPolicy?: BaiduAppDmPolicy;
|
|
15
|
-
allowFrom?: string[];
|
|
16
13
|
}
|
|
17
14
|
type BaiduAppConfig = BaiduAppAccountConfig & {
|
|
18
15
|
accounts?: Record<string, BaiduAppAccountConfig>;
|
|
@@ -31,19 +28,14 @@ interface ResolvedBaiduAppAccount {
|
|
|
31
28
|
canSendActive: boolean;
|
|
32
29
|
config: BaiduAppAccountConfig;
|
|
33
30
|
}
|
|
34
|
-
interface BaiduAppSendTarget {
|
|
35
|
-
userId: string;
|
|
36
|
-
}
|
|
37
31
|
interface BaiduAppInboundBase {
|
|
38
32
|
MsgId?: string;
|
|
39
33
|
msgid?: string;
|
|
40
34
|
aibotid?: string;
|
|
41
35
|
response_url?: string;
|
|
42
36
|
from?: {
|
|
43
|
-
userid?: string;
|
|
44
37
|
appkey?: string;
|
|
45
38
|
};
|
|
46
|
-
FromUserName?: string;
|
|
47
39
|
ToUserName?: string;
|
|
48
40
|
CreateTime?: number;
|
|
49
41
|
MsgType?: string;
|
|
@@ -136,16 +128,6 @@ declare const baiduAppPlugin: {
|
|
|
136
128
|
welcomeText: {
|
|
137
129
|
type: string;
|
|
138
130
|
};
|
|
139
|
-
dmPolicy: {
|
|
140
|
-
type: string;
|
|
141
|
-
enum: string[];
|
|
142
|
-
};
|
|
143
|
-
allowFrom: {
|
|
144
|
-
type: string;
|
|
145
|
-
items: {
|
|
146
|
-
type: string;
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
131
|
defaultAccount: {
|
|
150
132
|
type: string;
|
|
151
133
|
};
|
|
@@ -182,16 +164,6 @@ declare const baiduAppPlugin: {
|
|
|
182
164
|
welcomeText: {
|
|
183
165
|
type: string;
|
|
184
166
|
};
|
|
185
|
-
dmPolicy: {
|
|
186
|
-
type: string;
|
|
187
|
-
enum: string[];
|
|
188
|
-
};
|
|
189
|
-
allowFrom: {
|
|
190
|
-
type: string;
|
|
191
|
-
items: {
|
|
192
|
-
type: string;
|
|
193
|
-
};
|
|
194
|
-
};
|
|
195
167
|
};
|
|
196
168
|
};
|
|
197
169
|
};
|
|
@@ -223,13 +195,6 @@ declare const baiduAppPlugin: {
|
|
|
223
195
|
canSendActive: boolean;
|
|
224
196
|
webhookPath: string;
|
|
225
197
|
};
|
|
226
|
-
resolveAllowFrom: (params: {
|
|
227
|
-
cfg: PluginConfig;
|
|
228
|
-
accountId?: string;
|
|
229
|
-
}) => string[];
|
|
230
|
-
formatAllowFrom: (params: {
|
|
231
|
-
allowFrom: Array<string | number>;
|
|
232
|
-
}) => string[];
|
|
233
198
|
};
|
|
234
199
|
directory: {
|
|
235
200
|
canResolve: (params: {
|
|
@@ -400,7 +365,12 @@ interface SendMessageResult {
|
|
|
400
365
|
invaliduser?: string;
|
|
401
366
|
msgid?: string;
|
|
402
367
|
}
|
|
403
|
-
|
|
368
|
+
interface SendMessageOptions$1 {
|
|
369
|
+
msgid?: string;
|
|
370
|
+
streamId?: string;
|
|
371
|
+
chunkKey?: number;
|
|
372
|
+
}
|
|
373
|
+
declare function sendBaiduAppMessage(account: ResolvedBaiduAppAccount, message: string, options?: SendMessageOptions$1): Promise<SendMessageResult>;
|
|
404
374
|
|
|
405
375
|
interface SendMessageOptions {
|
|
406
376
|
text?: string;
|
|
@@ -410,10 +380,8 @@ interface SendResult {
|
|
|
410
380
|
msgid?: string;
|
|
411
381
|
error?: string;
|
|
412
382
|
}
|
|
413
|
-
declare function
|
|
414
|
-
declare function
|
|
415
|
-
declare function sendBaiduDM(account: ResolvedBaiduAppAccount, userId: string, options: SendMessageOptions): Promise<SendResult>;
|
|
416
|
-
declare function sendBaidu(account: ResolvedBaiduAppAccount, target: string, options: SendMessageOptions): Promise<SendResult>;
|
|
383
|
+
declare function sendBaiduDM(account: ResolvedBaiduAppAccount, options: SendMessageOptions): Promise<SendResult>;
|
|
384
|
+
declare function sendBaidu(account: ResolvedBaiduAppAccount, options: SendMessageOptions): Promise<SendResult>;
|
|
417
385
|
|
|
418
386
|
interface MoltbotPluginApi {
|
|
419
387
|
registerChannel: (opts: {
|
|
@@ -436,4 +404,4 @@ declare const plugin: {
|
|
|
436
404
|
register(api: MoltbotPluginApi): void;
|
|
437
405
|
};
|
|
438
406
|
|
|
439
|
-
export { type BaiduAppConfig, type
|
|
407
|
+
export { type BaiduAppConfig, type BaiduAppInboundMessage, DEFAULT_ACCOUNT_ID, type MoltbotPluginApi, type ResolvedBaiduAppAccount, type SendMessageOptions$1 as SendBaiduAppMessageOptions, type SendMessageOptions, type SendResult, baiduAppPlugin, plugin as default, getBaiduAppRuntime, sendBaidu, sendBaiduAppMessage, sendBaiduDM, setBaiduAppRuntime };
|
package/dist/index.js
CHANGED
|
@@ -4058,9 +4058,7 @@ var BaiduAppAccountSchema = external_exports.object({
|
|
|
4058
4058
|
appKey: external_exports.string().optional(),
|
|
4059
4059
|
appSecret: external_exports.string().optional(),
|
|
4060
4060
|
apiBase: external_exports.string().optional(),
|
|
4061
|
-
welcomeText: external_exports.string().optional()
|
|
4062
|
-
dmPolicy: external_exports.enum(["open", "pairing", "allowlist", "disabled"]).optional(),
|
|
4063
|
-
allowFrom: external_exports.array(external_exports.string()).optional()
|
|
4061
|
+
welcomeText: external_exports.string().optional()
|
|
4064
4062
|
});
|
|
4065
4063
|
BaiduAppAccountSchema.extend({
|
|
4066
4064
|
defaultAccount: external_exports.string().optional(),
|
|
@@ -4080,8 +4078,6 @@ var BaiduAppConfigJsonSchema = {
|
|
|
4080
4078
|
appSecret: { type: "string" },
|
|
4081
4079
|
apiBase: { type: "string" },
|
|
4082
4080
|
welcomeText: { type: "string" },
|
|
4083
|
-
dmPolicy: { type: "string", enum: ["open", "pairing", "allowlist", "disabled"] },
|
|
4084
|
-
allowFrom: { type: "array", items: { type: "string" } },
|
|
4085
4081
|
defaultAccount: { type: "string" },
|
|
4086
4082
|
accounts: {
|
|
4087
4083
|
type: "object",
|
|
@@ -4097,9 +4093,7 @@ var BaiduAppConfigJsonSchema = {
|
|
|
4097
4093
|
appKey: { type: "string" },
|
|
4098
4094
|
appSecret: { type: "string" },
|
|
4099
4095
|
apiBase: { type: "string" },
|
|
4100
|
-
welcomeText: { type: "string" }
|
|
4101
|
-
dmPolicy: { type: "string", enum: ["open", "pairing", "allowlist", "disabled"] },
|
|
4102
|
-
allowFrom: { type: "array", items: { type: "string" } }
|
|
4096
|
+
welcomeText: { type: "string" }
|
|
4103
4097
|
}
|
|
4104
4098
|
}
|
|
4105
4099
|
}
|
|
@@ -4176,12 +4170,6 @@ function resolveBaiduAppAccount(params) {
|
|
|
4176
4170
|
config: merged
|
|
4177
4171
|
};
|
|
4178
4172
|
}
|
|
4179
|
-
function resolveDmPolicy(config) {
|
|
4180
|
-
return config.dmPolicy ?? "pairing";
|
|
4181
|
-
}
|
|
4182
|
-
function resolveAllowFrom(config) {
|
|
4183
|
-
return config.allowFrom ?? [];
|
|
4184
|
-
}
|
|
4185
4173
|
|
|
4186
4174
|
// src/shared/logger.ts
|
|
4187
4175
|
function createLogger(prefix, opts) {
|
|
@@ -4194,27 +4182,6 @@ function createLogger(prefix, opts) {
|
|
|
4194
4182
|
error: (msg) => errorFn(`[${prefix}] [ERROR] ${msg}`)
|
|
4195
4183
|
};
|
|
4196
4184
|
}
|
|
4197
|
-
|
|
4198
|
-
// src/shared/dm-policy.ts
|
|
4199
|
-
function checkDmPolicy(params) {
|
|
4200
|
-
const { dmPolicy, senderId, allowFrom = [] } = params;
|
|
4201
|
-
switch (dmPolicy) {
|
|
4202
|
-
case "open":
|
|
4203
|
-
return { allowed: true };
|
|
4204
|
-
case "pairing":
|
|
4205
|
-
return { allowed: true };
|
|
4206
|
-
case "allowlist":
|
|
4207
|
-
if (allowFrom.includes(senderId)) {
|
|
4208
|
-
return { allowed: true };
|
|
4209
|
-
}
|
|
4210
|
-
return {
|
|
4211
|
-
allowed: false,
|
|
4212
|
-
reason: `sender ${senderId} not in DM allowlist`
|
|
4213
|
-
};
|
|
4214
|
-
default:
|
|
4215
|
-
return { allowed: true };
|
|
4216
|
-
}
|
|
4217
|
-
}
|
|
4218
4185
|
function decodeEncodingAESKey(encodingAESKey) {
|
|
4219
4186
|
const trimmed = encodingAESKey.trim();
|
|
4220
4187
|
if (!trimmed) {
|
|
@@ -4298,8 +4265,8 @@ function encryptBaiduAppPlaintext(params) {
|
|
|
4298
4265
|
}
|
|
4299
4266
|
|
|
4300
4267
|
// src/api.ts
|
|
4301
|
-
var logger = createLogger("openclaw-baiduapp
|
|
4302
|
-
async function sendBaiduAppMessage(account,
|
|
4268
|
+
var logger = createLogger("openclaw-baiduapp");
|
|
4269
|
+
async function sendBaiduAppMessage(account, message, options) {
|
|
4303
4270
|
if (!account.canSendActive) {
|
|
4304
4271
|
logger.error("Account not configured for active sending (missing appKey, token, or encodingAESKey)");
|
|
4305
4272
|
return {
|
|
@@ -4310,8 +4277,7 @@ async function sendBaiduAppMessage(account, target, message) {
|
|
|
4310
4277
|
}
|
|
4311
4278
|
const payload = {
|
|
4312
4279
|
msgtype: "text",
|
|
4313
|
-
text: { content: message }
|
|
4314
|
-
touser: target.userId
|
|
4280
|
+
text: { content: message }
|
|
4315
4281
|
};
|
|
4316
4282
|
const plaintext = JSON.stringify(payload);
|
|
4317
4283
|
const encrypt = encryptBaiduAppPlaintext({
|
|
@@ -4328,7 +4294,12 @@ async function sendBaiduAppMessage(account, target, message) {
|
|
|
4328
4294
|
});
|
|
4329
4295
|
const sendMessageUrl = `${account.apiBase}/chat/openclaw/callback`;
|
|
4330
4296
|
const url = `${sendMessageUrl}?timestamp=${encodeURIComponent(timestamp)}&ak=${encodeURIComponent(account.appKey ?? "")}&nonce=${encodeURIComponent(nonce)}&msg_signature=${encodeURIComponent(msgSignature)}`;
|
|
4331
|
-
const body = JSON.stringify({
|
|
4297
|
+
const body = JSON.stringify({
|
|
4298
|
+
encrypt,
|
|
4299
|
+
...options?.msgid != null ? { msgid: options.msgid } : {},
|
|
4300
|
+
...options?.streamId != null ? { streamId: options.streamId } : {},
|
|
4301
|
+
...options?.chunkKey != null ? { chunkKey: options.chunkKey } : {}
|
|
4302
|
+
});
|
|
4332
4303
|
logger.info(`POST ${url}`);
|
|
4333
4304
|
logger.debug(`request body: ${body}`);
|
|
4334
4305
|
const resp = await fetch(url, {
|
|
@@ -4380,33 +4351,10 @@ function extractBaiduAppContent(msg) {
|
|
|
4380
4351
|
}
|
|
4381
4352
|
return msgtype ? `[${msgtype}]` : "";
|
|
4382
4353
|
}
|
|
4383
|
-
function resolveSenderId(msg) {
|
|
4384
|
-
const userid = msg.from?.userid?.trim() ?? msg.FromUserName?.trim();
|
|
4385
|
-
return userid || "unknown";
|
|
4386
|
-
}
|
|
4387
4354
|
async function dispatchBaiduAppMessage(params) {
|
|
4388
4355
|
const { cfg, account, msg, core, hooks } = params;
|
|
4389
4356
|
const safeCfg = cfg ?? {};
|
|
4390
4357
|
const logger2 = createLogger("openclaw-baiduapp", { log: params.log, error: params.error });
|
|
4391
|
-
const senderId = resolveSenderId(msg);
|
|
4392
|
-
const chatId = senderId;
|
|
4393
|
-
const accountConfig = account?.config ?? {};
|
|
4394
|
-
const dmPolicy = resolveDmPolicy(accountConfig);
|
|
4395
|
-
const allowFrom = resolveAllowFrom(accountConfig);
|
|
4396
|
-
logger2.debug(`dispatch: sender=${senderId} dmPolicy=${dmPolicy} allowFrom=[${allowFrom.join(",")}]`);
|
|
4397
|
-
if (dmPolicy === "disabled") {
|
|
4398
|
-
logger2.info(`dispatch rejected: dm disabled for account ${account.accountId}`);
|
|
4399
|
-
return;
|
|
4400
|
-
}
|
|
4401
|
-
const policyResult = checkDmPolicy({
|
|
4402
|
-
dmPolicy,
|
|
4403
|
-
senderId,
|
|
4404
|
-
allowFrom
|
|
4405
|
-
});
|
|
4406
|
-
if (!policyResult.allowed) {
|
|
4407
|
-
logger2.info(`dispatch rejected: policy=${dmPolicy} reason=${policyResult.reason} sender=${senderId}`);
|
|
4408
|
-
return;
|
|
4409
|
-
}
|
|
4410
4358
|
const channel = core.channel;
|
|
4411
4359
|
if (!channel?.routing?.resolveAgentRoute || !channel.reply?.dispatchReplyWithBufferedBlockDispatcher) {
|
|
4412
4360
|
logger2.warn("core routing or buffered dispatcher missing, skipping dispatch");
|
|
@@ -4416,7 +4364,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4416
4364
|
cfg: safeCfg,
|
|
4417
4365
|
channel: "openclaw-baiduapp",
|
|
4418
4366
|
accountId: account.accountId,
|
|
4419
|
-
peer: { kind: "dm", id:
|
|
4367
|
+
peer: { kind: "dm", id: "default" }
|
|
4420
4368
|
});
|
|
4421
4369
|
logger2.info(
|
|
4422
4370
|
`route resolved: sessionKey=${route.sessionKey} agentId=${route.agentId ?? "default"} accountId=${route.accountId}`
|
|
@@ -4425,7 +4373,6 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4425
4373
|
logger2.debug(
|
|
4426
4374
|
`message content extracted: len=${rawBody.length} preview="${rawBody.slice(0, 80)}${rawBody.length > 80 ? "..." : ""}"`
|
|
4427
4375
|
);
|
|
4428
|
-
const fromLabel = `user:${senderId}`;
|
|
4429
4376
|
const storePath = channel.session?.resolveStorePath?.(safeCfg.session?.store, {
|
|
4430
4377
|
agentId: route.agentId
|
|
4431
4378
|
});
|
|
@@ -4436,48 +4383,42 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4436
4383
|
const envelopeOptions = channel.reply?.resolveEnvelopeFormatOptions ? channel.reply.resolveEnvelopeFormatOptions(safeCfg) : void 0;
|
|
4437
4384
|
const body = channel.reply?.formatAgentEnvelope ? channel.reply.formatAgentEnvelope({
|
|
4438
4385
|
channel: "Baidu App",
|
|
4439
|
-
from:
|
|
4386
|
+
from: "",
|
|
4440
4387
|
previousTimestamp,
|
|
4441
4388
|
envelope: envelopeOptions,
|
|
4442
4389
|
body: rawBody
|
|
4443
4390
|
}) : rawBody;
|
|
4444
4391
|
const msgid = msg.msgid ?? msg.MsgId ?? void 0;
|
|
4445
|
-
const from = `openclaw-baiduapp:user:${senderId}`;
|
|
4446
|
-
const to = `user:${senderId}`;
|
|
4447
4392
|
const ctxPayload = channel.reply?.finalizeInboundContext ? channel.reply.finalizeInboundContext({
|
|
4448
4393
|
Body: body,
|
|
4449
4394
|
RawBody: rawBody,
|
|
4450
4395
|
CommandBody: rawBody,
|
|
4451
|
-
From:
|
|
4452
|
-
To:
|
|
4396
|
+
From: "openclaw-baiduapp:user",
|
|
4397
|
+
To: "user",
|
|
4453
4398
|
SessionKey: route.sessionKey,
|
|
4454
4399
|
AccountId: route.accountId ?? account.accountId,
|
|
4455
4400
|
ChatType: "direct",
|
|
4456
|
-
ConversationLabel:
|
|
4457
|
-
SenderName: senderId,
|
|
4458
|
-
SenderId: senderId,
|
|
4401
|
+
ConversationLabel: "user",
|
|
4459
4402
|
Provider: "openclaw-baiduapp",
|
|
4460
4403
|
Surface: "openclaw-baiduapp",
|
|
4461
4404
|
MessageSid: msgid,
|
|
4462
4405
|
OriginatingChannel: "openclaw-baiduapp",
|
|
4463
|
-
OriginatingTo:
|
|
4406
|
+
OriginatingTo: "user"
|
|
4464
4407
|
}) : {
|
|
4465
4408
|
Body: body,
|
|
4466
4409
|
RawBody: rawBody,
|
|
4467
4410
|
CommandBody: rawBody,
|
|
4468
|
-
From:
|
|
4469
|
-
To:
|
|
4411
|
+
From: "openclaw-baiduapp:user",
|
|
4412
|
+
To: "user",
|
|
4470
4413
|
SessionKey: route.sessionKey,
|
|
4471
4414
|
AccountId: route.accountId ?? account.accountId,
|
|
4472
4415
|
ChatType: "direct",
|
|
4473
|
-
ConversationLabel:
|
|
4474
|
-
SenderName: senderId,
|
|
4475
|
-
SenderId: senderId,
|
|
4416
|
+
ConversationLabel: "user",
|
|
4476
4417
|
Provider: "openclaw-baiduapp",
|
|
4477
4418
|
Surface: "openclaw-baiduapp",
|
|
4478
4419
|
MessageSid: msgid,
|
|
4479
4420
|
OriginatingChannel: "openclaw-baiduapp",
|
|
4480
|
-
OriginatingTo:
|
|
4421
|
+
OriginatingTo: "user"
|
|
4481
4422
|
};
|
|
4482
4423
|
if (channel.session?.recordInboundSession && storePath) {
|
|
4483
4424
|
await channel.session.recordInboundSession({
|
|
@@ -4494,7 +4435,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4494
4435
|
channel: "openclaw-baiduapp",
|
|
4495
4436
|
accountId: account.accountId
|
|
4496
4437
|
}) : void 0;
|
|
4497
|
-
logger2.info(`dispatching to agent: sessionKey=${route.sessionKey}
|
|
4438
|
+
logger2.info(`dispatching to agent: sessionKey=${route.sessionKey}`);
|
|
4498
4439
|
await channel.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
4499
4440
|
ctx: ctxPayload,
|
|
4500
4441
|
cfg: safeCfg,
|
|
@@ -4515,7 +4456,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4515
4456
|
}
|
|
4516
4457
|
}
|
|
4517
4458
|
});
|
|
4518
|
-
logger2.info(`agent reply dispatch complete: sessionKey=${route.sessionKey}
|
|
4459
|
+
logger2.info(`agent reply dispatch complete: sessionKey=${route.sessionKey}`);
|
|
4519
4460
|
}
|
|
4520
4461
|
|
|
4521
4462
|
// src/runtime.ts
|
|
@@ -4718,8 +4659,7 @@ function parseBaiduAppPlainMessage(raw) {
|
|
|
4718
4659
|
MsgId: xmlData.MsgId,
|
|
4719
4660
|
content: xmlData.Content,
|
|
4720
4661
|
Content: xmlData.Content,
|
|
4721
|
-
from: xmlData.FromUserName ? {
|
|
4722
|
-
FromUserName: xmlData.FromUserName,
|
|
4662
|
+
from: xmlData.FromUserName ? { appkey: xmlData.FromUserName } : void 0,
|
|
4723
4663
|
ToUserName: xmlData.ToUserName,
|
|
4724
4664
|
CreateTime: xmlData.CreateTime ? Number(xmlData.CreateTime) : void 0,
|
|
4725
4665
|
BotID: xmlData.BotID ? Number(xmlData.BotID) : void 0,
|
|
@@ -4928,10 +4868,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4928
4868
|
target.statusSink?.({ lastInboundAt: Date.now() });
|
|
4929
4869
|
const msgtype = String(msg.msgtype ?? msg.MsgType ?? "").toLowerCase();
|
|
4930
4870
|
const msgid = msg.msgid ?? msg.MsgId ? String(msg.msgid ?? msg.MsgId) : void 0;
|
|
4931
|
-
|
|
4932
|
-
logger2.info(
|
|
4933
|
-
`inbound: type=${msgtype || "unknown"} msgid=${msgid ?? "none"} sender=${inboundSenderId ?? "unknown"} account=${target.account.accountId}`
|
|
4934
|
-
);
|
|
4871
|
+
logger2.info(`inbound: type=${msgtype || "unknown"} msgid=${msgid ?? "none"} account=${target.account.accountId}`);
|
|
4935
4872
|
if (msgtype === "stream") {
|
|
4936
4873
|
const streamId2 = String(msg.stream?.id ?? "").trim();
|
|
4937
4874
|
const state = streamId2 ? streams.get(streamId2) : void 0;
|
|
@@ -4977,13 +4914,10 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4977
4914
|
if (eventtype === "enter_chat" || eventtype === "subscribe") {
|
|
4978
4915
|
const welcome = target.account.config.welcomeText?.trim();
|
|
4979
4916
|
if (welcome && target.account.canSendActive) {
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
logger2.
|
|
4983
|
-
|
|
4984
|
-
logger2.error(`failed to send welcome message: ${String(err)}`);
|
|
4985
|
-
});
|
|
4986
|
-
}
|
|
4917
|
+
logger2.info("sending welcome message");
|
|
4918
|
+
sendBaiduAppMessage(target.account, welcome).catch((err) => {
|
|
4919
|
+
logger2.error(`failed to send welcome message: ${String(err)}`);
|
|
4920
|
+
});
|
|
4987
4921
|
}
|
|
4988
4922
|
jsonOk(
|
|
4989
4923
|
res,
|
|
@@ -5022,15 +4956,12 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5022
4956
|
});
|
|
5023
4957
|
logger2.info(`stream created: streamId=${streamId} msgid=${msgid ?? "none"}`);
|
|
5024
4958
|
const core = tryGetBaiduAppRuntime();
|
|
5025
|
-
const senderId = msg.from?.userid?.trim() ?? msg.FromUserName?.trim();
|
|
5026
4959
|
if (core) {
|
|
5027
4960
|
const state = streams.get(streamId);
|
|
5028
4961
|
if (state) {
|
|
5029
4962
|
state.started = true;
|
|
5030
4963
|
}
|
|
5031
|
-
logger2.info(
|
|
5032
|
-
`agent dispatch started: streamId=${streamId} sender=${senderId ?? "unknown"} canSendActive=${target.account.canSendActive}`
|
|
5033
|
-
);
|
|
4964
|
+
logger2.info(`agent dispatch started: streamId=${streamId} canSendActive=${target.account.canSendActive}`);
|
|
5034
4965
|
const hooks = {
|
|
5035
4966
|
onChunk: (text) => {
|
|
5036
4967
|
const current = streams.get(streamId);
|
|
@@ -5069,25 +5000,27 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5069
5000
|
current.updatedAt = Date.now();
|
|
5070
5001
|
const contentLen = current.content.trim().length;
|
|
5071
5002
|
logger2.info(
|
|
5072
|
-
`agent dispatch done: streamId=${streamId} contentLen=${contentLen} canSendActive=${target.account.canSendActive}
|
|
5003
|
+
`agent dispatch done: streamId=${streamId} contentLen=${contentLen} canSendActive=${target.account.canSendActive}`
|
|
5073
5004
|
);
|
|
5074
5005
|
if (!target.account.canSendActive) {
|
|
5075
5006
|
logger2.warn(
|
|
5076
5007
|
`active send skipped: appKey/appSecret not configured for account ${target.account.accountId}`
|
|
5077
5008
|
);
|
|
5078
|
-
} else if (!senderId) {
|
|
5079
|
-
logger2.warn(`active send skipped: senderId is empty`);
|
|
5080
5009
|
} else if (!contentLen) {
|
|
5081
5010
|
logger2.warn(`active send skipped: agent produced no content`);
|
|
5082
5011
|
}
|
|
5083
|
-
if (target.account.canSendActive &&
|
|
5012
|
+
if (target.account.canSendActive && current.content.trim()) {
|
|
5084
5013
|
try {
|
|
5085
5014
|
const chunks = splitMessageByBytes(current.content, MAX_MESSAGE_BYTES);
|
|
5086
5015
|
logger2.info(
|
|
5087
|
-
`[REPLY-MODE:ACTIVE-SEND] active send starting: streamId=${streamId}
|
|
5016
|
+
`[REPLY-MODE:ACTIVE-SEND] active send starting: streamId=${streamId} chunks=${chunks.length} contentLen=${contentLen}`
|
|
5088
5017
|
);
|
|
5089
5018
|
for (let i = 0; i < chunks.length; i++) {
|
|
5090
|
-
await sendBaiduAppMessage(target.account,
|
|
5019
|
+
await sendBaiduAppMessage(target.account, chunks[i], {
|
|
5020
|
+
msgid,
|
|
5021
|
+
streamId,
|
|
5022
|
+
chunkKey: i
|
|
5023
|
+
});
|
|
5091
5024
|
logger2.debug(`active send chunk ${i + 1}/${chunks.length} sent: streamId=${streamId}`);
|
|
5092
5025
|
}
|
|
5093
5026
|
logger2.info(
|
|
@@ -5229,12 +5162,7 @@ var baiduAppPlugin = {
|
|
|
5229
5162
|
configured: account.configured,
|
|
5230
5163
|
canSendActive: account.canSendActive,
|
|
5231
5164
|
webhookPath: account.config.webhookPath ?? "/openclaw-baiduapp"
|
|
5232
|
-
})
|
|
5233
|
-
resolveAllowFrom: (params) => {
|
|
5234
|
-
const account = resolveBaiduAppAccount({ cfg: params.cfg, accountId: params.accountId });
|
|
5235
|
-
return resolveAllowFrom(account.config);
|
|
5236
|
-
},
|
|
5237
|
-
formatAllowFrom: (params) => params.allowFrom.map((entry) => String(entry).trim()).filter(Boolean).map((entry) => entry.toLowerCase())
|
|
5165
|
+
})
|
|
5238
5166
|
},
|
|
5239
5167
|
directory: {
|
|
5240
5168
|
canResolve: (params) => {
|
|
@@ -5299,7 +5227,7 @@ var baiduAppPlugin = {
|
|
|
5299
5227
|
}
|
|
5300
5228
|
return results;
|
|
5301
5229
|
},
|
|
5302
|
-
getTargetFormats: () => ["openclaw-baiduapp
|
|
5230
|
+
getTargetFormats: () => ["openclaw-baiduapp"]
|
|
5303
5231
|
},
|
|
5304
5232
|
outbound: {
|
|
5305
5233
|
deliveryMode: "direct",
|
|
@@ -5313,19 +5241,8 @@ var baiduAppPlugin = {
|
|
|
5313
5241
|
error: new Error("Account not configured for active sending (missing appKey or appSecret)")
|
|
5314
5242
|
};
|
|
5315
5243
|
}
|
|
5316
|
-
let to = params.to;
|
|
5317
|
-
const channelPrefix = "openclaw-baiduapp:";
|
|
5318
|
-
if (to.startsWith(channelPrefix)) {
|
|
5319
|
-
to = to.slice(channelPrefix.length);
|
|
5320
|
-
}
|
|
5321
|
-
let target;
|
|
5322
|
-
if (to.startsWith("user:")) {
|
|
5323
|
-
target = { userId: to.slice(5) };
|
|
5324
|
-
} else {
|
|
5325
|
-
target = { userId: to };
|
|
5326
|
-
}
|
|
5327
5244
|
try {
|
|
5328
|
-
const result = await sendBaiduAppMessage(account,
|
|
5245
|
+
const result = await sendBaiduAppMessage(account, params.text);
|
|
5329
5246
|
return {
|
|
5330
5247
|
channel: "openclaw-baiduapp",
|
|
5331
5248
|
ok: result.ok,
|
|
@@ -5351,12 +5268,6 @@ var baiduAppPlugin = {
|
|
|
5351
5268
|
error: new Error("Account not configured for active sending (missing appKey or appSecret)")
|
|
5352
5269
|
};
|
|
5353
5270
|
}
|
|
5354
|
-
let to = params.to;
|
|
5355
|
-
const channelPrefix = "openclaw-baiduapp:";
|
|
5356
|
-
if (to.startsWith(channelPrefix)) {
|
|
5357
|
-
to = to.slice(channelPrefix.length);
|
|
5358
|
-
}
|
|
5359
|
-
const target = to.startsWith("user:") ? { userId: to.slice(5) } : { userId: to };
|
|
5360
5271
|
const content = params.text?.trim() || params.mediaUrl || "";
|
|
5361
5272
|
if (!content) {
|
|
5362
5273
|
return {
|
|
@@ -5367,7 +5278,7 @@ var baiduAppPlugin = {
|
|
|
5367
5278
|
};
|
|
5368
5279
|
}
|
|
5369
5280
|
try {
|
|
5370
|
-
const result = await sendBaiduAppMessage(account,
|
|
5281
|
+
const result = await sendBaiduAppMessage(account, content);
|
|
5371
5282
|
return {
|
|
5372
5283
|
channel: "openclaw-baiduapp",
|
|
5373
5284
|
ok: result.ok,
|
|
@@ -5439,38 +5350,16 @@ var baiduAppPlugin = {
|
|
|
5439
5350
|
};
|
|
5440
5351
|
|
|
5441
5352
|
// src/send.ts
|
|
5442
|
-
function
|
|
5443
|
-
let normalized = target.trim();
|
|
5444
|
-
const channelPrefix = "openclaw-baiduapp:";
|
|
5445
|
-
if (normalized.startsWith(channelPrefix)) {
|
|
5446
|
-
normalized = normalized.slice(channelPrefix.length);
|
|
5447
|
-
}
|
|
5448
|
-
if (type === "user" && normalized.startsWith("user:")) {
|
|
5449
|
-
return normalized;
|
|
5450
|
-
}
|
|
5451
|
-
if (normalized.startsWith("user:")) {
|
|
5452
|
-
normalized = normalized.slice(5);
|
|
5453
|
-
}
|
|
5454
|
-
return `user:${normalized}`;
|
|
5455
|
-
}
|
|
5456
|
-
function parseTarget(target) {
|
|
5457
|
-
if (target.startsWith("user:")) {
|
|
5458
|
-
return { userId: target.slice(5) };
|
|
5459
|
-
}
|
|
5460
|
-
return { userId: target };
|
|
5461
|
-
}
|
|
5462
|
-
async function sendBaiduDM(account, userId, options) {
|
|
5353
|
+
async function sendBaiduDM(account, options) {
|
|
5463
5354
|
if (!account.canSendActive) {
|
|
5464
5355
|
return {
|
|
5465
5356
|
ok: false,
|
|
5466
5357
|
error: "Account not configured for active sending (missing appKey or appSecret)"
|
|
5467
5358
|
};
|
|
5468
5359
|
}
|
|
5469
|
-
|
|
5470
|
-
const target = parseTarget(normalizedTarget);
|
|
5471
|
-
return sendMessage(account, target, options);
|
|
5360
|
+
return sendMessage(account, options);
|
|
5472
5361
|
}
|
|
5473
|
-
async function sendMessage(account,
|
|
5362
|
+
async function sendMessage(account, options) {
|
|
5474
5363
|
if (!options.text?.trim()) {
|
|
5475
5364
|
return {
|
|
5476
5365
|
ok: false,
|
|
@@ -5478,7 +5367,7 @@ async function sendMessage(account, target, options) {
|
|
|
5478
5367
|
};
|
|
5479
5368
|
}
|
|
5480
5369
|
try {
|
|
5481
|
-
const textResult = await sendBaiduAppMessage(account,
|
|
5370
|
+
const textResult = await sendBaiduAppMessage(account, options.text);
|
|
5482
5371
|
return {
|
|
5483
5372
|
ok: textResult.ok,
|
|
5484
5373
|
msgid: textResult.msgid,
|
|
@@ -5491,20 +5380,14 @@ async function sendMessage(account, target, options) {
|
|
|
5491
5380
|
};
|
|
5492
5381
|
}
|
|
5493
5382
|
}
|
|
5494
|
-
async function sendBaidu(account,
|
|
5383
|
+
async function sendBaidu(account, options) {
|
|
5495
5384
|
if (!account.canSendActive) {
|
|
5496
5385
|
return {
|
|
5497
5386
|
ok: false,
|
|
5498
5387
|
error: "Account not configured for active sending (missing appKey or appSecret)"
|
|
5499
5388
|
};
|
|
5500
5389
|
}
|
|
5501
|
-
|
|
5502
|
-
const channelPrefix = "openclaw-baiduapp:";
|
|
5503
|
-
if (normalizedTarget.startsWith(channelPrefix)) {
|
|
5504
|
-
normalizedTarget = normalizedTarget.slice(channelPrefix.length);
|
|
5505
|
-
}
|
|
5506
|
-
const parsedTarget = parseTarget(normalizedTarget);
|
|
5507
|
-
return sendMessage(account, parsedTarget, options);
|
|
5390
|
+
return sendMessage(account, options);
|
|
5508
5391
|
}
|
|
5509
5392
|
|
|
5510
5393
|
// index.ts
|
|
@@ -5529,6 +5412,6 @@ var plugin = {
|
|
|
5529
5412
|
};
|
|
5530
5413
|
var index_default = plugin;
|
|
5531
5414
|
|
|
5532
|
-
export { DEFAULT_ACCOUNT_ID, baiduAppPlugin, index_default as default, getBaiduAppRuntime,
|
|
5415
|
+
export { DEFAULT_ACCOUNT_ID, baiduAppPlugin, index_default as default, getBaiduAppRuntime, sendBaidu, sendBaiduAppMessage, sendBaiduDM, setBaiduAppRuntime };
|
|
5533
5416
|
//# sourceMappingURL=index.js.map
|
|
5534
5417
|
//# sourceMappingURL=index.js.map
|