sapper-iq 1.2.3 → 1.2.5
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/package.json +1 -1
- package/sapper.mjs +52 -31
package/package.json
CHANGED
package/sapper.mjs
CHANGED
|
@@ -1016,6 +1016,9 @@ project/
|
|
|
1016
1016
|
// Global flag — set after model selection, read in buildSystemPrompt
|
|
1017
1017
|
let _useNativeToolsFlag = false;
|
|
1018
1018
|
|
|
1019
|
+
// Models known to reject `think:true` (populated lazily on first failure).
|
|
1020
|
+
const modelsWithoutThinking = new Set();
|
|
1021
|
+
|
|
1019
1022
|
function buildSystemPrompt(agentContent = null, skillContents = []) {
|
|
1020
1023
|
const now = new Date();
|
|
1021
1024
|
const dateStr = now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
|
|
@@ -8621,8 +8624,9 @@ async function runSapper() {
|
|
|
8621
8624
|
}
|
|
8622
8625
|
return { result, success: true };
|
|
8623
8626
|
}
|
|
8624
|
-
|
|
8625
|
-
|
|
8627
|
+
let turnThinkingEnabled = shouldUseThinkingForInput(input);
|
|
8628
|
+
if (modelsWithoutThinking.has(selectedModel)) turnThinkingEnabled = false;
|
|
8629
|
+
|
|
8626
8630
|
let active = true;
|
|
8627
8631
|
while (active) {
|
|
8628
8632
|
if (stepMode) await safeQuestion(chalk.gray(promptLabel('questions.stepContinue', '[STEP] Press Enter to let AI think...')));
|
|
@@ -8630,38 +8634,55 @@ async function runSapper() {
|
|
|
8630
8634
|
spinner.start('Thinking...');
|
|
8631
8635
|
const aiStartTime = Date.now();
|
|
8632
8636
|
let response;
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
if
|
|
8642
|
-
|
|
8643
|
-
|
|
8644
|
-
|
|
8645
|
-
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
|
|
8649
|
-
|
|
8650
|
-
|
|
8651
|
-
|
|
8652
|
-
|
|
8653
|
-
|
|
8654
|
-
|
|
8655
|
-
chatOpts.tools = nativeToolDefs;
|
|
8656
|
-
}
|
|
8637
|
+
// Build chat options — pass native tools when supported
|
|
8638
|
+
const chatOpts = { model: selectedModel, messages, stream: true };
|
|
8639
|
+
if (effectiveContextLength()) {
|
|
8640
|
+
chatOpts.options = { num_ctx: effectiveContextLength() };
|
|
8641
|
+
}
|
|
8642
|
+
// Thinking can be forced on, forced off, or auto-disabled for simple prompts.
|
|
8643
|
+
if (turnThinkingEnabled) chatOpts.think = true;
|
|
8644
|
+
if (useNativeTools) {
|
|
8645
|
+
// Filter tool defs by agent restrictions if any
|
|
8646
|
+
if (currentAgentTools) {
|
|
8647
|
+
const toolNameMap = {
|
|
8648
|
+
list_directory: 'LIST', read_file: 'READ', search_files: 'SEARCH',
|
|
8649
|
+
write_file: 'WRITE', patch_file: 'PATCH', create_directory: 'MKDIR',
|
|
8650
|
+
ls: 'LS', cat: 'CAT', head: 'HEAD', tail: 'TAIL', grep: 'GREP', find: 'FIND',
|
|
8651
|
+
pwd: 'PWD', cd: 'CD', rmdir: 'RMDIR', changes: 'CHANGES',
|
|
8652
|
+
fetch_web: 'FETCH', recall_memory: 'MEMORY', open_url: 'OPEN', run_shell: 'SHELL'
|
|
8653
|
+
};
|
|
8654
|
+
chatOpts.tools = nativeToolDefs.filter(t =>
|
|
8655
|
+
isToolAllowedForAgent(currentAgentTools, toolNameMap[t.function.name])
|
|
8656
|
+
);
|
|
8657
|
+
} else {
|
|
8658
|
+
chatOpts.tools = nativeToolDefs;
|
|
8657
8659
|
}
|
|
8660
|
+
}
|
|
8661
|
+
try {
|
|
8658
8662
|
response = await ollama.chat(chatOpts);
|
|
8659
8663
|
} catch (ollamaError) {
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8664
|
+
const errMsg = ollamaError && ollamaError.message ? ollamaError.message : String(ollamaError);
|
|
8665
|
+
if (/does not support thinking/i.test(errMsg) && chatOpts.think) {
|
|
8666
|
+
modelsWithoutThinking.add(selectedModel);
|
|
8667
|
+
turnThinkingEnabled = false;
|
|
8668
|
+
delete chatOpts.think;
|
|
8669
|
+
console.log(chalk.yellow(` ⚠ "${selectedModel}" doesn't support thinking — retrying without it.`));
|
|
8670
|
+
try {
|
|
8671
|
+
response = await ollama.chat(chatOpts);
|
|
8672
|
+
} catch (retryErr) {
|
|
8673
|
+
spinner.stop();
|
|
8674
|
+
console.error(chalk.red('\n❌ Ollama error:'), retryErr.message);
|
|
8675
|
+
logEntry('error', { message: `Ollama error: ${retryErr.message}` });
|
|
8676
|
+
active = false;
|
|
8677
|
+
continue;
|
|
8678
|
+
}
|
|
8679
|
+
} else {
|
|
8680
|
+
spinner.stop();
|
|
8681
|
+
console.error(chalk.red('\n❌ Ollama error:'), errMsg);
|
|
8682
|
+
logEntry('error', { message: `Ollama error: ${errMsg}` });
|
|
8683
|
+
active = false;
|
|
8684
|
+
continue;
|
|
8685
|
+
}
|
|
8665
8686
|
}
|
|
8666
8687
|
spinner.stop();
|
|
8667
8688
|
|