src / index.ts
// Bundled by lmstudio-suite (scripts/package-plugins.mjs) from packages/plugin-generator. Do not edit; regenerate instead.
// packages/core/src/client.ts
import { LMStudioClient } from "@lmstudio/sdk";
// packages/core/src/data/calc.ts
var NUMBER_RE = /^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/;
function tokenize(expr) {
const tokens = [];
let i = 0;
while (i < expr.length) {
const c = expr[i];
if (c === " " || c === " " || c === "\n" || c === "\r") {
i++;
continue;
}
if ("+-*/%^()".includes(c)) {
tokens.push({ type: "op", value: c });
i++;
continue;
}
const m = NUMBER_RE.exec(expr.slice(i));
if (m) {
const num = Number(m[0]);
if (!Number.isFinite(num)) throw new Error(`invalid number '${m[0]}'`);
tokens.push({ type: "number", value: m[0], num });
i += m[0].length;
continue;
}
throw new Error(`unexpected character '${c}'`);
}
return tokens;
}
function evalArithmetic(expr) {
const tokens = tokenize(expr);
let pos = 0;
const peek = () => tokens[pos];
const next = () => tokens[pos++];
function parseExpr() {
let v = parseTerm();
while (peek() && (peek().value === "+" || peek().value === "-")) {
const op = next().value;
const rhs = parseTerm();
v = op === "+" ? v + rhs : v - rhs;
}
return v;
}
function parseTerm() {
let v = parseUnary();
while (peek() && ["*", "/", "%"].includes(peek().value)) {
const op = next().value;
const rhs = parseUnary();
if (op === "*") v *= rhs;
else if (op === "/") v /= rhs;
else v %= rhs;
}
return v;
}
function parseUnary() {
if (peek()?.value === "-") {
next();
return -parseUnary();
}
if (peek()?.value === "+") {
next();
return parseUnary();
}
return parsePower();
}
function parsePower() {
const base = parsePrimary();
if (peek()?.value === "^") {
next();
return Math.pow(base, parseUnary());
}
return base;
}
function parsePrimary() {
const t = peek();
if (!t) throw new Error("unexpected end of expression");
if (t.type === "number") {
next();
return t.num;
}
if (t.value === "(") {
next();
const v = parseExpr();
if (peek()?.value !== ")") throw new Error("missing closing ')'");
next();
return v;
}
throw new Error(`unexpected token '${t.value}'`);
}
if (tokens.length === 0) throw new Error("empty expression");
const result = parseExpr();
if (pos !== tokens.length) {
throw new Error(`unexpected token '${peek().value}'`);
}
if (!Number.isFinite(result))
throw new Error("result is not a finite number");
return result;
}
// packages/core/src/schedule/schedule.ts
var CRON_FIELDS_5 = [
[0, 59],
// minute
[0, 23],
// hour
[1, 31],
// day of month
[1, 12],
// month
[0, 7]
// day of week (0 and 7 = Sunday)
];
var CRON_FIELDS_6 = [
[0, 59],
// second
...CRON_FIELDS_5
];
// packages/core/src/compact/compact.ts
var DEFAULT_SUMMARY_DIRECTIVE = [
"Write a complete, well-narrated hand-off briefing for the AI agent that will",
"continue this work in a fresh chat with NONE of the prior context. Address it",
"directly to that agent as flowing, readable prose under short headed sections.",
"Be thorough and self-contained: include everything needed to resume seamlessly,",
"and use as much length as the material genuinely requires \u2014 do not cut detail",
"for brevity. But stay information-dense: no padding, repetition, or filler.",
"Cover the who / what / why / how / when: a full recap of the project and the",
"work or story so far; the characters or people (names, roles, voices,",
"relationships, arcs); the setting and timeline; the decisions made and the",
"reasoning behind them; open threads, constraints, and the tone or style to",
"honor; and exactly where things were left off with the immediate next step.",
"Be concrete and specific \u2014 real names, facts, and short quotes where they",
"matter. Narrate it as one continuous, coherent account, not terse fragments.",
"Write the briefing directly: no reasoning, no analysis, no <think> blocks,",
"no preamble."
].join("\n");
// packages/core/src/tools/web-tools.ts
import { tool } from "@lmstudio/sdk";
import { z } from "zod";
// packages/core/src/tools/http-tools.ts
import { tool as tool2 } from "@lmstudio/sdk";
import { z as z2 } from "zod";
// packages/core/src/tools/local-tools.ts
import { tool as tool3 } from "@lmstudio/sdk";
import { z as z3 } from "zod";
// packages/core/src/tools/map-tools.ts
import { tool as tool4 } from "@lmstudio/sdk";
import { z as z4 } from "zod";
// packages/core/src/tools/data-tools.ts
import { tool as tool5 } from "@lmstudio/sdk";
import { z as z5 } from "zod";
// packages/core/src/tools/memory-tools.ts
import { tool as tool6 } from "@lmstudio/sdk";
import { z as z6 } from "zod";
// packages/core/src/tools/time-tools.ts
import { tool as tool7 } from "@lmstudio/sdk";
import { z as z7 } from "zod";
// packages/core/src/tools/schedule-tools.ts
import { tool as tool8 } from "@lmstudio/sdk";
import { z as z8 } from "zod";
// packages/plugin-generator/src/generator.ts
function respondTo(message) {
const expr = message.trim();
if (!expr) return "Send me an arithmetic expression, e.g. (3 + 4) * 2.";
try {
return `${expr} = ${evalArithmetic(expr)}`;
} catch {
return `I only evaluate arithmetic (+ - * / % ^ and parentheses). "${expr}" isn't one \u2014 try e.g. 2 ^ 10.`;
}
}
function lastUserText(history) {
const messages = history.getMessagesArray();
for (let i = messages.length - 1; i >= 0; i--) {
const m = messages[i];
if (m && m.getRole() === "user") return m.getText();
}
return "";
}
// packages/plugin-generator/src/index.ts
async function generate(ctl, history) {
const reply = respondTo(lastUserText(history));
for (const fragment of reply.split(/(\s+)/)) {
if (fragment) ctl.fragmentGenerated(fragment);
}
}
async function main(context) {
context.withGenerator(generate);
}
export {
generate,
main
};