Skip to content

Commit

Permalink
quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollingj committed Aug 15, 2024
1 parent 7ee2d54 commit 21ca311
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 90 deletions.
183 changes: 95 additions & 88 deletions caret_canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,107 +4,114 @@ import { View } from "obsidian";
import { CaretPluginSettings, Edge, Node, SparkleConfig } from "./types";

export class CaretCanvas {
nodes: Node[];
edges: Edge[];
canvas: any;
canvasKeybinds: {
[command: string]: {
keybind: string;
description: string;
enabled: boolean;
}
};
constructor(readonly canvas_view: View) {
this.canvasKeybinds = {
NavigateUp: {
keybind: "ArrowUp",
description: "Move up in the canvas",
enabled: true
},
NavigateDown: {
keybind: "ArrowDown",
description: "Move down in the canvas",
enabled: true
},
NavigateLeft: {
keybind: "ArrowLeft",
description: "Move left in the canvas",
enabled: true
},
NavigateRight: {
keybind: "ArrowRight",
description: "Move right in the canvas",
enabled: true
}
nodes: Node[];
edges: Edge[];
canvas: any;
canvasKeybinds: {
[command: string]: {
keybind: string;
description: string;
enabled: boolean;
};
};
// @ts-ignore
if (!canvas_view || !canvas_view.canvas) {
return;
}
// @ts-ignore
const canvas = canvas_view.canvas;
this.canvas = canvas;
constructor(readonly canvas_view: View) {
this.canvasKeybinds = {
NavigateUp: {
keybind: "ArrowUp",
description: "Move up in the canvas",
enabled: true,
},
NavigateDown: {
keybind: "ArrowDown",
description: "Move down in the canvas",
enabled: true,
},
NavigateLeft: {
keybind: "ArrowLeft",
description: "Move left in the canvas",
enabled: true,
},
NavigateRight: {
keybind: "ArrowRight",
description: "Move right in the canvas",
enabled: true,
},
};
// @ts-ignore
if (!canvas_view || !canvas_view.canvas) {
return;
}
// @ts-ignore
const canvas = canvas_view.canvas;
this.canvas = canvas;

// node.unknownData.role = "user";
// node.unknownData.role = "user";

const canvas_data = canvas.getData();
const { edges, nodes } = canvas_data;
this.nodes = nodes;
this.edges = edges;
}
const canvas_data = canvas.getData();
const { edges, nodes } = canvas_data;
this.nodes = nodes;
this.edges = edges;
}

textById() {
const res: { [k: string]: string } = {};
this.nodes.forEach((node) => {
res[node.id] = node.text;
});
return res;
}
textById() {
const res: { [k: string]: string } = {};
this.nodes.forEach((node) => {
res[node.id] = node.text;
});
return res;
}

getNode(nodeId: string) {
const [res] = this.nodes.filter((node) => node.id === nodeId);
return new CaretNode(res, this);
}
getNode(nodeId: string) {
const [res] = this.nodes.filter((node) => node.id === nodeId);
return new CaretNode(res, this);
}

getLongestLineage(node_id: string) {
return CaretPlugin.getLongestLineage(this.nodes, this.edges, node_id);
}
getLongestLineage(node_id: string) {
return CaretPlugin.getLongestLineage(this.nodes, this.edges, node_id);
}

static fromPlugin(plugin: CaretPlugin) {
return new CaretCanvas(plugin.app.workspace.getMostRecentLeaf()!.view);
}
static fromPlugin(plugin: CaretPlugin) {
return new CaretCanvas(plugin.app.workspace.getMostRecentLeaf()!.view);
}
}

export function mergeSettingsAndSparkleConfig(settings: CaretPluginSettings, sparkle_config: SparkleConfig): SparkleConfig {
let model = settings.model;
let provider = settings.llm_provider;
let temperature = settings.temperature;
if (sparkle_config.model !== "default") {
model = sparkle_config.model;
}
if (sparkle_config.provider !== "default") {
provider = sparkle_config.provider;
}
if (sparkle_config.temperature !== settings.temperature) {
temperature = sparkle_config.temperature;
}
return { model, provider, temperature };
export function mergeSettingsAndSparkleConfig(
settings: CaretPluginSettings,
sparkle_config: SparkleConfig
): SparkleConfig {
let model = settings.model;
let provider = settings.llm_provider;
let temperature = settings.temperature;
let context_window: string | number = settings.context_window;
if (sparkle_config.model !== "default") {
model = sparkle_config.model;
}
if (sparkle_config.provider !== "default") {
provider = sparkle_config.provider;
}
if (sparkle_config.temperature !== settings.temperature) {
temperature = sparkle_config.temperature;
}
if (sparkle_config.context_window !== "default") {
context_window = sparkle_config.context_window;
}
return { model, provider, temperature, context_window };
}

export class CaretNode {
constructor(readonly node: Node, readonly canvas_nodes: CaretCanvas) {}
constructor(readonly node: Node, readonly canvas_nodes: CaretCanvas) {}

outgoingNodes() {
return this.canvas_nodes.edges
.filter((edge) => edge.fromNode === this.node.id)
.map((edge) => this.canvas_nodes.getNode(edge.toNode));
}
outgoingNodes() {
return this.canvas_nodes.edges
.filter((edge) => edge.fromNode === this.node.id)
.map((edge) => this.canvas_nodes.getNode(edge.toNode));
}

get id() {
return this.node.id;
}
get id() {
return this.node.id;
}

getLongestLineage() {
return this.canvas_nodes.getLongestLineage(this.node.id);
}
getLongestLineage() {
return this.canvas_nodes.getLongestLineage(this.node.id);
}
}
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { CaretCanvas } from "./caret_canvas";
const parseString = require("xml2js").parseString;

export const DEFAULT_SETTINGS: CaretPluginSettings = {
caret_version: "0.2.53",
caret_version: "0.2.54",
chat_logs_folder: "caret/chats",
chat_logs_date_format_bool: false,
chat_logs_rename_bool: true,
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "caret",
"name": "Caret",
"version": "0.2.53",
"version": "0.2.54",
"minAppVersion": "1.5.12",
"description": "Accelerate your work with LLMs in canvas and your notes",
"author": "Jake Colling",
Expand Down

0 comments on commit 21ca311

Please sign in to comment.