@stevezhou/sisu 0.2.1 → 0.3.0
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/commands.js +2 -4
- package/dist/logo.js +17 -3
- package/dist/main.js +9 -2
- package/dist/runtime/adapter.js +9 -1
- package/dist/runtime/launch.js +6 -1
- package/dist/runtime/models.js +13 -9
- package/dist/store.js +19 -0
- package/package.json +2 -2
- package/scripts/install-pager.js +25 -1
package/dist/commands.js
CHANGED
|
@@ -339,7 +339,8 @@ async function setTrainingCommand(optIn, http = http_1.defaultHttp) {
|
|
|
339
339
|
}
|
|
340
340
|
async function listModelsCommand(http = http_1.defaultHttp) {
|
|
341
341
|
const { models, defaultModel } = await (0, models_1.fetchModelCatalog)(http);
|
|
342
|
-
const
|
|
342
|
+
const last = (0, store_1.readSession)().last_model || '';
|
|
343
|
+
const current = models.some((row) => row.name === last) ? last : defaultModel;
|
|
343
344
|
if (!current && !models.length)
|
|
344
345
|
return 'no models available';
|
|
345
346
|
const lines = models.map((row) => {
|
|
@@ -347,9 +348,6 @@ async function listModelsCommand(http = http_1.defaultHttp) {
|
|
|
347
348
|
const extra = row.label !== row.name ? ` ${row.label}` : '';
|
|
348
349
|
return `${mark}${row.name}${extra}`;
|
|
349
350
|
});
|
|
350
|
-
if (current && !models.some((row) => row.name === current)) {
|
|
351
|
-
lines.unshift(`* ${current}`);
|
|
352
|
-
}
|
|
353
351
|
return lines.join('\n') || `* ${current}`;
|
|
354
352
|
}
|
|
355
353
|
async function setModelCommand(query, http = http_1.defaultHttp) {
|
package/dist/logo.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SISU_STILL_PHASE = exports.sisuTreeLines = exports.sisuTreeArt = exports.sisuMarkLines = exports.sisuMarkArt = void 0;
|
|
3
|
+
exports.SISU_STILL_PHASE = exports.SISU_BRAND = exports.sisuTreeLines = exports.sisuTreeArt = exports.sisuMarkLines = exports.sisuMarkArt = void 0;
|
|
4
4
|
exports.sisuMobiusArt = sisuMobiusArt;
|
|
5
5
|
exports.sisuWordmark = sisuWordmark;
|
|
6
|
+
exports.sisuProductSurfaces = sisuProductSurfaces;
|
|
6
7
|
exports.displayWidth = displayWidth;
|
|
7
8
|
exports.sisuSplashFrame = sisuSplashFrame;
|
|
8
9
|
exports.sisuSplashHeight = sisuSplashHeight;
|
|
@@ -22,7 +23,12 @@ const theme_1 = require("./pager/theme");
|
|
|
22
23
|
const RESET = '\x1b[0m';
|
|
23
24
|
const INK = '\x1b[38;2;220;214;204m';
|
|
24
25
|
const INK_DIM = '\x1b[38;2;140;132;120m';
|
|
25
|
-
|
|
26
|
+
exports.SISU_BRAND = {
|
|
27
|
+
zh: '思溯',
|
|
28
|
+
en: 'SiSu',
|
|
29
|
+
headline: '思有所溯',
|
|
30
|
+
};
|
|
31
|
+
const HEADLINE = exports.SISU_BRAND.headline;
|
|
26
32
|
function sisuMobiusArt(columns = 80, phase = 0, color = false) {
|
|
27
33
|
return (0, mobius_1.renderMobiusFrame)({
|
|
28
34
|
cols: (0, mobius_1.mobiusFrameWidth)(columns),
|
|
@@ -32,7 +38,15 @@ function sisuMobiusArt(columns = 80, phase = 0, color = false) {
|
|
|
32
38
|
});
|
|
33
39
|
}
|
|
34
40
|
function sisuWordmark() {
|
|
35
|
-
return [
|
|
41
|
+
return [exports.SISU_BRAND.zh, exports.SISU_BRAND.en.toUpperCase()].join('\n');
|
|
42
|
+
}
|
|
43
|
+
/** First-surface copy: splash, welcome, help, about. */
|
|
44
|
+
function sisuProductSurfaces() {
|
|
45
|
+
return {
|
|
46
|
+
splash: stripAnsi(sisuSplash(72, false)),
|
|
47
|
+
welcome: sisuWelcomeCopy(false, false).join('\n'),
|
|
48
|
+
helpAbout: `sisu — ${exports.SISU_BRAND.en} · ${exports.SISU_BRAND.zh} · ${exports.SISU_BRAND.headline}`,
|
|
49
|
+
};
|
|
36
50
|
}
|
|
37
51
|
function displayWidth(text) {
|
|
38
52
|
return (0, theme_1.visibleWidth)(text);
|
package/dist/main.js
CHANGED
|
@@ -5,10 +5,12 @@ exports.helpText = helpText;
|
|
|
5
5
|
exports.runCli = runCli;
|
|
6
6
|
const commands_1 = require("./commands");
|
|
7
7
|
const http_1 = require("./http");
|
|
8
|
+
const client_1 = require("./client");
|
|
9
|
+
const logo_1 = require("./logo");
|
|
8
10
|
const store_1 = require("./store");
|
|
9
11
|
const tui_1 = require("./tui");
|
|
10
12
|
function helpText() {
|
|
11
|
-
return
|
|
13
|
+
return `${(0, logo_1.sisuProductSurfaces)().helpAbout}
|
|
12
14
|
|
|
13
15
|
One login. Cloud quota. Local workspace.
|
|
14
16
|
|
|
@@ -31,7 +33,8 @@ Usage:
|
|
|
31
33
|
sisu history
|
|
32
34
|
sisu thread <conversation-id>
|
|
33
35
|
sisu training --on|--off
|
|
34
|
-
sisu
|
|
36
|
+
sisu interactive TUI (思溯 / SiSu · 思有所溯)
|
|
37
|
+
sisu --version
|
|
35
38
|
sisu help
|
|
36
39
|
|
|
37
40
|
Auth and workspaces live in $SISU_HOME (default ~/.sisu), shared with Desktop.
|
|
@@ -72,6 +75,10 @@ async function runCli(argv, deps = {}) {
|
|
|
72
75
|
printHelp();
|
|
73
76
|
return 0;
|
|
74
77
|
}
|
|
78
|
+
if (command === '--version' || command === '-V' || command === 'version') {
|
|
79
|
+
process.stdout.write(`sisu ${client_1.SISU_CLIENT_VERSION} — ${logo_1.SISU_BRAND.zh} ${logo_1.SISU_BRAND.en} · ${logo_1.SISU_BRAND.headline}\n`);
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
75
82
|
if (!command || command === 'tui') {
|
|
76
83
|
return (0, tui_1.runTui)((0, tui_1.defaultTuiIo)());
|
|
77
84
|
}
|
package/dist/runtime/adapter.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toProviderMessages = toProviderMessages;
|
|
4
4
|
exports.completeUrl = completeUrl;
|
|
5
5
|
exports.openaiCompatUrl = openaiCompatUrl;
|
|
6
|
+
exports.completeHeaders = completeHeaders;
|
|
6
7
|
exports.buildCompleteRequest = buildCompleteRequest;
|
|
7
8
|
exports.isServerSideAgentPayload = isServerSideAgentPayload;
|
|
8
9
|
exports.parseCompleteSse = parseCompleteSse;
|
|
@@ -11,6 +12,7 @@ exports.createSisuCloudModel = createSisuCloudModel;
|
|
|
11
12
|
const client_1 = require("../client");
|
|
12
13
|
const http_1 = require("../http");
|
|
13
14
|
const sse_1 = require("../sse");
|
|
15
|
+
const store_1 = require("../store");
|
|
14
16
|
const suite_1 = require("./suite");
|
|
15
17
|
/** OpenAI/Poe wire: assistant.tool_calls is {id,type,function:{name,arguments:string}}. */
|
|
16
18
|
function toProviderMessages(messages) {
|
|
@@ -39,6 +41,12 @@ function completeUrl(apiBase) {
|
|
|
39
41
|
function openaiCompatUrl(apiBase) {
|
|
40
42
|
return `${apiBase.replace(/\/+$/, '')}${suite_1.OPENAI_COMPAT_PATH}`;
|
|
41
43
|
}
|
|
44
|
+
function completeHeaders(token) {
|
|
45
|
+
return {
|
|
46
|
+
...(0, http_1.authHeaders)(token),
|
|
47
|
+
'x-sisu-conversation-id': (0, store_1.ensureConversationId)(),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
42
50
|
function buildCompleteRequest(request, options = {}) {
|
|
43
51
|
const stamp = (0, client_1.clientStamp)(options.client || 'cli');
|
|
44
52
|
return {
|
|
@@ -135,7 +143,7 @@ function createSisuCloudModel(http, options) {
|
|
|
135
143
|
}
|
|
136
144
|
const sent = await http(completeUrl(options.apiBase), {
|
|
137
145
|
method: 'POST',
|
|
138
|
-
headers: (
|
|
146
|
+
headers: completeHeaders(options.token),
|
|
139
147
|
body: JSON.stringify(payload),
|
|
140
148
|
});
|
|
141
149
|
if (!sent.ok) {
|
package/dist/runtime/launch.js
CHANGED
|
@@ -61,17 +61,22 @@ function sisuGrokBuildEnv() {
|
|
|
61
61
|
const auth = (0, store_1.readAuth)();
|
|
62
62
|
const home = (0, store_1.getSisuHome)();
|
|
63
63
|
const runtimeBase = auth ? sisuRuntimeApiBase(auth.api_base) : '';
|
|
64
|
+
const env = { ...process.env };
|
|
65
|
+
delete env.GROK_DEFAULT_MODEL;
|
|
64
66
|
return {
|
|
65
|
-
...
|
|
67
|
+
...env,
|
|
66
68
|
GROK_HOME: process.env.GROK_HOME || home,
|
|
67
69
|
SISU_HOME: home,
|
|
68
70
|
GROK_TELEMETRY_ENABLED: process.env.GROK_TELEMETRY_ENABLED || '0',
|
|
69
71
|
XAI_API_KEY: process.env.XAI_API_KEY || auth?.token || '',
|
|
70
72
|
SISU_API_BASE: auth?.api_base || process.env.SISU_API_BASE || 'https://www.sisu.chat',
|
|
73
|
+
SISU_CONVERSATION_ID: (0, store_1.ensureConversationId)(),
|
|
71
74
|
...(runtimeBase
|
|
72
75
|
? {
|
|
73
76
|
GROK_XAI_API_BASE_URL: runtimeBase,
|
|
74
77
|
XAI_API_BASE_URL: runtimeBase,
|
|
78
|
+
GROK_MODELS_BASE_URL: runtimeBase,
|
|
79
|
+
GROK_MODELS_LIST_URL: `${runtimeBase}/models`,
|
|
75
80
|
}
|
|
76
81
|
: {}),
|
|
77
82
|
};
|
package/dist/runtime/models.js
CHANGED
|
@@ -8,23 +8,27 @@ const store_1 = require("../store");
|
|
|
8
8
|
function normalizeModelKey(value) {
|
|
9
9
|
return value.toLowerCase().replace(/[-_.\s]/g, '');
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const response = await http(`${auth.api_base}/api/chat/models`, { headers: (0, http_1.authHeaders)(auth.token) });
|
|
14
|
-
const body = await response.json().catch(() => ({}));
|
|
15
|
-
if (!response.ok)
|
|
16
|
-
throw new Error((0, http_1.errorDetail)(body, `models failed (${response.status})`));
|
|
17
|
-
const rows = Array.isArray(body?.models) ? body.models : [];
|
|
11
|
+
function parseRuntimeCatalog(body) {
|
|
12
|
+
const rows = Array.isArray(body?.data) ? body.data : [];
|
|
18
13
|
const models = rows
|
|
19
14
|
.map((row) => {
|
|
20
|
-
const name = String(row?.name || '').trim();
|
|
15
|
+
const name = String(row?.id || row?.name || '').trim();
|
|
21
16
|
if (!name)
|
|
22
17
|
return null;
|
|
23
|
-
return { name, label: String(row
|
|
18
|
+
return { name, label: String(row?.name || row?.id || name).trim() || name };
|
|
24
19
|
})
|
|
25
20
|
.filter((row) => Boolean(row));
|
|
26
21
|
return { models, defaultModel: String(body?.default_model || '') };
|
|
27
22
|
}
|
|
23
|
+
async function fetchModelCatalog(http = http_1.defaultHttp) {
|
|
24
|
+
const auth = (0, store_1.requireAuth)();
|
|
25
|
+
const headers = (0, http_1.authHeaders)(auth.token);
|
|
26
|
+
const runtime = await http(`${auth.api_base}/api/runtime/v1/models`, { headers });
|
|
27
|
+
if (runtime.ok)
|
|
28
|
+
return parseRuntimeCatalog(await runtime.json().catch(() => ({})));
|
|
29
|
+
const body = await runtime.json().catch(() => ({}));
|
|
30
|
+
throw new Error((0, http_1.errorDetail)(body, `models failed (${runtime.status})`));
|
|
31
|
+
}
|
|
28
32
|
function resolveCatalogModel(query, models) {
|
|
29
33
|
const needle = normalizeModelKey(query);
|
|
30
34
|
if (!needle)
|
package/dist/store.js
CHANGED
|
@@ -9,11 +9,13 @@ exports.readAuth = readAuth;
|
|
|
9
9
|
exports.writeAuth = writeAuth;
|
|
10
10
|
exports.readSession = readSession;
|
|
11
11
|
exports.writeSession = writeSession;
|
|
12
|
+
exports.ensureConversationId = ensureConversationId;
|
|
12
13
|
exports.clearAuth = clearAuth;
|
|
13
14
|
exports.readWorkspaces = readWorkspaces;
|
|
14
15
|
exports.bindWorkspace = bindWorkspace;
|
|
15
16
|
exports.requireAuth = requireAuth;
|
|
16
17
|
exports.describeStatus = describeStatus;
|
|
18
|
+
const crypto_1 = require("crypto");
|
|
17
19
|
const fs_1 = __importDefault(require("fs"));
|
|
18
20
|
const os_1 = __importDefault(require("os"));
|
|
19
21
|
const path_1 = __importDefault(require("path"));
|
|
@@ -79,6 +81,7 @@ function readAuth() {
|
|
|
79
81
|
};
|
|
80
82
|
}
|
|
81
83
|
function writeAuth(record) {
|
|
84
|
+
const previous = readAuth();
|
|
82
85
|
writeJson(authPath(), {
|
|
83
86
|
token: record.token,
|
|
84
87
|
email: record.email,
|
|
@@ -87,6 +90,12 @@ function writeAuth(record) {
|
|
|
87
90
|
plan_code: record.plan_code || '',
|
|
88
91
|
name: record.name || '',
|
|
89
92
|
});
|
|
93
|
+
if (previous && previous.user_id !== record.user_id) {
|
|
94
|
+
const session = readSession();
|
|
95
|
+
if (session.last_conversation_id) {
|
|
96
|
+
writeSession({ ...session, last_conversation_id: undefined });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
90
99
|
}
|
|
91
100
|
function readSession() {
|
|
92
101
|
return readJson(sessionPath(), {});
|
|
@@ -94,6 +103,16 @@ function readSession() {
|
|
|
94
103
|
function writeSession(record) {
|
|
95
104
|
writeJson(sessionPath(), record);
|
|
96
105
|
}
|
|
106
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
107
|
+
function ensureConversationId() {
|
|
108
|
+
const session = readSession();
|
|
109
|
+
const current = String(session.last_conversation_id || '').trim();
|
|
110
|
+
if (UUID_RE.test(current))
|
|
111
|
+
return current;
|
|
112
|
+
const id = (0, crypto_1.randomUUID)();
|
|
113
|
+
writeSession({ ...session, last_conversation_id: id });
|
|
114
|
+
return id;
|
|
115
|
+
}
|
|
97
116
|
function clearAuth() {
|
|
98
117
|
try {
|
|
99
118
|
fs_1.default.unlinkSync(authPath());
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stevezhou/sisu",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "SiSu CLI —
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "SiSu CLI — 思溯 / SiSu · 思有所溯",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"homepage": "https://www.sisu.chat",
|
|
7
7
|
"bugs": {
|
package/scripts/install-pager.js
CHANGED
|
@@ -41,6 +41,18 @@ function releaseAssetUrl(version, key) {
|
|
|
41
41
|
return `https://github.com/hyzhou1990/sisu-cli/releases/download/v${version}/xai-grok-pager-${key}.br`
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
function pagerStampPath(dest) {
|
|
45
|
+
return `${dest}.version`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function installedPagerVersion(dest) {
|
|
49
|
+
try {
|
|
50
|
+
return fs.readFileSync(pagerStampPath(dest), 'utf8').trim()
|
|
51
|
+
} catch {
|
|
52
|
+
return ''
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
44
56
|
function writeBinary(bytes, dest) {
|
|
45
57
|
fs.mkdirSync(path.dirname(dest), { recursive: true, mode: 0o700 })
|
|
46
58
|
const tmp = `${dest}.tmp.${process.pid}`
|
|
@@ -49,6 +61,11 @@ function writeBinary(bytes, dest) {
|
|
|
49
61
|
fs.renameSync(tmp, dest)
|
|
50
62
|
}
|
|
51
63
|
|
|
64
|
+
function writePagerStamp(dest, version) {
|
|
65
|
+
if (!version) return
|
|
66
|
+
fs.writeFileSync(pagerStampPath(dest), `${version}\n`, { encoding: 'utf8', mode: 0o644 })
|
|
67
|
+
}
|
|
68
|
+
|
|
52
69
|
function decodePayload(buf) {
|
|
53
70
|
try {
|
|
54
71
|
return zlib.brotliDecompressSync(buf)
|
|
@@ -89,18 +106,22 @@ async function installPager(options = {}) {
|
|
|
89
106
|
if (!SUPPORTED.has(key)) {
|
|
90
107
|
return { ok: false, skipped: true, reason: `no prebuilt pager for ${key}` }
|
|
91
108
|
}
|
|
92
|
-
|
|
109
|
+
const have = fs.existsSync(dest)
|
|
110
|
+
const stamped = have ? installedPagerVersion(dest) : ''
|
|
111
|
+
if (!options.force && have && version && stamped === version) {
|
|
93
112
|
return { ok: true, dest, skipped: true, reason: 'already installed' }
|
|
94
113
|
}
|
|
95
114
|
if (options.file) {
|
|
96
115
|
const raw = decodePayload(fs.readFileSync(options.file))
|
|
97
116
|
writeBinary(raw, dest)
|
|
117
|
+
writePagerStamp(dest, version)
|
|
98
118
|
return { ok: true, dest }
|
|
99
119
|
}
|
|
100
120
|
if (!version) return { ok: false, reason: 'missing package version' }
|
|
101
121
|
const url = options.url || releaseAssetUrl(version, key)
|
|
102
122
|
const payload = await download(url)
|
|
103
123
|
writeBinary(decodePayload(payload), dest)
|
|
124
|
+
writePagerStamp(dest, version)
|
|
104
125
|
return { ok: true, dest, url }
|
|
105
126
|
}
|
|
106
127
|
|
|
@@ -108,10 +129,13 @@ module.exports = {
|
|
|
108
129
|
SUPPORTED,
|
|
109
130
|
decodePayload,
|
|
110
131
|
installPager,
|
|
132
|
+
installedPagerVersion,
|
|
111
133
|
pagerBinPath,
|
|
134
|
+
pagerStampPath,
|
|
112
135
|
platformKey,
|
|
113
136
|
releaseAssetUrl,
|
|
114
137
|
writeBinary,
|
|
138
|
+
writePagerStamp,
|
|
115
139
|
}
|
|
116
140
|
|
|
117
141
|
if (require.main === module) {
|