@ai-wendao/ant 0.4.13 → 0.4.14
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 +8 -4
- package/client.js +463 -371
- package/conversation.js +115 -8
- package/delegation.js +83 -154
- package/index.js +26 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -26,9 +26,9 @@ 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
28
|
const DELEGATION_DM_CHAT_PATH = '/api/ant-teams/delegation/dm-chat'
|
|
29
|
-
const DELEGATION_OWNER_CHALLENGE_PATH = '/api/ant-teams/delegation/owner-challenge'
|
|
30
29
|
const DELEGATION_STATUS_PATH = '/api/ant-teams/delegation/status'
|
|
31
30
|
const DELEGATION_CARDS_PATH = '/api/ant-teams/delegation/cards'
|
|
31
|
+
const DELEGATION_RULE_RECOGNITION_PATH = '/api/ant-teams/delegation/recognize'
|
|
32
32
|
const DELEGATION_SETTINGS_PATH = '/api/ant-teams/delegation/settings'
|
|
33
33
|
const DELEGATION_EXECUTORS_PATH = '/api/ant-teams/delegation/executors'
|
|
34
34
|
const DELEGATION_LOCAL_SETTINGS_PATH = '/api/ant-teams/delegation/local-settings'
|
|
@@ -321,7 +321,6 @@ async function fetchDelegationGroupSettings(request, ctx, credentials, settings,
|
|
|
321
321
|
}
|
|
322
322
|
const path = kind === 'groups' ? '/api/me/im-delegations/groups'
|
|
323
323
|
: kind === 'dm-chat' ? '/api/me/im-delegations/dm-chat'
|
|
324
|
-
: kind === 'challenge' ? '/api/me/im-delegations/owner-challenge'
|
|
325
324
|
: request.method === 'DELETE'
|
|
326
325
|
? `/api/me/im-delegations/bots/${encodeURIComponent(body.bot_id)}`
|
|
327
326
|
: '/api/me/im-delegations/bots'
|
|
@@ -426,6 +425,26 @@ async function fetchDelegationCards(request, ctx, credentials, settings) {
|
|
|
426
425
|
} catch { return jsonResponse(502, { message: '暂时无法连接 ANT 团队服务。' }) }
|
|
427
426
|
}
|
|
428
427
|
|
|
428
|
+
async function fetchDelegationRuleRecognition(request, credentials, settings, getHost) {
|
|
429
|
+
if (request.method !== 'POST') return jsonResponse(405, { message: '只支持 POST 请求。' })
|
|
430
|
+
try {
|
|
431
|
+
const connection = await readMemberConnection(credentials, settings)
|
|
432
|
+
if (!connection) return jsonResponse(401, { message: '请先连接 ANT 团队。' })
|
|
433
|
+
const raw = await request.text()
|
|
434
|
+
if (raw.length > 8_192) return jsonResponse(413, { message: '规则描述过长。' })
|
|
435
|
+
let body
|
|
436
|
+
try { body = JSON.parse(raw) } catch { return jsonResponse(400, { message: '规则识别请求格式无效。' }) }
|
|
437
|
+
if (typeof body?.description !== 'string' || !body.description.trim() || body.description.length > 4000) {
|
|
438
|
+
return jsonResponse(400, { message: '请填写不超过 4000 字符的规则描述。' })
|
|
439
|
+
}
|
|
440
|
+
const host = getHost?.()
|
|
441
|
+
if (!host?.recognizeRule) return jsonResponse(503, { message: '本机 DSH 协作会话尚未就绪,请稍后重试。' })
|
|
442
|
+
return jsonResponse(200, await host.recognizeRule(body.description))
|
|
443
|
+
} catch (error) {
|
|
444
|
+
return jsonResponse(502, { message: error?.message || '任务规则识别失败,请稍后重试。' })
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
429
448
|
async function fetchDelegationRuntimeSettings(request, credentials, settings) {
|
|
430
449
|
if (request.method !== 'GET') return jsonResponse(405, { message: '请求方式不支持。' })
|
|
431
450
|
try {
|
|
@@ -967,7 +986,6 @@ export function apply(ctx) {
|
|
|
967
986
|
[DELEGATION_ENROLLED_BOTS_PATH, ['GET', 'POST', 'DELETE'], 'bots'],
|
|
968
987
|
[DELEGATION_GROUPS_PATH, ['GET', 'PUT'], 'groups'],
|
|
969
988
|
[DELEGATION_DM_CHAT_PATH, ['PUT'], 'dm-chat'],
|
|
970
|
-
[DELEGATION_OWNER_CHALLENGE_PATH, ['POST'], 'challenge'],
|
|
971
989
|
]) {
|
|
972
990
|
connectionCtx.effect(() => connectionCtx.connection.fetch.register({
|
|
973
991
|
path, methods, requestBody: 'buffered',
|
|
@@ -983,6 +1001,11 @@ export function apply(ctx) {
|
|
|
983
1001
|
path: DELEGATION_CARDS_PATH, methods: ['GET', 'POST', 'PUT', 'DELETE'], requestBody: 'buffered',
|
|
984
1002
|
fetch: (request) => fetchDelegationCards(request, connectionCtx, connectionCtx.credentials, connectionCtx.settings),
|
|
985
1003
|
}), 'ant-teams: member task cards')
|
|
1004
|
+
connectionCtx.effect(() => connectionCtx.connection.fetch.register({
|
|
1005
|
+
path: DELEGATION_RULE_RECOGNITION_PATH, methods: ['POST'], requestBody: 'buffered',
|
|
1006
|
+
fetch: (request) => fetchDelegationRuleRecognition(request,
|
|
1007
|
+
connectionCtx.credentials, connectionCtx.settings, () => delegationHost),
|
|
1008
|
+
}), 'ant-teams: recognize collaboration task rule')
|
|
986
1009
|
connectionCtx.effect(() => connectionCtx.connection.fetch.register({
|
|
987
1010
|
path: DELEGATION_SETTINGS_PATH, methods: ['GET'], requestBody: 'buffered',
|
|
988
1011
|
fetch: (request) => fetchDelegationRuntimeSettings(request, connectionCtx.credentials, connectionCtx.settings),
|