feat(sdk): add media sends, quoted replies, and event waits

Add local media upload-and-send helpers with an optional Node file source
and stage-aware errors. Add explicit quoted replies and cancellable event
waits while preserving existing methods and handler contracts.

Propagate group-file publication failures instead of reporting success.
Cover cancellation, cleanup, signed message IDs, package exports, consumer
types, and real HTTP/WebSocket upload-to-send integration.

Validation: pnpm run ci (6231 tests passed, 9 skipped); SDK package contents
verified with npm pack --dry-run --ignore-scripts.
This commit is contained in:
DrSmoothl committed 2026-10-23 19:45:47 +08:00
1 parent 2d659b0ceb
commit fa5efcd310
28 files changed
+1798 -37

No files matched your search

+1
View File
@@ -26,6 +26,7 @@ export {
} from './chain.js';
export { escapeCqParam, escapeCqText } from './cq-format.js';
export { fromCQString, parseSegments, toCQString } from './cq.js';
export { quoteMessage } from './quote.js';
export { segments };
export const message = {
+42
View File
@@ -0,0 +1,42 @@
import type { AnyMessageSegment, OutgoingMessage } from '../types/index.js';
import { normalizeMessage } from './chain.js';
import { parseSegments } from './cq.js';
import { segments } from './segments.js';
/** Adds an existing message's ID as the quote without changing the supplied body. */
export function quoteMessage(
messageId: number,
message: OutgoingMessage,
options: { autoEscape?: boolean } = {},
): string | AnyMessageSegment[] {
if (
!Number.isInteger(messageId) ||
messageId === 0 ||
messageId < -2147483648 ||
messageId > 2147483647
) {
throw new TypeError('quoteMessage() requires a non-zero signed 32-bit message ID');
}
const normalized = normalizeMessage(message);
const quote = segments.reply(messageId);
if (typeof normalized === 'string') {
if (options.autoEscape) {
return [quote, segments.text(normalized)];
}
assertNoReply(parseSegments(normalized));
// Keep the original CQ body so extension fields are not lost in conversion.
return `[CQ:reply,id=${messageId}]${normalized}`;
}
assertNoReply(normalized);
return [quote, ...normalized];
}
function assertNoReply(message: AnyMessageSegment[]): void {
if (message.some((segment) => segment.type === 'reply')) {
throw new TypeError('quoteMessage() cannot add a quote to a message containing a reply');
}
}