@agent-api/app-engine 0.0.5 → 0.0.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.
|
@@ -49,7 +49,7 @@ function handleBusyInput(input, key, draft, cursor, history) {
|
|
|
49
49
|
}
|
|
50
50
|
if (key.delete) {
|
|
51
51
|
history.reset();
|
|
52
|
-
return deleteAtCursor(draft, cursor);
|
|
52
|
+
return cursor >= draft.length ? deleteBeforeCursor(draft, cursor) : deleteAtCursor(draft, cursor);
|
|
53
53
|
}
|
|
54
54
|
if (input && !key.ctrl && !key.meta) {
|
|
55
55
|
history.reset();
|
|
@@ -71,7 +71,7 @@ function handleReadyInput(input, key, draft, cursor, history) {
|
|
|
71
71
|
}
|
|
72
72
|
if (key.delete) {
|
|
73
73
|
history.reset();
|
|
74
|
-
return deleteAtCursor(draft, cursor);
|
|
74
|
+
return cursor >= draft.length ? deleteBeforeCursor(draft, cursor) : deleteAtCursor(draft, cursor);
|
|
75
75
|
}
|
|
76
76
|
if (input && !key.ctrl && !key.meta) {
|
|
77
77
|
history.reset();
|
|
@@ -93,18 +93,72 @@ function wrapTranscriptText(text, width) {
|
|
|
93
93
|
const max = Math.max(12, width);
|
|
94
94
|
if (text.length === 0)
|
|
95
95
|
return [""];
|
|
96
|
+
if (displayWidth(text) <= max)
|
|
97
|
+
return [text];
|
|
96
98
|
const lines = [];
|
|
97
99
|
let rest = text;
|
|
98
|
-
while (rest
|
|
99
|
-
const hard = rest
|
|
100
|
-
const softBreak = Math.max(hard.lastIndexOf(" "), hard.lastIndexOf("\t"));
|
|
101
|
-
const
|
|
102
|
-
|
|
100
|
+
while (displayWidth(rest) > max) {
|
|
101
|
+
const hard = takeColumns(rest, max);
|
|
102
|
+
const softBreak = Math.max(hard.text.lastIndexOf(" "), hard.text.lastIndexOf("\t"));
|
|
103
|
+
const soft = softBreak > 0 ? hard.text.slice(0, softBreak) : "";
|
|
104
|
+
const useSoftBreak = soft && displayWidth(soft) > Math.floor(max * 0.45);
|
|
105
|
+
const chunk = useSoftBreak ? soft : hard.text;
|
|
106
|
+
const index = useSoftBreak ? softBreak : hard.length;
|
|
107
|
+
lines.push(chunk.trimEnd());
|
|
103
108
|
rest = rest.slice(index).trimStart();
|
|
104
109
|
}
|
|
105
110
|
lines.push(rest);
|
|
106
111
|
return lines;
|
|
107
112
|
}
|
|
113
|
+
function takeColumns(text, maxColumns) {
|
|
114
|
+
let length = 0;
|
|
115
|
+
let output = "";
|
|
116
|
+
let columns = 0;
|
|
117
|
+
for (const char of Array.from(text)) {
|
|
118
|
+
const width = charWidth(char);
|
|
119
|
+
if (output && columns + width > maxColumns)
|
|
120
|
+
break;
|
|
121
|
+
output += char;
|
|
122
|
+
length += char.length;
|
|
123
|
+
columns += width;
|
|
124
|
+
if (columns >= maxColumns)
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
return { length, text: output };
|
|
128
|
+
}
|
|
129
|
+
function displayWidth(text) {
|
|
130
|
+
let width = 0;
|
|
131
|
+
for (const char of Array.from(text)) {
|
|
132
|
+
width += charWidth(char);
|
|
133
|
+
}
|
|
134
|
+
return width;
|
|
135
|
+
}
|
|
136
|
+
function charWidth(char) {
|
|
137
|
+
if (!char)
|
|
138
|
+
return 0;
|
|
139
|
+
const code = char.codePointAt(0) ?? 0;
|
|
140
|
+
if (code === 0)
|
|
141
|
+
return 0;
|
|
142
|
+
if (code < 32 || (code >= 0x7f && code < 0xa0))
|
|
143
|
+
return 0;
|
|
144
|
+
if (/^\p{Mark}$/u.test(char))
|
|
145
|
+
return 0;
|
|
146
|
+
return isWideCodePoint(code) ? 2 : 1;
|
|
147
|
+
}
|
|
148
|
+
function isWideCodePoint(code) {
|
|
149
|
+
return (code >= 0x1100 && (code <= 0x115f ||
|
|
150
|
+
code === 0x2329 ||
|
|
151
|
+
code === 0x232a ||
|
|
152
|
+
(code >= 0x2e80 && code <= 0xa4cf && code !== 0x303f) ||
|
|
153
|
+
(code >= 0xac00 && code <= 0xd7a3) ||
|
|
154
|
+
(code >= 0xf900 && code <= 0xfaff) ||
|
|
155
|
+
(code >= 0xfe10 && code <= 0xfe19) ||
|
|
156
|
+
(code >= 0xfe30 && code <= 0xfe6f) ||
|
|
157
|
+
(code >= 0xff00 && code <= 0xff60) ||
|
|
158
|
+
(code >= 0xffe0 && code <= 0xffe6) ||
|
|
159
|
+
(code >= 0x1f300 && code <= 0x1faff) ||
|
|
160
|
+
(code >= 0x20000 && code <= 0x3fffd)));
|
|
161
|
+
}
|
|
108
162
|
function roleLabel(role) {
|
|
109
163
|
if (role === "user")
|
|
110
164
|
return "You";
|
package/package.json
CHANGED