Project Files
dist / toolsProvider.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolsProvider = toolsProvider;
const sdk_1 = require("@lmstudio/sdk");
const zod_1 = require("zod");
const config_1 = require("./config");
const web_1 = require("./services/ingestion/web");
const youtube_1 = require("./services/ingestion/youtube");
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
async function toolsProvider(ctl) {
const config = ctl.getPluginConfig(config_1.configSchematics);
const tools = [];
const addSourceTool = (0, sdk_1.tool)({
name: "add_source",
description: "Adds a web page or YouTube video to the OpenBook context.",
parameters: {
url: zod_1.z.string().url().describe("The URL to add (Web page or YouTube)"),
type: zod_1.z.enum(["web", "youtube"]).describe("The type of source")
},
implementation: async ({ url, type }) => {
try {
if (type === "web") {
const result = await (0, web_1.extractWebContent)(url);
// We need to save this as a 'virtual file' or just text.
// For now, we'll write it to a temp file so the User can 'attach' it
// or we can auto-attach it.
// *Limitation*: Plugins cannot auto-attach files to the *current* chat easily without user action
// unless we manage a separate index.
// Strategy: Save to a 'sources' folder and return the path, telling the model
// to tell the user "I have saved the content to X, please upload it"
// OR simpler: Return the content directly in the tool output so it's in context.
return `SOURCE ADDED (WEB):\nTitle: ${result.title}\n\nContent:\n${result.content}`;
}
else if (type === "youtube") {
const whisperPath = config.get("whisperBinaryPath");
const tempDir = path.join(ctl.getWorkingDirectory(), "temp_ingest");
if (!fs.existsSync(tempDir))
fs.mkdirSync(tempDir, { recursive: true });
const transcript = await (0, youtube_1.downloadAndTranscribeYoutube)(url, tempDir, whisperPath);
return `SOURCE ADDED (YOUTUBE):\nURL: ${url}\n\nTranscript:\n${transcript}`;
}
return "Unknown source type.";
}
catch (e) {
return `Error adding source: ${e.message}`;
}
}
});
const podcastTool = (0, sdk_1.tool)({
name: "generate_podcast_script",
description: "Generates a detailed, long-form podcast script based on the current context.",
parameters: {
topic: zod_1.z.string().describe("The main topic of the podcast"),
hosts: zod_1.z.array(zod_1.z.string()).optional().default(["Nova", "Sage"]).describe("Names of the hosts (can be more than 2)"),
dispositions: zod_1.z.string().optional().describe("Describe the hosts' personalities (e.g., 'Nova is skeptical, Sage is an optimist')"),
length: zod_1.z.enum(["short", "medium", "long"]).optional().default("long").describe("Desired script length (short=500 words, long=2000+ words)")
},
implementation: async ({ topic, hosts, dispositions, length }) => {
let lengthInstruction = "";
if (length === "long") {
lengthInstruction = "This should be an exhaustive, long-form deep dive (at least 2000 words). Go into granular detail about all provided source materials.";
}
else if (length === "medium") {
lengthInstruction = "Provide a comprehensive discussion of moderate length (around 1000 words).";
}
else {
lengthInstruction = "Provide a concise summary in dialogue format (around 500 words).";
}
const personalityNote = dispositions ? `\nHost Dispositions: ${dispositions}` : "";
return `INSTRUCTION: Please generate a lively podcast script about "${topic}".
Hosts: ${hosts.join(", ")}${personalityNote}
Length Requirement: ${lengthInstruction}
GUIDELINES:
1. Use the FULL context provided in the previous messages (documents, web pages, transcripts).
2. Incorporate specific quotes and complex details from the sources.
3. Ensure a natural flow with host banter, transitions, and deep analysis.
4. DO NOT summarize; instead, have the hosts DISCUSS the material in depth.
5. Take advantage of the large context window to be as thorough as possible.
Format the output strictly as a dialogue script.`;
}
});
tools.push(addSourceTool);
tools.push(podcastTool);
return tools;
}