@qilin-agent/output-retention 3.1.4 → 3.1.6
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/lib/index.js +13 -1
- package/lib/types/index.d.ts +8 -0
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -278,8 +278,20 @@ function describeOmitted(omitted, unit) {
|
|
|
278
278
|
* @param recovery Tool-supplied guidance builder; receives the notice, returns a sentence (or `''`).
|
|
279
279
|
* @returns The combined footer line.
|
|
280
280
|
*/
|
|
281
|
+
/**
|
|
282
|
+
* Truncate text to at most `maxChars` UTF-16 code units without splitting a
|
|
283
|
+
* surrogate pair: a capped string ending in a leading surrogate drops it.
|
|
284
|
+
* @param text - the text to cap.
|
|
285
|
+
* @param maxChars - the maximum code units to keep.
|
|
286
|
+
* @returns the capped text, unchanged when it already fits.
|
|
287
|
+
*/
|
|
288
|
+
function truncateWithoutSplittingSurrogatePair(text, maxChars) {
|
|
289
|
+
if (text.length <= maxChars) return text;
|
|
290
|
+
const capped = text.slice(0, maxChars);
|
|
291
|
+
return /[\uD800-\uDBFF]$/.test(capped) ? capped.slice(0, -1) : capped;
|
|
292
|
+
}
|
|
281
293
|
function formatRetentionNotice(notice, recovery) {
|
|
282
294
|
return [describeOmitted(notice.omitted, notice.unit), recovery(notice)].filter((part) => part.length > 0).join(" ");
|
|
283
295
|
}
|
|
284
296
|
//#endregion
|
|
285
|
-
export { ItemRetainer, TextRetainer, describeOmitted, formatRetentionNotice };
|
|
297
|
+
export { ItemRetainer, TextRetainer, describeOmitted, formatRetentionNotice, truncateWithoutSplittingSurrogatePair };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -221,5 +221,13 @@ export declare function describeOmitted(omitted: Omitted, unit: RetentionNotice[
|
|
|
221
221
|
* @param recovery Tool-supplied guidance builder; receives the notice, returns a sentence (or `''`).
|
|
222
222
|
* @returns The combined footer line.
|
|
223
223
|
*/
|
|
224
|
+
/**
|
|
225
|
+
* Truncate text to at most `maxChars` UTF-16 code units without splitting a
|
|
226
|
+
* surrogate pair: a capped string ending in a leading surrogate drops it.
|
|
227
|
+
* @param text - the text to cap.
|
|
228
|
+
* @param maxChars - the maximum code units to keep.
|
|
229
|
+
* @returns the capped text, unchanged when it already fits.
|
|
230
|
+
*/
|
|
231
|
+
export declare function truncateWithoutSplittingSurrogatePair(text: string, maxChars: number): string;
|
|
224
232
|
export declare function formatRetentionNotice(notice: RetentionNotice, recovery: (notice: RetentionNotice) => string): string;
|
|
225
233
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qilin-agent/output-retention",
|
|
3
3
|
"description": "Zero-dependency bounded-retention primitive: ItemRetainer/TextRetainer + neutral notice helpers (what did we keep, what did we omit)",
|
|
4
|
-
"version": "3.1.
|
|
4
|
+
"version": "3.1.6",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
],
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@qilin-agent/kylin": "~4.0.
|
|
33
|
+
"@qilin-agent/kylin": "~4.0.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@qilin-agent/kylin": "~4.0.
|
|
36
|
+
"@qilin-agent/kylin": "~4.0.5"
|
|
37
37
|
}
|
|
38
38
|
}
|