@semalt-ai/code 1.4.1 → 1.4.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/README.md +0 -1
- package/index.js +54 -10
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -21,7 +21,6 @@ const DEFAULT_CONFIG = {
|
|
|
21
21
|
api_key: 'any',
|
|
22
22
|
default_model: 'default',
|
|
23
23
|
temperature: 0.7,
|
|
24
|
-
max_tokens: 4096,
|
|
25
24
|
request_timeout_ms: DEFAULT_API_TIMEOUT_MS,
|
|
26
25
|
stream: true,
|
|
27
26
|
models: [],
|
|
@@ -111,6 +110,51 @@ function boxLine(text, width) {
|
|
|
111
110
|
let AUTO_APPROVE_SHELL = false;
|
|
112
111
|
let AUTO_APPROVE_FILE = false;
|
|
113
112
|
|
|
113
|
+
function askPermissionLine(actionType) {
|
|
114
|
+
return actionType === 'shell'
|
|
115
|
+
? ' 1. Yes 2. Yes, always for shell 3. No'
|
|
116
|
+
: ' 1. Yes 2. Yes, always for files 3. No';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function readPermissionChoice() {
|
|
120
|
+
return new Promise((resolve) => {
|
|
121
|
+
if (!process.stdin.isTTY) {
|
|
122
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
123
|
+
rl.question(` ${FG_YELLOW}?${RST} `, (answer) => {
|
|
124
|
+
rl.close();
|
|
125
|
+
resolve((answer || '').trim());
|
|
126
|
+
});
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const wasRaw = typeof process.stdin.isRaw === 'boolean' ? process.stdin.isRaw : false;
|
|
131
|
+
readline.emitKeypressEvents(process.stdin);
|
|
132
|
+
process.stdin.setRawMode(true);
|
|
133
|
+
process.stdin.resume();
|
|
134
|
+
process.stdout.write(` ${FG_YELLOW}?${RST} `);
|
|
135
|
+
|
|
136
|
+
const onKeypress = (str, key = {}) => {
|
|
137
|
+
if (key.ctrl && key.name === 'c') {
|
|
138
|
+
process.stdin.setRawMode(wasRaw);
|
|
139
|
+
process.stdin.removeListener('keypress', onKeypress);
|
|
140
|
+
process.stdout.write('^C\n');
|
|
141
|
+
process.kill(process.pid, 'SIGINT');
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const value = (str || '').trim();
|
|
146
|
+
if (!value) return;
|
|
147
|
+
|
|
148
|
+
process.stdin.setRawMode(wasRaw);
|
|
149
|
+
process.stdin.removeListener('keypress', onKeypress);
|
|
150
|
+
process.stdout.write(`${value}\n`);
|
|
151
|
+
resolve(value);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
process.stdin.on('keypress', onKeypress);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
114
158
|
function askPermission(actionType, description) {
|
|
115
159
|
return new Promise((resolve) => {
|
|
116
160
|
if (actionType === 'shell' && AUTO_APPROVE_SHELL) {
|
|
@@ -126,16 +170,14 @@ function askPermission(actionType, description) {
|
|
|
126
170
|
console.log(` ${FG_YELLOW}${BOLD}⚠ Permission required${RST}`);
|
|
127
171
|
console.log(` ${FG_GRAY}${actionType}: ${description}${RST}`);
|
|
128
172
|
console.log();
|
|
129
|
-
console.log(` ${FG_CYAN}
|
|
173
|
+
console.log(` ${FG_CYAN}${askPermissionLine(actionType)}${RST}`);
|
|
130
174
|
console.log();
|
|
131
175
|
|
|
132
|
-
|
|
133
|
-
rl.question(` ${FG_YELLOW}?${RST} `, (answer) => {
|
|
134
|
-
rl.close();
|
|
176
|
+
readPermissionChoice().then((answer) => {
|
|
135
177
|
const choice = (answer || '').trim().toLowerCase();
|
|
136
|
-
if (choice === 'y' || choice === 'yes') {
|
|
178
|
+
if (choice === '1' || choice === 'y' || choice === 'yes') {
|
|
137
179
|
resolve(true);
|
|
138
|
-
} else if (choice === 'a' || choice === 'always') {
|
|
180
|
+
} else if (choice === '2' || choice === 'a' || choice === 'always') {
|
|
139
181
|
if (actionType === 'shell') AUTO_APPROVE_SHELL = true;
|
|
140
182
|
else AUTO_APPROVE_FILE = true;
|
|
141
183
|
console.log(` ${FG_GREEN}✓${RST} ${FG_DARK}Auto-approve enabled for ${actionType} operations${RST}`);
|
|
@@ -531,10 +573,13 @@ async function chatStream(messages, { model, temperature, maxTokens } = {}) {
|
|
|
531
573
|
model: model || config.default_model,
|
|
532
574
|
messages,
|
|
533
575
|
temperature: temperature !== undefined ? temperature : config.temperature,
|
|
534
|
-
max_tokens: maxTokens || config.max_tokens,
|
|
535
576
|
stream: true,
|
|
536
577
|
};
|
|
537
578
|
|
|
579
|
+
if (maxTokens !== undefined) {
|
|
580
|
+
payload.max_tokens = maxTokens;
|
|
581
|
+
}
|
|
582
|
+
|
|
538
583
|
const body = JSON.stringify(payload);
|
|
539
584
|
let res;
|
|
540
585
|
|
|
@@ -633,7 +678,6 @@ async function chatSync(messages, { model } = {}) {
|
|
|
633
678
|
model: model || config.default_model,
|
|
634
679
|
messages,
|
|
635
680
|
temperature: config.temperature,
|
|
636
|
-
max_tokens: config.max_tokens,
|
|
637
681
|
stream: false,
|
|
638
682
|
};
|
|
639
683
|
|
|
@@ -1130,7 +1174,7 @@ function cmdInit(opts) {
|
|
|
1130
1174
|
api_key: opts.apiKey || 'any',
|
|
1131
1175
|
default_model: opts.defaultModel || 'default',
|
|
1132
1176
|
temperature: 0.7,
|
|
1133
|
-
|
|
1177
|
+
request_timeout_ms: DEFAULT_API_TIMEOUT_MS,
|
|
1134
1178
|
stream: true,
|
|
1135
1179
|
models: config.models,
|
|
1136
1180
|
};
|