UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

3 lines (2 loc) • 2.22 kB
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url); { const __piWorkerThreads = require("node:worker_threads"); if (typeof __piWorkerThreads.markAsUncloneable !== "function") { __piWorkerThreads.markAsUncloneable = () => {}; } } var SHOW_HTML_PAGE_NAME="show_html_page",isRecord=value=>typeof value=="object"&&value!==null&&!Array.isArray(value);function inlinedPageCharacters(session,pending){let total=0,recorded=new Set;for(let entry of session.getEntries()){if(entry.type!=="message"||entry.message.role!=="toolResult"||entry.message.toolName!==SHOW_HTML_PAGE_NAME)continue;recorded.add(entry.message.toolCallId);let details=entry.message.details;isRecord(details)&&details.imagesInlined===!0&&typeof details.html=="string"&&(total+=details.html.length)}for(let[toolCallId,characters]of pending)recorded.has(toolCallId)?pending.delete(toolCallId):total+=characters;return total}function reserveHandedPage(session,pending,toolCallId,characters){let alreadyHanded=inlinedPageCharacters(session,pending),inlined=alreadyHanded+characters<=6291456;return inlined&&pending.set(toolCallId,characters),{inlined,alreadyHanded}}var IMAGES_INLINED="Local images were inlined.",overSessionBudgetText=alreadyHanded=>`Local images were inlined into the saved copy, but this session's pages already carry ${alreadyHanded} of the 6291456 characters of images a session can carry to a viewer, so a viewer on another machine will not see this page's images.`;function handedPageText(page){let where=page.shown?`The page was shown to the reader inline above your reply. A copy is saved at ${page.path}. `:`Wrote the page to ${page.path}. It was not displayed in this interface. `;return page.imagesInlined?`${where}${IMAGES_INLINED}`:page.fitsPage?`${where}${overSessionBudgetText(page.alreadyHanded)}`:`${where}Local images were inlined into the saved copy, but with them the page is ${page.inlinedLength} characters, over the 2097152 a page can carry to a viewer, so a viewer on another machine will not see the images. Use smaller images to show them everywhere.`}export{SHOW_HTML_PAGE_NAME,reserveHandedPage,IMAGES_INLINED,overSessionBudgetText,handedPageText};