summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-03-28 03:34:00 +0900
committerAdam Malczewski <[email protected]>2026-03-28 03:34:00 +0900
commit7edf1f2bbccd514a497ade838c821ca91d499bf9 (patch)
treed9c848f2a9cfd88f43bd0e783b664f1e249e75b3 /src
parent94bca96aec909890da7c06a03e5c2c6b380be4a8 (diff)
downloadai-pulse-obsidian-plugin-7edf1f2bbccd514a497ade838c821ca91d499bf9.tar.gz
ai-pulse-obsidian-plugin-7edf1f2bbccd514a497ade838c821ca91d499bf9.zip
cleanup typescript
Diffstat (limited to 'src')
-rw-r--r--src/chat-view.ts24
-rw-r--r--src/main.ts3
-rw-r--r--src/ollama-client.ts8
3 files changed, 18 insertions, 17 deletions
diff --git a/src/chat-view.ts b/src/chat-view.ts
index d48e04b..6816055 100644
--- a/src/chat-view.ts
+++ b/src/chat-view.ts
@@ -299,41 +299,41 @@ export class ChatView extends ItemView {
ollamaUrl: this.plugin.settings.ollamaUrl,
model: this.plugin.settings.model,
messages: this.messages,
- tools: hasTools ? enabledTools : undefined,
- app: hasTools ? this.plugin.app : undefined,
+ ...(hasTools ? { tools: enabledTools } : {}),
+ ...(hasTools ? { app: this.plugin.app } : {}),
options: {
temperature: this.plugin.settings.temperature,
num_ctx: this.plugin.settings.numCtx,
num_predict: this.plugin.settings.numPredict,
},
- userSystemPrompt,
- vaultContext,
+ ...(userSystemPrompt !== undefined ? { userSystemPrompt } : {}),
+ ...(vaultContext !== undefined ? { vaultContext } : {}),
onChunk,
- onToolCall: hasTools ? onToolCall : undefined,
- onApprovalRequest: hasTools ? onApprovalRequest : undefined,
+ ...(hasTools ? { onToolCall } : {}),
+ ...(hasTools ? { onApprovalRequest } : {}),
onCreateBubble,
abortSignal: this.abortController.signal,
});
// Finalize the last streaming bubble
if (currentBubble !== null) {
- await this.finalizeBubble(currentBubble as HTMLDivElement);
+ await this.finalizeBubble(currentBubble);
}
this.messages.push({ role: "assistant", content: response });
this.scrollToBottom();
} catch (err: unknown) {
// Finalize bubble even on error
if (currentBubble !== null) {
- (currentBubble as HTMLDivElement).removeClass("ai-pulse-streaming");
- const errorIcon = (currentBubble as HTMLDivElement).querySelector(".ai-pulse-loading-icon");
+ currentBubble.removeClass("ai-pulse-streaming");
+ const errorIcon = currentBubble.querySelector(".ai-pulse-loading-icon");
if (errorIcon !== null) {
errorIcon.remove();
}
// Remove empty bubble on error
- if ((currentBubble as HTMLDivElement).textContent?.trim() === "") {
- (currentBubble as HTMLDivElement).remove();
+ if (currentBubble.textContent?.trim() === "") {
+ currentBubble.remove();
}
- this.bubbleContent.delete(currentBubble as HTMLDivElement);
+ this.bubbleContent.delete(currentBubble);
}
const errMsg = err instanceof Error ? err.message : "Unknown error.";
diff --git a/src/main.ts b/src/main.ts
index e66a126..12dadaf 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,5 +1,6 @@
import { Plugin, WorkspaceLeaf } from "obsidian";
-import { AIPulseSettings, DEFAULT_SETTINGS } from "./settings";
+import type { AIPulseSettings } from "./settings";
+import { DEFAULT_SETTINGS } from "./settings";
import { ChatView, VIEW_TYPE_CHAT } from "./chat-view";
import { testConnection, listModels } from "./ollama-client";
import { getDefaultToolStates } from "./tools";
diff --git a/src/ollama-client.ts b/src/ollama-client.ts
index 9e66de7..ccf94a0 100644
--- a/src/ollama-client.ts
+++ b/src/ollama-client.ts
@@ -59,9 +59,9 @@ function parseToolCalls(value: unknown): ToolCallResponse[] {
const fnObj = fn as Record<string, unknown>;
if (typeof fnObj.name !== "string") continue;
result.push({
- type: typeof obj.type === "string" ? obj.type : undefined,
+ ...(typeof obj.type === "string" ? { type: obj.type } : {}),
function: {
- index: typeof fnObj.index === "number" ? fnObj.index : undefined,
+ ...(typeof fnObj.index === "number" ? { index: fnObj.index } : {}),
name: fnObj.name,
arguments: typeof fnObj.arguments === "object" && fnObj.arguments !== null
? fnObj.arguments as Record<string, unknown>
@@ -182,10 +182,10 @@ async function chatAgentLoop(opts: AgentLoopOptions): Promise<string> {
if (hasTools) {
parts.push(TOOL_SYSTEM_PROMPT);
}
- if (hasVaultContext) {
+ if (vaultContext !== undefined && vaultContext.trim() !== "") {
parts.push(vaultContext);
}
- if (hasUserPrompt) {
+ if (userSystemPrompt !== undefined && userSystemPrompt.trim() !== "") {
parts.push("USER INSTRUCTIONS:\n" + userSystemPrompt.trim());
}
workingMessages.unshift({ role: "system", content: parts.join("\n\n") });