UNPKG

taskforce-aiagent

Version:

TaskForce is a modular, open-source, production-ready TypeScript agent framework for orchestrating AI agents, LLM-powered autonomous agents, task pipelines, dynamic toolchains, RAG workflows and memory/retrieval systems.

110 lines (109 loc) 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.baseModelTokenLimits = void 0; exports.normalizeOutput = normalizeOutput; exports.checkDelegate = checkDelegate; exports.checkTool = checkTool; exports.interpolateTemplate = interpolateTemplate; exports.normalizeInput = normalizeInput; exports.cleanMarkdownJson = cleanMarkdownJson; exports.parseCSV = parseCSV; exports.parseXML = parseXML; exports.cleanFinalContext = cleanFinalContext; exports.getSafeReplacer = getSafeReplacer; exports.baseModelTokenLimits = { "gpt-3.5-turbo": 16384, "gpt-3.5-turbo-0125": 16384, "gpt-3.5-turbo-instruct": 4096, "gpt-4": 8192, "gpt-4-32k": 32768, "gpt-4o": 64000, "gpt-4o-mini": 16384, "meta-llama-3.1-8b-instruct": 8192, "nous-hermes-2-mistral-7b-dpo": 8192, "deepseek-chat": 16384, }; function normalizeOutput(text) { return text .replace(/\s{2,}/g, " ") .replace(/\n{2,}/g, "\n") .replace(/[ \t]+\n/g, "\n") .trim(); } function checkDelegate(output) { return output.match(/DELEGATE\(([^,]+),\s*"([^"]+)"\)/) !== null; } function checkTool(output) { return output.match(/TOOL\(([^,]+),\s*(\{.*?\})\)/g) !== null; } function interpolateTemplate(template, context) { return template.replace(/\{(.*?)\}/g, (_, key) => context[key.trim()] ?? `{${key}}`); } function normalizeInput(input) { try { const parsed = JSON.parse(input); if (typeof parsed === "object") { return Object.entries(parsed) .map(([k, v]) => `${k}: ${v}`) .join(", "); } } catch { return input .replace(/\{.*?\}/g, "") .replace(/\s{2,}/g, " ") .trim(); } return input; } function cleanMarkdownJson(raw) { let cleaned = raw.trim(); cleaned = cleaned.replace(/^```json\s*\n?/, ""); cleaned = cleaned.replace(/^```\s*\n?/, ""); cleaned = cleaned.replace(/\n*```$/, ""); cleaned = cleaned.replace(/```json/g, ""); cleaned = cleaned.replace(/```/g, ""); cleaned = cleaned.trim(); return cleaned; } function parseCSV(output) { const lines = output.trim().split("\n"); const headers = lines[0].split(","); return lines.slice(1).map((line) => { const values = line.split(","); const obj = {}; headers.forEach((h, i) => { obj[h.trim()] = values[i]?.trim() ?? ""; }); return obj; }); } function parseXML(output) { try { const parser = new DOMParser(); const xmlDoc = parser.parseFromString(output, "application/xml"); return xmlDoc; } catch { return output; } } function cleanFinalContext(finalContext) { if (typeof finalContext !== "object" || finalContext === null) return finalContext; const cleaned = { ...finalContext }; delete cleaned.__replanReason__; delete cleaned.__replanCount__; return cleaned; } function getSafeReplacer() { const seen = new WeakSet(); return (_key, value) => { if (typeof value === "object" && value !== null) { if (seen.has(value)) return "[Circular]"; seen.add(value); } return value; }; }