@stevezhou/sisu 0.1.9 → 0.1.10

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/dist/pager/app.js CHANGED
@@ -11,18 +11,23 @@ const logo_1 = require("../logo");
11
11
  const render_1 = require("./render");
12
12
  const ALT_ENTER = '\x1b[?1049h\x1b[?25l';
13
13
  const ALT_LEAVE = '\x1b[?1049l\x1b[?25h';
14
- function formatChromeStatus(email, quota, conversationId) {
14
+ function shortConversationId(id) {
15
+ const conv = (id || '').trim();
16
+ if (!conv || conv === 'new')
17
+ return '';
18
+ return conv.length > 12 ? conv.slice(0, 8) : conv;
19
+ }
20
+ function formatChromeStatus(email, quota, conversationId = '') {
15
21
  const who = (email || '').trim();
22
+ const conv = shortConversationId(conversationId);
16
23
  if (!who) {
17
- const conv = (conversationId || '').trim();
18
- return conv && conv !== 'new' ? `sisu · not signed in · ${conv}` : 'sisu · not signed in';
24
+ return conv ? `sisu · not signed in · ${conv}` : 'sisu · not signed in';
19
25
  }
20
26
  const parts = [who];
21
27
  const quotaText = (quota || '').trim();
22
28
  if (quotaText && quotaText !== 'quota unavailable')
23
29
  parts.push(quotaText);
24
- const conv = (conversationId || '').trim();
25
- if (conv && conv !== 'new')
30
+ if (conv)
26
31
  parts.push(conv);
27
32
  return parts.join(' · ');
28
33
  }
@@ -211,24 +216,24 @@ async function runPager(io, transport, options = {}) {
211
216
  paint();
212
217
  return;
213
218
  }
214
- state = pushEntry(state, 'status', 'Opening browser to sign in…');
219
+ state = { ...state, statusLine: 'Opening browser to sign in…' };
215
220
  paint();
216
221
  try {
217
222
  const email = await options.login((line) => {
218
223
  if (!running)
219
224
  return;
220
- state = pushEntry(state, 'status', line);
225
+ state = { ...state, statusLine: line };
221
226
  paint();
222
227
  });
223
228
  if (!running)
224
229
  return;
225
230
  chromeEmail = email;
226
231
  state = withChrome(state);
227
- state = pushEntry(state, 'status', `logged in as ${email}`);
228
232
  }
229
233
  catch (err) {
230
234
  if (!running)
231
235
  return;
236
+ state = withChrome(state);
232
237
  state = pushEntry(state, 'status', err instanceof Error ? err.message : String(err));
233
238
  }
234
239
  paint();
@@ -7,25 +7,13 @@ const mobius_1 = require("../mobius");
7
7
  const model_1 = require("./model");
8
8
  const theme_1 = require("./theme");
9
9
  Object.defineProperty(exports, "stripAnsi", { enumerable: true, get: function () { return theme_1.stripAnsi; } });
10
+ const text_1 = require("./text");
10
11
  const PROMPT_PREFIX = '› ';
11
12
  const PROMPT_BOX_ROWS = 2;
12
13
  const STATUS_ROWS = 1;
13
14
  const MARK_WIDTH = 2;
14
15
  function wrapPlain(text, width) {
15
- const max = Math.max(1, width);
16
- if (!text)
17
- return [''];
18
- const out = [];
19
- for (const paragraph of text.split('\n')) {
20
- if (!paragraph) {
21
- out.push('');
22
- continue;
23
- }
24
- for (let i = 0; i < paragraph.length; i += max) {
25
- out.push(paragraph.slice(i, i + max));
26
- }
27
- }
28
- return out;
16
+ return (0, text_1.wrapCells)(text, width);
29
17
  }
30
18
  function lineCount(text) {
31
19
  if (!text)
@@ -43,22 +31,25 @@ function paintKind(kind, body, theme) {
43
31
  return theme.dim(body);
44
32
  return theme.text(body);
45
33
  }
46
- function entryPrefix(kind) {
47
- if (kind === 'user')
48
- return 'you ';
49
- if (kind === 'tool')
50
- return 'tool ';
51
- return '';
34
+ function shownText(entry) {
35
+ if (entry.kind === 'assistant')
36
+ return (0, text_1.visibleAssistantText)(entry.text);
37
+ return entry.text;
52
38
  }
53
39
  function entryBodyLines(entry, wrapWidth) {
40
+ const text = shownText(entry);
54
41
  if (entry.folded) {
55
- const n = lineCount(entry.text);
42
+ const n = lineCount(text);
56
43
  const unit = n === 1 ? 'line' : 'lines';
57
44
  return wrapPlain(`${entry.kind} · ${n} ${unit}`, wrapWidth);
58
45
  }
59
- if (!entry.text)
46
+ if (entry.kind === 'user')
47
+ return ['You', ...wrapPlain(text || ' ', wrapWidth)];
48
+ if (entry.kind === 'tool')
49
+ return wrapPlain(text ? `tool ${text}` : 'tool', wrapWidth);
50
+ if (!text)
60
51
  return [''];
61
- return wrapPlain(`${entryPrefix(entry.kind)}${entry.text}`, wrapWidth);
52
+ return wrapPlain(text, wrapWidth);
62
53
  }
63
54
  function layoutScrollback(state, cols, theme) {
64
55
  const wrapWidth = Math.max(1, cols - MARK_WIDTH);
@@ -68,6 +59,10 @@ function layoutScrollback(state, cols, theme) {
68
59
  const entry = state.entries[i];
69
60
  const body = entryBodyLines(entry, wrapWidth);
70
61
  const selected = i === state.selected && state.entries.length > 0;
62
+ if (i > 0) {
63
+ lines.push('');
64
+ entryOf.push(i);
65
+ }
71
66
  for (let j = 0; j < body.length; j += 1) {
72
67
  const mark = selected && j === 0 ? theme.accent('▸ ') : ' ';
73
68
  lines.push(`${mark}${paintKind(entry.kind, body[j], theme)}`);
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /** Display-side text: hide model scratch and wrap by terminal cells. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.visibleAssistantText = visibleAssistantText;
5
+ exports.wrapCells = wrapCells;
6
+ const theme_1 = require("./theme");
7
+ const THINK_BLOCK = /<think\b[^>]*>[\s\S]*?<\/think>/gi;
8
+ const THINK_OPEN = /<think\b[^>]*>[\s\S]*$/i;
9
+ function visibleAssistantText(raw) {
10
+ let text = String(raw || '');
11
+ text = text.replace(THINK_BLOCK, '');
12
+ text = text.replace(THINK_OPEN, '');
13
+ return text.replace(/^\n+/, '').replace(/\n+$/, '');
14
+ }
15
+ function wrapCells(text, width) {
16
+ const max = Math.max(1, width);
17
+ if (!text)
18
+ return [''];
19
+ const out = [];
20
+ for (const paragraph of text.split('\n')) {
21
+ if (!paragraph) {
22
+ out.push('');
23
+ continue;
24
+ }
25
+ let line = '';
26
+ for (const ch of paragraph) {
27
+ if ((0, theme_1.visibleWidth)(line + ch) > max) {
28
+ if (line)
29
+ out.push(line);
30
+ line = ch;
31
+ }
32
+ else {
33
+ line += ch;
34
+ }
35
+ }
36
+ if (line)
37
+ out.push(line);
38
+ }
39
+ return out.length ? out : [''];
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stevezhou/sisu",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "SiSu CLI — one login, cloud quota, local workspace",
5
5
  "license": "UNLICENSED",
6
6
  "homepage": "https://www.sisu.chat",