evolcore 0.0.26 → 0.0.27
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/CHANGELOG.md +25 -0
- package/bin/codex-managed-acl.ps1 +43 -0
- package/dist/agents/baseagent-availability.js +68 -0
- package/dist/agents/claude-runner.js +123 -22
- package/dist/agents/codex/app-server-client.js +63 -26
- package/dist/agents/codex-runner.js +316 -411
- package/dist/agents/ecagent-runner.js +170 -25
- package/dist/agents/gemini-runner.js +6 -0
- package/dist/agents/runner-types.js +50 -2
- package/dist/aun/aid/agentmd.js +73 -31
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +180 -1
- package/dist/aun/aid/identity.js +3 -3
- package/dist/aun/group/history.js +303 -0
- package/dist/aun/group/identity.js +43 -0
- package/dist/aun/group/index.js +5 -0
- package/dist/aun/{msg/group.js → group/operations.js} +161 -38
- package/dist/aun/{menu-client.js → menu/client.js} +12 -7
- package/dist/aun/menu/index.js +2 -0
- package/dist/aun/menu/transport.js +49 -0
- package/dist/aun/msg/index.js +2 -1
- package/dist/aun/msg/managed-operation.js +84 -18
- package/dist/aun/msg/mention-schema.js +51 -0
- package/dist/aun/msg/p2p.js +13 -8
- package/dist/aun/msg/upload.js +43 -88
- package/dist/aun/outbox.js +29 -7
- package/dist/aun/rpc/client.js +1 -0
- package/dist/aun/storage/client.js +39 -50
- package/dist/channels/aun.js +522 -233
- package/dist/channels/daemon.js +10 -6
- package/dist/cli/agent-command.js +108 -6
- package/dist/cli/agent-create.js +515 -2
- package/dist/cli/agent.js +109 -8
- package/dist/cli/aun-commands.js +191 -42
- package/dist/cli/config.js +8 -5
- package/dist/cli/contact.js +2 -2
- package/dist/cli/ctl-command.js +2 -2
- package/dist/cli/daemon-commands.js +35 -23
- package/dist/cli/diag.js +2 -2
- package/dist/cli/fs-command.js +3 -3
- package/dist/cli/handoff-command.js +6 -6
- package/dist/cli/index.js +8 -2
- package/dist/cli/init.js +34 -1
- package/dist/cli/managed-command-guard.js +2 -1
- package/dist/cli/menu-client.js +9 -5
- package/dist/cli/model.js +3 -3
- package/dist/cli/queue-command.js +2 -2
- package/dist/cli/response.js +2 -2
- package/dist/cli/restart-monitor.js +16 -2
- package/dist/cli/task-command.js +59 -0
- package/dist/cli/task-context.js +97 -49
- package/dist/cli/trigger-command.js +20 -10
- package/dist/config/builtin-roles.js +10 -0
- package/dist/config/config-field-policy.js +11 -0
- package/dist/config/config-manager.js +32 -4
- package/dist/config/config-operation-service.js +20 -5
- package/dist/config/contact-book-store.js +1 -1
- package/dist/config/contact-book.js +1 -1
- package/dist/config/contact-operation-service.js +1 -1
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config-store.js +1 -1
- package/dist/core/agent-application-service.js +5 -0
- package/dist/core/audit/event-key.js +17 -2
- package/dist/core/audit/log-integrity.js +34 -8
- package/dist/core/auth/agent-delegation.js +48 -14
- package/dist/core/auth/auth-gateway.js +2 -0
- package/dist/core/auth/authorization-audit.js +34 -38
- package/dist/core/auth/operation-authorizer.js +67 -5
- package/dist/core/auth/operation-catalog.js +110 -0
- package/dist/core/auth/remote-access-store.js +115 -9
- package/dist/core/bootstrap-messages.js +66 -7
- package/dist/core/bootstrap-service.js +110 -19
- package/dist/core/command/agent-control.js +88 -7
- package/dist/core/command/agent-storage-menu.js +443 -0
- package/dist/core/command/cli-intent-parser.js +19 -0
- package/dist/core/command/command-handler.js +76 -39
- package/dist/core/command/data-root-resolver.js +273 -0
- package/dist/core/command/group-menu.js +7 -2
- package/dist/core/command/menu-catalog.js +34 -4
- package/dist/core/command/menu-handler.js +348 -77
- package/dist/core/command/menu-protocol.js +40 -6
- package/dist/core/command/role-menu.js +2 -2
- package/dist/core/command/slash-handler.js +37 -22
- package/dist/core/event-catalog.js +4 -0
- package/dist/core/evolagent-registry.js +28 -2
- package/dist/core/group/invite-service.js +924 -0
- package/dist/core/interaction-router.js +22 -8
- package/dist/core/message/im-renderer.js +76 -15
- package/dist/core/message/message-bridge.js +94 -11
- package/dist/core/message/message-log.js +5 -3
- package/dist/core/message/message-queue.js +73 -41
- package/dist/core/message/response-engine.js +709 -117
- package/dist/core/permission/approval-gateway.js +36 -3
- package/dist/core/permission/ec-command-parser.js +61 -29
- package/dist/core/permission/protected-paths.js +134 -16
- package/dist/core/permission/sandbox-runtime.js +72 -3
- package/dist/core/permission/tool-error-code.js +15 -0
- package/dist/core/permission/tool-policy.js +7 -7
- package/dist/core/relation/peer-identity.js +57 -6
- package/dist/core/relation/shared-data.js +106 -0
- package/dist/core/role/runtime-policy.js +64 -0
- package/dist/core/runtime-lock.js +10 -26
- package/dist/core/session/runner-task-history.js +170 -0
- package/dist/core/session/session-manager.js +34 -6
- package/dist/core/session/session-mapper.js +41 -0
- package/dist/core/session/session-turn-coordinator.js +37 -7
- package/dist/core/session/session-turns.js +48 -7
- package/dist/core/task/task-recovery-service.js +176 -0
- package/dist/core/task/task-resume-operation.js +32 -0
- package/dist/eck/group-rules-sync.js +5 -3
- package/dist/eck/kit-renderer.js +1 -0
- package/dist/index.js +308 -54
- package/dist/ipc.js +141 -15
- package/dist/paths.js +17 -4
- package/dist/product.js +2 -0
- package/dist/trigger/event-source.js +19 -0
- package/dist/trigger/feedback.js +233 -40
- package/dist/trigger/parser.js +55 -5
- package/dist/trigger/patch.js +9 -0
- package/dist/trigger/scheduler.js +30 -4
- package/dist/trigger/validation.js +20 -3
- package/dist/utils/ecweb-utils.js +1 -0
- package/dist/utils/error-utils.js +40 -2
- package/dist/utils/logger.js +23 -13
- package/dist/utils/tool-summary.js +59 -3
- package/dist/utils/welcome.js +174 -1
- package/ecagent/dist/harness/agent-harness.js +3 -0
- package/ecagent/dist/harness/session/jsonl-storage.js +21 -2
- package/kits/docs/INDEX.md +0 -6
- package/kits/docs/channels/aun.md +15 -2
- package/kits/docs/channels/feishu.md +1 -1
- package/kits/docs/context-assembly.md +29 -17
- package/kits/docs/evolcore/INDEX.md +8 -3
- package/kits/docs/evolcore/agent-create.md +39 -7
- package/kits/docs/evolcore/agent.md +33 -1
- package/kits/docs/evolcore/aid.md +9 -1
- package/kits/docs/evolcore/config.md +40 -1
- package/kits/docs/evolcore/group-collaboration.md +1 -1
- package/kits/docs/evolcore/group.md +117 -2
- package/kits/docs/evolcore/menu-client.md +16 -0
- package/kits/docs/evolcore/msg.md +3 -0
- package/kits/docs/evolcore/storage.md +3 -0
- package/kits/docs/evolcore/task.md +14 -0
- package/kits/docs/evolcore/trigger.md +51 -3
- package/kits/docs/venues/group.md +5 -0
- package/kits/eck_manifest.json +27 -0
- package/kits/rules/01-overview.md +11 -7
- package/kits/rules/04-relation.md +2 -1
- package/kits/rules/05-venue.md +1 -1
- package/kits/rules/06-channel.md +6 -4
- package/kits/schemas/agent-config.schema.12.json +25 -1
- package/kits/schemas/daemon.schema.6.json +2 -2
- package/kits/schemas/defaults.schema.5.json +1 -1
- package/kits/schemas/relation-config.schema.1.json +1 -1
- package/kits/schemas/relation-config.schema.5.json +1 -1
- package/kits/schemas/role-config.schema.1.json +14 -0
- package/kits/templates/roles/member.json +5 -0
- package/kits/templates/roles/visitor.json +5 -0
- package/kits/templates/system-fragments/baseagent.md +1 -1
- package/kits/templates/system-fragments/bootstrap.md +26 -9
- package/kits/templates/system-fragments/channel.md +8 -44
- package/kits/templates/system-fragments/commands.md +10 -2
- package/kits/templates/system-fragments/group-unread-history.md +7 -0
- package/kits/templates/system-fragments/reply.md +56 -0
- package/package.json +7 -3
- package/dist/aun/group-identity.js +0 -9
- /package/dist/aun/{group-fs-download.js → group/fs-download.js} +0 -0
- /package/dist/aun/{msg/group-index.js → group/index-rpc.js} +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Message Service TTL in seconds; unrelated to Menu execution/client timeouts. */
|
|
2
|
+
export const MENU_MESSAGE_TTL_SECONDS = 60;
|
|
3
|
+
export const MENU_VOLATILE_SDK_VERSION = '0.5.17';
|
|
4
|
+
function parseSdkVersion(value) {
|
|
5
|
+
if (typeof value !== 'string' || !/^\d+\.\d+\.\d+$/.test(value.trim()))
|
|
6
|
+
return undefined;
|
|
7
|
+
const parts = value.trim().split('.').map(Number);
|
|
8
|
+
return parts.every(Number.isSafeInteger) ? parts : undefined;
|
|
9
|
+
}
|
|
10
|
+
/** Volatile cursors and device targeting require the SDK's 0.5.17 contract. */
|
|
11
|
+
export function supportsMenuVolatileTransport(value) {
|
|
12
|
+
const version = parseSdkVersion(value);
|
|
13
|
+
if (!version)
|
|
14
|
+
return false;
|
|
15
|
+
const minimum = parseSdkVersion(MENU_VOLATILE_SDK_VERSION);
|
|
16
|
+
return version[0] > minimum[0]
|
|
17
|
+
|| (version[0] === minimum[0] && (version[1] > minimum[1]
|
|
18
|
+
|| (version[1] === minimum[1] && version[2] >= minimum[2])));
|
|
19
|
+
}
|
|
20
|
+
/** Read only the SDK's public sender_device_id, never a payload/recipient device. */
|
|
21
|
+
export function menuSenderDeviceId(value) {
|
|
22
|
+
if (typeof value !== 'string' || value.length > 256 || /[\u0000-\u001f\u007f]/.test(value))
|
|
23
|
+
return undefined;
|
|
24
|
+
return value.trim() || undefined;
|
|
25
|
+
}
|
|
26
|
+
/** Enforce the Menu wire policy at the final P2P send boundary, including retries. */
|
|
27
|
+
export function menuTransportParams(method, params) {
|
|
28
|
+
if (method !== 'message.send' || typeof params.payload?.type !== 'string'
|
|
29
|
+
|| !params.payload.type.startsWith('menu.'))
|
|
30
|
+
return params;
|
|
31
|
+
if (params.payload.type !== 'menu.response')
|
|
32
|
+
return { ...params, ttl: MENU_MESSAGE_TTL_SECONDS };
|
|
33
|
+
const { to_device_id: target, menu_client_sdk_version: sdkVersion, ...rest } = params;
|
|
34
|
+
delete rest.device_id;
|
|
35
|
+
if (!supportsMenuVolatileTransport(sdkVersion ?? params.protected_headers?.sdk_version)) {
|
|
36
|
+
// Evol App versions backed by fastaun < 0.5.17 do not consume the
|
|
37
|
+
// volatile cursor or understand device-targeted Menu responses.
|
|
38
|
+
return rest;
|
|
39
|
+
}
|
|
40
|
+
if (target === undefined)
|
|
41
|
+
return { ...rest, ttl: MENU_MESSAGE_TTL_SECONDS };
|
|
42
|
+
const deviceId = menuSenderDeviceId(target);
|
|
43
|
+
if (!deviceId) {
|
|
44
|
+
throw Object.assign(new Error('Invalid Menu reply device'), { code: 'INVALID_MENU_REPLY_DEVICE', retryable: false });
|
|
45
|
+
}
|
|
46
|
+
// device_id takes precedence in the SDK; do not let it override the captured
|
|
47
|
+
// request sender. A rejected target is never retried as an AID broadcast.
|
|
48
|
+
return { ...rest, ttl: MENU_MESSAGE_TTL_SECONDS, to_device_id: deviceId };
|
|
49
|
+
}
|
package/dist/aun/msg/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { msgSend, msgPull, msgAck, msgRecall, msgOnline, } from './p2p.js';
|
|
2
2
|
export { msgHistory, MAX_MSG_HISTORY_LIMIT } from './history.js';
|
|
3
|
-
export {
|
|
3
|
+
export { groupHistory, parseGroupHistoryArgs, GroupHistoryError } from '../group/index.js';
|
|
4
|
+
export { groupSend, groupPull, groupAck, groupCreate, groupInfo, groupList, groupUpdate, groupDissolve, groupSuspend, groupResume, groupJoin, groupLeave, groupInvite, groupInvites, groupAcceptInvite, groupRejectInvite, groupRevokeInvite, groupKick, groupMembers, groupOnline, groupSetRole, groupTransferOwner, groupBan, groupUnban, groupBanlist, groupBlock, groupUnblock, groupBlocklist, groupReportStatus, groupMemberStatuses, groupRules, groupUpdateRules, groupRulesFileGet, groupRulesFileSet, groupRulesFilePublish, } from '../group/index.js';
|
|
4
5
|
export { uploadFileAndBuildPayload, inferPayloadType, isValidPayloadType } from './upload.js';
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { TextDecoder } from 'util';
|
|
2
2
|
import { getAidStore, loadClient, SLOT } from '../aid/index.js';
|
|
3
3
|
import { msgHistory } from './history.js';
|
|
4
|
+
import { groupHistory, parseGroupHistoryArgs, GroupHistoryError } from '../group/history.js';
|
|
4
5
|
import { msgOnline } from './p2p.js';
|
|
5
6
|
import { resolveRoot } from '../../paths.js';
|
|
6
|
-
import {
|
|
7
|
+
import { normalizeGroupAid } from '../group/identity.js';
|
|
7
8
|
import { isValidAid } from '../aid/validation.js';
|
|
8
9
|
import { tryParseChannelKey } from '../../core/channel-loader.js';
|
|
9
|
-
import { downloadGroupFsBytes } from '../group
|
|
10
|
-
import { groupBan, groupBanlist, groupCreate, groupDissolve, groupInfo, groupInvite, groupJoin, groupKick, groupLeave, groupList, groupMembers, groupOnline, groupPull, groupAck, groupAcceptInvite, groupInvites, groupRejectInvite, groupRevokeInvite, groupResume, groupRules, groupRulesFileGet, groupRulesFilePublish, groupRulesFileSet, groupSetRole, groupSuspend, groupTransferOwner, groupUnban, groupUpdate, groupUpdateRules, } from '
|
|
10
|
+
import { downloadGroupFsBytes } from '../group/fs-download.js';
|
|
11
|
+
import { groupBan, groupBanlist, groupBlock, groupUnblock, groupBlocklist, groupReportStatus, groupMemberStatuses, groupCreate, groupDissolve, groupInfo, groupInvite, groupJoin, groupKick, groupLeave, groupList, groupMembers, groupOnline, groupPull, groupAck, groupAcceptInvite, groupInvites, groupRejectInvite, groupRevokeInvite, groupResume, groupRules, groupRulesFileGet, groupRulesFilePublish, groupRulesFileSet, groupSetRole, groupSuspend, groupTransferOwner, groupUnban, groupUpdate, groupUpdateRules, } from '../group/operations.js';
|
|
11
12
|
/** Rules uploaded by a managed task are carried as bounded UTF-8 content. */
|
|
12
13
|
export const MAX_MANAGED_GROUP_RULES_BYTES = 4 * 1024;
|
|
13
14
|
const RELATION_GROUP_READ_KINDS = new Set([
|
|
14
15
|
'info',
|
|
15
16
|
'pull',
|
|
17
|
+
'history',
|
|
16
18
|
'members',
|
|
17
19
|
'online',
|
|
20
|
+
'member-statuses',
|
|
18
21
|
'rules.get',
|
|
19
22
|
'rules.get-legacy',
|
|
20
23
|
]);
|
|
@@ -22,6 +25,11 @@ const RELATION_GROUP_READ_KINDS = new Set([
|
|
|
22
25
|
export function isManagedGroupRelationRead(command) {
|
|
23
26
|
return RELATION_GROUP_READ_KINDS.has(command.kind);
|
|
24
27
|
}
|
|
28
|
+
/** Members may change only the current Agent's own reception and reported status. */
|
|
29
|
+
export function isManagedGroupRelationWrite(command) {
|
|
30
|
+
return command.kind === 'report-status'
|
|
31
|
+
|| ((command.kind === 'block' || command.kind === 'unblock') && command.memberAid === command.from);
|
|
32
|
+
}
|
|
25
33
|
export class ManagedGroupOperationError extends Error {
|
|
26
34
|
code;
|
|
27
35
|
constructor(code, message) {
|
|
@@ -33,6 +41,7 @@ export class ManagedGroupOperationError extends Error {
|
|
|
33
41
|
const GROUP_VALUE_FLAGS = new Set([
|
|
34
42
|
'--format', '--after-seq', '--limit', '--visibility', '--description', '--join-mode', '--group-id',
|
|
35
43
|
'--name', '--page', '--size', '--mode', '--question', '--max-pending', '--message', '--answer', '--duration', '--member-type',
|
|
44
|
+
'--reason', '--online-status', '--work-status',
|
|
36
45
|
]);
|
|
37
46
|
function failGroup(code, reason) {
|
|
38
47
|
return { ok: false, code, reason };
|
|
@@ -73,13 +82,16 @@ function requiredAid(value, label) {
|
|
|
73
82
|
return failGroup('INVALID_AID', `invalid ${label}: ${aid}`);
|
|
74
83
|
return aid;
|
|
75
84
|
}
|
|
76
|
-
function requiredGroup(value) {
|
|
85
|
+
function requiredGroup(value, from) {
|
|
77
86
|
const groupId = String(value || '').trim();
|
|
78
87
|
if (!groupId)
|
|
79
88
|
return failGroup('INVALID_ARGUMENT', 'missing group AID');
|
|
80
|
-
|
|
81
|
-
return
|
|
82
|
-
|
|
89
|
+
try {
|
|
90
|
+
return normalizeGroupAid(groupId, from?.slice(from.indexOf('.') + 1));
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
return failGroup('INVALID_GROUP', `invalid group AID: ${groupId}: ${error.message}`);
|
|
94
|
+
}
|
|
83
95
|
}
|
|
84
96
|
function numberFlag(flags, name) {
|
|
85
97
|
const raw = flags.get(name);
|
|
@@ -108,7 +120,7 @@ function withFromAndGroup(sub, parsed, operationId, groupRequired = true) {
|
|
|
108
120
|
return from;
|
|
109
121
|
let groupId;
|
|
110
122
|
if (groupRequired) {
|
|
111
|
-
const parsedGroup = requiredGroup(parsed.positionals[1]);
|
|
123
|
+
const parsedGroup = requiredGroup(parsed.positionals[1], from);
|
|
112
124
|
if (typeof parsedGroup !== 'string')
|
|
113
125
|
return parsedGroup;
|
|
114
126
|
groupId = parsedGroup;
|
|
@@ -121,6 +133,15 @@ export function resolveManagedGroupOperation(argv) {
|
|
|
121
133
|
const sub = raw[0];
|
|
122
134
|
if (!sub || sub === 'send')
|
|
123
135
|
return failGroup('NOT_ALLOWED', 'managed group operations do not allow send; use the group send daemon route');
|
|
136
|
+
if (sub === 'history') {
|
|
137
|
+
try {
|
|
138
|
+
const history = parseGroupHistoryArgs(raw);
|
|
139
|
+
return command('history', 'ec.group.history', ['group', ...raw], history.from, { groupId: history.groupId, history });
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
return failGroup('INVALID_ARGUMENT', error instanceof Error ? error.message : String(error));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
124
145
|
const parsed = parseFlags(raw.slice(1));
|
|
125
146
|
if (!('positionals' in parsed))
|
|
126
147
|
return parsed;
|
|
@@ -186,9 +207,10 @@ export function resolveManagedGroupOperation(argv) {
|
|
|
186
207
|
return failGroup('INVALID_ARGUMENT', 'invalid --visibility');
|
|
187
208
|
if (joinMode !== undefined && !['open', 'approval', 'invite_only', 'closed'].includes(joinMode))
|
|
188
209
|
return failGroup('INVALID_ARGUMENT', 'invalid --join-mode');
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
210
|
+
const rawGroupId = values.get('--group-id');
|
|
211
|
+
const groupId = rawGroupId === undefined ? undefined : requiredGroup(rawGroupId, from);
|
|
212
|
+
if (groupId !== undefined && typeof groupId !== 'string')
|
|
213
|
+
return groupId;
|
|
192
214
|
return command(sub, 'ec.group.create', ['group', sub, from, name], from, { name, visibility, description: values.get('--description'), joinMode, groupId });
|
|
193
215
|
}
|
|
194
216
|
const simple = new Map([
|
|
@@ -197,12 +219,16 @@ export function resolveManagedGroupOperation(argv) {
|
|
|
197
219
|
['join', 'ec.group.join'], ['leave', 'ec.group.leave'], ['invite', 'ec.group.invite'], ['kick', 'ec.group.kick'],
|
|
198
220
|
['members', 'ec.group.members'], ['online', 'ec.group.online'], ['role', 'ec.group.role'], ['owner', 'ec.group.owner'],
|
|
199
221
|
['ban', 'ec.group.ban'], ['unban', 'ec.group.unban'],
|
|
222
|
+
['block', 'ec.group.block'], ['unblock', 'ec.group.unblock'], ['blocklist', 'ec.group.blocklist'],
|
|
223
|
+
['report-status', 'ec.group.report-status'], ['member-statuses', 'ec.group.member-statuses'],
|
|
200
224
|
]);
|
|
201
225
|
if (simple.has(sub)) {
|
|
202
226
|
const allowedFlags = {
|
|
203
227
|
pull: ['--after-seq', '--limit'], ack: [], info: [], update: ['--name', '--description'], dissolve: [],
|
|
204
228
|
suspend: [], resume: [], join: ['--message', '--answer'], leave: [], invite: ['--member-type'], kick: [],
|
|
205
229
|
members: ['--page', '--size'], online: [], role: [], owner: [], ban: ['--duration'], unban: [],
|
|
230
|
+
block: ['--reason'], unblock: [], blocklist: [],
|
|
231
|
+
'report-status': ['--online-status', '--work-status'], 'member-statuses': [],
|
|
206
232
|
};
|
|
207
233
|
const flagsError = onlyFlags(values, allowedFlags[sub] ?? []);
|
|
208
234
|
if (flagsError)
|
|
@@ -253,13 +279,25 @@ export function resolveManagedGroupOperation(argv) {
|
|
|
253
279
|
extra.members = members;
|
|
254
280
|
extra.memberType = memberType;
|
|
255
281
|
}
|
|
256
|
-
else if (sub === 'kick' || sub === 'unban') {
|
|
282
|
+
else if (sub === 'kick' || sub === 'unban' || sub === 'block' || sub === 'unblock') {
|
|
257
283
|
if (positionals.length !== 3)
|
|
258
284
|
return failGroup('INVALID_ARGUMENT', `${sub} requires a member AID`);
|
|
259
285
|
const memberAid = requiredAid(positionals[2], 'member AID');
|
|
260
286
|
if (typeof memberAid !== 'string')
|
|
261
287
|
return memberAid;
|
|
262
288
|
extra.memberAid = memberAid;
|
|
289
|
+
if (sub === 'block')
|
|
290
|
+
extra.reason = values.get('--reason');
|
|
291
|
+
}
|
|
292
|
+
else if (sub === 'report-status') {
|
|
293
|
+
if (positionals.length !== 2)
|
|
294
|
+
return failGroup('INVALID_ARGUMENT', 'report-status accepts exactly <from> <group-aid>');
|
|
295
|
+
const onlineStatus = values.get('--online-status');
|
|
296
|
+
const workStatus = values.get('--work-status');
|
|
297
|
+
if (onlineStatus === undefined || workStatus === undefined) {
|
|
298
|
+
return failGroup('INVALID_ARGUMENT', 'report-status requires --online-status and --work-status');
|
|
299
|
+
}
|
|
300
|
+
Object.assign(extra, { onlineStatus, workStatus });
|
|
263
301
|
}
|
|
264
302
|
else if (sub === 'members') {
|
|
265
303
|
if (positionals.length !== 2)
|
|
@@ -305,7 +343,7 @@ export function resolveManagedGroupOperation(argv) {
|
|
|
305
343
|
extra.durationSeconds = durationSeconds;
|
|
306
344
|
extra.list = positionals.length === 2;
|
|
307
345
|
}
|
|
308
|
-
else if (sub === 'info' || sub === 'dissolve' || sub === 'suspend' || sub === 'resume' || sub === 'leave' || sub === 'online') {
|
|
346
|
+
else if (sub === 'info' || sub === 'dissolve' || sub === 'suspend' || sub === 'resume' || sub === 'leave' || sub === 'online' || sub === 'blocklist' || sub === 'member-statuses') {
|
|
309
347
|
if (positionals.length !== 2)
|
|
310
348
|
return failGroup('INVALID_ARGUMENT', `${sub} accepts exactly <from> <group-aid>`);
|
|
311
349
|
}
|
|
@@ -318,7 +356,7 @@ export function resolveManagedGroupOperation(argv) {
|
|
|
318
356
|
const from = requiredAid(positionals[0], 'from AID');
|
|
319
357
|
if (typeof from !== 'string')
|
|
320
358
|
return from;
|
|
321
|
-
const groupId = requiredGroup(positionals[1]);
|
|
359
|
+
const groupId = requiredGroup(positionals[1], from);
|
|
322
360
|
if (typeof groupId !== 'string')
|
|
323
361
|
return groupId;
|
|
324
362
|
const rest = positionals.slice(2);
|
|
@@ -354,7 +392,17 @@ export function resolveManagedGroupOperation(argv) {
|
|
|
354
392
|
return failGroup('NOT_ALLOWED', `unsupported managed group command: ${sub}`);
|
|
355
393
|
}
|
|
356
394
|
/** Execute a parsed command using daemon-owned AUN credentials and root. */
|
|
357
|
-
export async function executeManagedGroupOperation(command, rulesContent) {
|
|
395
|
+
export async function executeManagedGroupOperation(command, rulesContent, historyContext = {}) {
|
|
396
|
+
if (command.kind === 'history') {
|
|
397
|
+
try {
|
|
398
|
+
return groupHistory(command.history, historyContext);
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
if (error instanceof GroupHistoryError)
|
|
402
|
+
throw new ManagedGroupOperationError(error.code, error.message);
|
|
403
|
+
throw error;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
358
406
|
const opts = { aunPath: resolveRoot() };
|
|
359
407
|
let result;
|
|
360
408
|
switch (command.kind) {
|
|
@@ -427,6 +475,21 @@ export async function executeManagedGroupOperation(command, rulesContent) {
|
|
|
427
475
|
case 'unban':
|
|
428
476
|
result = await groupUnban({ from: command.from, groupId: command.groupId, memberAid: command.memberAid, ...opts });
|
|
429
477
|
break;
|
|
478
|
+
case 'block':
|
|
479
|
+
result = await groupBlock({ from: command.from, groupId: command.groupId, memberAid: command.memberAid, reason: command.reason, ...opts });
|
|
480
|
+
break;
|
|
481
|
+
case 'unblock':
|
|
482
|
+
result = await groupUnblock({ from: command.from, groupId: command.groupId, memberAid: command.memberAid, ...opts });
|
|
483
|
+
break;
|
|
484
|
+
case 'blocklist':
|
|
485
|
+
result = await groupBlocklist({ from: command.from, groupId: command.groupId, ...opts });
|
|
486
|
+
break;
|
|
487
|
+
case 'report-status':
|
|
488
|
+
result = await groupReportStatus({ from: command.from, groupId: command.groupId, onlineStatus: command.onlineStatus, workStatus: command.workStatus, ...opts });
|
|
489
|
+
break;
|
|
490
|
+
case 'member-statuses':
|
|
491
|
+
result = await groupMemberStatuses({ from: command.from, groupId: command.groupId, ...opts });
|
|
492
|
+
break;
|
|
430
493
|
case 'rules.get':
|
|
431
494
|
result = await groupRulesFileGet({ from: command.from, groupId: command.groupId, ...opts });
|
|
432
495
|
break;
|
|
@@ -678,10 +741,13 @@ function parseRemote(value, allowEmpty) {
|
|
|
678
741
|
const separator = value.indexOf(':');
|
|
679
742
|
if (separator <= 0)
|
|
680
743
|
return failFs('INVALID_PATH', 'remote path must use <group-aid>:<absolute-path>');
|
|
681
|
-
|
|
744
|
+
let groupId;
|
|
682
745
|
const remotePath = value.slice(separator + 1);
|
|
683
|
-
|
|
684
|
-
|
|
746
|
+
try {
|
|
747
|
+
groupId = normalizeGroupAid(value.slice(0, separator).trim());
|
|
748
|
+
}
|
|
749
|
+
catch (error) {
|
|
750
|
+
return failFs('INVALID_GROUP', `invalid group AID: ${error.message}`);
|
|
685
751
|
}
|
|
686
752
|
if (remotePath === '' && allowEmpty)
|
|
687
753
|
return { groupId, remotePath: '' };
|
|
@@ -18,3 +18,54 @@ export function normalizeAunMentionEntries(raw) {
|
|
|
18
18
|
}
|
|
19
19
|
return entries;
|
|
20
20
|
}
|
|
21
|
+
/** Reject unsupported attention values before normalizing the outbound payload. */
|
|
22
|
+
export function parseAunAttention(value) {
|
|
23
|
+
if (value === undefined)
|
|
24
|
+
return undefined;
|
|
25
|
+
if (value === 'completed' || value === 'failed' || value === 'required' || value === 'interrupted')
|
|
26
|
+
return value;
|
|
27
|
+
throw Object.assign(new Error('attention must be completed, failed, required, or interrupted'), {
|
|
28
|
+
code: 'INVALID_ATTENTION',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Project runner state as a pair, using the structured status as the authority.
|
|
33
|
+
* Action cards always require action. All other business payloads omit both
|
|
34
|
+
* fields, including explicit/custom payloads and entries retried from outbox.
|
|
35
|
+
*/
|
|
36
|
+
export function withAunAttention(payload, fallback) {
|
|
37
|
+
parseAunAttention(payload.attention);
|
|
38
|
+
parseAunAttention(fallback);
|
|
39
|
+
const attention = payload.type === 'action_card'
|
|
40
|
+
? 'required'
|
|
41
|
+
: payload.type === 'task.status' && typeof payload.status === 'string'
|
|
42
|
+
? aunStatusAttention(payload.status)
|
|
43
|
+
: undefined;
|
|
44
|
+
const normalized = { ...payload };
|
|
45
|
+
delete normalized.terminal;
|
|
46
|
+
delete normalized.attention;
|
|
47
|
+
return attention === undefined
|
|
48
|
+
? normalized
|
|
49
|
+
: { ...normalized, terminal: attention !== 'required', attention };
|
|
50
|
+
}
|
|
51
|
+
export function aunStatusAttention(status) {
|
|
52
|
+
switch (status) {
|
|
53
|
+
case 'done':
|
|
54
|
+
case 'completed': return 'completed';
|
|
55
|
+
case 'error':
|
|
56
|
+
case 'timeout': return 'failed';
|
|
57
|
+
case 'interrupted': return 'interrupted';
|
|
58
|
+
case 'requires_action': return 'required';
|
|
59
|
+
default: return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Business messages and command feedback never inherit runner attention. */
|
|
63
|
+
export function aunOutboundAttention(payload) {
|
|
64
|
+
parseAunAttention(payload.attention);
|
|
65
|
+
switch (payload.kind) {
|
|
66
|
+
case 'interaction': return 'required';
|
|
67
|
+
default: return payload.kind.startsWith('status.')
|
|
68
|
+
? aunStatusAttention(payload.kind.slice(7))
|
|
69
|
+
: undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
package/dist/aun/msg/p2p.js
CHANGED
|
@@ -8,9 +8,9 @@ import { normalizeCodexTextPayload, readBestTaskRuntimeContext, runtimeRefMessag
|
|
|
8
8
|
import { chatDirPath } from '../../core/session/session-fs-store.js';
|
|
9
9
|
import { resolvePaths } from '../../paths.js';
|
|
10
10
|
import { ipcQuery } from '../../ipc.js';
|
|
11
|
-
import {
|
|
11
|
+
import { readDelegationCredential } from '../../core/auth/agent-delegation.js';
|
|
12
12
|
import { loadDaemonConfig } from '../../config-store.js';
|
|
13
|
-
import { normalizeAunMentionEntries } from './mention-schema.js';
|
|
13
|
+
import { normalizeAunMentionEntries, withAunAttention } from './mention-schema.js';
|
|
14
14
|
const DAEMON_SEND_TIMEOUT_GRACE_MS = 10_000;
|
|
15
15
|
const DEFAULT_IDLE_TIMEOUT_MS = 120_000;
|
|
16
16
|
const MAX_TIMER_MS = 2_147_483_647;
|
|
@@ -110,7 +110,7 @@ function msgSendLogMetadata(args, payload, runtimeContext) {
|
|
|
110
110
|
}
|
|
111
111
|
async function tryDaemonMsgSend(args, payload, runtimeContext, file) {
|
|
112
112
|
const delegatedTask = !!process.env.EVOLCORE_SESSION_ID
|
|
113
|
-
|| !!
|
|
113
|
+
|| !!readDelegationCredential();
|
|
114
114
|
if (!runtimeContext) {
|
|
115
115
|
return delegatedTask
|
|
116
116
|
? { ok: false, code: 'DELEGATION_REQUIRED', error: 'Task runtime context is unavailable' }
|
|
@@ -138,9 +138,9 @@ async function tryDaemonMsgSend(args, payload, runtimeContext, file) {
|
|
|
138
138
|
handoffContext: args.handoffContext,
|
|
139
139
|
originSessionId: runtimeContext.sessionId,
|
|
140
140
|
originMessageId: runtimeContext.messageId,
|
|
141
|
-
delegationToken:
|
|
141
|
+
delegationToken: readDelegationCredential(),
|
|
142
142
|
log: msgSendLogMetadata(args, payload, runtimeContext),
|
|
143
|
-
}, daemonTaskSendIpcTimeoutMs(!!file));
|
|
143
|
+
}, daemonTaskSendIpcTimeoutMs(!!file), { throwOnError: true });
|
|
144
144
|
return response ?? {
|
|
145
145
|
ok: false,
|
|
146
146
|
code: 'AUN_DAEMON_UNAVAILABLE',
|
|
@@ -228,7 +228,7 @@ export async function msgSend(args) {
|
|
|
228
228
|
try {
|
|
229
229
|
let payload;
|
|
230
230
|
if (args.body.mode !== 'file') {
|
|
231
|
-
payload = buildSimplePayload(args.body);
|
|
231
|
+
payload = withAunAttention(buildSimplePayload(args.body));
|
|
232
232
|
normalizeCodexTextPayload(payload, runtimeContext);
|
|
233
233
|
if (Object.prototype.hasOwnProperty.call(payload, 'mentions')) {
|
|
234
234
|
payload.mentions = normalizeAunMentionEntries(payload.mentions);
|
|
@@ -272,7 +272,7 @@ export async function msgSend(args) {
|
|
|
272
272
|
const idStore = await getAidStore({ slotId: args.slotId ?? SLOT.cli, aunPath: args.aunPath });
|
|
273
273
|
let peerIdentity;
|
|
274
274
|
try {
|
|
275
|
-
peerIdentity = await PeerIdentityCache.resolve('aun', args.to, selfAgentDir, idStore, false);
|
|
275
|
+
peerIdentity = await PeerIdentityCache.resolve('aun', args.to, selfAgentDir, idStore, false, args.aunPath);
|
|
276
276
|
}
|
|
277
277
|
finally {
|
|
278
278
|
try {
|
|
@@ -297,6 +297,7 @@ export async function msgSend(args) {
|
|
|
297
297
|
payload.mentions = normalizeAunMentionEntries(payload.mentions);
|
|
298
298
|
}
|
|
299
299
|
const encrypt = resolveAunMessageEncrypt(args.encrypt);
|
|
300
|
+
payload = withAunAttention(payload);
|
|
300
301
|
const sendParams = { to: args.to, payload, encrypt };
|
|
301
302
|
const result = await conn.call('message.send', sendParams);
|
|
302
303
|
const messageId = typeof result?.message_id === 'string' && result.message_id.trim()
|
|
@@ -353,11 +354,15 @@ export async function msgPull(args) {
|
|
|
353
354
|
return {
|
|
354
355
|
ok: true,
|
|
355
356
|
messages: result?.messages ?? [],
|
|
356
|
-
count: result?.count ?? 0,
|
|
357
|
+
count: result?.count ?? result?.messages?.length ?? 0,
|
|
357
358
|
latest_seq: result?.latest_seq ?? 0,
|
|
358
359
|
earliest_available_seq: result?.earliest_available_seq ?? null,
|
|
359
360
|
ephemeral_earliest_available_seq: result?.ephemeral_earliest_available_seq ?? null,
|
|
360
361
|
ephemeral_dropped_count: result?.ephemeral_dropped_count ?? 0,
|
|
362
|
+
...(typeof result?.latest_volatile_cursor === 'string' ? { latest_volatile_cursor: result.latest_volatile_cursor } : {}),
|
|
363
|
+
...(typeof result?.volatile_earliest_cursor === 'string' ? { volatile_earliest_cursor: result.volatile_earliest_cursor } : {}),
|
|
364
|
+
...(typeof result?.volatile_dropped_count === 'number' ? { volatile_dropped_count: result.volatile_dropped_count } : {}),
|
|
365
|
+
...(typeof result?.volatile_has_more === 'boolean' ? { volatile_has_more: result.volatile_has_more } : {}),
|
|
361
366
|
};
|
|
362
367
|
}
|
|
363
368
|
catch (e) {
|
package/dist/aun/msg/upload.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import {
|
|
4
|
+
import { formatSize } from '../../utils/media-cache.js';
|
|
5
5
|
const EXT_TYPE_MAP = {
|
|
6
6
|
'.png': 'image', '.jpg': 'image', '.jpeg': 'image',
|
|
7
7
|
'.gif': 'image', '.webp': 'image', '.svg': 'image',
|
|
@@ -11,6 +11,15 @@ const EXT_TYPE_MAP = {
|
|
|
11
11
|
'.opus': 'voice', '.mp3': 'voice', '.aac': 'voice',
|
|
12
12
|
'.m4a': 'voice', '.wav': 'voice', '.flac': 'voice', '.ogg': 'voice',
|
|
13
13
|
};
|
|
14
|
+
const EXT_CONTENT_TYPE_MAP = {
|
|
15
|
+
'.txt': 'text/plain', '.md': 'text/markdown', '.csv': 'text/csv',
|
|
16
|
+
'.json': 'application/json', '.xml': 'application/xml', '.html': 'text/html',
|
|
17
|
+
'.pdf': 'application/pdf', '.zip': 'application/zip',
|
|
18
|
+
'.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',
|
|
19
|
+
'.gif': 'image/gif', '.webp': 'image/webp', '.svg': 'image/svg+xml',
|
|
20
|
+
'.mp4': 'video/mp4', '.mov': 'video/quicktime', '.webm': 'video/webm',
|
|
21
|
+
'.mp3': 'audio/mpeg', '.wav': 'audio/wav', '.ogg': 'audio/ogg',
|
|
22
|
+
};
|
|
14
23
|
export function inferPayloadType(filename) {
|
|
15
24
|
const ext = path.extname(filename).toLowerCase();
|
|
16
25
|
return EXT_TYPE_MAP[ext] ?? 'file';
|
|
@@ -20,109 +29,57 @@ export function isValidPayloadType(value) {
|
|
|
20
29
|
}
|
|
21
30
|
/** 单次上传最大大小(与 daemon sendFile 一致)。 */
|
|
22
31
|
export const MAX_AUN_ATTACHMENT_SIZE = 10 * 1024 * 1024;
|
|
23
|
-
/**
|
|
24
|
-
* Inline JSON-RPC 上传阈值。超过该大小直接使用上传会话,避免把文件
|
|
25
|
-
* Base64 编码后放进 storage.put_object 的 RPC 参数。
|
|
26
|
-
*/
|
|
27
|
-
export const INLINE_AUN_ATTACHMENT_SIZE = 64 * 1024;
|
|
28
|
-
/** server 端 inline 上限错误的识别特征。优先匹配错误消息里的“inline 上限”字样。 */
|
|
29
|
-
function isInlineLimitError(err) {
|
|
30
|
-
const msg = err?.message ?? '';
|
|
31
|
-
return /inline\s*上限|inline limit|create_upload_session/i.test(msg);
|
|
32
|
-
}
|
|
33
32
|
/**
|
|
34
33
|
* 上传内存中的二进制内容并构造发送用的标准附件 payload。
|
|
35
34
|
*/
|
|
36
35
|
export async function uploadBufferAndBuildPayload(conn, ownerAid, data, filename, opts) {
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
36
|
+
const displayFilename = path.basename(filename);
|
|
37
|
+
if (!displayFilename.trim() || displayFilename === '.' || displayFilename === '..') {
|
|
39
38
|
throw new Error('文件名不能为空');
|
|
40
39
|
}
|
|
41
40
|
if (data.length === 0) {
|
|
42
|
-
throw new Error(`文件为空: ${
|
|
41
|
+
throw new Error(`文件为空: ${displayFilename}`);
|
|
43
42
|
}
|
|
44
43
|
if (data.length > MAX_AUN_ATTACHMENT_SIZE) {
|
|
45
|
-
throw new Error(`文件过大 (${formatSize(data.length)}, 上限 ${formatSize(MAX_AUN_ATTACHMENT_SIZE)}): ${
|
|
44
|
+
throw new Error(`文件过大 (${formatSize(data.length)}, 上限 ${formatSize(MAX_AUN_ATTACHMENT_SIZE)}): ${displayFilename}`);
|
|
46
45
|
}
|
|
47
46
|
const sha256 = crypto.createHash('sha256').update(data).digest('hex');
|
|
48
|
-
const
|
|
49
|
-
|
|
47
|
+
const explicitContentType = opts?.contentType?.trim() || undefined;
|
|
48
|
+
// Storage keys have a narrower character set than local filenames. Keep the
|
|
49
|
+
// original basename in the attachment; only the opaque storage key is sanitized.
|
|
50
|
+
const storageFilename = displayFilename.replace(/[^A-Za-z0-9._-]/g, '_');
|
|
51
|
+
const objectKey = `shared/${crypto.randomUUID()}/${storageFilename}`;
|
|
50
52
|
const total = data.length;
|
|
51
53
|
const report = (phase, bytes) => opts?.onProgress?.({ phase, bytes, total });
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
report('inline', total);
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
if (!isInlineLimitError(e))
|
|
69
|
-
throw e;
|
|
70
|
-
useUploadSession = true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// inline 被拒或文件超过 inline 阈值:session + HTTP PUT
|
|
74
|
-
if (useUploadSession) {
|
|
75
|
-
report('session-create', 0);
|
|
76
|
-
const session = await conn.call('storage.create_upload_session', {
|
|
77
|
-
object_key: objectKey,
|
|
78
|
-
size_bytes: total,
|
|
79
|
-
content_type: contentType,
|
|
80
|
-
});
|
|
81
|
-
const uploadUrl = session?.upload_url;
|
|
82
|
-
if (!uploadUrl)
|
|
83
|
-
throw new Error('storage.create_upload_session 未返回 upload_url');
|
|
84
|
-
// 简单 Buffer 上传 + 周期性进度(不用流,避免某些 storage 网关对 chunked / duplex 不友好)
|
|
85
|
-
report('http-put', 0);
|
|
86
|
-
const PROGRESS_TICK_MS = 250;
|
|
87
|
-
let lastBytes = 0;
|
|
88
|
-
const tickerStart = Date.now();
|
|
89
|
-
// 实际上一次性发送;等待响应期间按 2MB/s 估算进度,且不超过 99%。
|
|
90
|
-
const ticker = setInterval(() => {
|
|
91
|
-
const elapsed = Date.now() - tickerStart;
|
|
92
|
-
const estimated = Math.min(total - 1, Math.floor((elapsed / 1000) * 2 * 1024 * 1024));
|
|
93
|
-
if (estimated > lastBytes) {
|
|
94
|
-
lastBytes = estimated;
|
|
95
|
-
report('http-put', estimated);
|
|
96
|
-
}
|
|
97
|
-
}, PROGRESS_TICK_MS);
|
|
98
|
-
let uploadResp;
|
|
54
|
+
// Use the client-owned facade so storage RPCs stay inside the SDK. Do not
|
|
55
|
+
// rebuild StorageVFS over conn.call: SDK-internal RPCs are not application APIs.
|
|
56
|
+
report('upload', 0);
|
|
57
|
+
const uploaded = await conn.storage.writeBytes(`/${objectKey}`, data, {
|
|
58
|
+
contentType: explicitContentType,
|
|
59
|
+
public: true,
|
|
60
|
+
overwrite: true,
|
|
61
|
+
});
|
|
62
|
+
// Use the stored MIME instead of inferring a second, potentially different
|
|
63
|
+
// type for the attachment. Older storage responses may omit this metadata.
|
|
64
|
+
let contentType = uploaded.contentType?.trim() || explicitContentType;
|
|
65
|
+
if (!contentType && typeof conn.storage.stat === 'function') {
|
|
99
66
|
try {
|
|
100
|
-
|
|
101
|
-
method: 'PUT',
|
|
102
|
-
body: new Blob([new Uint8Array(data)], { type: contentType }),
|
|
103
|
-
headers: { 'Content-Type': contentType },
|
|
104
|
-
});
|
|
67
|
+
contentType = (await conn.storage.stat(`/${objectKey}`)).contentType?.trim();
|
|
105
68
|
}
|
|
106
|
-
|
|
107
|
-
|
|
69
|
+
catch {
|
|
70
|
+
// A successful upload should remain usable when a legacy facade cannot
|
|
71
|
+
// perform a follow-up stat call.
|
|
108
72
|
}
|
|
109
|
-
if (!uploadResp.ok)
|
|
110
|
-
throw new Error(`HTTP 上传失败: ${uploadResp.status}`);
|
|
111
|
-
report('http-put', total);
|
|
112
|
-
report('session-complete', total);
|
|
113
|
-
await conn.call('storage.complete_upload', {
|
|
114
|
-
object_key: objectKey,
|
|
115
|
-
sha256,
|
|
116
|
-
content_type: contentType,
|
|
117
|
-
is_private: false,
|
|
118
|
-
size_bytes: total,
|
|
119
|
-
});
|
|
120
73
|
}
|
|
74
|
+
if (!contentType)
|
|
75
|
+
contentType = EXT_CONTENT_TYPE_MAP[path.extname(displayFilename).toLowerCase()] ?? 'application/octet-stream';
|
|
76
|
+
if (!contentType)
|
|
77
|
+
throw new Error('Storage 上传结果缺少 Content-Type');
|
|
121
78
|
report('done', total);
|
|
122
79
|
const attachment = {
|
|
123
80
|
owner_aid: ownerAid,
|
|
124
81
|
object_key: objectKey,
|
|
125
|
-
filename:
|
|
82
|
+
filename: displayFilename,
|
|
126
83
|
size_bytes: total,
|
|
127
84
|
sha256,
|
|
128
85
|
content_type: contentType,
|
|
@@ -135,7 +92,7 @@ export async function uploadBufferAndBuildPayload(conn, ownerAid, data, filename
|
|
|
135
92
|
type = opts.as;
|
|
136
93
|
}
|
|
137
94
|
else {
|
|
138
|
-
type = inferPayloadType(
|
|
95
|
+
type = inferPayloadType(displayFilename);
|
|
139
96
|
}
|
|
140
97
|
const payload = {
|
|
141
98
|
type,
|
|
@@ -144,7 +101,7 @@ export async function uploadBufferAndBuildPayload(conn, ownerAid, data, filename
|
|
|
144
101
|
if (opts?.text)
|
|
145
102
|
payload.text = opts.text;
|
|
146
103
|
else if (type === 'file')
|
|
147
|
-
payload.text = `📎 ${
|
|
104
|
+
payload.text = `📎 ${displayFilename} (${formatSize(total)})`;
|
|
148
105
|
if (type === 'voice' && opts?.transcript)
|
|
149
106
|
payload.transcript = opts.transcript;
|
|
150
107
|
return { payload, type, attachment };
|
|
@@ -152,9 +109,7 @@ export async function uploadBufferAndBuildPayload(conn, ownerAid, data, filename
|
|
|
152
109
|
/**
|
|
153
110
|
* 上传本地文件并构造发送用的 payload。
|
|
154
111
|
*
|
|
155
|
-
*
|
|
156
|
-
* storage.create_upload_session + HTTP PUT + storage.complete_upload,避免
|
|
157
|
-
* 将大文件编码后放入 JSON-RPC。此时通过 onProgress 上报字节级进度。
|
|
112
|
+
* 通过 SDK StorageVFS 协商并执行上传,onProgress 上报上传阶段。
|
|
158
113
|
*/
|
|
159
114
|
export async function uploadFileAndBuildPayload(conn, ownerAid, filePath, opts) {
|
|
160
115
|
const absPath = path.resolve(filePath);
|