@arhen/pi-senja 1.4.0 → 1.5.1
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/package.json +1 -1
- package/src/tool-groups.ts +36 -0
package/package.json
CHANGED
package/src/tool-groups.ts
CHANGED
|
@@ -431,6 +431,37 @@ export function createTranscriptView(
|
|
|
431
431
|
const previews = new WeakSet<Component>();
|
|
432
432
|
type Thought = ReturnType<typeof thinkingRow>;
|
|
433
433
|
const originals = new WeakMap<Component, MouseRegion>();
|
|
434
|
+
const styledMarkdown = new WeakSet<Markdown>();
|
|
435
|
+
function styleFences(part: Markdown) {
|
|
436
|
+
if (styledMarkdown.has(part) || Object.hasOwn(part, "renderToken")) return;
|
|
437
|
+
const native = Reflect.get(part, "renderToken");
|
|
438
|
+
if (typeof native !== "function") return;
|
|
439
|
+
// ponytail: Pi has no block renderer hook; override this instance only while its native token method exists.
|
|
440
|
+
Reflect.set(
|
|
441
|
+
part,
|
|
442
|
+
"renderToken",
|
|
443
|
+
(token: { type: string; text: string; lang?: string; raw?: string }, width: number, ...rest: unknown[]) => {
|
|
444
|
+
if (token.type !== "code" || !/^ {0,3}(?:`{3,}|~{3,})/.test(token.raw ?? "") || width < 1)
|
|
445
|
+
return native.call(part, token, width, ...rest);
|
|
446
|
+
const source = stripTerminalSequences(token.text)
|
|
447
|
+
.replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "")
|
|
448
|
+
.replace(/\t/g, " ")
|
|
449
|
+
.split("\n");
|
|
450
|
+
const lang = summary(token.lang).split(" ")[0] || "code";
|
|
451
|
+
const inset = width >= 8 ? " " : "";
|
|
452
|
+
const gutter = width >= 4 ? theme.fg("borderMuted", "▏") + " " : "";
|
|
453
|
+
const inner = width - inset.length - visibleWidth(gutter);
|
|
454
|
+
const lines = [inset + theme.fg("customMessageLabel", truncateToWidth(lang, width - inset.length, "…"))];
|
|
455
|
+
for (const logical of source) {
|
|
456
|
+
for (const row of wrapTextWithAnsi(logical, inner)) lines.push(inset + gutter + theme.fg("text", row));
|
|
457
|
+
}
|
|
458
|
+
if (rest[0] && rest[0] !== "space") lines.push("");
|
|
459
|
+
return lines;
|
|
460
|
+
},
|
|
461
|
+
);
|
|
462
|
+
styledMarkdown.add(part);
|
|
463
|
+
part.invalidate();
|
|
464
|
+
}
|
|
434
465
|
function styleThoughts(message: AssistantMessageComponent): Thought[] | undefined {
|
|
435
466
|
const [content] = message.children;
|
|
436
467
|
if (message.children.length !== 1 || !(content instanceof Container)) return;
|
|
@@ -438,6 +469,7 @@ export function createTranscriptView(
|
|
|
438
469
|
let onlyThoughts = true;
|
|
439
470
|
for (const [i, part] of content.children.entries()) {
|
|
440
471
|
if (part instanceof Spacer) continue;
|
|
472
|
+
if (part instanceof Markdown) styleFences(part);
|
|
441
473
|
const region = originals.get(part) ?? part;
|
|
442
474
|
const child = region instanceof MouseRegion ? Reflect.get(region, "child") : undefined;
|
|
443
475
|
if (!(region instanceof MouseRegion) || !(child instanceof Text || child instanceof Markdown)) {
|
|
@@ -700,6 +732,10 @@ export function createTranscriptView(
|
|
|
700
732
|
const [content] = message.children;
|
|
701
733
|
if (content instanceof Container) {
|
|
702
734
|
for (const [i, part] of content.children.entries()) {
|
|
735
|
+
if (part instanceof Markdown && styledMarkdown.has(part)) {
|
|
736
|
+
Reflect.deleteProperty(part, "renderToken");
|
|
737
|
+
part.invalidate();
|
|
738
|
+
}
|
|
703
739
|
const original = originals.get(part);
|
|
704
740
|
if (original) content.children[i] = original;
|
|
705
741
|
}
|