@ai-wendao/ant 0.4.4 → 0.4.6
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/README.md +1 -1
- package/client.js +544 -199
- package/delegation.js +29 -0
- package/index.js +10 -4
- package/package.json +1 -1
package/delegation.js
CHANGED
|
@@ -1048,6 +1048,8 @@ export function startDelegationHost(ctx, readConnection, { ledger = new Delegati
|
|
|
1048
1048
|
const consumers = new Map()
|
|
1049
1049
|
let enrolledFingerprints = new Set()
|
|
1050
1050
|
let enrolledOrigins = new Map()
|
|
1051
|
+
let dmChatEnabledByFingerprint = new Map()
|
|
1052
|
+
const dmDisabledNoticeAt = new Map()
|
|
1051
1053
|
let legacyDmGrants = []
|
|
1052
1054
|
let legacyGroupGrants = []
|
|
1053
1055
|
let enrollmentKnown = false
|
|
@@ -1270,6 +1272,25 @@ export function startDelegationHost(ctx, readConnection, { ledger = new Delegati
|
|
|
1270
1272
|
scheduleProcess(entry, 'ANT owner binding reply stalled:')
|
|
1271
1273
|
return { accepted: true }
|
|
1272
1274
|
}
|
|
1275
|
+
if (dmChatEnabledByFingerprint.get(event.fingerprint) === false) {
|
|
1276
|
+
const noticeKey = `${event.fingerprint}\0${event.actor.id}`
|
|
1277
|
+
const now = Date.now()
|
|
1278
|
+
for (const [key, at] of dmDisabledNoticeAt) if (now - at >= 5 * 60_000) dmDisabledNoticeAt.delete(key)
|
|
1279
|
+
if (now - (dmDisabledNoticeAt.get(noticeKey) || 0) >= 5 * 60_000) {
|
|
1280
|
+
dmDisabledNoticeAt.set(noticeKey, now)
|
|
1281
|
+
while (dmDisabledNoticeAt.size > 500) dmDisabledNoticeAt.delete(dmDisabledNoticeAt.keys().next().value)
|
|
1282
|
+
try {
|
|
1283
|
+
const notice = await ctx.dshIm.replyChecked(event.botId, event.reply,
|
|
1284
|
+
'机器人所有者已关闭此机器人的私聊。请联系所有者在 ANT 插件的“机器人与聊天”页重新开启;群聊设置不受影响。',
|
|
1285
|
+
{ expectedFingerprint: event.fingerprint, signal: signal || controller.signal })
|
|
1286
|
+
if (notice?.sent !== true) dmDisabledNoticeAt.delete(noticeKey)
|
|
1287
|
+
} catch (error) {
|
|
1288
|
+
dmDisabledNoticeAt.delete(noticeKey)
|
|
1289
|
+
logger.warn?.('ANT 私聊关闭提示暂不可用:', error?.message)
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return { accepted: true }
|
|
1293
|
+
}
|
|
1273
1294
|
const proposedLegacy = parseDelegatedPrRequest(text)
|
|
1274
1295
|
const matchingLegacy = proposedLegacy.kind === 'pr_review' && legacyDmGrants.some((grant) =>
|
|
1275
1296
|
grant.bot_fingerprint === event.fingerprint && grant.pr_number === proposedLegacy.pr_number
|
|
@@ -1482,6 +1503,7 @@ export function startDelegationHost(ctx, readConnection, { ledger = new Delegati
|
|
|
1482
1503
|
consumers.clear()
|
|
1483
1504
|
enrolledFingerprints = new Set()
|
|
1484
1505
|
enrolledOrigins = new Map()
|
|
1506
|
+
dmChatEnabledByFingerprint = new Map()
|
|
1485
1507
|
legacyDmGrants = []
|
|
1486
1508
|
legacyGroupGrants = []
|
|
1487
1509
|
enrollmentKnown = false
|
|
@@ -1523,6 +1545,8 @@ export function startDelegationHost(ctx, readConnection, { ledger = new Delegati
|
|
|
1523
1545
|
if (enrollmentKnown) {
|
|
1524
1546
|
enrolledFingerprints = new Set(deviceEnrolled.map((bot) => bot.bot_fingerprint))
|
|
1525
1547
|
enrolledOrigins = new Map(deviceEnrolled.map((bot) => [bot.bot_fingerprint, bot.gitea_origin]))
|
|
1548
|
+
dmChatEnabledByFingerprint = new Map(deviceEnrolled.map((bot) =>
|
|
1549
|
+
[bot.bot_fingerprint, bot.dm_chat_enabled !== false]))
|
|
1526
1550
|
}
|
|
1527
1551
|
let groups = []
|
|
1528
1552
|
try {
|
|
@@ -1605,6 +1629,11 @@ export function startDelegationHost(ctx, readConnection, { ledger = new Delegati
|
|
|
1605
1629
|
if (refreshing) await refreshDone
|
|
1606
1630
|
if (!stopped) await refresh()
|
|
1607
1631
|
}
|
|
1632
|
+
stop.setDmChat = (fingerprint, enabled) => {
|
|
1633
|
+
if (typeof fingerprint === 'string' && typeof enabled === 'boolean') {
|
|
1634
|
+
dmChatEnabledByFingerprint.set(fingerprint.toLowerCase(), enabled)
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1608
1637
|
stop.cancelTask = async (taskId, serviceUrl) => {
|
|
1609
1638
|
await ready
|
|
1610
1639
|
if (stopped || !ledgerReady) return false
|
package/index.js
CHANGED
|
@@ -25,6 +25,7 @@ const DELEGATION_BOTS_PATH = '/api/ant-teams/delegation/bots'
|
|
|
25
25
|
const DELEGATION_GRANTS_PATH = '/api/ant-teams/delegation/grants'
|
|
26
26
|
const DELEGATION_ENROLLED_BOTS_PATH = '/api/ant-teams/delegation/enrolled-bots'
|
|
27
27
|
const DELEGATION_GROUPS_PATH = '/api/ant-teams/delegation/groups'
|
|
28
|
+
const DELEGATION_DM_CHAT_PATH = '/api/ant-teams/delegation/dm-chat'
|
|
28
29
|
const DELEGATION_OWNER_CHALLENGE_PATH = '/api/ant-teams/delegation/owner-challenge'
|
|
29
30
|
const DELEGATION_STATUS_PATH = '/api/ant-teams/delegation/status'
|
|
30
31
|
const DELEGATION_CARDS_PATH = '/api/ant-teams/delegation/cards'
|
|
@@ -281,7 +282,8 @@ async function fetchDelegationGrants(request, ctx, credentials, settings) {
|
|
|
281
282
|
}
|
|
282
283
|
|
|
283
284
|
async function fetchDelegationGroupSettings(request, ctx, credentials, settings, kind, getHost) {
|
|
284
|
-
const methods = kind === 'groups' ? ['GET', 'PUT'] : kind === '
|
|
285
|
+
const methods = kind === 'groups' ? ['GET', 'PUT'] : kind === 'dm-chat' ? ['PUT']
|
|
286
|
+
: kind === 'challenge' ? ['POST'] : ['GET', 'POST', 'DELETE']
|
|
285
287
|
if (!methods.includes(request.method)) return jsonResponse(405, { message: '请求方式不支持。' })
|
|
286
288
|
let connection
|
|
287
289
|
try { connection = await readMemberConnection(credentials, settings) } catch {
|
|
@@ -312,6 +314,7 @@ async function fetchDelegationGroupSettings(request, ctx, credentials, settings,
|
|
|
312
314
|
return jsonResponse(400, { message: '机器人编号无效。' })
|
|
313
315
|
}
|
|
314
316
|
const path = kind === 'groups' ? '/api/me/im-delegations/groups'
|
|
317
|
+
: kind === 'dm-chat' ? '/api/me/im-delegations/dm-chat'
|
|
315
318
|
: kind === 'challenge' ? '/api/me/im-delegations/owner-challenge'
|
|
316
319
|
: request.method === 'DELETE'
|
|
317
320
|
? `/api/me/im-delegations/bots/${encodeURIComponent(body.bot_id)}`
|
|
@@ -331,11 +334,13 @@ async function fetchDelegationGroupSettings(request, ctx, credentials, settings,
|
|
|
331
334
|
redirect: 'manual', signal: AbortSignal.timeout(12_000),
|
|
332
335
|
})
|
|
333
336
|
if (response.status === 404 && request.method !== 'DELETE') {
|
|
334
|
-
return jsonResponse(426, { message: '
|
|
337
|
+
return jsonResponse(426, { message: '团队服务端尚未支持这项协作设置,请联系管理员升级 ANT 服务端。' })
|
|
335
338
|
}
|
|
336
339
|
if (response.status === 204) {
|
|
337
|
-
if (
|
|
338
|
-
const
|
|
340
|
+
if (['groups', 'dm-chat'].includes(kind) && request.method === 'PUT') {
|
|
341
|
+
const host = getHost?.()
|
|
342
|
+
if (kind === 'dm-chat') host?.setDmChat?.(body.bot_fingerprint, body.enabled)
|
|
343
|
+
const refresh = host?.refresh
|
|
339
344
|
if (refresh) await refresh().catch(() => undefined)
|
|
340
345
|
}
|
|
341
346
|
return new Response(null, { status: 204 })
|
|
@@ -943,6 +948,7 @@ export function apply(ctx) {
|
|
|
943
948
|
for (const [path, methods, kind] of [
|
|
944
949
|
[DELEGATION_ENROLLED_BOTS_PATH, ['GET', 'POST', 'DELETE'], 'bots'],
|
|
945
950
|
[DELEGATION_GROUPS_PATH, ['GET', 'PUT'], 'groups'],
|
|
951
|
+
[DELEGATION_DM_CHAT_PATH, ['PUT'], 'dm-chat'],
|
|
946
952
|
[DELEGATION_OWNER_CHALLENGE_PATH, ['POST'], 'challenge'],
|
|
947
953
|
]) {
|
|
948
954
|
connectionCtx.effect(() => connectionCtx.connection.fetch.register({
|