GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(provider-core): text generation context cuts no longer split an e… · pingdotgg/t3code@2ad6712

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/provider-core/src/server
    • textGenerationUtils.test.ts
    • textGenerationUtils.ts
    • threadTitleContext.test.ts
    • threadTitleContext.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/provider-core/src/server/textGenerationUtils.test.ts‎

Copy file name to clipboardExpand all lines: packages/provider-core/src/server/textGenerationUtils.test.ts
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { describe, expect, it } from "vite-plus/test";
22

3-
import { sanitizeCommitSubject, sanitizeThreadTitle } from "./textGenerationUtils.ts";
3+
import { limitSection, sanitizeCommitSubject, sanitizeThreadTitle } from "./textGenerationUtils.ts";
4+
5+
describe("limitSection", () => {
6+
it("cuts a long section without splitting an emoji", () => {
7+
expect(limitSection(`${"a".repeat(9)}🚀 more`, 10)).toBe(`${"a".repeat(9)}\n\n[truncated]`);
8+
});
9+
});
410

511
describe("sanitizeCommitSubject", () => {
612
// regression: #19181 truncation split grapheme clusters at the subject limit
Collapse file

‎packages/provider-core/src/server/textGenerationUtils.ts‎

Copy file name to clipboardExpand all lines: packages/provider-core/src/server/textGenerationUtils.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export function toJsonSchemaObject(schema: Schema.Top): unknown {
1919

2020
export function limitSection(value: string, maxChars: number): string {
2121
if (value.length <= maxChars) return value;
22-
const truncated = value.slice(0, maxChars);
22+
// Half an emoji serializes to a lone surrogate escape, which provider JSON parsers reject.
23+
const last = value.charCodeAt(maxChars - 1);
24+
const truncated = value.slice(0, last >= 0xd800 && last <= 0xdbff ? maxChars - 1 : maxChars);
2325
return `${truncated}\n\n[truncated]`;
2426
}
2527

Collapse file

‎packages/provider-core/src/server/threadTitleContext.test.ts‎

Copy file name to clipboardExpand all lines: packages/provider-core/src/server/threadTitleContext.test.ts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from "vite-plus/test";
22
import { ChatAttachmentId } from "@t3tools/contracts";
33
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
4-
import { formatThreadTitleContext } from "./threadTitleContext.ts";
4+
import { formatThreadTitleContext, limitTitleMessage } from "./threadTitleContext.ts";
55

66
describe("thread title context", () => {
77
it.each(["", "Ultrathink:\n"])("keeps attachments without bootstrap text (%j)", (prefix) => {
@@ -54,4 +54,9 @@ describe("thread title context", () => {
5454
expect(result.message).not.toContain("System instructions");
5555
expect(result.message.match(/USER:/g)).toHaveLength(1);
5656
});
57+
58+
it("cuts both ends of a long message without splitting an emoji", () => {
59+
const result = limitTitleMessage(`${"a".repeat(9)}🚀${"b".repeat(20)}🚀${"c".repeat(9)}`, 41);
60+
expect(result).toBe(`${"a".repeat(9)}\n[Content truncated]\n${"c".repeat(9)}`);
61+
});
5762
});
Collapse file

‎packages/provider-core/src/server/threadTitleContext.ts‎

Copy file name to clipboardExpand all lines: packages/provider-core/src/server/threadTitleContext.ts
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ export function limitTitleMessage(text: string, budget: number): string {
1717
if (text.length <= budget) return text;
1818
if (budget <= TRUNCATED.length) return "";
1919
const available = budget - TRUNCATED.length;
20-
const head = Math.ceil(available / 2);
21-
const tail = available - head;
20+
let head = Math.ceil(available / 2);
21+
let tail = available - head;
22+
// Half an emoji serializes to a lone surrogate escape, which provider JSON parsers reject.
23+
const last = text.charCodeAt(head - 1);
24+
if (last >= 0xd800 && last <= 0xdbff) head -= 1;
25+
const first = text.charCodeAt(text.length - tail);
26+
if (tail > 0 && first >= 0xdc00 && first <= 0xdfff) tail -= 1;
2227
return `${text.slice(0, head)}${TRUNCATED}${tail > 0 ? text.slice(-tail) : ""}`;
2328
}
2429

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.