|
|
@@ -563,30 +563,39 @@ export function createInteractionToolsFromDeps(
|
|
|
const chatRequestOptions = hooks?.getChatRequestOptions?.() ?? {};
|
|
|
let response: Awaited<ReturnType<typeof chatCompletion>> | undefined;
|
|
|
if (instrumentedPipeline.config?.client && instrumentedPipeline.config?.model) {
|
|
|
- response = await chatCompletion(
|
|
|
- instrumentedPipeline.config.client,
|
|
|
- instrumentedPipeline.config.model,
|
|
|
- [
|
|
|
+ try {
|
|
|
+ response = await chatCompletion(
|
|
|
+ instrumentedPipeline.config.client,
|
|
|
+ instrumentedPipeline.config.model,
|
|
|
+ [
|
|
|
+ {
|
|
|
+ role: "system",
|
|
|
+ content: [
|
|
|
+ "You are InkOS inside the terminal workbench.",
|
|
|
+ "Respond conversationally and briefly.",
|
|
|
+ "If there is no active book, help the user decide what to write next.",
|
|
|
+ "If there is an active book, keep the answer grounded in that book context.",
|
|
|
+ ].join(" "),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ role: "user",
|
|
|
+ content: `activeBook=${bookLabel}\nautomationMode=${options.automationMode}\nmessage=${input}`,
|
|
|
+ },
|
|
|
+ ],
|
|
|
{
|
|
|
- role: "system",
|
|
|
- content: [
|
|
|
- "You are InkOS inside the terminal workbench.",
|
|
|
- "Respond conversationally and briefly.",
|
|
|
- "If there is no active book, help the user decide what to write next.",
|
|
|
- "If there is an active book, keep the answer grounded in that book context.",
|
|
|
- ].join(" "),
|
|
|
+ temperature: chatRequestOptions.temperature ?? 0.4,
|
|
|
+ ...(chatRequestOptions.maxTokens !== undefined && { maxTokens: chatRequestOptions.maxTokens }),
|
|
|
+ onTextDelta: hooks?.onChatTextDelta,
|
|
|
},
|
|
|
- {
|
|
|
- role: "user",
|
|
|
- content: `activeBook=${bookLabel}\nautomationMode=${options.automationMode}\nmessage=${input}`,
|
|
|
- },
|
|
|
- ],
|
|
|
- {
|
|
|
- temperature: chatRequestOptions.temperature ?? 0.4,
|
|
|
- ...(chatRequestOptions.maxTokens !== undefined && { maxTokens: chatRequestOptions.maxTokens }),
|
|
|
- onTextDelta: hooks?.onChatTextDelta,
|
|
|
- },
|
|
|
- );
|
|
|
+ );
|
|
|
+ } catch (err) {
|
|
|
+ // Thinking models (e.g. kimi-k2.5) may return empty content for simple inputs.
|
|
|
+ // Only swallow empty-content errors; re-throw everything else (network, auth, etc.)
|
|
|
+ const msg = err instanceof Error ? err.message : "";
|
|
|
+ if (!msg.includes("empty") && !msg.includes("content")) {
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return {
|