From 636b0323075225c584b62719ed51e75521bb7ffb Mon Sep 17 00:00:00 2001
From: aura <nw@moneybot.cc>
Date: Tue, 17 Feb 2026 22:39:42 +0100
Subject: push source

---
 moneyjsx/src/util.tsx | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 moneyjsx/src/util.tsx

(limited to 'moneyjsx/src/util.tsx')

diff --git a/moneyjsx/src/util.tsx b/moneyjsx/src/util.tsx
new file mode 100644
index 0000000..097502e
--- /dev/null
+++ b/moneyjsx/src/util.tsx
@@ -0,0 +1,83 @@
+import * as api from './api';
+import * as chat from './chat';
+
+export function escapeHtml( html: string ) {
+  const entityMap = {
+    '&': '&amp;',
+    '<': '&lt;',
+    '>': '&gt;',
+    '"': '&quot;',
+    "'": '&#39;',
+    '/': '&#x2F;',
+    '`': '&#x60;',
+    '=': '&#x3D;'
+  };
+
+  return String( html ).replace( /[&<>"'`=\/]/g, ( s ) => {
+    return entityMap[s];
+  } );
+}
+
+export function parseJWT( token: string ) : any {
+  const parts = token.split( '.' );
+  let encoded = parts[1];
+  encoded = encoded.replace(/-/g, '+').replace(/_/g, '/');
+  const pad = encoded.length % 4;
+  if( pad === 1 )
+    throw new Error( 'what the fuck' );
+  if( pad > 1 )
+    encoded += new Array( 5 - pad ).join( '=' );
+
+  const payload = JSON.parse( atob( encoded ) );
+  return payload;
+}
+
+export function isToolStr( buf: string, model: api.Model ) {
+  const trimmed = buf.replace( /\s+/g, '' ).toLowerCase();
+  const capabilities = model.capabilities;
+
+  for( let tool in capabilities ) {
+    let name = tool.toLowerCase();
+    let str = `{"name":"${name}"`;
+
+    let not_matched = false;
+    for( let i = 0; i < Math.min( trimmed.length, str.length ); i++ ) {
+      if( trimmed[i] !== str[i] ) {
+        not_matched = true;
+        break;
+      }
+    }
+
+    if( !not_matched )
+      return true;
+  }
+
+  return false;
+}
+
+export function getToolCall( msg: chat.Msg ) {
+  let first_bracket = msg.content.indexOf( '{' );
+  let last_bracket = msg.content.lastIndexOf( '}' );
+
+  if( first_bracket == -1 || last_bracket == -1 )
+    return null;
+
+  let call = msg.content.substring( first_bracket, last_bracket + 1 );
+  let json = null;
+  try { json = JSON.parse( call ); }
+  catch( e ) { return null; }
+
+  return json;
+}
+
+export function sizeHumanReadable( size: number ) {
+  if( size < 1024 )
+    return size + ' B';
+  else if( size < 1024 * 1024 )
+    return ( size / 1024 ).toFixed( 2 ) + ' KB';
+  else if( size < 1024 * 1024 * 1024 )
+    return ( size / 1024 / 1024 ).toFixed( 2 ) + ' MB';
+  else
+    return ( size / 1024 / 1024 / 1024 ).toFixed( 2 ) + ' GB';
+}
+
-- 
cgit v1.2.3

