chore(qqbot): inline legacy text chunk helper

This commit is contained in:
Peter Steinberger
2026-05-01 11:26:48 +01:00
parent 5f42438cf7
commit 404446f758
2 changed files with 17 additions and 28 deletions

View File

@@ -23,6 +23,23 @@ import {
} from "./engine/messaging/target-parser.js";
import type { ResolvedQQBotAccount } from "./types.js";
/** Maximum text length for a single QQ Bot message. */
export const TEXT_CHUNK_LIMIT = 5000;
/**
* Naive text chunking fallback.
*
* The outbound pipeline normally uses `runtime.channel.text.chunkMarkdownText`;
* this remains exported for callers that need the legacy channel helper.
*/
export function chunkText(text: string, limit: number = TEXT_CHUNK_LIMIT): string[] {
const chunks: string[] = [];
for (let i = 0; i < text.length; i += limit) {
chunks.push(text.slice(i, i + limit));
}
return chunks.length > 0 ? chunks : [text];
}
// Shared promise so concurrent multi-account startups serialize the dynamic
// import of the gateway module, avoiding an ESM circular-dependency race.
let _gatewayModulePromise: Promise<typeof import("./bridge/gateway.js")> | undefined;

View File

@@ -1,28 +0,0 @@
/**
* Text chunking constants and fallback.
*
* The actual chunking logic is provided by the framework runtime
* (`runtime.channel.text.chunkMarkdownText`) and injected via the
* outbound dispatch pipeline — NOT via a global singleton.
*
* This module only exports the chunk limit constant and a naive
* fallback splitter for edge cases outside the pipeline.
*/
/** Maximum text length for a single QQ Bot message. */
export const TEXT_CHUNK_LIMIT = 5000;
/**
* Naive text chunking fallback.
*
* Used only by code outside the outbound pipeline that needs a
* simple split. The real markdown-aware chunking is always done
* via `runtime.channel.text.chunkMarkdownText` inside the pipeline.
*/
export function chunkText(text: string, limit: number = TEXT_CHUNK_LIMIT): string[] {
const chunks: string[] = [];
for (let i = 0; i < text.length; i += limit) {
chunks.push(text.slice(i, i + limit));
}
return chunks.length > 0 ? chunks : [text];
}