it("does not let </tool_result> close a <tool_call> block", () => {
expectVisibleText( 'Prefix\n<tool_call>{"name":"x"}</tool_result>LEAK</tool_call>\nSuffix', "Prefix\n\nSuffix",
);
});
it("hides dangling <tool_call> content to end-of-string", () => {
expectVisibleText( 'Let me run.\n<tool_call>\n{"name": "find", "arguments": {}}\n', "Let me run.\n",
);
});
it("strips Qwen-style <tool_call> with whitespace before nested XML", () => {
expectVisibleText( "prefix\n<tool_call>\n<function=search><parameter=query>test</parameter></function>\n</tool_call>\nsuffix", "prefix\n\nsuffix",
);
});
it("strips dangling Qwen-style <tool_call> with nested XML to end", () => {
expectVisibleText("prefix\n<tool_call><function=read><parameter=path>/home", "prefix\n");
});
it("does not close early on </tool_call> text inside JSON strings", () => {
expectVisibleText(
[ "prefix", "<tool_call>", '{"name":"x","arguments":{"html":"<div></tool_call><span>leak</span>"}}', "</tool_call>", "suffix",
].join("\n"), "prefix\n\nsuffix",
);
});
it("does not close early on </tool_call> text inside single-quoted payload strings", () => {
expectVisibleText(
[ "prefix", "<tool_call>", "{'html':'</tool_call> leak','tail':'still hidden'}", "</tool_call>", "suffix",
].join("\n"), "prefix\n\nsuffix",
);
});
it("does not close early on mismatched closing tool tags", () => {
expectVisibleText(
[ "prefix", "<tool_call>", '{"name":"read",', "</function_calls>", "still-hidden", "</tool_call>", "suffix",
].join("\n"), "prefix\n\nsuffix",
);
});
it("hides truncated <tool_call openings that never reach >", () => {
expectVisibleText('prefix\n<tool_call\n{"name":"find","arguments":{}}', "prefix\n");
});
it("hides truncated <tool_call openings with attributes before JSON payload", () => {
expectVisibleText('prefix\n<tool_call name="find"\n{"arguments":{}}', "prefix\n");
});
it("preserves lone <tool_call> mentions in normal prose", () => {
expectVisibleText("Use <tool_call> to invoke tools.", "Use <tool_call> to invoke tools.");
});
it("preserves lone <function> mentions in normal prose", () => {
expectVisibleText( "Use <function> declarations in your WASM text format.", "Use <function> declarations in your WASM text format.",
);
});
it("preserves inline code references to tool_call tags", () => {
expectVisibleText("Use `<tool_call>` to invoke tools.", "Use `<tool_call>` to invoke tools.");
});
});
describe("model special token stripping", () => {
it("strips Kimi/GLM special tokens in isolation", () => {
expectVisibleText("<|assistant|>Here is the answer<|end|>", "Here is the answer");
});
it("preserves indentation in code blocks", () => { const input = [ "<|assistant|>Here is the code:", "", "```python", "def foo():", " if True:", " return 42", "```",
].join("\n"); const expected = [ "Here is the code:", "", "```python", "def foo():", " if True:", " return 42", "```",
].join("\n");
expectVisibleText(input, expected);
});
it("preserves special tokens inside fenced code blocks", () => { const input = [ "Here are the model tokens:", "", "```", "<|assistant|>Hello<|end|>", "```", "", "As you can see above.",
].join("\n");
expectVisibleText(input, input);
});
it("preserves special tokens inside inline code spans", () => {
expectVisibleText( "The token `<|assistant|>` marks the start.", "The token `<|assistant|>` marks the start.",
);
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.