@aliou/pi-neuralwatt 0.19.1 → 0.19.3
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/CHANGELOG.md +12 -0
- package/dist/provider/index.js +22 -32
- package/extensions/command-quotas/components/quota-tabs.ts +1 -1
- package/extensions/command-quotas/components/quotas-display.ts +1 -1
- package/extensions/provider/commands/settings/api-base-url-editor.ts +1 -1
- package/package.json +3 -3
- package/src/models/public-models.ts +18 -25
- package/extensions/shared/truncate.ts +0 -292
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @aliou/pi-extension-template
|
|
2
2
|
|
|
3
|
+
## 0.19.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1f5106f: Sync the offline fallback model table with the live Neuralwatt API: remove the retired Kimi K3 models (`kimi-k3`, `kimi-k3-fast`, `kimi-k3-flex`) and update the `nw-large` tracking alias to its new target, Kimi K3.1 Pro (lower pricing and the K3.1 Pro effort contract including `medium`).
|
|
8
|
+
|
|
9
|
+
## 0.19.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 0c42dbd: Add Kimi K3.1 Pro and Kimi K3.1 Pro (flex) to the offline fallback model table (fixes #146). New Moonshot flagship family: 1M context, vision, reasoning efforts max/high/medium/low/none with `xhigh` → `max` and `minimal` → `low` aliases; flex variant priced at the 0.65 discount multiplier.
|
|
14
|
+
|
|
3
15
|
## 0.19.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/provider/index.js
CHANGED
|
@@ -464,49 +464,39 @@ const NEURALWATT_MODELS = [
|
|
|
464
464
|
}]],
|
|
465
465
|
[{
|
|
466
466
|
cost: {
|
|
467
|
-
input:
|
|
468
|
-
output:
|
|
469
|
-
cacheRead: .
|
|
467
|
+
input: 2,
|
|
468
|
+
output: 10,
|
|
469
|
+
cacheRead: .2
|
|
470
470
|
},
|
|
471
471
|
vision: true,
|
|
472
472
|
reasoningMetadata: {
|
|
473
473
|
supported_efforts: [
|
|
474
474
|
"max",
|
|
475
475
|
"high",
|
|
476
|
+
"medium",
|
|
476
477
|
"low",
|
|
477
478
|
"none"
|
|
478
479
|
],
|
|
479
480
|
mandatory: false,
|
|
480
481
|
effort_aliases: {
|
|
481
482
|
xhigh: "max",
|
|
482
|
-
medium: "high",
|
|
483
483
|
minimal: "low"
|
|
484
484
|
}
|
|
485
485
|
}
|
|
486
|
-
}, [
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
},
|
|
501
|
-
{
|
|
502
|
-
id: "kimi-k3-flex",
|
|
503
|
-
name: "Kimi K3 (flex)",
|
|
504
|
-
contextWindow: 1048560,
|
|
505
|
-
maxOutputTokens: null,
|
|
506
|
-
reasoning: true,
|
|
507
|
-
costMultiplier: .65
|
|
508
|
-
}
|
|
509
|
-
]],
|
|
486
|
+
}, [{
|
|
487
|
+
id: "kimi-k3.1-pro",
|
|
488
|
+
name: "Kimi K3.1 Pro",
|
|
489
|
+
contextWindow: 1048560,
|
|
490
|
+
maxOutputTokens: null,
|
|
491
|
+
reasoning: true
|
|
492
|
+
}, {
|
|
493
|
+
id: "kimi-k3.1-pro-flex",
|
|
494
|
+
name: "Kimi K3.1 Pro (flex)",
|
|
495
|
+
contextWindow: 1048560,
|
|
496
|
+
maxOutputTokens: null,
|
|
497
|
+
reasoning: true,
|
|
498
|
+
costMultiplier: .65
|
|
499
|
+
}]],
|
|
510
500
|
[{
|
|
511
501
|
cost: {
|
|
512
502
|
input: .435,
|
|
@@ -541,22 +531,22 @@ const NEURALWATT_MODELS = [
|
|
|
541
531
|
}]],
|
|
542
532
|
[{
|
|
543
533
|
cost: {
|
|
544
|
-
input:
|
|
545
|
-
output:
|
|
546
|
-
cacheRead: .
|
|
534
|
+
input: 2,
|
|
535
|
+
output: 10,
|
|
536
|
+
cacheRead: .2
|
|
547
537
|
},
|
|
548
538
|
vision: true,
|
|
549
539
|
reasoningMetadata: {
|
|
550
540
|
supported_efforts: [
|
|
551
541
|
"max",
|
|
552
542
|
"high",
|
|
543
|
+
"medium",
|
|
553
544
|
"low",
|
|
554
545
|
"none"
|
|
555
546
|
],
|
|
556
547
|
mandatory: false,
|
|
557
548
|
effort_aliases: {
|
|
558
549
|
xhigh: "max",
|
|
559
|
-
medium: "high",
|
|
560
550
|
minimal: "low"
|
|
561
551
|
}
|
|
562
552
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { truncateToWidth } from "@aliou/pi-utils-ui";
|
|
1
2
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
3
|
import type { NeuralwattQuotas } from "../../../src/types/quota-api";
|
|
3
4
|
import {
|
|
@@ -10,7 +11,6 @@ import {
|
|
|
10
11
|
formatTokens,
|
|
11
12
|
formatUsd,
|
|
12
13
|
} from "../../../src/utils/quota-format";
|
|
13
|
-
import { truncateToWidth } from "../../shared/truncate";
|
|
14
14
|
import { renderProgressBar } from "./progress-bar";
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { truncateToWidth } from "@aliou/pi-utils-ui";
|
|
1
2
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
3
|
import { DynamicBorder } from "@earendil-works/pi-coding-agent";
|
|
3
4
|
import type { Component, TUI } from "@earendil-works/pi-tui";
|
|
4
5
|
import { Loader, matchesKey } from "@earendil-works/pi-tui";
|
|
5
6
|
import type { NeuralwattQuotas } from "../../../src/types/quota-api";
|
|
6
|
-
import { truncateToWidth } from "../../shared/truncate";
|
|
7
7
|
import {
|
|
8
8
|
renderCreditsTab,
|
|
9
9
|
renderSubscriptionTab,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { truncateToWidth } from "@aliou/pi-utils-ui";
|
|
1
2
|
import type { Component, SettingsListTheme } from "@earendil-works/pi-tui";
|
|
2
3
|
import { Input, Key, matchesKey } from "@earendil-works/pi-tui";
|
|
3
|
-
import { truncateToWidth } from "../../../shared/truncate";
|
|
4
4
|
|
|
5
5
|
export interface ApiBaseUrlEditorOptions {
|
|
6
6
|
initial: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aliou/pi-neuralwatt",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@aliou/pi-utils-settings": "^0.24.0",
|
|
46
|
-
"@aliou/pi-utils-ui": "^0.
|
|
46
|
+
"@aliou/pi-utils-ui": "^0.6.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@earendil-works/pi-ai": "1.5.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"typebox": "*"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@aliou/biome-plugins": "^0.
|
|
55
|
+
"@aliou/biome-plugins": "^0.18.1",
|
|
56
56
|
"@biomejs/biome": "^2.6.4",
|
|
57
57
|
"@changesets/cli": "^2.27.11",
|
|
58
58
|
"@earendil-works/pi-ai": "1.5.0",
|
|
@@ -75,16 +75,16 @@ const GLM_5_3_FLASH: NeuralwattModelFamily = {
|
|
|
75
75
|
},
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
// MoonshotAI. K3
|
|
79
|
-
//
|
|
80
|
-
// to
|
|
81
|
-
const
|
|
82
|
-
cost: { input:
|
|
78
|
+
// MoonshotAI. K3.1 Pro is a separate flagship from K3: cheaper, multimodal
|
|
79
|
+
// with a broader effort contract (max/high/medium/low/none, default max),
|
|
80
|
+
// aliasing `xhigh` to `max` and `minimal` to `low`.
|
|
81
|
+
const KIMI_K3_1_PRO: NeuralwattModelFamily = {
|
|
82
|
+
cost: { input: 2, output: 10, cacheRead: 0.2 },
|
|
83
83
|
vision: true,
|
|
84
84
|
reasoningMetadata: {
|
|
85
|
-
supported_efforts: ["max", "high", "low", "none"],
|
|
85
|
+
supported_efforts: ["max", "high", "medium", "low", "none"],
|
|
86
86
|
mandatory: false,
|
|
87
|
-
effort_aliases: { xhigh: "max",
|
|
87
|
+
effort_aliases: { xhigh: "max", minimal: "low" },
|
|
88
88
|
},
|
|
89
89
|
};
|
|
90
90
|
|
|
@@ -107,16 +107,16 @@ const MIMO_V2_6_PRO: NeuralwattModelFamily = {
|
|
|
107
107
|
},
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
// Neuralwatt tracking alias: the current large model, today Kimi K3. The
|
|
111
|
-
// alias moves to newer models over time, so it snapshots K3's contract
|
|
112
|
-
// instead of sharing the
|
|
110
|
+
// Neuralwatt tracking alias: the current large model, today Kimi K3.1 Pro. The
|
|
111
|
+
// alias moves to newer models over time, so it snapshots K3.1 Pro's contract
|
|
112
|
+
// instead of sharing the KIMI_K3_1_PRO family.
|
|
113
113
|
const NW_LARGE: NeuralwattModelFamily = {
|
|
114
|
-
cost: { input:
|
|
114
|
+
cost: { input: 2, output: 10, cacheRead: 0.2 },
|
|
115
115
|
vision: true,
|
|
116
116
|
reasoningMetadata: {
|
|
117
|
-
supported_efforts: ["max", "high", "low", "none"],
|
|
117
|
+
supported_efforts: ["max", "high", "medium", "low", "none"],
|
|
118
118
|
mandatory: false,
|
|
119
|
-
effort_aliases: { xhigh: "max",
|
|
119
|
+
effort_aliases: { xhigh: "max", minimal: "low" },
|
|
120
120
|
},
|
|
121
121
|
};
|
|
122
122
|
|
|
@@ -255,25 +255,18 @@ const FAMILIES: [NeuralwattModelFamily, NeuralwattVariantSpec[]][] = [
|
|
|
255
255
|
],
|
|
256
256
|
],
|
|
257
257
|
[
|
|
258
|
-
|
|
258
|
+
KIMI_K3_1_PRO,
|
|
259
259
|
[
|
|
260
260
|
{
|
|
261
|
-
id: "kimi-k3",
|
|
262
|
-
name: "Kimi K3",
|
|
261
|
+
id: "kimi-k3.1-pro",
|
|
262
|
+
name: "Kimi K3.1 Pro",
|
|
263
263
|
contextWindow: 1048560,
|
|
264
264
|
maxOutputTokens: null,
|
|
265
265
|
reasoning: true,
|
|
266
266
|
},
|
|
267
267
|
{
|
|
268
|
-
id: "kimi-k3-
|
|
269
|
-
name: "Kimi K3
|
|
270
|
-
contextWindow: 1048560,
|
|
271
|
-
maxOutputTokens: null,
|
|
272
|
-
reasoning: false,
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
id: "kimi-k3-flex",
|
|
276
|
-
name: "Kimi K3 (flex)",
|
|
268
|
+
id: "kimi-k3.1-pro-flex",
|
|
269
|
+
name: "Kimi K3.1 Pro (flex)",
|
|
277
270
|
contextWindow: 1048560,
|
|
278
271
|
maxOutputTokens: null,
|
|
279
272
|
reasoning: true,
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Truncate text to `maxWidth` display cells, appending `ellipsis` when text
|
|
5
|
-
* overflows. Unlike `truncateToWidth` from `@earendil-works/pi-tui`, this
|
|
6
|
-
* never injects resets (so caller-applied styling survives truncation) and
|
|
7
|
-
* its CSI parser accepts every escape sequence final, so non-SGR sequences
|
|
8
|
-
* neither swallow visible text nor skew the measured width.
|
|
9
|
-
*/
|
|
10
|
-
export function truncateToWidth(
|
|
11
|
-
text: string,
|
|
12
|
-
maxWidth: number,
|
|
13
|
-
ellipsis = "…",
|
|
14
|
-
pad = false,
|
|
15
|
-
): string {
|
|
16
|
-
if (maxWidth <= 0) return "";
|
|
17
|
-
if (text.length === 0) return pad ? " ".repeat(maxWidth) : "";
|
|
18
|
-
|
|
19
|
-
const ellipsisWidth = visibleWidth(ellipsis);
|
|
20
|
-
if (ellipsisWidth >= maxWidth) {
|
|
21
|
-
const textWidth = visibleWidth(text);
|
|
22
|
-
if (textWidth <= maxWidth) {
|
|
23
|
-
return pad ? text + " ".repeat(maxWidth - textWidth) : text;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const clippedEllipsis = truncateFragmentToWidth(ellipsis, maxWidth);
|
|
27
|
-
if (clippedEllipsis.width === 0) {
|
|
28
|
-
return pad ? " ".repeat(maxWidth) : "";
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return finalizeTruncatedResult(
|
|
32
|
-
"",
|
|
33
|
-
0,
|
|
34
|
-
clippedEllipsis.text,
|
|
35
|
-
clippedEllipsis.width,
|
|
36
|
-
maxWidth,
|
|
37
|
-
pad,
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (isPrintableAscii(text)) {
|
|
42
|
-
if (text.length <= maxWidth) {
|
|
43
|
-
return pad ? text + " ".repeat(maxWidth - text.length) : text;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const targetWidth = maxWidth - ellipsisWidth;
|
|
47
|
-
return finalizeTruncatedResult(
|
|
48
|
-
text.slice(0, targetWidth),
|
|
49
|
-
targetWidth,
|
|
50
|
-
ellipsis,
|
|
51
|
-
ellipsisWidth,
|
|
52
|
-
maxWidth,
|
|
53
|
-
pad,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const targetWidth = maxWidth - ellipsisWidth;
|
|
58
|
-
let result = "";
|
|
59
|
-
let visibleSoFar = 0;
|
|
60
|
-
let keptWidth = 0;
|
|
61
|
-
let keepContiguousPrefix = true;
|
|
62
|
-
let overflowed = false;
|
|
63
|
-
let exhaustedInput = false;
|
|
64
|
-
const hasAnsi = text.includes("\u001b");
|
|
65
|
-
const hasTabs = text.includes("\t");
|
|
66
|
-
|
|
67
|
-
if (!hasAnsi && !hasTabs) {
|
|
68
|
-
for (const { segment } of segmenter.segment(text)) {
|
|
69
|
-
const width = visibleWidth(segment);
|
|
70
|
-
if (keepContiguousPrefix && keptWidth + width <= targetWidth) {
|
|
71
|
-
result += segment;
|
|
72
|
-
keptWidth += width;
|
|
73
|
-
} else {
|
|
74
|
-
keepContiguousPrefix = false;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
visibleSoFar += width;
|
|
78
|
-
if (visibleSoFar > maxWidth) {
|
|
79
|
-
overflowed = true;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exhaustedInput = !overflowed;
|
|
84
|
-
} else {
|
|
85
|
-
let index = 0;
|
|
86
|
-
let pendingAnsi = "";
|
|
87
|
-
while (index < text.length) {
|
|
88
|
-
const ansi = readAnsiSequence(text, index);
|
|
89
|
-
if (ansi) {
|
|
90
|
-
pendingAnsi += ansi;
|
|
91
|
-
index += ansi.length;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (text[index] === "\t") {
|
|
96
|
-
if (keepContiguousPrefix && keptWidth + 3 <= targetWidth) {
|
|
97
|
-
if (pendingAnsi) {
|
|
98
|
-
result += pendingAnsi;
|
|
99
|
-
pendingAnsi = "";
|
|
100
|
-
}
|
|
101
|
-
result += "\t";
|
|
102
|
-
keptWidth += 3;
|
|
103
|
-
} else {
|
|
104
|
-
keepContiguousPrefix = false;
|
|
105
|
-
pendingAnsi = "";
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
visibleSoFar += 3;
|
|
109
|
-
if (visibleSoFar > maxWidth) {
|
|
110
|
-
overflowed = true;
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
index++;
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
let end = index;
|
|
118
|
-
while (end < text.length && text[end] !== "\t") {
|
|
119
|
-
const nextAnsi = readAnsiSequence(text, end);
|
|
120
|
-
if (nextAnsi) break;
|
|
121
|
-
end++;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
for (const { segment } of segmenter.segment(text.slice(index, end))) {
|
|
125
|
-
const width = visibleWidth(segment);
|
|
126
|
-
if (keepContiguousPrefix && keptWidth + width <= targetWidth) {
|
|
127
|
-
if (pendingAnsi) {
|
|
128
|
-
result += pendingAnsi;
|
|
129
|
-
pendingAnsi = "";
|
|
130
|
-
}
|
|
131
|
-
result += segment;
|
|
132
|
-
keptWidth += width;
|
|
133
|
-
} else {
|
|
134
|
-
keepContiguousPrefix = false;
|
|
135
|
-
pendingAnsi = "";
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
visibleSoFar += width;
|
|
139
|
-
if (visibleSoFar > maxWidth) {
|
|
140
|
-
overflowed = true;
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (overflowed) break;
|
|
146
|
-
index = end;
|
|
147
|
-
}
|
|
148
|
-
exhaustedInput = index >= text.length;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (!overflowed && exhaustedInput) {
|
|
152
|
-
return pad ? text + " ".repeat(Math.max(0, maxWidth - visibleSoFar)) : text;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return finalizeTruncatedResult(
|
|
156
|
-
result,
|
|
157
|
-
keptWidth,
|
|
158
|
-
ellipsis,
|
|
159
|
-
ellipsisWidth,
|
|
160
|
-
maxWidth,
|
|
161
|
-
pad,
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
166
|
-
|
|
167
|
-
function isPrintableAscii(text: string): boolean {
|
|
168
|
-
for (let index = 0; index < text.length; index++) {
|
|
169
|
-
const code = text.charCodeAt(index);
|
|
170
|
-
if (code < 0x20 || code > 0x7e) return false;
|
|
171
|
-
}
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function truncateFragmentToWidth(
|
|
176
|
-
text: string,
|
|
177
|
-
maxWidth: number,
|
|
178
|
-
): { text: string; width: number } {
|
|
179
|
-
if (maxWidth <= 0 || text.length === 0) {
|
|
180
|
-
return { text: "", width: 0 };
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (isPrintableAscii(text)) {
|
|
184
|
-
const clipped = text.slice(0, maxWidth);
|
|
185
|
-
return { text: clipped, width: clipped.length };
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const hasAnsi = text.includes("\u001b");
|
|
189
|
-
const hasTabs = text.includes("\t");
|
|
190
|
-
if (!hasAnsi && !hasTabs) {
|
|
191
|
-
let result = "";
|
|
192
|
-
let width = 0;
|
|
193
|
-
|
|
194
|
-
for (const { segment } of segmenter.segment(text)) {
|
|
195
|
-
const segmentWidth = visibleWidth(segment);
|
|
196
|
-
if (width + segmentWidth > maxWidth) break;
|
|
197
|
-
result += segment;
|
|
198
|
-
width += segmentWidth;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return { text: result, width };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
let result = "";
|
|
205
|
-
let width = 0;
|
|
206
|
-
let index = 0;
|
|
207
|
-
let pendingAnsi = "";
|
|
208
|
-
|
|
209
|
-
while (index < text.length) {
|
|
210
|
-
const ansi = readAnsiSequence(text, index);
|
|
211
|
-
if (ansi) {
|
|
212
|
-
pendingAnsi += ansi;
|
|
213
|
-
index += ansi.length;
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (text[index] === "\t") {
|
|
218
|
-
if (width + 3 > maxWidth) break;
|
|
219
|
-
if (pendingAnsi) {
|
|
220
|
-
result += pendingAnsi;
|
|
221
|
-
pendingAnsi = "";
|
|
222
|
-
}
|
|
223
|
-
result += "\t";
|
|
224
|
-
width += 3;
|
|
225
|
-
index++;
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
let end = index;
|
|
230
|
-
while (end < text.length && text[end] !== "\t") {
|
|
231
|
-
const nextAnsi = readAnsiSequence(text, end);
|
|
232
|
-
if (nextAnsi) break;
|
|
233
|
-
end++;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
for (const { segment } of segmenter.segment(text.slice(index, end))) {
|
|
237
|
-
const segmentWidth = visibleWidth(segment);
|
|
238
|
-
if (width + segmentWidth > maxWidth) {
|
|
239
|
-
return { text: result, width };
|
|
240
|
-
}
|
|
241
|
-
if (pendingAnsi) {
|
|
242
|
-
result += pendingAnsi;
|
|
243
|
-
pendingAnsi = "";
|
|
244
|
-
}
|
|
245
|
-
result += segment;
|
|
246
|
-
width += segmentWidth;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
index = end;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return { text: result, width };
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function finalizeTruncatedResult(
|
|
256
|
-
prefix: string,
|
|
257
|
-
prefixWidth: number,
|
|
258
|
-
ellipsis: string,
|
|
259
|
-
ellipsisWidth: number,
|
|
260
|
-
maxWidth: number,
|
|
261
|
-
pad: boolean,
|
|
262
|
-
): string {
|
|
263
|
-
const width = prefixWidth + ellipsisWidth;
|
|
264
|
-
const result = ellipsis.length > 0 ? `${prefix}${ellipsis}` : prefix;
|
|
265
|
-
return pad ? result + " ".repeat(Math.max(0, maxWidth - width)) : result;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function readAnsiSequence(text: string, index: number): string | null {
|
|
269
|
-
const ESCAPE = "\u001b";
|
|
270
|
-
if (text[index] !== ESCAPE) return null;
|
|
271
|
-
|
|
272
|
-
const next = text[index + 1];
|
|
273
|
-
if (next === "[") {
|
|
274
|
-
const code = text.slice(index);
|
|
275
|
-
const pattern = new RegExp(`^${ESCAPE}\\[[0-?]*[ -/]*[@-~]`, "u");
|
|
276
|
-
const match = code.match(pattern);
|
|
277
|
-
return match?.[0] ?? text[index];
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (next === "]" || next === "_") {
|
|
281
|
-
const rest = text.slice(index);
|
|
282
|
-
const bel = rest.indexOf("\u0007");
|
|
283
|
-
const st = rest.indexOf("\u001b\\");
|
|
284
|
-
const end = [bel, st]
|
|
285
|
-
.filter((value) => value >= 0)
|
|
286
|
-
.sort((a, b) => a - b)[0];
|
|
287
|
-
if (end === undefined) return text[index];
|
|
288
|
-
return rest.slice(0, end + (end === st ? 2 : 1));
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return text.slice(index, Math.min(index + 2, text.length));
|
|
292
|
-
}
|