import { blob } from "https://esm.town/v/std/blob";
import process from "node:process";
import { TodoistApi } from "npm:@doist/todoist-api-typescript";
import Instructor from "npm:@instructor-ai/instructor";
import Jimp from "npm:jimp";
import OpenAI from "npm:openai";
import { z } from "npm:zod";
const force_update_database = false;
const TODOIST_API_KEY = process.env.TODOIST_API_KEY;
const HABITIFY_API_KEY = process.env.HABITIFY_API_KEY;
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
const DEF_TIMEZONE = "America/Los_Angeles";
var add_to_habitify_todoist_project_id = "XXXX";
var todoist_dict_mapping = {
"Image Notes": {
"todoist-section-id": "XXXX",
"habitify-area-name": "undefined",
specialPrompt: "only_image",
},
"Text Notes": {
"habitify-area-name": "undefined",
"todoist-section-id": "XXXX",
specialPrompt: "only_text",
},
Cats: {
"todoist-section-id": "XXXX",
"habitify-area-name": "Cats",
specialPrompt: "",
},
Food: {
"todoist-section-id": "XXXX",
"habitify-area-name": "Health",
specialPrompt: "track_calories",
},
};
const todoistapi = new TodoistApi(TODOIST_API_KEY);
const oai = new OpenAI({
apiKey: OPENAI_API_KEY ?? undefined,
});
const client = Instructor({
client: oai,
mode: "TOOLS",
});
function getHabitifyAreaName(section_id) {
if (!section_id) {
return ["undefined", ""];
}
for (var key in todoist_dict_mapping) {
if (todoist_dict_mapping[key]["todoist-section-id"] === section_id) {
return [
todoist_dict_mapping[key]["habitify-area-name"],
todoist_dict_mapping[key]["specialPrompt"].toLowerCase(),
];
}
}
return ["undefined", ""];
}
function convertDateObject(due) {
function convertToISOWithOffset(datetimeStr, timezoneStr) {
const date = new Date(datetimeStr);
const [, sign, hours, minutes] = timezoneStr.match(
/GMT ([+-])(\d{1,2}):(\d{2})/,
);
date.setUTCMinutes(
date.getUTCMinutes()
+ (parseInt(hours) * 60 + parseInt(minutes)) * (sign === "+" ? 1 : -1),
);
return (
date.toISOString().split(".")[0]
+ `${sign}${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`
);
}
const formatDate = (date, datetime, timezone) => {
let isoString = datetime ? datetime : date;
if (timezone && timezone.startsWith("GMT") && timezone.length > 3) {
return convertToISOWithOffset(datetime, timezone);
} else {
return isoString;
}
};