@tencent-connect/qqbot-nodejs 1.0.3
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 +205 -0
- package/USAGE.md +804 -0
- package/dist/QQBot.d.ts +536 -0
- package/dist/QQBot.d.ts.map +1 -0
- package/dist/QQBot.js +752 -0
- package/dist/QQBot.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/access-policy.d.ts +54 -0
- package/dist/middleware/access-policy.d.ts.map +1 -0
- package/dist/middleware/access-policy.js +93 -0
- package/dist/middleware/access-policy.js.map +1 -0
- package/dist/middleware/concurrency-guard.d.ts +105 -0
- package/dist/middleware/concurrency-guard.d.ts.map +1 -0
- package/dist/middleware/concurrency-guard.js +325 -0
- package/dist/middleware/concurrency-guard.js.map +1 -0
- package/dist/middleware/content-sanitizer.d.ts +47 -0
- package/dist/middleware/content-sanitizer.d.ts.map +1 -0
- package/dist/middleware/content-sanitizer.js +85 -0
- package/dist/middleware/content-sanitizer.js.map +1 -0
- package/dist/middleware/envelope-formatter.d.ts +51 -0
- package/dist/middleware/envelope-formatter.d.ts.map +1 -0
- package/dist/middleware/envelope-formatter.js +97 -0
- package/dist/middleware/envelope-formatter.js.map +1 -0
- package/dist/middleware/error-handler.d.ts +36 -0
- package/dist/middleware/error-handler.d.ts.map +1 -0
- package/dist/middleware/error-handler.js +59 -0
- package/dist/middleware/error-handler.js.map +1 -0
- package/dist/middleware/history-buffer.d.ts +84 -0
- package/dist/middleware/history-buffer.d.ts.map +1 -0
- package/dist/middleware/history-buffer.js +113 -0
- package/dist/middleware/history-buffer.js.map +1 -0
- package/dist/middleware/index.d.ts +71 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +48 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/mention-gate.d.ts +99 -0
- package/dist/middleware/mention-gate.d.ts.map +1 -0
- package/dist/middleware/mention-gate.js +117 -0
- package/dist/middleware/mention-gate.js.map +1 -0
- package/dist/middleware/message-filter.d.ts +38 -0
- package/dist/middleware/message-filter.d.ts.map +1 -0
- package/dist/middleware/message-filter.js +60 -0
- package/dist/middleware/message-filter.js.map +1 -0
- package/dist/middleware/quote-ref.d.ts +106 -0
- package/dist/middleware/quote-ref.d.ts.map +1 -0
- package/dist/middleware/quote-ref.js +168 -0
- package/dist/middleware/quote-ref.js.map +1 -0
- package/dist/middleware/rate-limiter.d.ts +43 -0
- package/dist/middleware/rate-limiter.d.ts.map +1 -0
- package/dist/middleware/rate-limiter.js +77 -0
- package/dist/middleware/rate-limiter.js.map +1 -0
- package/dist/middleware/slash-command.d.ts +112 -0
- package/dist/middleware/slash-command.d.ts.map +1 -0
- package/dist/middleware/slash-command.js +203 -0
- package/dist/middleware/slash-command.js.map +1 -0
- package/dist/middleware/types.d.ts +175 -0
- package/dist/middleware/types.d.ts.map +1 -0
- package/dist/middleware/types.js +138 -0
- package/dist/middleware/types.js.map +1 -0
- package/dist/middleware/typing-indicator.d.ts +54 -0
- package/dist/middleware/typing-indicator.d.ts.map +1 -0
- package/dist/middleware/typing-indicator.js +68 -0
- package/dist/middleware/typing-indicator.js.map +1 -0
- package/dist/protocol/api/api-client.d.ts +27 -0
- package/dist/protocol/api/api-client.d.ts.map +1 -0
- package/dist/protocol/api/api-client.js +119 -0
- package/dist/protocol/api/api-client.js.map +1 -0
- package/dist/protocol/api/media-chunked.d.ts +68 -0
- package/dist/protocol/api/media-chunked.d.ts.map +1 -0
- package/dist/protocol/api/media-chunked.js +298 -0
- package/dist/protocol/api/media-chunked.js.map +1 -0
- package/dist/protocol/api/media.d.ts +46 -0
- package/dist/protocol/api/media.d.ts.map +1 -0
- package/dist/protocol/api/media.js +101 -0
- package/dist/protocol/api/media.js.map +1 -0
- package/dist/protocol/api/messages.d.ts +86 -0
- package/dist/protocol/api/messages.d.ts.map +1 -0
- package/dist/protocol/api/messages.js +200 -0
- package/dist/protocol/api/messages.js.map +1 -0
- package/dist/protocol/api/retry.d.ts +23 -0
- package/dist/protocol/api/retry.d.ts.map +1 -0
- package/dist/protocol/api/retry.js +102 -0
- package/dist/protocol/api/retry.js.map +1 -0
- package/dist/protocol/api/routes.d.ts +23 -0
- package/dist/protocol/api/routes.d.ts.map +1 -0
- package/dist/protocol/api/routes.js +50 -0
- package/dist/protocol/api/routes.js.map +1 -0
- package/dist/protocol/api/token.d.ts +38 -0
- package/dist/protocol/api/token.d.ts.map +1 -0
- package/dist/protocol/api/token.js +191 -0
- package/dist/protocol/api/token.js.map +1 -0
- package/dist/protocol/gateway/codec.d.ts +9 -0
- package/dist/protocol/gateway/codec.d.ts.map +1 -0
- package/dist/protocol/gateway/codec.js +32 -0
- package/dist/protocol/gateway/codec.js.map +1 -0
- package/dist/protocol/gateway/constants.d.ts +71 -0
- package/dist/protocol/gateway/constants.d.ts.map +1 -0
- package/dist/protocol/gateway/constants.js +91 -0
- package/dist/protocol/gateway/constants.js.map +1 -0
- package/dist/protocol/gateway/event-dispatcher.d.ts +97 -0
- package/dist/protocol/gateway/event-dispatcher.d.ts.map +1 -0
- package/dist/protocol/gateway/event-dispatcher.js +155 -0
- package/dist/protocol/gateway/event-dispatcher.js.map +1 -0
- package/dist/protocol/gateway/gateway-connection.d.ts +73 -0
- package/dist/protocol/gateway/gateway-connection.d.ts.map +1 -0
- package/dist/protocol/gateway/gateway-connection.js +293 -0
- package/dist/protocol/gateway/gateway-connection.js.map +1 -0
- package/dist/protocol/gateway/reconnect.d.ts +25 -0
- package/dist/protocol/gateway/reconnect.d.ts.map +1 -0
- package/dist/protocol/gateway/reconnect.js +118 -0
- package/dist/protocol/gateway/reconnect.js.map +1 -0
- package/dist/protocol/index.d.ts +41 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +46 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/transport/index.d.ts +8 -0
- package/dist/protocol/transport/index.d.ts.map +1 -0
- package/dist/protocol/transport/index.js +4 -0
- package/dist/protocol/transport/index.js.map +1 -0
- package/dist/protocol/transport/types.d.ts +109 -0
- package/dist/protocol/transport/types.d.ts.map +1 -0
- package/dist/protocol/transport/types.js +15 -0
- package/dist/protocol/transport/types.js.map +1 -0
- package/dist/protocol/transport/webhook-server-node.d.ts +14 -0
- package/dist/protocol/transport/webhook-server-node.d.ts.map +1 -0
- package/dist/protocol/transport/webhook-server-node.js +57 -0
- package/dist/protocol/transport/webhook-server-node.js.map +1 -0
- package/dist/protocol/transport/webhook-verify.d.ts +49 -0
- package/dist/protocol/transport/webhook-verify.d.ts.map +1 -0
- package/dist/protocol/transport/webhook-verify.js +98 -0
- package/dist/protocol/transport/webhook-verify.js.map +1 -0
- package/dist/protocol/transport/webhook.d.ts +37 -0
- package/dist/protocol/transport/webhook.d.ts.map +1 -0
- package/dist/protocol/transport/webhook.js +183 -0
- package/dist/protocol/transport/webhook.js.map +1 -0
- package/dist/protocol/types.d.ts +270 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +59 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/protocol/utils/audio.d.ts +79 -0
- package/dist/protocol/utils/audio.d.ts.map +1 -0
- package/dist/protocol/utils/audio.js +501 -0
- package/dist/protocol/utils/audio.js.map +1 -0
- package/dist/protocol/utils/decode-media-path.d.ts +26 -0
- package/dist/protocol/utils/decode-media-path.d.ts.map +1 -0
- package/dist/protocol/utils/decode-media-path.js +79 -0
- package/dist/protocol/utils/decode-media-path.js.map +1 -0
- package/dist/protocol/utils/ffmpeg.d.ts +38 -0
- package/dist/protocol/utils/ffmpeg.d.ts.map +1 -0
- package/dist/protocol/utils/ffmpeg.js +119 -0
- package/dist/protocol/utils/ffmpeg.js.map +1 -0
- package/dist/protocol/utils/file-utils.d.ts +42 -0
- package/dist/protocol/utils/file-utils.d.ts.map +1 -0
- package/dist/protocol/utils/file-utils.js +108 -0
- package/dist/protocol/utils/file-utils.js.map +1 -0
- package/dist/protocol/utils/format.d.ts +10 -0
- package/dist/protocol/utils/format.d.ts.map +1 -0
- package/dist/protocol/utils/format.js +68 -0
- package/dist/protocol/utils/format.js.map +1 -0
- package/dist/protocol/utils/image-size.d.ts +56 -0
- package/dist/protocol/utils/image-size.d.ts.map +1 -0
- package/dist/protocol/utils/image-size.js +185 -0
- package/dist/protocol/utils/image-size.js.map +1 -0
- package/dist/protocol/utils/media-source.d.ts +145 -0
- package/dist/protocol/utils/media-source.d.ts.map +1 -0
- package/dist/protocol/utils/media-source.js +175 -0
- package/dist/protocol/utils/media-source.js.map +1 -0
- package/dist/protocol/utils/media-tags.d.ts +15 -0
- package/dist/protocol/utils/media-tags.d.ts.map +1 -0
- package/dist/protocol/utils/media-tags.js +150 -0
- package/dist/protocol/utils/media-tags.js.map +1 -0
- package/dist/protocol/utils/media-type.d.ts +41 -0
- package/dist/protocol/utils/media-type.d.ts.map +1 -0
- package/dist/protocol/utils/media-type.js +89 -0
- package/dist/protocol/utils/media-type.js.map +1 -0
- package/dist/protocol/utils/payload.d.ts +52 -0
- package/dist/protocol/utils/payload.d.ts.map +1 -0
- package/dist/protocol/utils/payload.js +100 -0
- package/dist/protocol/utils/payload.js.map +1 -0
- package/dist/protocol/utils/ref-attachments.d.ts +80 -0
- package/dist/protocol/utils/ref-attachments.d.ts.map +1 -0
- package/dist/protocol/utils/ref-attachments.js +121 -0
- package/dist/protocol/utils/ref-attachments.js.map +1 -0
- package/dist/protocol/utils/ref-index-store.d.ts +69 -0
- package/dist/protocol/utils/ref-index-store.d.ts.map +1 -0
- package/dist/protocol/utils/ref-index-store.js +227 -0
- package/dist/protocol/utils/ref-index-store.js.map +1 -0
- package/dist/protocol/utils/reply-limiter.d.ts +75 -0
- package/dist/protocol/utils/reply-limiter.d.ts.map +1 -0
- package/dist/protocol/utils/reply-limiter.js +123 -0
- package/dist/protocol/utils/reply-limiter.js.map +1 -0
- package/dist/protocol/utils/session-store.d.ts +73 -0
- package/dist/protocol/utils/session-store.d.ts.map +1 -0
- package/dist/protocol/utils/session-store.js +274 -0
- package/dist/protocol/utils/session-store.js.map +1 -0
- package/dist/protocol/utils/target.d.ts +53 -0
- package/dist/protocol/utils/target.d.ts.map +1 -0
- package/dist/protocol/utils/target.js +104 -0
- package/dist/protocol/utils/target.js.map +1 -0
- package/dist/protocol/utils/text-chunk.d.ts +21 -0
- package/dist/protocol/utils/text-chunk.d.ts.map +1 -0
- package/dist/protocol/utils/text-chunk.js +25 -0
- package/dist/protocol/utils/text-chunk.js.map +1 -0
- package/dist/protocol/utils/text-parsing.d.ts +40 -0
- package/dist/protocol/utils/text-parsing.d.ts.map +1 -0
- package/dist/protocol/utils/text-parsing.js +126 -0
- package/dist/protocol/utils/text-parsing.js.map +1 -0
- package/dist/protocol/utils/upload-cache.d.ts +27 -0
- package/dist/protocol/utils/upload-cache.d.ts.map +1 -0
- package/dist/protocol/utils/upload-cache.js +73 -0
- package/dist/protocol/utils/upload-cache.js.map +1 -0
- package/dist/protocol/utils/voice-text.d.ts +9 -0
- package/dist/protocol/utils/voice-text.d.ts.map +1 -0
- package/dist/protocol/utils/voice-text.js +16 -0
- package/dist/protocol/utils/voice-text.js.map +1 -0
- package/dist/storage/index.d.ts +23 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +21 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/kv-store.d.ts +85 -0
- package/dist/storage/kv-store.d.ts.map +1 -0
- package/dist/storage/kv-store.js +184 -0
- package/dist/storage/kv-store.js.map +1 -0
- package/dist/storage/session-adapter.d.ts +35 -0
- package/dist/storage/session-adapter.d.ts.map +1 -0
- package/dist/storage/session-adapter.js +48 -0
- package/dist/storage/session-adapter.js.map +1 -0
- package/dist/streaming.d.ts +67 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +207 -0
- package/dist/streaming.js.map +1 -0
- package/package.json +90 -0
- package/src/QQBot.ts +1123 -0
- package/src/index.ts +175 -0
- package/src/middleware/access-policy.ts +139 -0
- package/src/middleware/concurrency-guard.ts +450 -0
- package/src/middleware/content-sanitizer.ts +125 -0
- package/src/middleware/envelope-formatter.ts +140 -0
- package/src/middleware/error-handler.ts +77 -0
- package/src/middleware/history-buffer.ts +169 -0
- package/src/middleware/index.ts +129 -0
- package/src/middleware/mention-gate.ts +227 -0
- package/src/middleware/message-filter.ts +82 -0
- package/src/middleware/quote-ref.ts +237 -0
- package/src/middleware/rate-limiter.ts +112 -0
- package/src/middleware/slash-command.ts +307 -0
- package/src/middleware/types.ts +273 -0
- package/src/middleware/typing-indicator.ts +107 -0
- package/src/protocol/api/api-client.ts +170 -0
- package/src/protocol/api/media-chunked.ts +517 -0
- package/src/protocol/api/media.ts +188 -0
- package/src/protocol/api/messages.ts +345 -0
- package/src/protocol/api/retry.ts +157 -0
- package/src/protocol/api/routes.ts +62 -0
- package/src/protocol/api/token.ts +250 -0
- package/src/protocol/gateway/codec.ts +33 -0
- package/src/protocol/gateway/constants.ts +98 -0
- package/src/protocol/gateway/event-dispatcher.ts +275 -0
- package/src/protocol/gateway/gateway-connection.ts +375 -0
- package/src/protocol/gateway/reconnect.ts +155 -0
- package/src/protocol/index.ts +238 -0
- package/src/protocol/transport/index.ts +17 -0
- package/src/protocol/transport/types.ts +121 -0
- package/src/protocol/transport/webhook-server-node.ts +64 -0
- package/src/protocol/transport/webhook-verify.ts +118 -0
- package/src/protocol/transport/webhook.ts +237 -0
- package/src/protocol/types.ts +305 -0
- package/src/protocol/utils/audio.ts +663 -0
- package/src/protocol/utils/decode-media-path.ts +88 -0
- package/src/protocol/utils/ffmpeg.ts +131 -0
- package/src/protocol/utils/file-utils.ts +121 -0
- package/src/protocol/utils/format.ts +69 -0
- package/src/protocol/utils/image-size.ts +236 -0
- package/src/protocol/utils/media-source.ts +243 -0
- package/src/protocol/utils/media-tags.ts +177 -0
- package/src/protocol/utils/media-type.ts +102 -0
- package/src/protocol/utils/payload.ts +157 -0
- package/src/protocol/utils/ref-attachments.ts +190 -0
- package/src/protocol/utils/ref-index-store.ts +279 -0
- package/src/protocol/utils/reply-limiter.ts +164 -0
- package/src/protocol/utils/session-store.ts +346 -0
- package/src/protocol/utils/target.ts +121 -0
- package/src/protocol/utils/text-chunk.ts +29 -0
- package/src/protocol/utils/text-parsing.ts +153 -0
- package/src/protocol/utils/upload-cache.ts +107 -0
- package/src/protocol/utils/voice-text.ts +16 -0
- package/src/storage/index.ts +24 -0
- package/src/storage/kv-store.ts +243 -0
- package/src/storage/session-adapter.ts +66 -0
- package/src/streaming.ts +255 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-type.js","sourceRoot":"","sources":["../../../src/protocol/utils/media-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAKzC,sCAAsC;AACtC,MAAM,CAAC,MAAM,iBAAiB,GAAwC;IACpE,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AACrF,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE5F;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,MAAM,OAAO,GAAG,SAAS,CAAC,WAAW,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;AACvE,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,oBAAoB,CAAC,MAAc;IACjD,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM,gBAAgB,GAA2B;IACtD,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;CACpB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured payload encoding for QQ Bot agentic outputs.
|
|
3
|
+
*
|
|
4
|
+
* Two related but distinct text-encoding protocols:
|
|
5
|
+
*
|
|
6
|
+
* 1. `QQBOT_PAYLOAD:` — emitted by the model in agent output to request
|
|
7
|
+
* structured behaviour (cron reminders, media-by-path sends).
|
|
8
|
+
* 2. `QQBOT_CRON:` — base64 wrapper used to persist cron-reminder
|
|
9
|
+
* payloads in scheduled-job queues.
|
|
10
|
+
*
|
|
11
|
+
* Both are pure string transforms with no I/O.
|
|
12
|
+
*/
|
|
13
|
+
import type { ChatScope } from "../types.js";
|
|
14
|
+
/** Structured reminder payload emitted by the model. */
|
|
15
|
+
export interface CronReminderPayload {
|
|
16
|
+
type: "cron_reminder";
|
|
17
|
+
content: string;
|
|
18
|
+
targetType: ChatScope;
|
|
19
|
+
targetAddress: string;
|
|
20
|
+
originalMessageId?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Structured media payload emitted by the model. */
|
|
23
|
+
export interface MediaPayload {
|
|
24
|
+
type: "media";
|
|
25
|
+
mediaType: "image" | "audio" | "video" | "file";
|
|
26
|
+
source: "url" | "file";
|
|
27
|
+
path: string;
|
|
28
|
+
caption?: string;
|
|
29
|
+
}
|
|
30
|
+
export type QQBotPayload = CronReminderPayload | MediaPayload;
|
|
31
|
+
/** Result of parsing model output into a structured payload. */
|
|
32
|
+
export interface ParseResult {
|
|
33
|
+
isPayload: boolean;
|
|
34
|
+
payload?: QQBotPayload;
|
|
35
|
+
text?: string;
|
|
36
|
+
error?: string;
|
|
37
|
+
}
|
|
38
|
+
/** Parse model output that may start with the QQ Bot structured payload prefix. */
|
|
39
|
+
export declare function parseQQBotPayload(text: string): ParseResult;
|
|
40
|
+
/** Encode a cron reminder payload into the stored cron-message format. */
|
|
41
|
+
export declare function encodePayloadForCron(payload: CronReminderPayload): string;
|
|
42
|
+
/** Decode a stored cron payload. */
|
|
43
|
+
export declare function decodeCronPayload(message: string): {
|
|
44
|
+
isCronPayload: boolean;
|
|
45
|
+
payload?: CronReminderPayload;
|
|
46
|
+
error?: string;
|
|
47
|
+
};
|
|
48
|
+
/** Type guard for cron reminder payloads. */
|
|
49
|
+
export declare function isCronReminderPayload(payload: QQBotPayload): payload is CronReminderPayload;
|
|
50
|
+
/** Type guard for media payloads. */
|
|
51
|
+
export declare function isMediaPayload(payload: QQBotPayload): payload is MediaPayload;
|
|
52
|
+
//# sourceMappingURL=payload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../../../src/protocol/utils/payload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAI7C,wDAAwD;AACxD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,SAAS,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;IAChD,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG,YAAY,CAAC;AAE9D,gEAAgE;AAChE,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAWD,mFAAmF;AACnF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAyC3D;AAID,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAIzE;AAED,oCAAoC;AACpC,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;IAClD,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAgCA;AAID,6CAA6C;AAC7C,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,IAAI,mBAAmB,CAE3F;AAED,qCAAqC;AACrC,wBAAgB,cAAc,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,IAAI,YAAY,CAE7E"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured payload encoding for QQ Bot agentic outputs.
|
|
3
|
+
*
|
|
4
|
+
* Two related but distinct text-encoding protocols:
|
|
5
|
+
*
|
|
6
|
+
* 1. `QQBOT_PAYLOAD:` — emitted by the model in agent output to request
|
|
7
|
+
* structured behaviour (cron reminders, media-by-path sends).
|
|
8
|
+
* 2. `QQBOT_CRON:` — base64 wrapper used to persist cron-reminder
|
|
9
|
+
* payloads in scheduled-job queues.
|
|
10
|
+
*
|
|
11
|
+
* Both are pure string transforms with no I/O.
|
|
12
|
+
*/
|
|
13
|
+
const PAYLOAD_PREFIX = "QQBOT_PAYLOAD:";
|
|
14
|
+
const CRON_PREFIX = "QQBOT_CRON:";
|
|
15
|
+
function formatErr(e) {
|
|
16
|
+
return e instanceof Error ? e.message : String(e);
|
|
17
|
+
}
|
|
18
|
+
// ============ QQBOT_PAYLOAD: ============
|
|
19
|
+
/** Parse model output that may start with the QQ Bot structured payload prefix. */
|
|
20
|
+
export function parseQQBotPayload(text) {
|
|
21
|
+
const trimmedText = text.trim();
|
|
22
|
+
if (!trimmedText.startsWith(PAYLOAD_PREFIX)) {
|
|
23
|
+
return { isPayload: false, text };
|
|
24
|
+
}
|
|
25
|
+
const jsonContent = trimmedText.slice(PAYLOAD_PREFIX.length).trim();
|
|
26
|
+
if (!jsonContent) {
|
|
27
|
+
return { isPayload: true, error: "Payload body is empty" };
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const payload = JSON.parse(jsonContent);
|
|
31
|
+
if (!payload.type) {
|
|
32
|
+
return { isPayload: true, error: "Payload is missing the type field" };
|
|
33
|
+
}
|
|
34
|
+
if (payload.type === "cron_reminder") {
|
|
35
|
+
if (!payload.content || !payload.targetType || !payload.targetAddress) {
|
|
36
|
+
return {
|
|
37
|
+
isPayload: true,
|
|
38
|
+
error: "cron_reminder payload is missing required fields (content, targetType, targetAddress)",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (payload.type === "media") {
|
|
43
|
+
if (!payload.mediaType || !payload.source || !payload.path) {
|
|
44
|
+
return {
|
|
45
|
+
isPayload: true,
|
|
46
|
+
error: "media payload is missing required fields (mediaType, source, path)",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { isPayload: true, payload };
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
return { isPayload: true, error: `Failed to parse JSON: ${formatErr(e)}` };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// ============ QQBOT_CRON: ============
|
|
57
|
+
/** Encode a cron reminder payload into the stored cron-message format. */
|
|
58
|
+
export function encodePayloadForCron(payload) {
|
|
59
|
+
const jsonString = JSON.stringify(payload);
|
|
60
|
+
const base64 = Buffer.from(jsonString, "utf-8").toString("base64");
|
|
61
|
+
return `${CRON_PREFIX}${base64}`;
|
|
62
|
+
}
|
|
63
|
+
/** Decode a stored cron payload. */
|
|
64
|
+
export function decodeCronPayload(message) {
|
|
65
|
+
const trimmedMessage = message.trim();
|
|
66
|
+
if (!trimmedMessage.startsWith(CRON_PREFIX)) {
|
|
67
|
+
return { isCronPayload: false };
|
|
68
|
+
}
|
|
69
|
+
const base64Content = trimmedMessage.slice(CRON_PREFIX.length);
|
|
70
|
+
if (!base64Content) {
|
|
71
|
+
return { isCronPayload: true, error: "Cron payload body is empty" };
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const jsonString = Buffer.from(base64Content, "base64").toString("utf-8");
|
|
75
|
+
const payload = JSON.parse(jsonString);
|
|
76
|
+
if (payload.type !== "cron_reminder") {
|
|
77
|
+
return {
|
|
78
|
+
isCronPayload: true,
|
|
79
|
+
error: `Expected type cron_reminder but got ${String(payload.type)}`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (!payload.content || !payload.targetType || !payload.targetAddress) {
|
|
83
|
+
return { isCronPayload: true, error: "Cron payload is missing required fields" };
|
|
84
|
+
}
|
|
85
|
+
return { isCronPayload: true, payload };
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
return { isCronPayload: true, error: `Failed to decode cron payload: ${formatErr(e)}` };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// ============ Type guards ============
|
|
92
|
+
/** Type guard for cron reminder payloads. */
|
|
93
|
+
export function isCronReminderPayload(payload) {
|
|
94
|
+
return payload.type === "cron_reminder";
|
|
95
|
+
}
|
|
96
|
+
/** Type guard for media payloads. */
|
|
97
|
+
export function isMediaPayload(payload) {
|
|
98
|
+
return payload.type === "media";
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=payload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.js","sourceRoot":"","sources":["../../../src/protocol/utils/payload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAkCH,MAAM,cAAc,GAAG,gBAAgB,CAAC;AACxC,MAAM,WAAW,GAAG,aAAa,CAAC;AAElC,SAAS,SAAS,CAAC,CAAU;IAC3B,OAAO,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,2CAA2C;AAE3C,mFAAmF;AACnF,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAEhC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QAC5C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACpC,CAAC;IAED,MAAM,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAEpE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC;IAC7D,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAiB,CAAC;QAExD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,mC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AED,qCAAqC;AACrC,MAAM,UAAU,cAAc,CAAC,OAAqB;IAClD,OAAO,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quoted-message reference index types and rendering helpers.
|
|
3
|
+
*
|
|
4
|
+
* These types describe the per-message metadata captured for QQ Bot
|
|
5
|
+
* "quote / reply" features. The SDK is the single source of truth so
|
|
6
|
+
* platform consumers (history replay, current-turn rendering, ref-index
|
|
7
|
+
* cache) can share one vocabulary.
|
|
8
|
+
*
|
|
9
|
+
* Zero external dependencies — pure type + string formatting.
|
|
10
|
+
*/
|
|
11
|
+
/** Summary stored for one quoted message. */
|
|
12
|
+
export interface RefIndexEntry {
|
|
13
|
+
content: string;
|
|
14
|
+
senderId: string;
|
|
15
|
+
senderName?: string;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
isBot?: boolean;
|
|
18
|
+
attachments?: RefAttachmentSummary[];
|
|
19
|
+
}
|
|
20
|
+
/** Attachment summary persisted alongside a ref index entry. */
|
|
21
|
+
export interface RefAttachmentSummary {
|
|
22
|
+
type: "image" | "voice" | "video" | "file" | "unknown";
|
|
23
|
+
filename?: string;
|
|
24
|
+
contentType?: string;
|
|
25
|
+
transcript?: string;
|
|
26
|
+
transcriptSource?: "stt" | "asr" | "tts" | "fallback";
|
|
27
|
+
localPath?: string;
|
|
28
|
+
url?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Canonical attachment shape shared by history entries and ref entries. */
|
|
31
|
+
export type AttachmentSummary = RefAttachmentSummary;
|
|
32
|
+
/**
|
|
33
|
+
* Rendering mode.
|
|
34
|
+
*
|
|
35
|
+
* - `"inline"`: current turn + history replay. No transcript-source tag.
|
|
36
|
+
* Tags are separated by newlines.
|
|
37
|
+
* - `"ref"`: quoted-message block. Appends `[source: …]` to voice
|
|
38
|
+
* transcripts when `transcriptSource` is present. Tags are separated
|
|
39
|
+
* by spaces so the block fits on one line.
|
|
40
|
+
*/
|
|
41
|
+
export type RenderMode = "inline" | "ref";
|
|
42
|
+
/** Human-readable labels for transcript provenance (prompt contract). */
|
|
43
|
+
export declare const TRANSCRIPT_SOURCE_LABELS: Record<NonNullable<RefAttachmentSummary["transcriptSource"]>, string>;
|
|
44
|
+
/** Options controlling how the tag list is rendered. */
|
|
45
|
+
export interface RenderOptions {
|
|
46
|
+
mode: RenderMode;
|
|
47
|
+
/** Separator between tags. Defaults per mode: inline=`\n`, ref=` `. */
|
|
48
|
+
separator?: string;
|
|
49
|
+
/** Returned when `attachments` is empty/undefined. Defaults to `""`. */
|
|
50
|
+
emptyFallback?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Render a list of attachments into an LLM-facing tag string.
|
|
54
|
+
*
|
|
55
|
+
* Shared grammar (both modes):
|
|
56
|
+
*
|
|
57
|
+
* ```
|
|
58
|
+
* attachment_with_source := "MEDIA:" SOURCE [voice_suffix]
|
|
59
|
+
* voice_suffix := ' (transcript: "' TEXT '")' [source_suffix]
|
|
60
|
+
* attachment_no_source := "[" TYPE_LABEL [": " FILENAME] [voice_suffix_bare] "]" [source_suffix_bare]
|
|
61
|
+
* voice_suffix_bare := ' (transcript: "' TEXT '")'
|
|
62
|
+
* source_suffix := " [source: " LABEL "]" ← ref mode only
|
|
63
|
+
* source_suffix_bare := " [source: " LABEL "]" ← ref mode only
|
|
64
|
+
* TYPE_LABEL := "image" | "voice" | "video" | "file" | "attachment"
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* The **only** mode-dependent decoration is the `source_suffix` (present
|
|
68
|
+
* in `ref`, absent in `inline`). Every other token is identical.
|
|
69
|
+
*/
|
|
70
|
+
export declare function renderAttachmentTags(attachments: readonly AttachmentSummary[] | undefined, options: RenderOptions): string;
|
|
71
|
+
/**
|
|
72
|
+
* Shorthand for `renderAttachmentTags(attachments, { mode: "inline" })`.
|
|
73
|
+
*
|
|
74
|
+
* Kept as the primary entry point for group history / current-turn
|
|
75
|
+
* rendering where the terse inline form is always wanted.
|
|
76
|
+
*/
|
|
77
|
+
export declare function formatAttachmentTags(attachments?: readonly AttachmentSummary[]): string;
|
|
78
|
+
/** Format a ref-index entry into text suitable for model context. */
|
|
79
|
+
export declare function formatRefEntryForAgent(entry: RefIndexEntry): string;
|
|
80
|
+
//# sourceMappingURL=ref-attachments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref-attachments.d.ts","sourceRoot":"","sources":["../../../src/protocol/utils/ref-attachments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,oBAAoB,EAAE,CAAC;CACtC;AAED,gEAAgE;AAChE,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,UAAU,CAAC;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,4EAA4E;AAC5E,MAAM,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;AAErD;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE1C,yEAAyE;AACzE,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAC3C,WAAW,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,CAAC,EACrD,MAAM,CAMP,CAAC;AAEF,wDAAwD;AACxD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAID;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,SAAS,iBAAiB,EAAE,GAAG,SAAS,EACrD,OAAO,EAAE,aAAa,GACrB,MAAM,CAYR;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,CAAC,EAAE,SAAS,iBAAiB,EAAE,GAAG,MAAM,CAEvF;AAED,qEAAqE;AACrE,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAanE"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quoted-message reference index types and rendering helpers.
|
|
3
|
+
*
|
|
4
|
+
* These types describe the per-message metadata captured for QQ Bot
|
|
5
|
+
* "quote / reply" features. The SDK is the single source of truth so
|
|
6
|
+
* platform consumers (history replay, current-turn rendering, ref-index
|
|
7
|
+
* cache) can share one vocabulary.
|
|
8
|
+
*
|
|
9
|
+
* Zero external dependencies — pure type + string formatting.
|
|
10
|
+
*/
|
|
11
|
+
/** Human-readable labels for transcript provenance (prompt contract). */
|
|
12
|
+
export const TRANSCRIPT_SOURCE_LABELS = {
|
|
13
|
+
stt: "local STT",
|
|
14
|
+
asr: "platform ASR",
|
|
15
|
+
tts: "TTS source",
|
|
16
|
+
fallback: "fallback text",
|
|
17
|
+
};
|
|
18
|
+
// ============ Public API ============
|
|
19
|
+
/**
|
|
20
|
+
* Render a list of attachments into an LLM-facing tag string.
|
|
21
|
+
*
|
|
22
|
+
* Shared grammar (both modes):
|
|
23
|
+
*
|
|
24
|
+
* ```
|
|
25
|
+
* attachment_with_source := "MEDIA:" SOURCE [voice_suffix]
|
|
26
|
+
* voice_suffix := ' (transcript: "' TEXT '")' [source_suffix]
|
|
27
|
+
* attachment_no_source := "[" TYPE_LABEL [": " FILENAME] [voice_suffix_bare] "]" [source_suffix_bare]
|
|
28
|
+
* voice_suffix_bare := ' (transcript: "' TEXT '")'
|
|
29
|
+
* source_suffix := " [source: " LABEL "]" ← ref mode only
|
|
30
|
+
* source_suffix_bare := " [source: " LABEL "]" ← ref mode only
|
|
31
|
+
* TYPE_LABEL := "image" | "voice" | "video" | "file" | "attachment"
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* The **only** mode-dependent decoration is the `source_suffix` (present
|
|
35
|
+
* in `ref`, absent in `inline`). Every other token is identical.
|
|
36
|
+
*/
|
|
37
|
+
export function renderAttachmentTags(attachments, options) {
|
|
38
|
+
if (!attachments?.length) {
|
|
39
|
+
return options.emptyFallback ?? "";
|
|
40
|
+
}
|
|
41
|
+
const parts = [];
|
|
42
|
+
for (const att of attachments) {
|
|
43
|
+
parts.push(renderOne(att, options.mode));
|
|
44
|
+
}
|
|
45
|
+
const separator = options.separator ?? (options.mode === "ref" ? " " : "\n");
|
|
46
|
+
return parts.join(separator);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Shorthand for `renderAttachmentTags(attachments, { mode: "inline" })`.
|
|
50
|
+
*
|
|
51
|
+
* Kept as the primary entry point for group history / current-turn
|
|
52
|
+
* rendering where the terse inline form is always wanted.
|
|
53
|
+
*/
|
|
54
|
+
export function formatAttachmentTags(attachments) {
|
|
55
|
+
return renderAttachmentTags(attachments, { mode: "inline" });
|
|
56
|
+
}
|
|
57
|
+
/** Format a ref-index entry into text suitable for model context. */
|
|
58
|
+
export function formatRefEntryForAgent(entry) {
|
|
59
|
+
const parts = [];
|
|
60
|
+
if (entry.content.trim()) {
|
|
61
|
+
parts.push(entry.content);
|
|
62
|
+
}
|
|
63
|
+
const attachmentTags = renderAttachmentTags(entry.attachments, { mode: "ref" });
|
|
64
|
+
if (attachmentTags) {
|
|
65
|
+
parts.push(attachmentTags);
|
|
66
|
+
}
|
|
67
|
+
return parts.join(" ") || "[empty message]";
|
|
68
|
+
}
|
|
69
|
+
// ============ Internal ============
|
|
70
|
+
/**
|
|
71
|
+
* Render a single attachment.
|
|
72
|
+
*
|
|
73
|
+
* The function is split into two orthogonal concerns:
|
|
74
|
+
* - `renderBody`: the shared "MEDIA:{source}…" or "[type…]" string.
|
|
75
|
+
* - `renderSourceSuffix`: ref-mode-only `" [source: …]"` tail.
|
|
76
|
+
*
|
|
77
|
+
* Both consumers produce the same body; only the suffix differs.
|
|
78
|
+
*/
|
|
79
|
+
function renderOne(att, mode) {
|
|
80
|
+
const body = renderBody(att);
|
|
81
|
+
const suffix = mode === "ref" ? renderSourceSuffix(att) : "";
|
|
82
|
+
return body + suffix;
|
|
83
|
+
}
|
|
84
|
+
/** Shared, mode-agnostic body of the tag. */
|
|
85
|
+
function renderBody(att) {
|
|
86
|
+
const source = att.localPath || att.url;
|
|
87
|
+
const voiceSuffix = att.type === "voice" && att.transcript ? ` (transcript: "${att.transcript}")` : "";
|
|
88
|
+
if (source) {
|
|
89
|
+
return `MEDIA:${source}${voiceSuffix}`;
|
|
90
|
+
}
|
|
91
|
+
const label = labelForType(att.type);
|
|
92
|
+
const namePart = att.filename ? `: ${att.filename}` : "";
|
|
93
|
+
return `[${label}${namePart}${voiceSuffix}]`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Ref-mode-only tail that records where a voice transcript came from.
|
|
97
|
+
* Empty string when the attachment isn't a transcribed voice message.
|
|
98
|
+
*/
|
|
99
|
+
function renderSourceSuffix(att) {
|
|
100
|
+
if (att.type !== "voice" || !att.transcript || !att.transcriptSource) {
|
|
101
|
+
return "";
|
|
102
|
+
}
|
|
103
|
+
const label = TRANSCRIPT_SOURCE_LABELS[att.transcriptSource] ?? att.transcriptSource;
|
|
104
|
+
return ` [source: ${label}]`;
|
|
105
|
+
}
|
|
106
|
+
/** Canonical single-word label for each attachment type. */
|
|
107
|
+
function labelForType(type) {
|
|
108
|
+
switch (type) {
|
|
109
|
+
case "image":
|
|
110
|
+
return "image";
|
|
111
|
+
case "voice":
|
|
112
|
+
return "voice";
|
|
113
|
+
case "video":
|
|
114
|
+
return "video";
|
|
115
|
+
case "file":
|
|
116
|
+
return "file";
|
|
117
|
+
default:
|
|
118
|
+
return "attachment";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=ref-attachments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref-attachments.js","sourceRoot":"","sources":["../../../src/protocol/utils/ref-attachments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAuCH,yEAAyE;AACzE,MAAM,CAAC,MAAM,wBAAwB,GAGjC;IACF,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,YAAY;IACjB,QAAQ,EAAE,eAAe;CAC1B,CAAC;AAWF,uCAAuC;AAEvC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,oBAAoB,CAClC,WAAqD,EACrD,OAAsB;IAEtB,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,aAAa,IAAI,EAAE,CAAC;IACrC,CAAC;IAED,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC7E,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;A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AC;IAErF,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,SAAS,MAAM,GAAG,WAAW,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACzD,OAAO,IAAI,KAAK,GAAG,QAAQ,GAAG,WAAW,GAAG,CAAC;AAC/C,CAAC;AAED;;;GAGG;AACH,SAAS,kBAAkB,CAAC,GAAsB;IAChD,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACrE,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,KAAK,GAAG,wBAAwB,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,GAAG,CAAC,gBAAgB,CAAC;IACrF,OAAO,aAAa,KAAK,GAAG,CAAC;AAC/B,CAAC;AAED,4DAA4D;AAC5D,SAAS,YAAY,CAAC,IAA+B;IACnD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB;YACE,OAAO,YAAY,CAAC;IACxB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic JSONL-backed ref-index store.
|
|
3
|
+
*
|
|
4
|
+
* QQ Bot quote / reply messages identify the quoted message via a
|
|
5
|
+
* `refMsgIdx` string. To render the quoted-message preview the bot needs
|
|
6
|
+
* to remember the original sender + content + attachments associated
|
|
7
|
+
* with each `refMsgIdx`. This class implements the storage layer of that
|
|
8
|
+
* cache:
|
|
9
|
+
*
|
|
10
|
+
* - Append-only JSONL on disk (cheap writes, replay on startup).
|
|
11
|
+
* - Bounded in-memory map with TTL eviction.
|
|
12
|
+
* - Compaction when on-disk lines >> in-memory entries.
|
|
13
|
+
*
|
|
14
|
+
* Path resolution is **delegated to the embedder** via the constructor:
|
|
15
|
+
* the SDK itself does not know where the host application wants its data
|
|
16
|
+
* (`~/.openclaw/qqbot/data/ref-index.jsonl`, `/var/lib/qqbot/...`, etc).
|
|
17
|
+
*/
|
|
18
|
+
import type { RefIndexEntry } from "./ref-attachments.js";
|
|
19
|
+
/** Optional logger contract used for diagnostic messages. */
|
|
20
|
+
export interface RefIndexStoreLogger {
|
|
21
|
+
log?: (msg: string) => void;
|
|
22
|
+
error?: (msg: string) => void;
|
|
23
|
+
}
|
|
24
|
+
/** Configuration for {@link JsonlRefIndexStore}. */
|
|
25
|
+
export interface JsonlRefIndexStoreOptions {
|
|
26
|
+
/** Resolve the on-disk JSONL file path. Called lazily on first I/O. */
|
|
27
|
+
filePath: () => string;
|
|
28
|
+
/** Ensure the parent directory exists. Called before each append. */
|
|
29
|
+
ensureDir: () => void;
|
|
30
|
+
/** Maximum number of in-memory entries before LRU-by-create-time eviction. */
|
|
31
|
+
maxEntries?: number;
|
|
32
|
+
/** Time-to-live for each entry, in milliseconds. */
|
|
33
|
+
ttlMs?: number;
|
|
34
|
+
/** Disk lines / cache entries ratio that triggers compaction. */
|
|
35
|
+
compactThresholdRatio?: number;
|
|
36
|
+
/** Optional logger for diagnostics. */
|
|
37
|
+
logger?: RefIndexStoreLogger;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Append-only JSONL store for QQ Bot ref-index entries.
|
|
41
|
+
*
|
|
42
|
+
* Each instance owns one file path and one in-memory map. Multi-account
|
|
43
|
+
* deployments should construct one store per logical scope.
|
|
44
|
+
*/
|
|
45
|
+
export declare class JsonlRefIndexStore {
|
|
46
|
+
private readonly options;
|
|
47
|
+
private cache;
|
|
48
|
+
private totalLinesOnDisk;
|
|
49
|
+
constructor(options: JsonlRefIndexStoreOptions);
|
|
50
|
+
/** Persist a refIdx mapping for one message. */
|
|
51
|
+
set(refIdx: string, entry: RefIndexEntry): void;
|
|
52
|
+
/** Look up one quoted message by refIdx. */
|
|
53
|
+
get(refIdx: string): RefIndexEntry | null;
|
|
54
|
+
/** Compact the store before process exit when needed. */
|
|
55
|
+
flush(): void;
|
|
56
|
+
/** Return diagnostic stats. */
|
|
57
|
+
getStats(): {
|
|
58
|
+
size: number;
|
|
59
|
+
maxEntries: number;
|
|
60
|
+
totalLinesOnDisk: number;
|
|
61
|
+
filePath: string;
|
|
62
|
+
};
|
|
63
|
+
private loadFromFile;
|
|
64
|
+
private appendLine;
|
|
65
|
+
private shouldCompact;
|
|
66
|
+
private compactFile;
|
|
67
|
+
private evictIfNeeded;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=ref-index-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref-index-store.d.ts","sourceRoot":"","sources":["../../../src/protocol/utils/ref-index-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,6DAA6D;AAC7D,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B;AAED,oDAAoD;AACpD,MAAM,WAAW,yBAAyB;IACxC,uEAAuE;IACvE,QAAQ,EAAE,MAAM,MAAM,CAAC;IACvB,qEAAqE;IACrE,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,KAAK,CAAC,EAAE,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