@kunal_dutt/token-lens 0.2.27 → 0.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/check-agent.mjs +22 -22
- package/gateway.mjs +13 -13
- package/package.json +1 -1
- package/sdk.mjs +4 -0
- package/server.mjs +141 -90
- package/token-lens.mcpb +0 -0
- package/types/src/core/coach.d.ts +113 -0
- package/types/src/core/index.d.ts +1 -0
package/check-agent.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
2
|
-
import{execFileSync as Pi}from"node:child_process";import{existsSync as Ii,readFileSync as Mi,writeFileSync as ji}from"node:fs";import{join as
|
|
2
|
+
import{execFileSync as Pi}from"node:child_process";import{existsSync as Ii,readFileSync as Mi,writeFileSync as ji}from"node:fs";import{join as Aa}from"node:path";var E="<|endoftext|>",j="<|fim_prefix|>",x="<|fim_middle|>",D="<|fim_suffix|>",G="<|im_start|>",q="<|im_end|>",N="<|im_sep|>",L="<|endofprompt|>",be="<|startoftext|>",Y="<|start|>",X="<|end|>",Q="<|message|>",Z="<|channel|>",ee="<|return|>",ae="<|constrain|>",ie="<|call|>";var xe=e=>e<=127;function ke(e){if(e.length===0)return!1;let a=e.charCodeAt(e.length-1);return a>=55296&&a<=56319}function Ra(e){let a=0;for(;a<e.length;){let i=e[a],n=0,r=0;if(i<=127)n=1,r=i;else if((i&224)===192){if(n=2,r=i&31,i<=193)return!1}else if((i&240)===224)n=3,r=i&15;else if((i&248)===240){if(n=4,r=i&7,i>244)return!1}else return!1;if(a+n>e.length)return!1;for(let t=1;t<n;t++){let o=e[a+t];if(o===void 0||(o&192)!==128)return!1;r=r<<6|o&63}if(n===2&&r<128||n===3&&r<2048||n===4&&r<65536||r>=55296&&r<=57343||r>1114111)return!1;a+=n}return!0}var za=new TextDecoder("utf8",{fatal:!1});function De(e){if(Ra(e))return za.decode(e)}function Ne(e,a){let i=Math.min(e.length,a.length);for(let n=0;n<i;n++)if(e[n]!==a[n])return e[n]-a[n];return e.length-a.length}function Le(e){let a=0;return e.forEach(i=>{a=Math.max(a,i)}),a}function fe(e){return e.replace(/[$()*+.?[\\\]^{|}]/g,"\\$&")}function ve(e){let a=[...e].map(fe).join("|");return new RegExp(`(${a})`)}var se=new Uint8Array(0),U=new TextDecoder("utf8"),Be=class{mergeableBytePairRankCount;bytePairRankDecoder;bytePairNonUtfRankDecoder=new Map;bytePairNonUtfSortedEncoder;bytePairStringRankEncoder;tokenSplitRegex;specialTokensEncoder;specialTokensDecoder;specialTokenPatternRegex;textEncoder=new TextEncoder;mergeCache;mergeCacheSize;constructor({bytePairRankDecoder:e,specialTokensEncoder:a,tokenSplitRegex:i,mergeCacheSize:n=1e5}){this.bytePairRankDecoder=e,this.bytePairStringRankEncoder=new Map,this.mergeCacheSize=n,n>0&&(this.mergeCache=new Map),this.mergeableBytePairRankCount=Object.keys(e).length;let r=[];e.forEach((o,s)=>{if(typeof o=="string"){this.bytePairStringRankEncoder.set(o,s);return}let l=new Uint8Array(o);r.push([l,s]),this.bytePairNonUtfRankDecoder.set(s,l)}),this.bytePairNonUtfSortedEncoder=r.sort((o,s)=>Ne(o[0],s[0])),this.specialTokensEncoder=a??new Map,this.specialTokensDecoder=a?new Map([...a].map(([o,s])=>[s,o])):new Map,this.tokenSplitRegex=i;let t=[...this.specialTokensEncoder.keys()].map(fe).join("|");try{this.specialTokenPatternRegex=new RegExp(t,"y")}catch{throw new Error("Invalid regular expression pattern.")}}setMergeCacheSize(e){this.mergeCacheSize===0&&e>0&&(this.mergeCache=new Map),this.mergeCacheSize=e,e===0&&(this.mergeCache=void 0)}clearMergeCache(){this.mergeCache?.clear()}*encodeNativeGenerator(e,a){let i=0,n=0;for(;;){let r=this.findNextSpecialToken(e,a,i),t=r?.[0],o=t??e.length,s=i===0&&o===e.length?e:e.slice(i,o);for(let[l]of s.matchAll(this.tokenSplitRegex)){let c=this.getBpeRankFromString(l);if(c!==void 0){n=1,yield[c];continue}let d=this.bytePairEncode(l);n=d.length,yield d}if(t!==void 0){let l=r[1],c=this.specialTokensEncoder.get(l);if(c===void 0)throw new Error(`Special token "${l}" is not in the special token encoder.`);yield[c],i=t+l.length,n=1}else break}return n}encodeNative(e,a){let i=0,n=[];for(;;){let r=this.findNextSpecialToken(e,a,i),t=r?.[0],o=t??e.length,s=i===0&&o===e.length?e:e.slice(i,o);for(let[l]of s.matchAll(this.tokenSplitRegex)){let c=this.getBpeRankFromString(l);if(c!==void 0){n.push(c);continue}let d=this.bytePairEncode(l);n.push(...d)}if(t!==void 0){let l=r[1],c=this.specialTokensEncoder.get(l);if(c===void 0)throw new Error(`Special token "${l}" is not in the special token encoder.`);n.push(c),i=t+l.length}else break}return n}countNative(e,a){let i=0,n=0;for(;;){let r=this.findNextSpecialToken(e,a,i),t=r?.[0],o=t??e.length,s=i===0&&o===e.length?e:e.slice(i,o);for(let[l]of s.matchAll(this.tokenSplitRegex)){if(this.getBpeRankFromString(l)!==void 0){n++;continue}let c=this.bytePairEncode(l);n+=c.length}if(t!==void 0){let l=r[1];if(this.specialTokensEncoder.get(l)===void 0)throw new Error(`Special token "${l}" is not in the special token encoder.`);n++,i=t+l.length}else break}return n}*decodeNativeGenerator(e){for(let a of e){let i=this.tryDecodeToken(a);i&&(yield i)}}decodeNative(e){let a="",i=se;for(let n of e){let r=this.tryDecodeToken(n);if(r===void 0)throw new Error(`Token ${n} is not in the byte pair encoder.`);if(typeof r=="string")i!==se&&(a+=U.decode(i,{stream:!0}),i=se),a+=r;else{let t=new Uint8Array(i.length+r.length);t.set(i),t.set(r,i.length),i=t}}return i!==se&&(a+=U.decode(i,{stream:!0})),a}async*decodeNativeAsyncIterable(e){for await(let a of e){let i=this.tryDecodeToken(a);i&&(yield i)}}getBpeRankFromString(e){return this.bytePairStringRankEncoder.get(e)}getBpeRankFromStringOrThrow(e){let a=this.getBpeRankFromString(e);if(a===void 0)throw new Error(`The byte-pair encoding does not contain a value for: ${e}`);return a}getBpeRankFromBytes(e){let a=De(e);if(a!==void 0)return this.getBpeRankFromString(a);let i=this.binarySearch(e);if(i!==-1)return this.bytePairNonUtfSortedEncoder[i][1]}getBpeRankFromBytesOrThrow(e){let a=this.getBpeRankFromBytes(e);if(a===void 0)throw new Error(`The byte-pair encoding does not contain a value for: ${e.toString()}`);return a}binarySearch(e){let a=0,i=this.bytePairNonUtfSortedEncoder.length-1;for(;a<=i;){let n=a+i>>>1,r=this.bytePairNonUtfSortedEncoder[n][0],t=0,o=Math.min(r.length,e.length);for(let s=0;s<o&&(t=r[s]-e[s],t===0);s++);if(t===0&&(t=r.length-e.length),t===0)return n;t<0?a=n+1:i=n-1}return-1}findNextSpecialToken(e,a,i){let n=i;for(;;){this.specialTokenPatternRegex.lastIndex=n;let r=this.specialTokenPatternRegex.exec(e);if(!r)return;let t=r[0];if(a?.has(t))return[r.index+n,t];n=r.index+n+1}}tryDecodeToken(e){let a=this.bytePairRankDecoder[e];if(typeof a=="string")return a;if(typeof a=="object"){let i=this.bytePairNonUtfRankDecoder.get(e);if(i)return i}return this.specialTokensDecoder.get(e)}addToMergeCache(e,a){if(this.mergeCache){if(this.mergeCache.size>=this.mergeCacheSize){let i=this.mergeCache.keys().next().value;this.mergeCache.delete(i)}this.mergeCache.set(e,a)}}bytePairEncode(e){if(e.length===1&&xe(e.codePointAt(0)))return[this.getBpeRankFromStringOrThrow(e)];if(this.mergeCache?.has(e)){let n=this.mergeCache.get(e);return this.mergeCache.delete(e),this.mergeCache.set(e,n),n}let a=this.textEncoder.encode(e),i=this.bytePairMerge(a);return this.addToMergeCache(e,i),i}bytePairMerge(e){let a=[],i=[],n=(t,o=a[t],s=a[t+2])=>{if(s===void 0)return Number.POSITIVE_INFINITY;let l=e.subarray(o,s);return this.getBpeRankFromBytes(l)??Number.POSITIVE_INFINITY};for(let t=0;t<=e.length;t++)a.push(t),t<e.length-1?i.push(n(t,t,t+2)):i.push(Number.POSITIVE_INFINITY);for(;a.length>1;){let t=Number.POSITIVE_INFINITY,o=-1;for(let s=0;s<i.length-1;s++){let l=i[s];l<t&&(t=l,o=s)}if(t===Number.POSITIVE_INFINITY||o===-1)break;a.splice(o+1,1),i.splice(o,1),i[o]=n(o),o>0&&(i[o-1]=n(o-1))}let r=[];for(let t=0;t<a.length-1;t++){let o=a[t],s=a[t+1],l=this.getBpeRankFromBytesOrThrow(e.subarray(o,s));r.push(l)}return r}};function Pa(e,a){let i=0;if(e.role&&(i+=a(e.role)),e.content&&(i+=a(e.content)),e.name&&(i+=a(e.name)+1),e.function_call){let{name:n,arguments:r}=e.function_call;n&&(i+=a(n)),r&&(i+=a(r)),i+=3}return i+=3,e.role==="function"&&(i-=2),i}function Fe(e,a,i){if(!e.properties)return"";let n=[],r=new Set(e.required??[]),t=" ".repeat(a);for(let[o,s]of Object.entries(e.properties)){s.description&&a<2&&n.push(`${t}// ${s.description}`);let l=r.has(o),c=i(s,a);n.push(`${t}${o}${l?"":"?"}: ${c},`)}return n.join(`
|
|
3
3
|
`)}function ye(e,a){switch(e.type){case"string":return e.enum?.map(i=>JSON.stringify(i)).join(" | ")??"string";case"integer":case"number":return e.enum?.map(i=>`${i}`).join(" | ")??"number";case"boolean":return"boolean";case"null":return"null";case"array":return e.items?`${ye(e.items,a)}[]`:"any[]";case"object":return`{
|
|
4
|
-
${
|
|
5
|
-
${" ".repeat(a)}}`;default:return"any"}}function Ia(e){let a=["namespace functions {",""];for(let i of e){i.description&&a.push(`// ${i.description}`);let{parameters:n}=i,r=n?.properties;if(!n||!r||Object.keys(r).length===0)a.push(`type ${i.name} = () => any;`);else{a.push(`type ${i.name} = (_: {`);let t=
|
|
4
|
+
${Fe(e,a+2,ye)}
|
|
5
|
+
${" ".repeat(a)}}`;default:return"any"}}function Ia(e){let a=["namespace functions {",""];for(let i of e){i.description&&a.push(`// ${i.description}`);let{parameters:n}=i,r=n?.properties;if(!n||!r||Object.keys(r).length===0)a.push(`type ${i.name} = () => any;`);else{a.push(`type ${i.name} = (_: {`);let t=Fe(n,0,ye);t.length>0&&a.push(t),a.push("}) => any;")}a.push("")}return a.push("} // namespace functions"),a.join(`
|
|
6
6
|
`)}function Ma(e,a){let i=a(Ia(e));return i+=9,i}function ja(e,a,i){return!a||i||e.role!=="system"||!e.content||e.content.endsWith(`
|
|
7
7
|
`)?e:{...e,content:`${e.content}
|
|
8
|
-
`}}function
|
|
8
|
+
`}}function Ge(e,a){let{messages:i,functions:n,function_call:r}=e,t=!!(n&&n.length>0),o=!1,s=0;for(let l of i){let c=ja(l,t,o);(c!==l&&l.role==="system"||l.role==="system"&&t&&!o)&&(o=!0),s+=Pa(c,a)}return s+=3,t&&n&&(s+=Ma(n,a),i.some(l=>l.role==="system")&&(s-=4)),r&&r!=="auto"&&(r==="none"?s+=1:typeof r=="object"&&r.name&&(s+=a(r.name)+4)),s}var qe=["chat-latest","chatgpt-4o-latest","codex-mini-latest","computer-use-preview","computer-use-preview-2025-03-11","daybreak-blue-latest","daybreak-red-latest","gpt-3.5","gpt-3.5-0301","gpt-3.5-turbo","gpt-3.5-turbo-0125","gpt-3.5-turbo-0613","gpt-3.5-turbo-1106","gpt-3.5-turbo-16k-0613","gpt-3.5-turbo-instruct","gpt-4","gpt-4-0125-preview","gpt-4-0314","gpt-4-0613","gpt-4-1106-preview","gpt-4-1106-vision-preview","gpt-4-32k","gpt-4-turbo","gpt-4-turbo-2024-04-09","gpt-4-turbo-preview","gpt-4.1","gpt-4.1-2025-04-14","gpt-4.1-mini","gpt-4.1-mini-2025-04-14","gpt-4.1-nano","gpt-4.1-nano-2025-04-14","gpt-4.5-preview","gpt-4.5-preview-2025-02-27","gpt-4o","gpt-4o-2024-05-13","gpt-4o-2024-08-06","gpt-4o-2024-11-20","gpt-4o-audio-preview","gpt-4o-audio-preview-2024-10-01","gpt-4o-audio-preview-2024-12-17","gpt-4o-audio-preview-2025-06-03","gpt-4o-mini","gpt-4o-mini-2024-07-18","gpt-4o-mini-audio-preview","gpt-4o-mini-audio-preview-2024-12-17","gpt-4o-mini-search-preview","gpt-4o-mini-search-preview-2025-03-11","gpt-4o-search-preview","gpt-4o-search-preview-2025-03-11","gpt-5","gpt-5-2025-08-07","gpt-5-chat-latest","gpt-5-codex","gpt-5-mini","gpt-5-mini-2025-08-07","gpt-5-nano","gpt-5-nano-2025-08-07","gpt-5-pro","gpt-5-pro-2025-10-06","gpt-5.1","gpt-5.1-2025-11-13","gpt-5.1-chat-latest","gpt-5.1-codex","gpt-5.1-codex-max","gpt-5.1-codex-mini","gpt-5.2","gpt-5.2-2025-12-11","gpt-5.2-chat-latest","gpt-5.2-codex","gpt-5.2-pro","gpt-5.2-pro-2025-12-11","gpt-5.3-chat-latest","gpt-5.3-codex","gpt-5.4","gpt-5.4-2026-03-05","gpt-5.4-mini","gpt-5.4-mini-2026-03-17","gpt-5.4-nano","gpt-5.4-nano-2026-03-17","gpt-5.4-pro","gpt-5.4-pro-2026-03-05","gpt-5.5","gpt-5.5-2026-04-23","gpt-5.5-pro","gpt-5.5-pro-2026-04-23","gpt-5.6-cyber","gpt-5.6-luna","gpt-5.6-sol","gpt-5.6-terra","gpt-audio","gpt-audio-1.5","gpt-audio-2025-08-28","gpt-audio-mini","gpt-audio-mini-2025-10-06","gpt-audio-mini-2025-12-15","gpt-image-1","gpt-oss-120b","gpt-oss-20b","o1","o1-2024-12-17","o1-mini","o1-mini-2024-09-12","o1-preview","o1-preview-2024-09-12","o1-pro","o1-pro-2025-03-19","o3","o3-2025-04-16","o3-deep-research","o3-deep-research-2025-06-26","o3-mini","o3-mini-2025-01-31","o3-pro","o3-pro-2025-06-10","o4-mini","o4-mini-2025-04-16","o4-mini-deep-research","o4-mini-deep-research-2025-06-26"];var He=Object.defineProperty,Ue=(e,a)=>{let i={};for(var n in e)He(i,n,{get:e[n],enumerable:!0});return a||He(i,Symbol.toStringTag,{value:"Module"}),i};var Ve=Ue({cl100k_base:()=>Oa,gpt2:()=>xa,o200k_base:()=>Ba,o200k_harmony:()=>Fa,p50k_base:()=>Da,p50k_edit:()=>La,r50k_base:()=>Na}),xa=["gpt2","gpt-2"],Da=["text-davinci-002","text-davinci-003","code-davinci-001","code-davinci-002","davinci-codex","code-cushman-001","code-cushman-002","cushman-codex"],Na=["text-ada-001","text-babbage-001","text-curie-001","text-davinci-001","ada","babbage","curie","davinci","code-search-ada-code-001","code-search-ada-text-001","text-similarity-ada-001","text-search-ada-doc-001","text-search-ada-query-001","text-similarity-babbage-001","text-search-babbage-doc-001","text-search-babbage-query-001","code-search-babbage-code-001","code-search-babbage-text-001","text-similarity-curie-001","text-search-curie-doc-001","text-search-curie-query-001","text-similarity-davinci-001","text-search-davinci-doc-001","text-search-davinci-query-001"],La=["code-davinci-edit-001","text-davinci-edit-001"],Oa=["gpt-3.5","gpt-3.5-0301","gpt-3.5-turbo","gpt-3.5-turbo-0125","gpt-3.5-turbo-0613","gpt-3.5-turbo-1106","gpt-3.5-turbo-16k-0613","gpt-3.5-turbo-instruct","gpt-4","gpt-4-0125-preview","gpt-4-0314","gpt-4-0613","gpt-4-1106-preview","gpt-4-1106-vision-preview","gpt-4-32k","gpt-4-turbo","gpt-4-turbo-2024-04-09","gpt-4-turbo-preview","text-embedding-3-large","text-embedding-3-small","text-embedding-ada-002","babbage-002","davinci-002"],Ba=[],Fa=["gpt-oss-20b","gpt-oss-120b"];var We=Object.fromEntries(Object.entries(Ve).flatMap(([e,a])=>a.map(i=>[i,e]))),Ga={messageSeparator:`
|
|
9
9
|
`,roleSeparator:`
|
|
10
|
-
`},qa={messageSeparator:"",roleSeparator:N},We=Object.fromEntries(Ge.flatMap(e=>e.startsWith("gpt-3.5")?[[e,Ga]]:[[e,qa]]));var V=new RegExp("'s|'t|'re|'ve|'m|'ll|'d| ?\\p{L}+| ?\\p{N}+| ?[^\\s\\p{L}\\p{N}]+|\\s+(?!\\S)|\\s+","gu"),Je=String.raw`'(?:[sS]|[dD]|[mM]|[tT]|[lL][lL]|[vV][eE]|[rR][eE])`,Ke=String.raw`(?:${Je})?`,Ha=String.raw`${Je}|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s+$|\s*[\r\n]|\s+(?!\S)|\s`,$e=new RegExp(Ha,"gu"),Ua=String.raw`[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}]*[\p{Ll}\p{Lm}\p{Lo}\p{M}]+${Ke}|[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}]+[\p{Ll}\p{Lm}\p{Lo}\p{M}]*${Ke}|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n/]*|\s*[\r\n]+|\s+(?!\S)|\s+`,oe=new RegExp(Ua,"gu");function Ye(e){return{tokenSplitRegex:$e,bytePairRankDecoder:e,specialTokensEncoder:new Map([[A,100257],[j,100258],[x,100259],[D,100260],[G,100264],[q,100265],[N,100266],[L,100276]])}}var Va=[[A,199999],[j,2e5],[x,200001],[D,200002],[G,200003],[q,200004],[N,200005],[L,200006]],Wa=()=>new Map(Va);function Xe(e){return{tokenSplitRegex:oe,bytePairRankDecoder:e,specialTokensEncoder:Wa()}}var Ka=200013,Ja=201088,$a=[[be,199998],[A,199999],["<|reserved_200000|>",2e5],["<|reserved_200001|>",200001],[ee,200002],[ae,200003],["<|reserved_200004|>",200004],[Z,200005],[Y,200006],[X,200007],[Q,200008],["<|reserved_200009|>",200009],["<|reserved_200010|>",200010],["<|reserved_200011|>",200011],[ie,200012]];function Qe(e){let a=new Map($a);for(let i=Ka;i<Ja;i+=1)a.set(`<|reserved_${i}|>`,i);return a.set(L,200018),{tokenSplitRegex:oe,bytePairRankDecoder:e,specialTokensEncoder:a,chatFormatter:"harmony"}}function Ze(e){return{expectedVocabularySize:50281,tokenSplitRegex:V,bytePairRankDecoder:e,specialTokensEncoder:new Map([[A,50256]])}}function ea(e){return{tokenSplitRegex:V,bytePairRankDecoder:e,specialTokensEncoder:new Map([[A,50256],[j,50281],[x,50282],[D,50283]])}}function aa(e){return{expectedVocabularySize:50257,tokenSplitRegex:V,bytePairRankDecoder:e,specialTokensEncoder:new Map([[A,50256]])}}function we(e,a){let i=a(e);switch(e.toLowerCase()){case"gpt2":case"r50k_base":return aa(i);case"p50k_base":return Ze(i);case"p50k_edit":return ea(i);case"cl100k_base":return Ye(i);case"o200k_base":return Xe(i);case"o200k_harmony":return Qe(i);default:throw new Error(`Unknown encoding name: ${e}`)}}var ia=class Se{static EndOfPrompt=L;static EndOfText=A;static FimMiddle=x;static FimPrefix=j;static FimSuffix=D;modelName;modelSpec;bytePairEncodingCoreProcessor;specialTokensEncoder;specialTokensSet;allSpecialTokenRegex;defaultSpecialTokenConfig;chatFormatter;countChatCompletionTokens;vocabularySize;constructor({bytePairRankDecoder:a,specialTokensEncoder:i,expectedVocabularySize:n,modelName:r,modelSpec:t,chatFormatter:o,...s}){this.specialTokensEncoder=i,this.specialTokensSet=new Set(this.specialTokensEncoder.keys()),this.allSpecialTokenRegex=ve(this.specialTokensSet),this.bytePairEncodingCoreProcessor=new Oe({bytePairRankDecoder:a,specialTokensEncoder:i,...s}),this.defaultSpecialTokenConfig=this.processSpecialTokens();let l=Math.max(a.length-1,Ne(i));if(this.vocabularySize=this.bytePairEncodingCoreProcessor.mergeableBytePairRankCount+i.size,n!==void 0){if(this.vocabularySize!==n)throw new Error("The number of mergeable tokens and special tokens must be equal to expectedVocabularySize.");if(l!==n-1)throw new Error(`The model encodings are invalid. The maximum token value must be equal to expectedVocabularySize - 1. Currently ${l}, expected ${n-1}`)}this.encode=this.encode.bind(this),this.decode=this.decode.bind(this),this.encodeGenerator=this.encodeGenerator.bind(this),this.decodeGenerator=this.decodeGenerator.bind(this),this.decodeAsyncGenerator=this.decodeAsyncGenerator.bind(this),this.decodeAsync=this.decodeAsync.bind(this),this.isWithinTokenLimit=this.isWithinTokenLimit.bind(this),this.encodeChat=this.encodeChat.bind(this),this.encodeChatGenerator=this.encodeChatGenerator.bind(this),this.countTokens=this.countTokens.bind(this),this.setMergeCacheSize=this.setMergeCacheSize.bind(this),this.clearMergeCache=this.clearMergeCache.bind(this),this.estimateCost=this.estimateCost.bind(this),t?.supported_features?.includes("function_calling")&&(this.countChatCompletionTokens=this.countChatCompletionTokensInternal.bind(this)),this.modelName=r,this.modelSpec=t,this.chatFormatter=o??"chatml"}*encodeHarmonyChatGenerator(a,i){let n=this.specialTokensEncoder.get(Y),r=this.specialTokensEncoder.get(Q),t=this.specialTokensEncoder.get(X),o=this.specialTokensEncoder.get(ee),s=this.specialTokensEncoder.get(ie),l=this.specialTokensEncoder.get(Z),c=this.specialTokensEncoder.get(ae);if(n===void 0||r===void 0||t===void 0||o===void 0||s===void 0||l===void 0||c===void 0)throw new Error("Harmony chat format requires dedicated special tokens.");let d=p=>p.length>0?this.encode(p):[],u=p=>{switch(p){case"<|return|>":return o;case"<|call|>":return s;default:return t}};for(let p of a){if(p.content===void 0)throw new Error("Content must be defined for all messages.");let y=p.name??p.role??"user";yield[n],yield d(y);let h=p.recipient&&(p.recipientPlacement==="role"||!p.channel),f=p.recipient&&!h;h&&(yield d(` to=${p.recipient}`)),p.channel&&(yield[l],yield d(p.channel),f&&(yield d(` to=${p.recipient}`))),p.constraint&&(yield[c],yield d(p.constraint)),yield[r],yield*this.encodeGenerator(p.content,i),yield[u(p.terminator)]}let g=i?.primeWithAssistantResponse??"assistant";g.length>0&&(yield[n],yield d(g))}static getEncodingApi(a,i){let n=we(a,i);return new Se(n)}static getEncodingApiForModel(a,i,n){let r=Ve[a]??"o200k_base",t=we(r,i);return new Se({...t,modelName:a,modelSpec:n})}processSpecialTokens({allowedSpecial:a,disallowedSpecial:i}={}){let n;if(a==="all"||a?.has("all")){a=new Set(this.specialTokensSet);let r=a;if(i==="all")throw new Error('allowedSpecial and disallowedSpecial cannot both be set to "all".');typeof i=="object"?i.forEach(t=>r.delete(t)):i=new Set}if(!i||i==="all"||i.has("all")){i=new Set(this.specialTokensSet);let r=i;a?.size?(a.forEach(t=>r.delete(t)),i.forEach(t=>a.delete(t)),i.size>0&&(n=ve(i))):n=this.allSpecialTokenRegex}return{allowedSpecial:a,regexPattern:n}}encodeGenerator(a,i){let n=i?this.processSpecialTokens(i):this.defaultSpecialTokenConfig;if(n.regexPattern){let r=a.match(n.regexPattern);if(r!==null)throw new Error(`Disallowed special token found: ${r[0]}`)}return this.bytePairEncodingCoreProcessor.encodeNativeGenerator(a,n.allowedSpecial)}encode(a,i){let n=i?this.processSpecialTokens(i):this.defaultSpecialTokenConfig;if(n.regexPattern){let r=a.match(n.regexPattern);if(r!==null)throw new Error(`Disallowed special token found: ${r[0]}`)}return this.bytePairEncodingCoreProcessor.encodeNative(a,n.allowedSpecial)}*encodeChatGenerator(a,i=this.modelName,n){if(!i)throw new Error("Model name must be provided either during initialization or passed in to the method.");let r=We[i];if(!r)throw new Error(`Model '${i}' does not support chat.`);if(this.chatFormatter==="harmony"){yield*this.encodeHarmonyChatGenerator(a,n);return}let t=this.specialTokensEncoder.get(G),o=this.specialTokensEncoder.get(q);if(t===void 0||o===void 0)throw new Error(`Model '${i}' does not support chat.`);let s=new Set([N]),{messageSeparator:l,roleSeparator:c}=r,d=l.length>0?this.encode(l):[],u=c.length>0?this.encode(c,{allowedSpecial:s}):[],g=new Map;for(let{role:y="system",name:h=y,content:f}of a){if(f===void 0)throw new Error("Content must be defined for all messages.");yield[t];let _=g.get(h)??this.encode(h);g.set(h,_),yield _,u.length>0&&(yield u),yield*this.encodeGenerator(f,n),yield[o],yield d}let p=n?.primeWithAssistantResponse??"assistant";p.length>0&&(yield[t],yield*this.encodeGenerator(p,n)),u.length>0&&(yield u)}encodeChat(a,i=this.modelName,n){return[...this.encodeChatGenerator(a,i,n)].flat()}isWithinTokenLimit(a,i,n){let r=typeof a=="string"?this.encodeGenerator(a,n):this.encodeChatGenerator(a,void 0,n),t=0;for(let o of r)if(t+=o.length,t>i)return!1;return t}countTokens(a,i){if(typeof a=="string"){let t=i?this.processSpecialTokens(i):this.defaultSpecialTokenConfig;if(t.regexPattern){let o=a.match(t.regexPattern);if(o!==null)throw new Error(`Disallowed special token found: ${o[0]}`)}return this.bytePairEncodingCoreProcessor.countNative(a,t.allowedSpecial)}let n=this.encodeChatGenerator(a,void 0,i),r=0;for(let t of n)r+=t.length;return r}countStringTokens(a){return a?this.bytePairEncodingCoreProcessor.countNative(a):0}countChatCompletionTokensInternal(a){return Fe(a,i=>this.countStringTokens(i))}setMergeCacheSize(a){this.bytePairEncodingCoreProcessor.setMergeCacheSize(a)}clearMergeCache(){this.bytePairEncodingCoreProcessor.clearMergeCache()}decode(a){return this.bytePairEncodingCoreProcessor.decodeNative(a)}*decodeGenerator(a){let i=this.bytePairEncodingCoreProcessor.decodeNativeGenerator(a),n="";for(let r of i)n+=typeof r=="string"?r:U.decode(r,{stream:!0}),!(n.length===0||ke(n))&&(yield n,n="");n.length>0&&(yield n)}async*decodeAsyncGenerator(a){let i=this.bytePairEncodingCoreProcessor.decodeNativeAsyncIterable(a),n="";for await(let r of i)n+=typeof r=="string"?r:U.decode(r,{stream:!0}),!(n.length===0||ke(n))&&(yield n,n="");n.length>0&&(yield n)}async decodeAsync(a){let i=this.bytePairEncodingCoreProcessor.decodeNativeAsyncIterable(a),n="";for await(let r of i)n+=typeof r=="string"?r:U.decode(r,{stream:!0});return n}estimateCost(a,i=this.modelSpec){if(!i)throw new Error("Model spec must be provided either during initialization or passed in to the method.");if(!i.price_data)throw new Error(`No cost information available for model: ${i.name}`);let n=i.price_data,r={},t=a/1e6;return n.main&&(r.main={input:n.main.input&&n.main.input*t,output:n.main.output&&n.main.output*t,cached_input:n.main.cached_input&&n.main.cached_input*t,cached_output:n.main.cached_output&&n.main.cached_output*t}),n.batch&&(r.batch={input:n.batch.input&&n.batch.input*t,output:n.batch.output&&n.batch.output*t,cached_input:n.batch.cached_input&&n.batch.cached_input*t,cached_output:n.batch.cached_output&&n.batch.cached_output*t}),r}};var na=["!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~",[161],[162],[163],[164],[165],[166],[167],[168],[169],[170],[171],[172],[174],[175],[176],[177],[178],[179],[180],[181],[182],[183],[184],[185],[186],[187],[188],[189],[190],[191],[192],[193],[194],[195],[196],[197],[198],[199],[200],[201],[202],[203],[204],[205],[206],[207],[208],[209],[210],[211],[212],[213],[214],[215],[216],[217],[218],[219],[220],[221],[222],[223],[224],[225],[226],[227],[228],[229],[230],[231],[232],[233],[234],[235],[236],[237],[238],[239],[240],[241],[242],[243],[244],[245],[246],[247],[248],[249],[250],[251],[252],[253],[254],[255],"\0","","","","","","","\x07","\b"," ",`
|
|
10
|
+
`},qa={messageSeparator:"",roleSeparator:N},Ke=Object.fromEntries(qe.flatMap(e=>e.startsWith("gpt-3.5")?[[e,Ga]]:[[e,qa]]));var V=new RegExp("'s|'t|'re|'ve|'m|'ll|'d| ?\\p{L}+| ?\\p{N}+| ?[^\\s\\p{L}\\p{N}]+|\\s+(?!\\S)|\\s+","gu"),$e=String.raw`'(?:[sS]|[dD]|[mM]|[tT]|[lL][lL]|[vV][eE]|[rR][eE])`,Je=String.raw`(?:${$e})?`,Ha=String.raw`${$e}|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s+$|\s*[\r\n]|\s+(?!\S)|\s`,Ye=new RegExp(Ha,"gu"),Ua=String.raw`[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}]*[\p{Ll}\p{Lm}\p{Lo}\p{M}]+${Je}|[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}]+[\p{Ll}\p{Lm}\p{Lo}\p{M}]*${Je}|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n/]*|\s*[\r\n]+|\s+(?!\S)|\s+`,oe=new RegExp(Ua,"gu");function Xe(e){return{tokenSplitRegex:Ye,bytePairRankDecoder:e,specialTokensEncoder:new Map([[E,100257],[j,100258],[x,100259],[D,100260],[G,100264],[q,100265],[N,100266],[L,100276]])}}var Va=[[E,199999],[j,2e5],[x,200001],[D,200002],[G,200003],[q,200004],[N,200005],[L,200006]],Wa=()=>new Map(Va);function Qe(e){return{tokenSplitRegex:oe,bytePairRankDecoder:e,specialTokensEncoder:Wa()}}var Ka=200013,Ja=201088,$a=[[be,199998],[E,199999],["<|reserved_200000|>",2e5],["<|reserved_200001|>",200001],[ee,200002],[ae,200003],["<|reserved_200004|>",200004],[Z,200005],[Y,200006],[X,200007],[Q,200008],["<|reserved_200009|>",200009],["<|reserved_200010|>",200010],["<|reserved_200011|>",200011],[ie,200012]];function Ze(e){let a=new Map($a);for(let i=Ka;i<Ja;i+=1)a.set(`<|reserved_${i}|>`,i);return a.set(L,200018),{tokenSplitRegex:oe,bytePairRankDecoder:e,specialTokensEncoder:a,chatFormatter:"harmony"}}function ea(e){return{expectedVocabularySize:50281,tokenSplitRegex:V,bytePairRankDecoder:e,specialTokensEncoder:new Map([[E,50256]])}}function aa(e){return{tokenSplitRegex:V,bytePairRankDecoder:e,specialTokensEncoder:new Map([[E,50256],[j,50281],[x,50282],[D,50283]])}}function ia(e){return{expectedVocabularySize:50257,tokenSplitRegex:V,bytePairRankDecoder:e,specialTokensEncoder:new Map([[E,50256]])}}function we(e,a){let i=a(e);switch(e.toLowerCase()){case"gpt2":case"r50k_base":return ia(i);case"p50k_base":return ea(i);case"p50k_edit":return aa(i);case"cl100k_base":return Xe(i);case"o200k_base":return Qe(i);case"o200k_harmony":return Ze(i);default:throw new Error(`Unknown encoding name: ${e}`)}}var na=class Se{static EndOfPrompt=L;static EndOfText=E;static FimMiddle=x;static FimPrefix=j;static FimSuffix=D;modelName;modelSpec;bytePairEncodingCoreProcessor;specialTokensEncoder;specialTokensSet;allSpecialTokenRegex;defaultSpecialTokenConfig;chatFormatter;countChatCompletionTokens;vocabularySize;constructor({bytePairRankDecoder:a,specialTokensEncoder:i,expectedVocabularySize:n,modelName:r,modelSpec:t,chatFormatter:o,...s}){this.specialTokensEncoder=i,this.specialTokensSet=new Set(this.specialTokensEncoder.keys()),this.allSpecialTokenRegex=ve(this.specialTokensSet),this.bytePairEncodingCoreProcessor=new Be({bytePairRankDecoder:a,specialTokensEncoder:i,...s}),this.defaultSpecialTokenConfig=this.processSpecialTokens();let l=Math.max(a.length-1,Le(i));if(this.vocabularySize=this.bytePairEncodingCoreProcessor.mergeableBytePairRankCount+i.size,n!==void 0){if(this.vocabularySize!==n)throw new Error("The number of mergeable tokens and special tokens must be equal to expectedVocabularySize.");if(l!==n-1)throw new Error(`The model encodings are invalid. The maximum token value must be equal to expectedVocabularySize - 1. Currently ${l}, expected ${n-1}`)}this.encode=this.encode.bind(this),this.decode=this.decode.bind(this),this.encodeGenerator=this.encodeGenerator.bind(this),this.decodeGenerator=this.decodeGenerator.bind(this),this.decodeAsyncGenerator=this.decodeAsyncGenerator.bind(this),this.decodeAsync=this.decodeAsync.bind(this),this.isWithinTokenLimit=this.isWithinTokenLimit.bind(this),this.encodeChat=this.encodeChat.bind(this),this.encodeChatGenerator=this.encodeChatGenerator.bind(this),this.countTokens=this.countTokens.bind(this),this.setMergeCacheSize=this.setMergeCacheSize.bind(this),this.clearMergeCache=this.clearMergeCache.bind(this),this.estimateCost=this.estimateCost.bind(this),t?.supported_features?.includes("function_calling")&&(this.countChatCompletionTokens=this.countChatCompletionTokensInternal.bind(this)),this.modelName=r,this.modelSpec=t,this.chatFormatter=o??"chatml"}*encodeHarmonyChatGenerator(a,i){let n=this.specialTokensEncoder.get(Y),r=this.specialTokensEncoder.get(Q),t=this.specialTokensEncoder.get(X),o=this.specialTokensEncoder.get(ee),s=this.specialTokensEncoder.get(ie),l=this.specialTokensEncoder.get(Z),c=this.specialTokensEncoder.get(ae);if(n===void 0||r===void 0||t===void 0||o===void 0||s===void 0||l===void 0||c===void 0)throw new Error("Harmony chat format requires dedicated special tokens.");let d=p=>p.length>0?this.encode(p):[],u=p=>{switch(p){case"<|return|>":return o;case"<|call|>":return s;default:return t}};for(let p of a){if(p.content===void 0)throw new Error("Content must be defined for all messages.");let y=p.name??p.role??"user";yield[n],yield d(y);let h=p.recipient&&(p.recipientPlacement==="role"||!p.channel),f=p.recipient&&!h;h&&(yield d(` to=${p.recipient}`)),p.channel&&(yield[l],yield d(p.channel),f&&(yield d(` to=${p.recipient}`))),p.constraint&&(yield[c],yield d(p.constraint)),yield[r],yield*this.encodeGenerator(p.content,i),yield[u(p.terminator)]}let g=i?.primeWithAssistantResponse??"assistant";g.length>0&&(yield[n],yield d(g))}static getEncodingApi(a,i){let n=we(a,i);return new Se(n)}static getEncodingApiForModel(a,i,n){let r=We[a]??"o200k_base",t=we(r,i);return new Se({...t,modelName:a,modelSpec:n})}processSpecialTokens({allowedSpecial:a,disallowedSpecial:i}={}){let n;if(a==="all"||a?.has("all")){a=new Set(this.specialTokensSet);let r=a;if(i==="all")throw new Error('allowedSpecial and disallowedSpecial cannot both be set to "all".');typeof i=="object"?i.forEach(t=>r.delete(t)):i=new Set}if(!i||i==="all"||i.has("all")){i=new Set(this.specialTokensSet);let r=i;a?.size?(a.forEach(t=>r.delete(t)),i.forEach(t=>a.delete(t)),i.size>0&&(n=ve(i))):n=this.allSpecialTokenRegex}return{allowedSpecial:a,regexPattern:n}}encodeGenerator(a,i){let n=i?this.processSpecialTokens(i):this.defaultSpecialTokenConfig;if(n.regexPattern){let r=a.match(n.regexPattern);if(r!==null)throw new Error(`Disallowed special token found: ${r[0]}`)}return this.bytePairEncodingCoreProcessor.encodeNativeGenerator(a,n.allowedSpecial)}encode(a,i){let n=i?this.processSpecialTokens(i):this.defaultSpecialTokenConfig;if(n.regexPattern){let r=a.match(n.regexPattern);if(r!==null)throw new Error(`Disallowed special token found: ${r[0]}`)}return this.bytePairEncodingCoreProcessor.encodeNative(a,n.allowedSpecial)}*encodeChatGenerator(a,i=this.modelName,n){if(!i)throw new Error("Model name must be provided either during initialization or passed in to the method.");let r=Ke[i];if(!r)throw new Error(`Model '${i}' does not support chat.`);if(this.chatFormatter==="harmony"){yield*this.encodeHarmonyChatGenerator(a,n);return}let t=this.specialTokensEncoder.get(G),o=this.specialTokensEncoder.get(q);if(t===void 0||o===void 0)throw new Error(`Model '${i}' does not support chat.`);let s=new Set([N]),{messageSeparator:l,roleSeparator:c}=r,d=l.length>0?this.encode(l):[],u=c.length>0?this.encode(c,{allowedSpecial:s}):[],g=new Map;for(let{role:y="system",name:h=y,content:f}of a){if(f===void 0)throw new Error("Content must be defined for all messages.");yield[t];let _=g.get(h)??this.encode(h);g.set(h,_),yield _,u.length>0&&(yield u),yield*this.encodeGenerator(f,n),yield[o],yield d}let p=n?.primeWithAssistantResponse??"assistant";p.length>0&&(yield[t],yield*this.encodeGenerator(p,n)),u.length>0&&(yield u)}encodeChat(a,i=this.modelName,n){return[...this.encodeChatGenerator(a,i,n)].flat()}isWithinTokenLimit(a,i,n){let r=typeof a=="string"?this.encodeGenerator(a,n):this.encodeChatGenerator(a,void 0,n),t=0;for(let o of r)if(t+=o.length,t>i)return!1;return t}countTokens(a,i){if(typeof a=="string"){let t=i?this.processSpecialTokens(i):this.defaultSpecialTokenConfig;if(t.regexPattern){let o=a.match(t.regexPattern);if(o!==null)throw new Error(`Disallowed special token found: ${o[0]}`)}return this.bytePairEncodingCoreProcessor.countNative(a,t.allowedSpecial)}let n=this.encodeChatGenerator(a,void 0,i),r=0;for(let t of n)r+=t.length;return r}countStringTokens(a){return a?this.bytePairEncodingCoreProcessor.countNative(a):0}countChatCompletionTokensInternal(a){return Ge(a,i=>this.countStringTokens(i))}setMergeCacheSize(a){this.bytePairEncodingCoreProcessor.setMergeCacheSize(a)}clearMergeCache(){this.bytePairEncodingCoreProcessor.clearMergeCache()}decode(a){return this.bytePairEncodingCoreProcessor.decodeNative(a)}*decodeGenerator(a){let i=this.bytePairEncodingCoreProcessor.decodeNativeGenerator(a),n="";for(let r of i)n+=typeof r=="string"?r:U.decode(r,{stream:!0}),!(n.length===0||ke(n))&&(yield n,n="");n.length>0&&(yield n)}async*decodeAsyncGenerator(a){let i=this.bytePairEncodingCoreProcessor.decodeNativeAsyncIterable(a),n="";for await(let r of i)n+=typeof r=="string"?r:U.decode(r,{stream:!0}),!(n.length===0||ke(n))&&(yield n,n="");n.length>0&&(yield n)}async decodeAsync(a){let i=this.bytePairEncodingCoreProcessor.decodeNativeAsyncIterable(a),n="";for await(let r of i)n+=typeof r=="string"?r:U.decode(r,{stream:!0});return n}estimateCost(a,i=this.modelSpec){if(!i)throw new Error("Model spec must be provided either during initialization or passed in to the method.");if(!i.price_data)throw new Error(`No cost information available for model: ${i.name}`);let n=i.price_data,r={},t=a/1e6;return n.main&&(r.main={input:n.main.input&&n.main.input*t,output:n.main.output&&n.main.output*t,cached_input:n.main.cached_input&&n.main.cached_input*t,cached_output:n.main.cached_output&&n.main.cached_output*t}),n.batch&&(r.batch={input:n.batch.input&&n.batch.input*t,output:n.batch.output&&n.batch.output*t,cached_input:n.batch.cached_input&&n.batch.cached_input*t,cached_output:n.batch.cached_output&&n.batch.cached_output*t}),r}};var ra=["!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~",[161],[162],[163],[164],[165],[166],[167],[168],[169],[170],[171],[172],[174],[175],[176],[177],[178],[179],[180],[181],[182],[183],[184],[185],[186],[187],[188],[189],[190],[191],[192],[193],[194],[195],[196],[197],[198],[199],[200],[201],[202],[203],[204],[205],[206],[207],[208],[209],[210],[211],[212],[213],[214],[215],[216],[217],[218],[219],[220],[221],[222],[223],[224],[225],[226],[227],[228],[229],[230],[231],[232],[233],[234],[235],[236],[237],[238],[239],[240],[241],[242],[243],[244],[245],[246],[247],[248],[249],[250],[251],[252],[253],[254],[255],"\0","","","","","","","\x07","\b"," ",`
|
|
11
11
|
`,"\v","\f","\r","","","","","","","","","","","","","","\x1B","","","",""," ","\x7F",[128],[129],[130],[131],[132],[133],[134],[135],[136],[137],[138],[139],[140],[141],[142],[143],[144],[145],[146],[147],[148],[149],[150],[151],[152],[153],[154],[155],[156],[157],[158],[159],[160],[173]," "," ","in","er"," t"," a","en","on","re"," s","at","or","es"," ","an"," "," d","he"," c"," p","is","ar","it",`
|
|
12
12
|
|
|
13
13
|
`,"al",[224,164],"le","ou"," m"," f"," w"," b","as","ing"," the","ic","et"," o","ion","ed","el"," n","ro","ent",[32,208],"nd","st",[225,131],"\u0430"," l"," in",`;
|
|
@@ -1808,7 +1808,7 @@ ${" ".repeat(a)}}`;default:return"any"}}function Ia(e){let a=["namespace functio
|
|
|
1808
1808
|
|
|
1809
1809
|
`," d\xE9pass","\u0192","\u05E4\u05E7\u05D9\u05D3","nera","\u0E40\u0E21\u0E37\u0E2D\u0E07"," vaya"," particulars"," moreover"," gato"," aner"," Hale","Floating","\u0435\u049B\u0438\u043D",".Math","annual","_gain",".Infrastructure",".ignore"," waits","wk"," dispro","Tin"," anima","\u5B8B","\u0630\u0641"," \u0434\u0435\u0441\u044F\u0442"," moderation","\u622A\u56FE","-match"," promoci\xF3n"," vergeten"," Providence","swiper",'"\u05D9',"amua","winner","BUILD","\u5177\u6709",">';"," bilden"," \u0915\u0941\u0928\u0948"," Sellers","Innen","okin","trat"," sega","-\u0576",".Contact"," equipments","IPA","\u09C7\u09B6\u09A8",">Name","(EXIT"," durchgef\xFChrt"," \u5927\u53D1\u5FEB\u4E09\u5F00\u5956","_adapter"," aaye","\u0CAC\u0CB9\u0CC1\u0CA6\u0CC1","izzato"," demolition"," adem"," \u0C1A\u0C46\u0C02\u0C26\u0C3F\u0C28"," shines"," SECTION"," pade"," lifespan"," \u8FDE"," Hes"," Roles","ASCADE","ngo"," moni","Expansion","Ranking"," \u0BB5\u0B95","veyor"," Sharma"," \u0442\u0438\u0433","(Chat"," SCORE"," pointe"," \u092E\u0928\u094D\u0924"," \u0627\u0644\u062F\u0643\u062A\u0648\u0631"," \u10E2\u10D4\u10E0","\u0C30\u0C4D\u0C1A"," \u043B\u044E\u0431\u043E\u043C"," \u0432\u043E\u0441\u043F\u0430\u043B"," \u0939\u092E\u093E\u0930\u0940"," alimento"," hant"," minist\xE8re"," Ney"," \u0432\u043E\u0437\u0434\u0443\u0445"," Benedict"," advises"," informazioni"," garant\xEDa",":C","kert","etcode","(Enum","\u0440\u0430\u043B\u0430",".DATA","\uFF3F\u8001\u53F8\u673A"," \u0442\u0435\u0430\u0442"," proportional"," \u0A97\u0AAF\u0ACB"," Admir","\u0440\u044F"," t\xF6\xF6t"," \u044F\u043A\u0430\u044F"," \xC9l","st\xE4nde"," dyr","imbali"," siunners","\u09E7\u09E8"," \xE1ra"," \u0645\u0645\u062A","Expiry","addir"," neatly"," \u0411\u0443\u0434"," \u25BA","\u0E32\u0E2B\u0E32\u0E23"," hawa"," liitty"," \u043A\u0430\u043F\u0438\u0442"," aisle","_character"," Yen","\u5341\u5206"," \u0D09\u0D2F","(hr"," ukuth"," Gecko"," considerada"," Seasons","quettes"," certificado","utterstock"," \u0AA4\u0ABE\u0AB2","asarkan","\u0E27\u0E21"," \u0447\u0435\u0442\u0432\u0435\u0440"," \u05E9\u05D4\u05DD"," \u0986\u09DF","\u09C7\u09B8\u09CD\u0995"," onu\u0148"," \u770B"," \u0930\u0916\u093E"," Insight","\u062F\u064A\u0648",'(",",'," biased","\u0941\u0933\u0947","NBA","\u201CAs"," t\xF6rt"," \u0432\u043E\u043A\u0440\u0443\u0433"," Gad",".buf","ampang"," incompet"," \u0D2A\u0D32","isque"," \u6D77\u5357"," chorus","nus"," handbook"," Ner"," Mkuu"," \u0632\u0645\u06CC\u0646\u0647","sce"," lawa","\uD2C0"," incremento","\u03B5\u03B9\u03C4\u03BF\u03C5\u03C1\u03B3"," Risiko"," Nationale"," iwwer",` ).
|
|
1810
1810
|
|
|
1811
|
-
`,"iplina","\u04AF\u04AF\u0445","ignty","tracker"," Absch","bett","adto"," Activation","\u2019l"," conjunt"," mounts","\u9700\u6C42"," Alleg","(binding"," banget",")Math"," metu","\u4E9A\u6D32\u7CBE\u54C1"," \u0438\u043C\u0435\u043D\u0438"," \u043F\u043E\u043C\u043E\u0447\u044C"," convierte"," \u0AA8\u0AB5\u0ABE"," psychologist","\u03C3\u03BF\u03C5\u03BC\u03B5"," mitigation","Deadline","IRS","renia","\u0C41\u0C24\u0C42"," revela"," \u10DB\u10D8\u10DB\u10D3\u10D8\u10DC"," \u0622\u0633\u06CC"," apparaat"," seldom","\u0910"," gland","\u0627\u0644\u0634",";;;"," Primer","ramer"," downtime"," \u05D3\u05D0\u05E8","Chunks","\u0443\u0441\u043E\u0432"," inscription"," kjer","\u0C48\u0C24","\u0111a"," colaboradores"," portfolios","\u093E\u0930\u094D\u091F","\xEComh"," dropout","\u5B59"," daemon"," ocupa","eterangan","uj\u0105c"," dirs"],
|
|
1811
|
+
`,"iplina","\u04AF\u04AF\u0445","ignty","tracker"," Absch","bett","adto"," Activation","\u2019l"," conjunt"," mounts","\u9700\u6C42"," Alleg","(binding"," banget",")Math"," metu","\u4E9A\u6D32\u7CBE\u54C1"," \u0438\u043C\u0435\u043D\u0438"," \u043F\u043E\u043C\u043E\u0447\u044C"," convierte"," \u0AA8\u0AB5\u0ABE"," psychologist","\u03C3\u03BF\u03C5\u03BC\u03B5"," mitigation","Deadline","IRS","renia","\u0C41\u0C24\u0C42"," revela"," \u10DB\u10D8\u10DB\u10D3\u10D8\u10DC"," \u0622\u0633\u06CC"," apparaat"," seldom","\u0910"," gland","\u0627\u0644\u0634",";;;"," Primer","ramer"," downtime"," \u05D3\u05D0\u05E8","Chunks","\u0443\u0441\u043E\u0432"," inscription"," kjer","\u0C48\u0C24","\u0111a"," colaboradores"," portfolios","\u093E\u0930\u094D\u091F","\xEComh"," dropout","\u5B59"," daemon"," ocupa","eterangan","uj\u0105c"," dirs"],ta=[" dew"," \u0441\u0443\u043C\u043C\u0443"," reciente",".?"," Temporary","Hints"," \u05D0\u05B7\u05DC\u05E2"," \u53F0\u6E7E"," asegur\xF3","handlers"," \u0438\u0441\u0435\u043C","(normal"," Webcam","\u0627\u0644\u062A\u0627\u0644\u064A"," Kenny"," \u10E8\u10D4\u10E1\u10D0\u10D1\u10D0\u10DB\u10D8\u10E1"," l\xE4bi","letso","\u6838\u5FC3"," blant"," btw"," \u5C11\u5987"," chew","\u10D0\u10DA\u10D3","\u8BA1\u5212\u7F51","\u2019\xE9cole"," Xana"," zase"," Helena","ivariate","\u0438\u043A\u043E","(Field"," unacceptable"," probabilities","mynd"," \u043F\u043E\u0445\u0443\u0434"," \uD65C\uC6A9","exual"," piloto"," complicado"," svol","enciales"," donating","-engine",`("'`,"OMS","leton","\u0430\u043D\u043A"," \u041D\u0430\u0448"," CLICK","\u0578\u0582\u0584"," \uC54A\uC740","\u05D5\u05E0\u05EA"," \u044E\u043B"," \u0935\u093E\u0939","terminate","\uFF0C\u300C","\u0578\u0582\u0569\u0575\u0578\u0582\u0576\u056B\u0581"," \u05D1\u05E2\u05D5\u05DC\u05DD"," \u0430\u04AD\u044B\u0525"," Investor"," Brace"," erros"," bree","yre","anggan",[233,143]," payouts"," addon","\u0E31\u0E15\u0E23"," kyll\xE4"," POT"," \uD65C\uB3D9"," ukuf","\u0648\u064A\u0646","ibazo"," ])"," Dragons"," REALLY","-shop"," DBG"," \u0930\u093E\u0937\u094D\u091F\u094D\u0930\u0940\u092F"," humain","zyk","aload"," electrons"," \u0641\u0631\u0635","/questions"," \u10DB\u10DD\u10EB","\u0438\u0442\u043E\u0432","ACING"," b\u1EDFi"," per"," overleg"," li\xE9s"," especializada"," siun"," decreto",":http","\u05DB\u05E9\u05D9\u05D5"," Constructs",".IM",`#\r
|
|
1812
1812
|
`," \u0445\u043E\u0442\u044C"," Junk"," gesto"," interdisciplinary","\u1015\u103A","\u9EA6"," \u0531\u0580\u0581\u0561\u056D"," creams","amas\u0131"," Twig","\u043E\u0436\u0434\u0435\u043D\u0438\u0435"," \u043C\u0430\u0433\u0430\u0437\u0438\u043D"," cea"," cemetery",">?","pthread"," zacht","_PERIOD"," pearl","-rel"," \u0628\u0627\u0644\u062D","loge","\u0440\u044B\u0432","=?,","\u0627\u0626\u0647\u0627","Kap"," faig"," \u09AD\u09BE\u09AC","\u0C3E\u0C38\u0C4D",'"testing',"layers"," experi\xEAncias"," monna"," Heel","\u0A30\u0A3E","-manager"," \u0628\u0634\u0623\u0646"," reduzir"," \u0433\u043E\u0432\u043E\u0440\u0438\u0442\u044C","Elig"," dejado","Monitoring"," GTX",".ie","\u3000\u636E","\u0BBF\u0BA9\u0BCD\u0BA9"," serviced"," impeccable","Alice","qb"," concre","-task"," kommune"," \u0441\u0442\u0430\u0432\u043A\u0438","Adapt"," coste","entation"," pares","-breaking"," Tata"," \u0432\u0435\u043B\u0438\u0447"," textual","\u76D1\u542C","-mar"," infatti","ograma","\u0650\u064A"," \u0648\u0693\u0627\u0646\u062F\u06D0","\u0D15\u0D4D\u0D15\u0D3E\u0D30","Looks"," ceann"," americana"," \u043D\u043E\u0432\u043E\u0439","_STORE"," upholstery"," \u0B95\u0BA3"," ethnicity"," \u0AAA\u0ACD\u0AB2","\u05DE\u05E2\u05E8"," candidats","Favorites"," \u0AB5\u0ABF\u0AB5\u0ABF\u0AA7","onstruk","Balancer","blica","varo","\u0432\u044B\u0447\u0430\u0439"," orchestra"," \u0627\u0644\u0646\u062C"," \u09B8\u0982\u09AC\u09BE\u09A6","ilta"," \u09B9\u09AF\u09BC\u09C7\u099B\u09C7","\u03BA\u03C1\u03B1"," Yon","\u05D9\u05D0\u05DC","\xE4tta","characters","appel","-public"," bagaimana","(asset"," kommenden","laag"," comforting"," \u0441\u0432\u0438\u0434\u0435\u0442\u0435\u043B\u044C"," *@","hift","eteilig","act\xE9r","\u06C1\u0648\u0631","aurante","abulous"," cunt"," \u0648\u063A\u064A\u0631\u0647\u0627"," cooled"," abak"," prisoner"," \u043F\u043E\u0441\u0430\u0434"," swings","birds"," D\xFCss"," \u0219","\u10D0\u10E1\u10E2","Infinity"," Sohn","\u0E08\u0E4A\u0E01"," \u09AD\u09C2"," vacancy"," ANG"," \u0627\u0644\u0645\u0642\u062F"," )("," jk"," Muito",".python","\u043E\u0440\u0430\u0442\u0438"," frontier"," vode"," organiseren"," bumps","?page","organic",".cy","\u0E32\u0E22\u0E38","\u200C\u200C","-standing","-variable"," pertenec"," \u0C1F\u0C4D\u0C30","\u053C",`*****
|
|
1813
1813
|
`," kuka"," "," tu\u1ED5i","dro","\u0642\u0627\u0645\u0629","\u8B70","Quota"," Lange","samples","ographers"," \u10DB\u10D7\u10D4\u10DA\u10D8","screens",".drag","-board","leyo"," dagegen"," \u0646\u0642\u0637\u0629","\u0CB2\u0CC7"," \u0434\u0435\u0440\u0436\u0430\u0432"," sosyal"," \u0A38\u0A2E"," sv\xE6rt"," webinars","gard","\u0433\u04E1","ordo"," ghosts"," Heap"," VMware"," \u0627\u062D\u0645\u062F"," \xF3leo"," Beitr\xE4ge","_GO"," \u062A\u0631\u064A\u062F","jc"," \u0643\u062A\u0628"," WK"," Leser","\u30FC\u30D3","otov"," descuento","\uD3ED","\u65E5\u4E0A\u5348"," saad","\u094B\u0938"," yanzu"," Roo"," raster","-written"," (((("," Older"," dnia"," geni\u015F","Hace"," restit"," tasi",' ?>"><?',"\u05D9\u05DE\u05D5\u05EA"," Notebook"," \u0411\u043B\u0430\u0433"," Por\xE9m"," Zusammenhang","_special","_\u5317\u4EACpk"," Dup"," \u044D\u043A\u0438","izzling","ceptors"," supermerc"," congel"," Interpret"," \u0CA6\u0CC7\u0CB6","_WORLD","\u06AA\u0646"," pocas"," Techniques"," bmp"," Prev","atables","\uFF3C(^","estaan"," \uC790\uB3D9"," endere\xE7o"," depan"," \u0441\u043B\u043E\u0432\u0430\u043C"," \u0E17\u0E38\u0E01",".variable","\u0E2B\u0E21\u0E32\u0E22","-------------</"," \u0441\u043D\u0430"," Gr\xE2ce"," \u0645\u0627\u0631\u0633",`));
|
|
1814
1814
|
|
|
@@ -3266,24 +3266,24 @@ ${" ".repeat(a)}}`;default:return"any"}}function Ia(e){let a=["namespace functio
|
|
|
3266
3266
|
`," ffur","-All","Constru","Retrieved"," incr\xEDveis"," \u0438\u043C\u043A\u043E"," foliga"," Balanced","\u1021\u101E"," schlechten"," \u03B1\u03BB\u03BB\u03B1\u03B3"," \u0436\u0430\u0441\u0430\u043F"," S\u01A1n","\u0438\u0440\u0430\u0438","\u10D8\u10DC\u10D4"," milioane","EMU","\u2019\xE9viter"," hyr"," encontre"," hallar"," tablas","_Long","<Cell"," interacted"," figsize"," \u10D6\u10E6"," \u0447\u043E\u0432\u0435\u043A"," Codigo"," dedica\xE7\xE3o"," stolet"," Orten","Philip"," \xE9mission","\u0E32\u0E2B\u0E25\u0E35"," bearbeiten"," mierda","holde","\u0443\u0432\u0430\u0432","<Component"," WPA","\u05E6\u05D9\u05DC\u05D5\u05DD","SSA"," Allies"," B\xE1r","_mer","_SMS"," \u0918\u0942\u092E"," Fixtures"," Bask"," \u5F90"," tradu\xE7\xE3o","blicke"," hammered"," \u0441\u04AF\u043F"," \u0431\u0438\u0433","olu\xE7\xE3o"," electricians","\u0631\u06CC\u0634\u0646"," pitsaaner"," cier"," Receita","\u9EBB\u5C06"," \u0437\u0430\u043A\u043E\u043D\u043E\u0434\u0430\u0442\u0435\u043B\u044C\u0441\u0442\u0432\u0430"," \u10DE\u10D0\u10E1\u10E3\u10EE\u10D8\u10E1\u10DB\u10D2","-operated","\u0D4A\u0D2A\u0D4D\u0D2A\u0D02"," hassles","\u093E\u0924\u0930","\u0430\u043D\u0430\u0433\u0430\u0440\u0430","\u05E0\u05D8\u05E8","Japgolly"," doeleinden"," \u043F\u0435\u0440\u0435\u0439\u0442\u0438"," temsil"," ol\xEDmp"," Spazier"," \u0627\u0644\u0633\u0645\u0627"," pressione"," fiscais","l\u0259rini"," abode"," tantric","()],","rello"," \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044E","\u5FAE\u8F6F\u96C5\u9ED1","\u0633\u0631\u0627\u0626\u064A\u0644\u064A\u0629"," uitzending","flok"," escult"," Cerro"," is\xE6r"," kobiet","uree","\u0C95\u0CCA","encha"," adhesives"," paura","\u30C3\u30D4\u30F3\u30B0","\u0E27\u0E31\u0E22"," names"," slimmer","milk"," \u0A95\u0AB0\u0AA4\u0AC0"," Cim"," \u0441\u0432\u044F\u0437\u0430\u043D","\u200C\u0C28\u0C4D"," Chauff"," vingers","\u0430\u0446\u0430\u0440\u0442"," webcast",".notice"," m\u1EB7c","Passengers"," \u05E4\u05BC\u05E8\u05D0\u05B8\u05D3\u05D5\u05E7\u05D8\u05DF","\u0430\u043C\u0435\u0442\u0440"," VBA"," \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0435\u0442\u0441\u044F",`])));
|
|
3267
3267
|
`," surfers"," \u05DE\u05EA\u05D0\u05D9\u05DD",`')):
|
|
3268
3268
|
`,".apk","\u1EDBm"," \u05D4\u05DE\u05D6"," brincar"," AMOLED"," nate"," ayaan"," phosphorylation"," \u0985\u09AA\u09C7\u0995\u09CD\u09B7"," Eats"," Converse","\u094D\u092F\u0942\u091F\u0930","Traveler","inggi","\u05D5\u05E8\u05D2"," almoh"," \u0625\u0641\u0631\u064A\u0642\u064A\u0627"," Magazin"," Arme","\u0E23\u0E01\u0E34\u0E08"," a\u015Fk","-lines"," \u0627\u0644\u0623\u0645\u0627\u0643\u0646","\u516C\u5E73"," kv\xE4ll"," mlx"," \u092E\u0928\u094D\u0924\u094D\u0930\u0940","\u10D0\u10D5\u10D8\u10D0"," teks"," lumea"," legyen"," zwing"," boost"," J\xFA","\u5F69\u7968\u8BBA\u575B"," \u0434\u044D"," \u043E\u0448\u0438\u0431\u043E\u043A","\u0561\u056F\u0561\u0576\u056B","\u0E24\u0E29\u0E20\u0E32\u0E04\u0E21","ebwa"," tipu"," domini"," Gurgaon","combat"," Resist"," \u0930\u094B\u091C\u0917\u093E\u0930","strategie","\u0A17\u0A40","(locator","MONTH"," atlik"," \uB79C","\u0627\u0644\u0633\u064A"," rzecz"," W\xE4"," deportivos"," Facilit","-able"," evitare"," thong"," \u6D3B","\uBB34\uB8CC"," mace"," Extraordinary","\u0927\u093E"," konflik"," livelihoods"," \u043A\u043E\u043C\u043F\u043E\u043D\u0435\u043D\u0442\u043E\u0432"," kuitenkaan","\u5E78\u8FD0\u98DE\u8247","Corpus"," besch\xE4d"," \u05D3\u05D5\u05D3"," dentant"," nweta"," heath"," \u0936\u0941\u0915\u094D\u0930\u092C\u093E\u0930"," mnemonic",".Filters",`','".$`," \u0905\u0938\u094D\u0924","isite"," asawa","\u5E74\u6708"," gotas"," \u0C2A\u0C28\u0C3F\u0C1A","Dek"," Pact","'agence","fei\xE7o"," B\xF6yle","venteen","notif"," \u0410\u043D\u0434\u0440\u0435\u0439","\u591A\u5E74","mittedly","\u8CA1\u5E03"," \u043A\u043E\u043C\u043F\u0430\u043A\u0442","trk","\u0928\u094D\u0926\u094D\u0930\u0940\u092F"," miesto"," Kait"," \u0CAC\u0CB8"," spec"," Injector"," logarith","entions"," \u0447\u0435\u043B","Collateral"," confes","\u093F\u0939\u0930"," sufri\xF3","CRI"," tuge","urllib"," k\u013C"," verpleeg"," application's","(Constructor","\u09BE\u09B2\u09BE"," vulputate"," \u043E\u043F\u0443\u0445"," Nordrhein","allage","\xEDsimas","ornado","\u0438\u0434\u0435\u0440","m\xE9nyek","Qua"," pelicula","\uC131\uACFC","\u3011-"," hemi"," touristes"," absentee"," Nether",".PAGE"," i\u015Fg\xE4r"," efectivos"," saav"," ","flashdata"," sembler"," ikuku"," \u099F\u09BE\u0987",` \u201D
|
|
3269
|
-
`,"\u5F69\u7968\u5E73\u53F0\u5F00\u6237","\u65C1",".\u0413","uckles"," \u0627\u0644\u062E\u0627\u0631","\u0432\u043E\u043B\u044C"," \u043D\u0435\u0432\u043E\u0437\u043C\u043E\u0436",".gradient"," ebile"," Athlete"," \u0442\u04B1\u0440\u0493\u0430\u043D"," Syrie",".processing"," Consultancy"," thrills","\u0642\u0631\u0627\u0621","(varargin","k\xFCnfte"," \u5F6D","-knit","riedenheit"," t\xE4nka","']//","udies","hacer"," Th\xE9\xE2tre","av\u7535\u5F71"," Armada","-techn","ibris","veli"," razloga","-Hop"," \u05DE\u05D7\u05D3\u05E9"," Bloggers"," controversies"," \u0C1A\u0C30\u0C4D\u0C2F"," \u0D2A\u0D4D\u0D30\u0D2E\u0D41\u0D16","_unc","werfen"," \u043B\u043E\u043C"," \u043F\u043E\u043A\u0443\u043F\u0430\u0442\u0435\u043B\u0435\u0439"," \u0433\u043B\u0430\u0437\u0430\u043C\u0438"," \u05D1\u05E2\u05D5\u05D3"," nanot"," ws"," \u043A\u0435\u0437\u0434\u0435\u0441","):("," Produit","Aircraft","iffen"," patrones"," par\xE2metros","Cursos"," cocos"],
|
|
3270
|
-
`?16:1;n+=Math.max(1,Math.ceil(r.length/t))}return Math.max(1,Math.round(Math.max(i,n)))}function T(e,a){if(!e)return{tokens:0,exact:a.tokenizer!=="heuristic"};if(a.tokenizer==="o200k")try{return{tokens:
|
|
3271
|
-
`),i=e.match(ei)??[],{instruction:n,material:r}=
|
|
3269
|
+
`,"\u5F69\u7968\u5E73\u53F0\u5F00\u6237","\u65C1",".\u0413","uckles"," \u0627\u0644\u062E\u0627\u0631","\u0432\u043E\u043B\u044C"," \u043D\u0435\u0432\u043E\u0437\u043C\u043E\u0436",".gradient"," ebile"," Athlete"," \u0442\u04B1\u0440\u0493\u0430\u043D"," Syrie",".processing"," Consultancy"," thrills","\u0642\u0631\u0627\u0621","(varargin","k\xFCnfte"," \u5F6D","-knit","riedenheit"," t\xE4nka","']//","udies","hacer"," Th\xE9\xE2tre","av\u7535\u5F71"," Armada","-techn","ibris","veli"," razloga","-Hop"," \u05DE\u05D7\u05D3\u05E9"," Bloggers"," controversies"," \u0C1A\u0C30\u0C4D\u0C2F"," \u0D2A\u0D4D\u0D30\u0D2E\u0D41\u0D16","_unc","werfen"," \u043B\u043E\u043C"," \u043F\u043E\u043A\u0443\u043F\u0430\u0442\u0435\u043B\u0435\u0439"," \u0433\u043B\u0430\u0437\u0430\u043C\u0438"," \u05D1\u05E2\u05D5\u05D3"," nanot"," ws"," \u043A\u0435\u0437\u0434\u0435\u0441","):("," Produit","Aircraft","iffen"," patrones"," par\xE2metros","Cursos"," cocos"],sa=ra.concat(ta);ra.length=0;ta.length=0;var Ya=na.getEncodingApi("o200k_base",()=>sa),{decode:Qn,decodeAsyncGenerator:Zn,decodeGenerator:er,encode:ar,encodeGenerator:ir,isWithinTokenLimit:nr,countTokens:oa,encodeChat:rr,encodeChatGenerator:tr,vocabularySize:sr,setMergeCacheSize:or,clearMergeCache:lr,estimateCost:cr}=Ya;var Xa=/[A-Za-z]+|\d+|[^\sA-Za-z\d]|\n[ \t]*/g;function _e(e,a=4){if(!e)return 0;let i=e.length/a,n=0;for(let r of e.match(Xa)??[]){let t=/^[A-Za-z]/.test(r)?6:/^\d/.test(r)?3:r[0]===`
|
|
3270
|
+
`?16:1;n+=Math.max(1,Math.ceil(r.length/t))}return Math.max(1,Math.round(Math.max(i,n)))}function T(e,a){if(!e)return{tokens:0,exact:a.tokenizer!=="heuristic"};if(a.tokenizer==="o200k")try{return{tokens:oa(e),exact:!0}}catch{}return{tokens:_e(e,a.charsPerToken),exact:!1}}var Qa={debugging:[/\b(error|exception|traceback|stack ?trace|crash(es|ed|ing)?|segfault|undefined is not|cannot read propert|null pointer|stack overflow)\b/],coding:[/\b(code|function|method|class|script|refactor|implement|api|endpoint|regex|sql|query|unit tests?|typescript|javascript|python|java|rust|golang|c\+\+|react|component|compile|deploy)\b/],editing:[/\b(proofread|rewrite|rephrase|reword|edit|polish|improve|fix (the )?grammar|make (it|this) (sound|more|less)|tone of)\b/],summarizing:[/\b(summari[sz]e|summary|tl;?dr|key (points|takeaways)|condense|recap|gist)\b/],translation:[/\btranslat(e|ion)\b|\b(in|into) (english|hindi|spanish|french|german|japanese|chinese|arabic|portuguese|italian|korean|russian)\b/],analysis:[/\b(analy[sz]e|analysis|dataset|csv|spreadsheet|table|chart|trend|average|median|correlat|statistics?|metrics?)\b/],brainstorming:[/\b(brainstorm|ideas? for|suggest (some|a few)|come up with|names? for|list of ideas)\b/],writing:[/\b(write|draft|compose|blog|essay|article|email|cover letter|post|story|poem|speech|announcement|outline)\b/],research:[/^(what|why|how|when|where|who|which|is|are|can|does|do|should|explain|compare|tell me)\b/,/\b(explain|difference between|compare|pros and cons|research|sources?)\b/]},Za=/\b(bug|broken|fails?|failing|doesn'?t work|not working|wrong output|fix (this|the|my|it))\b/,la=["debugging","translation","summarizing","editing","analysis","coding","brainstorming","writing","research"],ei=/```[\s\S]*?```|~~~[\s\S]*?~~~/g,Ae=/^\s*(def |class |function |const |let |var |import |from \S+ import|#include|public |private |return\b|if\s*\(|for\s*\(|while\s*\(|\}|\{|<\/?[a-z][\w-]*[ >])|;\s*$/,le=/^\s*(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}|\[\d{2}:\d{2}:\d{2}|\[?(INFO|WARN|WARNING|ERROR|DEBUG|TRACE|FATAL)\]?\b|at .+[(:]\d+|File ".+", line \d+|Traceback \(most recent call last\)|\w+(Error|Exception)(: |$)|Caused by:)/,ai=/^\s*([^,\t\n]+[,\t]){2,}[^,\t\n]+\s*$|^\s*[[{]\s*"\w+"\s*:/,ii=/\b(in|under|within|at most|max(imum)?|no more than|about|around|exactly|only)\s+\d+\s*(words?|sentences?|bullets?|bullet points|lines?|paragraphs?|points?|items?|characters?|chars?|tokens?)\b|\b(\d+|one|two|three|four|five|six|seven|eight|nine|ten)[- ](words?|sentences?|bullets?|bullet points|lines?|paragraphs?|points?|ideas?|items?)\b|\b(brief(ly)?|concise(ly)?|short(ly)?|succinct(ly)?|tl;?dr|one[- ]liner|yes or no|just the (answer|code|diff))\b/,ni=/\b(full|entire|whole|complete)\s+(file|code|script|program|document|text|essay)\b|\brewrite (the )?(whole|entire)\b/;function ri(e,a){let i=e.filter(n=>n.trim());return i.length?i.filter(n=>a.test(n)).length/i.length:0}function Ee(e){let a=e.replace(/^\s+/,""),i=e.length-a.length,n=/\n\s*\n|:\s*\n/.exec(a);if(!n)return{instruction:e,material:""};let r=i+n.index+n[0].length;return{instruction:e.slice(0,r),material:e.slice(r)}}function ne(e){let a=e.split(`
|
|
3271
|
+
`),i=e.match(ei)??[],{instruction:n,material:r}=Ee(e),t=n.toLowerCase().trim(),o={hasCode:i.length>0||ri(a,Ae)>.3,hasLogs:a.filter(d=>le.test(d)).length>=2,hasData:a.filter(d=>ai.test(d)).length>=3,pastedTokens:_e(r),hasLengthLimit:ii.test(e.toLowerCase()),asksForFullOutput:ni.test(t)},s=new Map;for(let d of la){let u=Qa[d],g=u.reduce((p,y)=>p+(y.test(t)?2:0),0);!g&&r&&(g=u.reduce((p,y)=>p+(y.test(r.slice(0,2e3).toLowerCase())?.5:0),0)),s.set(d,g)}(o.hasCode||o.hasLogs)&&Za.test(t)&&s.set("debugging",(s.get("debugging")??0)+2),o.hasLogs&&s.set("debugging",(s.get("debugging")??0)+2),o.hasCode&&s.set("coding",(s.get("coding")??0)+1.5),o.hasData&&s.set("analysis",(s.get("analysis")??0)+1);let l="chat",c=0;for(let d of la){let u=s.get(d)??0;u>c&&(l=d,c=u)}return{task:l,confidence:Math.min(1,c/4),signals:o}}var ca=new Set(["chat","writing","brainstorming","research"]);var ti=[["number",/\b\d+(?:[.,]\d+)*%?/g],["url",/https?:\/\/\S+/g],["code",/`[^`\n]+`/g],["quote",/"[^"\n]{1,200}"|“[^”\n]{1,200}”/g],["negation",/\b(?:not|no|never|none|nothing|nor|without|cannot|can't|don't|doesn't|didn't|won't|wouldn't|shouldn't|isn't|aren't|wasn't|mustn't)\b/gi],["constraint",/\b(?:must|only|exactly|always|avoid|at least|at most|required|mandatory|strictly|unless|except)\b/gi]];function ce(e){let a=new Map;for(let[i,n]of ti)for(let r of e.match(n)??[]){let t=`${i}:${r.toLowerCase()}`;a.set(t,(a.get(t)??0)+1)}return a}function W(e,a,i="count"){let n=ce(e),r=ce(a),t=[];for(let[o,s]of n)(r.get(o)??0)<(i==="count"?s:1)&&t.push(o);return{ok:t.length===0,lost:t}}function Ce(e,a){let i=ce(e),n=ce(a),r={};for(let t of i.keys()){let o=t.slice(0,t.indexOf(":")),[s,l]=r[o]??[0,0];r[o]=[s+1,l+(n.has(t)?1:0)]}return r}var si=new Set("please kindly thank thanks much lot advance hi hello hey there chatgpt claude gemini basically actually really very just simply quite literally totally definitely important worth noting note make sure order regard respect fact purpose event point time near future large number majority able wondering like love want need you your would could will can helpful assistant language model act possible mind think step breath deep take reasoning thought process work before answering answer show explain spite due lets let's the that this with for are was is it's its and".split(" ")),ua=/[a-z][a-z'-]{2,}/g;function ue(e,a){let i=new Set(a.toLowerCase().match(ua)??[]),n=new Set;for(let r of e.toLowerCase().match(ua)??[])!i.has(r)&&!si.has(r)&&n.add(r);return[...n]}var b=(e,a,i,n,r=!1)=>({re:new RegExp(e,"gim"),repl:a,name:i,level:n,reasoningOnly:r}),oi=[b(String.raw`\bdue to the fact that\b`,"because","wordy phrasing","light"),b(String.raw`\bin spite of the fact that\b`,"although","wordy phrasing","light"),b(String.raw`\bin the event that\b`,"if","wordy phrasing","light"),b(String.raw`\bfor the purpose of\b`,"for","wordy phrasing","light"),b(String.raw`\bin order to\b`,"to","wordy phrasing","light"),b(String.raw`\bwith (?:regard|respect) to\b`,"about","wordy phrasing","light"),b(String.raw`\bat this point in time\b`,"now","wordy phrasing","light"),b(String.raw`\bin the near future\b`,"soon","wordy phrasing","light"),b(String.raw`\ba large number of\b`,"many","wordy phrasing","light"),b(String.raw`\bthe majority of\b`,"most","wordy phrasing","light"),b(String.raw`\b(is|are) able to\b`,"can","wordy phrasing","light"),b(String.raw`\bmake sure that\b`,"ensure","wordy phrasing","light"),b(String.raw`\b(?:let'?s|please)?\s*think (?:about (?:this|it) )?step[- ]by[- ]step\b[.,]?\s*`,"","step-by-step (model already reasons)","light",!0),b(String.raw`\btake a deep breath(?: and)?[.,]?\s*`,"","step-by-step (model already reasons)","light",!0),b(String.raw`\b(?:show|explain) your (?:reasoning|thought process|work) (?:step[- ]by[- ]step )?(?:before (?:answering|you answer))[.,]?\s*`,"","step-by-step (model already reasons)","light",!0),b(String.raw`^\s*(?:hi|hello|hey)(?: there)?(?: chatgpt| claude| gemini)?[,!.]?\s*`,"","politeness","balanced"),b(String.raw`(^|[.!?]\s+)(?:could|can|would|will) you (?:please )?(?:kindly )?([^.!?\n]*)\?`,"$1$2.","politeness","balanced"),b(String.raw`(^|[.!?]\s+)(?:could|can|would|will) you (?:please )?(?:kindly )?`,"$1","politeness","balanced"),b(String.raw`\bi would (?:really )?(?:like|love) (?:for )?you to\b\s*`,"","politeness","balanced"),b(String.raw`\bi (?:want|need) you to\b\s*`,"","politeness","balanced"),b(String.raw`\bplease\b,?\s*`,"","politeness","balanced"),b(String.raw`\bkindly\b\s*`,"","politeness","balanced"),b(String.raw`\bthank you(?: so much| very much| a lot)?(?: in advance)?[.!]?`,"","politeness","balanced"),b(String.raw`\bthanks(?: so much| very much| a lot)?(?: in advance)?[.!]?`,"","politeness","balanced"),b(String.raw`\b(?:it is|it's) (?:important|worth noting) (?:to note )?that\b\s*`,"","filler","balanced"),b(String.raw`\b(?:please )?note that\b\s*`,"","filler","balanced"),b(String.raw`\b(?:you are|act as|as) (?:an?|my) (?:ai|large language model|helpful assistant|ai assistant)[,.]?\s*`,"","filler","balanced"),b(String.raw`\bi was wondering if\b\s*`,"","filler","balanced"),b(String.raw`(?<!\bnot )\b(?:basically|actually|really|very|just|simply|quite|literally|totally|definitely)\b\s*`,"","hedges","aggressive"),b(String.raw`\b(?:if possible|if you can|if you don't mind)\b[,.]?\s*`,"","hedges","aggressive")],de={light:0,balanced:1,aggressive:2},li=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/,ci=new RegExp(["`[^`\\n]+`","https?:\\/\\/\\S+","<([A-Za-z][\\w-]*)[^>]*>[\\s\\S]*?<\\/\\1>",'"""[\\s\\S]*?"""'].join("|"),"g");function ui(e){return/^\s*>/.test(e)||/^\s{4,}\S/.test(e)||Ae.test(e)||le.test(e)}function di(e,a){return a&&/^[A-Z]/.test(e)?a[0].toUpperCase()+a.slice(1):a}function mi(e,a,i){for(let n of oi){if(de[n.level]>de[a.level]||n.reasoningOnly&&!a.profile.reasoning)continue;n.re.lastIndex=0;let r=e.replace(n.re,(...t)=>{let o=t[0],s=t.slice(1,-2),l=n.repl.replace(/\$(\d)/g,(d,u)=>s[Number(u)-1]??""),c=n.repl.startsWith("$1")?s[0]??"":"";return c+di(o.slice(c.length),l.slice(c.length))});r!==e&&(i.push(n.name),e=r)}return e}function pi(e,a){let i=new Set;return e.split(`
|
|
3272
3272
|
`).map(n=>n.split(/(?<=[.!?])\s+/).filter(r=>{let t=r.replace(/\W+/g," ").trim().toLowerCase();return t.split(" ").length<4?!0:i.has(t)?(a.push("repeated sentence"),!1):(i.add(t),!0)}).join(" ")).join(`
|
|
3273
3273
|
`)}function gi(e){return e.replace(/[ \t]+/g," ").replace(/ +([,.;:!?])/g,"$1").replace(/([,;:])(?=[.!?])/g,"").replace(/^[ ,;:]+/gm,"").replace(/ +$/gm,"").replace(/\n{3,}/g,`
|
|
3274
3274
|
|
|
3275
|
-
`).replace(/(^|[.!?]\s+)([a-z])/gm,(a,i,n)=>i+n.toUpperCase())}function
|
|
3275
|
+
`).replace(/(^|[.!?]\s+)([a-z])/gm,(a,i,n)=>i+n.toUpperCase())}function da(e,a,i){if(!e.trim())return e;let n=e.slice(0,e.length-e.trimStart().length),r=e.slice(e.trimEnd().length),t=[],o=d=>`\0${t.push(d)-1}\0`,s=e.trim().replace(ci,o);s=s.split(`
|
|
3276
3276
|
`).map(d=>ui(d)?o(d):d).join(`
|
|
3277
|
-
`),de[a.level]>=de.balanced&&(s=pi(s,i));let l=s,c=[];for(s=gi(mi(s,a,c)),W(l,s).ok?i.push(...c):s=l;/\u0000\d+\u0000/.test(s);)s=s.replace(/\u0000(\d+)\u0000/g,(d,u)=>t[Number(u)]);return n+s+r}var
|
|
3278
|
-
`),r=[];for(let s=0;s<n.length;){let l=s,c=0;for(;l<n.length&&
|
|
3279
|
-
`)}function
|
|
3280
|
-
`).filter(i=>i.trim());return a.length>=3&&a.filter(i=>le.test(i)||
|
|
3277
|
+
`),de[a.level]>=de.balanced&&(s=pi(s,i));let l=s,c=[];for(s=gi(mi(s,a,c)),W(l,s).ok?i.push(...c):s=l;/\u0000\d+\u0000/.test(s);)s=s.replace(/\u0000(\d+)\u0000/g,(d,u)=>t[Number(u)]);return n+s+r}var ga=/^\s*at .*(node_modules|node:internal|internal\/|java\.base|java\.|javax\.|jdk\.internal|sun\.|org\.springframework|org\.apache|kotlin\.|scala\.|<anonymous>)|^\s*File ".*(site-packages|dist-packages|lib\/python\d|\/usr\/lib)/,hi=e=>e.replace(/\d{4}-\d{2}-\d{2}[T ][\d:.,]+Z?/g,"<ts>").replace(/\b0x[0-9a-f]+\b/gi,"<hex>").replace(/\d+/g,"#").trim();function ma(e,a,i){let n=e.split(`
|
|
3278
|
+
`),r=[];for(let s=0;s<n.length;){let l=s,c=0;for(;l<n.length&&ga.test(n[l]);)l+=/^\s*File "/.test(n[l])&&l+1<n.length&&/^\s{4,}\S/.test(n[l+1])&&!/^\s*(File|at) /.test(n[l+1])?2:1,c++;if(c>=3){let d=/^\s*/.exec(n[s])[0];r.push(`${d}... ${c} library frames omitted`),i.push("library stack frames"),s=l}else r.push(n[s]),s++}let t=a==="aggressive"?hi:s=>s,o=[];for(let s=0;s<r.length;){let l=s+1;for(;l<r.length&&r[s].trim()&&t(r[l])===t(r[s]);)l++;o.push(r[s]),l-s>=3?(o.push(`... same line repeated ${l-s-1} more times`),i.push("repeated log lines")):o.push(...r.slice(s+1,l)),s=l}return o.join(`
|
|
3279
|
+
`)}function pa(e){let a=e.split(`
|
|
3280
|
+
`).filter(i=>i.trim());return a.length>=3&&a.filter(i=>le.test(i)||ga.test(i)).length/a.length>=.4}function bi(e,a){let i=/^(?:```|~~~)\s*([\w+-]*)/.exec(e)?.[1]?.toLowerCase()??"",n=e.replace(/^(?:```|~~~).*\n?/,"");if(/^(md|markdown|diff|patch|text|txt)$/.test(i)||/"""|'''|`[^`\n]*\n|<<-?\s*['"]?\w+/.test(n))return e;let r=e.replace(/[ \t]+$/gm,"").replace(/\n{4,}/g,`
|
|
3281
3281
|
|
|
3282
|
-
`);return r!==e&&a.push("whitespace in code"),r}function O(e,a){let i=[],{instruction:n}=Ae(e),r=n.length,t=a.task==="debugging"&&a.level!=="light",o=0,s=[];for(let[u,g]of e.split(li).entries()){let p=o;if(o+=g.length,u%2===1){s.push(t&&ma(g)?da(g,a.level,i):a.level==="light"?g:bi(g,i));continue}let y=g.slice(0,Math.max(0,r-p)),h=g.slice(y.length),f=h;t&&ma(h)?f=da(h,a.level,i):la.has(a.task)&&(f=ua(h,a,i)),s.push(ua(y,a,i)+f)}let l=s.join(""),c=T(e,a.profile).tokens,d=T(l,a.profile).tokens;return d>=c||!l.trim()?{text:e,rules:[],originalTokens:c,tokens:c,saved:0}:{text:l,rules:[...new Set(i)],originalTokens:c,tokens:d,saved:c-d}}function Te(e,a="input"){let i=e.pricing;return i?(a==="output"?i.outputPerMTok:a==="cached"?i.cachedInputPerMTok??i.inputPerMTok:i.inputPerMTok)/1e6:null}function K(e,a,i="input"){let n=Te(a,i);return n===null?null:e*n}function F(e,a,i="input"){let n=K(e,a,i);return{tokens:e,usd:n,usdPer1k:n===null?null:n*1e3}}function ga(e,a){let i=Te(a,"input"),n=Te(a,"cached"),r=i===null||n===null?null:e*(i-n);return{tokens:e,usd:r,usdPer1k:r===null?null:r*1e3}}function J(e){if(e==null||!Number.isFinite(e))return"n/a";let a=Math.abs(e),i=e<0?"-":"";if(a===0)return"$0";if(a>=100)return`${i}$${a.toLocaleString("en-US",{maximumFractionDigits:0})}`;if(a>=.1)return`${i}$${a.toFixed(2)}`;let n=Math.min(8,Math.max(2,1-Math.floor(Math.log10(a))));return`${i}$${a.toFixed(n).replace(/(\.\d*?[1-9])0+$/,"$1")}`}var v=e=>e,H={"gpt-astra":v({id:"gpt-astra",label:"GPT-6 Astra",family:"openai",contextWindow:105e4,tokenizer:"heuristic",charsPerToken:4.2,reasoning:!0,pricing:{inputPerMTok:10,outputPerMTok:50}}),"gpt-reasoning":v({id:"gpt-reasoning",label:"GPT (thinking)",family:"openai",contextWindow:196e3,tokenizer:"o200k",charsPerToken:4.2,reasoning:!0,lighterAlternative:"the Instant / non-thinking model",pricing:{inputPerMTok:5,outputPerMTok:30,cachedInputPerMTok:.5}}),gpt:v({id:"gpt",label:"GPT",family:"openai",contextWindow:128e3,tokenizer:"o200k",charsPerToken:4.2,reasoning:!1,pricing:{inputPerMTok:2.5,outputPerMTok:15,cachedInputPerMTok:.25}}),"claude-fable":v({id:"claude-fable",label:"Claude Fable",family:"anthropic",contextWindow:1e6,tokenizer:"heuristic",charsPerToken:3.5,reasoning:!0,notes:["Claude reads XML-style tags well: wrap pasted material in <doc>\u2026</doc> instead of explaining it."],pricing:{inputPerMTok:10,outputPerMTok:50,cachedInputPerMTok:.25}}),"claude-opus":v({id:"claude-opus",label:"Claude Opus",family:"anthropic",contextWindow:2e5,tokenizer:"heuristic",charsPerToken:3.5,reasoning:!1,lighterAlternative:"Sonnet or Haiku",notes:["Claude reads XML-style tags well: wrap pasted material in <doc>\u2026</doc> instead of explaining it."],pricing:{inputPerMTok:4,outputPerMTok:20,cachedInputPerMTok:.2}}),"claude-sonnet":v({id:"claude-sonnet",label:"Claude Sonnet",family:"anthropic",contextWindow:2e5,tokenizer:"heuristic",charsPerToken:3.5,reasoning:!1,lighterAlternative:"Haiku",notes:["Claude reads XML-style tags well: wrap pasted material in <doc>\u2026</doc> instead of explaining it."],pricing:{inputPerMTok:2,outputPerMTok:10,cachedInputPerMTok:.2}}),"claude-haiku":v({id:"claude-haiku",label:"Claude Haiku",family:"anthropic",contextWindow:2e5,tokenizer:"heuristic",charsPerToken:3.5,reasoning:!1,pricing:{inputPerMTok:.1,outputPerMTok:.5,cachedInputPerMTok:.01}}),"gemini-pro":v({id:"gemini-pro",label:"Gemini Pro",family:"google",contextWindow:1e6,tokenizer:"heuristic",charsPerToken:4,reasoning:!0,lighterAlternative:"Flash",pricing:{inputPerMTok:2,outputPerMTok:12,cachedInputPerMTok:.2,longContext:{aboveTokens:2e5,inputPerMTok:4,outputPerMTok:18}}}),"gemini-flash":v({id:"gemini-flash",label:"Gemini Flash",family:"google",contextWindow:1e6,tokenizer:"heuristic",charsPerToken:4,reasoning:!1,pricing:{inputPerMTok:1.5,outputPerMTok:9,cachedInputPerMTok:.15}}),deepseek:v({id:"deepseek",label:"DeepSeek",family:"deepseek",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!1,pricing:{inputPerMTok:.28,outputPerMTok:.42,cachedInputPerMTok:.028}}),"deepseek-reasoning":v({id:"deepseek-reasoning",label:"DeepSeek (thinking)",family:"deepseek",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!0,lighterAlternative:"the non-thinking mode",pricing:{inputPerMTok:.55,outputPerMTok:2.19,cachedInputPerMTok:.14}}),mistral:v({id:"mistral",label:"Mistral",family:"mistral",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!1,pricing:{inputPerMTok:2,outputPerMTok:6}}),grok:v({id:"grok",label:"Grok",family:"xai",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:4,reasoning:!1,pricing:{inputPerMTok:2,outputPerMTok:6}}),llama:v({id:"llama",label:"Llama",family:"other",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.9,reasoning:!1,pricing:{inputPerMTok:.27,outputPerMTok:.85}}),qwen:v({id:"qwen",label:"Qwen",family:"other",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!1,pricing:{inputPerMTok:.4,outputPerMTok:1.2}}),kimi:v({id:"kimi",label:"Kimi",family:"other",contextWindow:256e3,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!1,pricing:{inputPerMTok:.6,outputPerMTok:2.5,cachedInputPerMTok:.15}}),glm:v({id:"glm",label:"GLM",family:"other",contextWindow:2e5,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!1,pricing:{inputPerMTok:.6,outputPerMTok:2.2,cachedInputPerMTok:.11}}),command:v({id:"command",label:"Cohere Command",family:"other",contextWindow:256e3,tokenizer:"heuristic",charsPerToken:4,reasoning:!1,pricing:{inputPerMTok:2.5,outputPerMTok:10}}),sonar:v({id:"sonar",label:"Perplexity Sonar",family:"other",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:4,reasoning:!1,pricing:{inputPerMTok:1,outputPerMTok:1}}),gemma:v({id:"gemma",label:"Gemma",family:"other",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.9,reasoning:!1,pricing:{inputPerMTok:.1,outputPerMTok:.2}}),phi:v({id:"phi",label:"Phi",family:"other",contextWindow:16e3,tokenizer:"heuristic",charsPerToken:3.9,reasoning:!1,pricing:{inputPerMTok:.07,outputPerMTok:.14}}),generic:v({id:"generic",label:"Unknown model",family:"other",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:4,reasoning:!1,pricing:{inputPerMTok:2,outputPerMTok:10}})},ki=[[/\b(fable|mythos)\b/,"claude-fable"],[/\bastra\b|\bgpt[- ]?6\b/,"gpt-astra"],[/\bclaude\b.*\bopus\b|\bopus\b/,"claude-opus"],[/\bsonnet\b/,"claude-sonnet"],[/\bhaiku\b/,"claude-haiku"],[/\b(qwen|qwq)/,"qwen"],[/\b(glm|chatglm|zhipu)\b|\bglm-?\d/,"glm"],[/\b(kimi|moonshot)/,"kimi"],[/\bgemma/,"gemma"],[/\bgemini\b.*\bflash\b|\bflash\b/,"gemini-flash"],[/\bgemini\b.*\b(pro|ultra|deep think)\b|^\s*\d(\.\d)?\s*pro\b|\bdeep think\b/,"gemini-pro"],[/\bdeepseek\b.*\b(r1|reason|think|deepthink)|\bdeepthink\b/,"deepseek-reasoning"],[/\bdeepseek\b/,"deepseek"],[/\b(mistral|le chat|magistral|codestral)\b/,"mistral"],[/\bgrok\b/,"grok"],[/\bllama|codellama/,"llama"],[/\bcommand[- ]?(r|a)\b|\bcohere\b/,"command"],[/\bsonar\b|\bperplexity\b/,"sonar"],[/\bphi-?\d/,"phi"],[/\bo[1-9](-mini|-pro)?\b|\bgpt[- ]?\S*\s*(thinking|pro)\b|\bthinking\b/,"gpt-reasoning"],[/\b(gpt|chatgpt)\b|\bgpt-?\d/,"gpt"],[/\bgemini\b/,"gemini-pro"],[/\bclaude\b/,"claude-sonnet"]];var fi={chatgpt:"gpt",claude:"claude-sonnet",gemini:"gemini-flash",deepseek:"deepseek",mistral:"mistral",grok:"grok",generic:"generic"},vi=[];var _r={...H};function re(e,a="generic"){let i=(e??"").toLowerCase().replace(/\s+/g," ").trim();if(i){for(let[n,r]of vi)if(n.test(i))return H[r];if(a==="gemini"&&/\b(pro|deep think)\b/.test(i))return H["gemini-pro"];if(a==="gemini"&&/\bflash\b/.test(i))return H["gemini-flash"];if(a==="deepseek"&&/\b(deepthink|r1|think)/.test(i))return H["deepseek-reasoning"];for(let[n,r]of ki)if(n.test(i))return H[r]}return H[fi[a]??"generic"]}function ze(e,a){return e===a||W(e,a,"presence").ok&&ue(e,a).length===0}function Re(e){return Array.isArray(e)?e.map(Re):!e||typeof e!="object"?e:Object.fromEntries(Object.entries(e).filter(([a])=>a!=="description").map(([a,i])=>[a,Re(i)]))}function ha(e){let a=[];e.system&&a.push(["system prompt",e.system]);for(let i of e.tools??[]){i.description&&a.push([`tool ${i.name}`,i.description]);let n=(r,t)=>{if(Array.isArray(r))r.forEach((o,s)=>n(o,`${t}[${s}]`));else if(r&&typeof r=="object")for(let[o,s]of Object.entries(r))o==="description"&&typeof s=="string"?a.push([`tool ${i.name} ${t}`,s]):n(s,`${t}.${o}`)};n(i.parameters,"params")}for(let[i,n]of(e.examples??[]).entries())a.push([`example ${i+1}`,n]);return e.prompt&&a.push(["next prompt",e.prompt]),a}var me=(e,a)=>`${e} ${a}${e===1?"":"s"}`;function ba(e,a){let i=[],n=ha(e),r=new Map(ha(a)),t={},o=[];for(let[h,f]of n){let _=r.get(h)??"";for(let[R,[I,he]]of Object.entries(Ce(f,_))){let[C,te]=t[R]??[0,0];t[R]=[C+I,te+he]}W(f,_,"presence").ok||o.push(h)}let s=Object.entries(t).map(([h,[f,_]])=>`${_}/${f} ${h}s`);i.push({name:"Facts and constraints kept",passed:o.length===0,detail:o.length?`Lost in: ${o.join(", ")}`:s.length?`Kept ${s.join(", ")}.`:"No numbers, links, code or constraint words to keep."});let l=[];for(let[h,f]of n){let _=ue(f,r.get(h)??"");_.length&&l.push(`${h}: ${_.join(", ")}`)}i.push({name:"Instructions kept",passed:l.length===0,detail:l.length?`Missing words: ${l.join("; ")}`:`Every content word of ${me(n.length,"text")} is still there; only filler was removed.`});let c=(h=[])=>JSON.stringify(h.map(f=>[f.name,Re(f.parameters??null)])),d=c(e.tools)===c(a.tools);i.push({name:"Tool interface unchanged",passed:d,detail:d?`${me(e.tools?.length??0,"tool")}: same names, parameters, types, required fields and enums.`:"Tool names or parameter schemas differ."});let u=e.messages??[],g=a.messages??[],p=0,y=u.length===g.length&&u.every((h,f)=>{let _=g[f];if(_.role!==h.role)return!1;if(_.content===h.content)return!0;let R=/^\[Same content as message (\d+) above\.\]$/.exec(_.content),I=!!R&&u[Number(R[1])-1]?.content.trim()===h.content.trim();return I&&p++,I});return u.length&&i.push({name:"Conversation unchanged",passed:y,detail:y?`${me(u.length,"message")} in order${p?`; ${me(p,"exact repeat")} replaced by a pointer to the first copy`:", all verbatim"}.`:"Messages were dropped, reordered or edited."}),i.push({name:"Model and examples unchanged",passed:(e.examples?.length??0)===(a.examples?.length??0),detail:"Token Lens never switches the model or drops examples on its own."}),{passed:i.every(h=>h.passed),checks:i}}var S=e=>e.toLocaleString("en-US"),ka=(e,a)=>a?Math.round(e/a*100):0;function fa(e){return`${e.name}
|
|
3282
|
+
`);return r!==e&&a.push("whitespace in code"),r}function O(e,a){let i=[],{instruction:n}=Ee(e),r=n.length,t=a.task==="debugging"&&a.level!=="light",o=0,s=[];for(let[u,g]of e.split(li).entries()){let p=o;if(o+=g.length,u%2===1){s.push(t&&pa(g)?ma(g,a.level,i):a.level==="light"?g:bi(g,i));continue}let y=g.slice(0,Math.max(0,r-p)),h=g.slice(y.length),f=h;t&&pa(h)?f=ma(h,a.level,i):ca.has(a.task)&&(f=da(h,a,i)),s.push(da(y,a,i)+f)}let l=s.join(""),c=T(e,a.profile).tokens,d=T(l,a.profile).tokens;return d>=c||!l.trim()?{text:e,rules:[],originalTokens:c,tokens:c,saved:0}:{text:l,rules:[...new Set(i)],originalTokens:c,tokens:d,saved:c-d}}function Te(e,a="input"){let i=e.pricing;return i?(a==="output"?i.outputPerMTok:a==="cached"?i.cachedInputPerMTok??i.inputPerMTok:i.inputPerMTok)/1e6:null}function K(e,a,i="input"){let n=Te(a,i);return n===null?null:e*n}function F(e,a,i="input"){let n=K(e,a,i);return{tokens:e,usd:n,usdPer1k:n===null?null:n*1e3}}function ha(e,a){let i=Te(a,"input"),n=Te(a,"cached"),r=i===null||n===null?null:e*(i-n);return{tokens:e,usd:r,usdPer1k:r===null?null:r*1e3}}function J(e){if(e==null||!Number.isFinite(e))return"n/a";let a=Math.abs(e),i=e<0?"-":"";if(a===0)return"$0";if(a>=100)return`${i}$${a.toLocaleString("en-US",{maximumFractionDigits:0})}`;if(a>=.1)return`${i}$${a.toFixed(2)}`;let n=Math.min(8,Math.max(2,1-Math.floor(Math.log10(a))));return`${i}$${a.toFixed(n).replace(/(\.\d*?[1-9])0+$/,"$1")}`}var v=e=>e,H={"gpt-astra":v({id:"gpt-astra",label:"GPT-6 Astra",family:"openai",contextWindow:105e4,tokenizer:"heuristic",charsPerToken:4.2,reasoning:!0,pricing:{inputPerMTok:10,outputPerMTok:50}}),"gpt-reasoning":v({id:"gpt-reasoning",label:"GPT (thinking)",family:"openai",contextWindow:196e3,tokenizer:"o200k",charsPerToken:4.2,reasoning:!0,lighterAlternative:"the Instant / non-thinking model",pricing:{inputPerMTok:5,outputPerMTok:30,cachedInputPerMTok:.5}}),gpt:v({id:"gpt",label:"GPT",family:"openai",contextWindow:128e3,tokenizer:"o200k",charsPerToken:4.2,reasoning:!1,pricing:{inputPerMTok:2.5,outputPerMTok:15,cachedInputPerMTok:.25}}),"claude-fable":v({id:"claude-fable",label:"Claude Fable",family:"anthropic",contextWindow:1e6,tokenizer:"heuristic",charsPerToken:3.5,reasoning:!0,notes:["Claude reads XML-style tags well: wrap pasted material in <doc>\u2026</doc> instead of explaining it."],pricing:{inputPerMTok:10,outputPerMTok:50,cachedInputPerMTok:.25}}),"claude-opus":v({id:"claude-opus",label:"Claude Opus",family:"anthropic",contextWindow:2e5,tokenizer:"heuristic",charsPerToken:3.5,reasoning:!1,lighterAlternative:"Sonnet or Haiku",notes:["Claude reads XML-style tags well: wrap pasted material in <doc>\u2026</doc> instead of explaining it."],pricing:{inputPerMTok:4,outputPerMTok:20,cachedInputPerMTok:.2}}),"claude-sonnet":v({id:"claude-sonnet",label:"Claude Sonnet",family:"anthropic",contextWindow:2e5,tokenizer:"heuristic",charsPerToken:3.5,reasoning:!1,lighterAlternative:"Haiku",notes:["Claude reads XML-style tags well: wrap pasted material in <doc>\u2026</doc> instead of explaining it."],pricing:{inputPerMTok:2,outputPerMTok:10,cachedInputPerMTok:.2}}),"claude-haiku":v({id:"claude-haiku",label:"Claude Haiku",family:"anthropic",contextWindow:2e5,tokenizer:"heuristic",charsPerToken:3.5,reasoning:!1,pricing:{inputPerMTok:.1,outputPerMTok:.5,cachedInputPerMTok:.01}}),"gemini-pro":v({id:"gemini-pro",label:"Gemini Pro",family:"google",contextWindow:1e6,tokenizer:"heuristic",charsPerToken:4,reasoning:!0,lighterAlternative:"Flash",pricing:{inputPerMTok:2,outputPerMTok:12,cachedInputPerMTok:.2,longContext:{aboveTokens:2e5,inputPerMTok:4,outputPerMTok:18}}}),"gemini-flash":v({id:"gemini-flash",label:"Gemini Flash",family:"google",contextWindow:1e6,tokenizer:"heuristic",charsPerToken:4,reasoning:!1,pricing:{inputPerMTok:1.5,outputPerMTok:9,cachedInputPerMTok:.15}}),deepseek:v({id:"deepseek",label:"DeepSeek",family:"deepseek",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!1,pricing:{inputPerMTok:.28,outputPerMTok:.42,cachedInputPerMTok:.028}}),"deepseek-reasoning":v({id:"deepseek-reasoning",label:"DeepSeek (thinking)",family:"deepseek",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!0,lighterAlternative:"the non-thinking mode",pricing:{inputPerMTok:.55,outputPerMTok:2.19,cachedInputPerMTok:.14}}),mistral:v({id:"mistral",label:"Mistral",family:"mistral",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!1,pricing:{inputPerMTok:2,outputPerMTok:6}}),grok:v({id:"grok",label:"Grok",family:"xai",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:4,reasoning:!1,pricing:{inputPerMTok:2,outputPerMTok:6}}),llama:v({id:"llama",label:"Llama",family:"other",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.9,reasoning:!1,pricing:{inputPerMTok:.27,outputPerMTok:.85}}),qwen:v({id:"qwen",label:"Qwen",family:"other",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!1,pricing:{inputPerMTok:.4,outputPerMTok:1.2}}),kimi:v({id:"kimi",label:"Kimi",family:"other",contextWindow:256e3,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!1,pricing:{inputPerMTok:.6,outputPerMTok:2.5,cachedInputPerMTok:.15}}),glm:v({id:"glm",label:"GLM",family:"other",contextWindow:2e5,tokenizer:"heuristic",charsPerToken:3.8,reasoning:!1,pricing:{inputPerMTok:.6,outputPerMTok:2.2,cachedInputPerMTok:.11}}),command:v({id:"command",label:"Cohere Command",family:"other",contextWindow:256e3,tokenizer:"heuristic",charsPerToken:4,reasoning:!1,pricing:{inputPerMTok:2.5,outputPerMTok:10}}),sonar:v({id:"sonar",label:"Perplexity Sonar",family:"other",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:4,reasoning:!1,pricing:{inputPerMTok:1,outputPerMTok:1}}),gemma:v({id:"gemma",label:"Gemma",family:"other",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:3.9,reasoning:!1,pricing:{inputPerMTok:.1,outputPerMTok:.2}}),phi:v({id:"phi",label:"Phi",family:"other",contextWindow:16e3,tokenizer:"heuristic",charsPerToken:3.9,reasoning:!1,pricing:{inputPerMTok:.07,outputPerMTok:.14}}),generic:v({id:"generic",label:"Unknown model",family:"other",contextWindow:128e3,tokenizer:"heuristic",charsPerToken:4,reasoning:!1,pricing:{inputPerMTok:2,outputPerMTok:10}})},ki=[[/\b(fable|mythos)\b/,"claude-fable"],[/\bastra\b|\bgpt[- ]?6\b/,"gpt-astra"],[/\bclaude\b.*\bopus\b|\bopus\b/,"claude-opus"],[/\bsonnet\b/,"claude-sonnet"],[/\bhaiku\b/,"claude-haiku"],[/\b(qwen|qwq)/,"qwen"],[/\b(glm|chatglm|zhipu)\b|\bglm-?\d/,"glm"],[/\b(kimi|moonshot)/,"kimi"],[/\bgemma/,"gemma"],[/\bgemini\b.*\bflash\b|\bflash\b/,"gemini-flash"],[/\bgemini\b.*\b(pro|ultra|deep think)\b|^\s*\d(\.\d)?\s*pro\b|\bdeep think\b/,"gemini-pro"],[/\bdeepseek\b.*\b(r1|reason|think|deepthink)|\bdeepthink\b/,"deepseek-reasoning"],[/\bdeepseek\b/,"deepseek"],[/\b(mistral|le chat|magistral|codestral)\b/,"mistral"],[/\bgrok\b/,"grok"],[/\bllama|codellama/,"llama"],[/\bcommand[- ]?(r|a)\b|\bcohere\b/,"command"],[/\bsonar\b|\bperplexity\b/,"sonar"],[/\bphi-?\d/,"phi"],[/\bo[1-9](-mini|-pro)?\b|\bgpt[- ]?\S*\s*(thinking|pro)\b|\bthinking\b/,"gpt-reasoning"],[/\b(gpt|chatgpt)\b|\bgpt-?\d/,"gpt"],[/\bgemini\b/,"gemini-pro"],[/\bclaude\b/,"claude-sonnet"]];var fi={chatgpt:"gpt",claude:"claude-sonnet",gemini:"gemini-flash",deepseek:"deepseek",mistral:"mistral",grok:"grok",generic:"generic"},vi=[];var _r={...H};function re(e,a="generic"){let i=(e??"").toLowerCase().replace(/\s+/g," ").trim();if(i){for(let[n,r]of vi)if(n.test(i))return H[r];if(a==="gemini"&&/\b(pro|deep think)\b/.test(i))return H["gemini-pro"];if(a==="gemini"&&/\bflash\b/.test(i))return H["gemini-flash"];if(a==="deepseek"&&/\b(deepthink|r1|think)/.test(i))return H["deepseek-reasoning"];for(let[n,r]of ki)if(n.test(i))return H[r]}return H[fi[a]??"generic"]}var Pr=5*36e5,Ir=7*864e5;function ze(e,a){return e===a||W(e,a,"presence").ok&&ue(e,a).length===0}function Re(e){return Array.isArray(e)?e.map(Re):!e||typeof e!="object"?e:Object.fromEntries(Object.entries(e).filter(([a])=>a!=="description").map(([a,i])=>[a,Re(i)]))}function ba(e){let a=[];e.system&&a.push(["system prompt",e.system]);for(let i of e.tools??[]){i.description&&a.push([`tool ${i.name}`,i.description]);let n=(r,t)=>{if(Array.isArray(r))r.forEach((o,s)=>n(o,`${t}[${s}]`));else if(r&&typeof r=="object")for(let[o,s]of Object.entries(r))o==="description"&&typeof s=="string"?a.push([`tool ${i.name} ${t}`,s]):n(s,`${t}.${o}`)};n(i.parameters,"params")}for(let[i,n]of(e.examples??[]).entries())a.push([`example ${i+1}`,n]);return e.prompt&&a.push(["next prompt",e.prompt]),a}var me=(e,a)=>`${e} ${a}${e===1?"":"s"}`;function ka(e,a){let i=[],n=ba(e),r=new Map(ba(a)),t={},o=[];for(let[h,f]of n){let _=r.get(h)??"";for(let[R,[I,he]]of Object.entries(Ce(f,_))){let[C,te]=t[R]??[0,0];t[R]=[C+I,te+he]}W(f,_,"presence").ok||o.push(h)}let s=Object.entries(t).map(([h,[f,_]])=>`${_}/${f} ${h}s`);i.push({name:"Facts and constraints kept",passed:o.length===0,detail:o.length?`Lost in: ${o.join(", ")}`:s.length?`Kept ${s.join(", ")}.`:"No numbers, links, code or constraint words to keep."});let l=[];for(let[h,f]of n){let _=ue(f,r.get(h)??"");_.length&&l.push(`${h}: ${_.join(", ")}`)}i.push({name:"Instructions kept",passed:l.length===0,detail:l.length?`Missing words: ${l.join("; ")}`:`Every content word of ${me(n.length,"text")} is still there; only filler was removed.`});let c=(h=[])=>JSON.stringify(h.map(f=>[f.name,Re(f.parameters??null)])),d=c(e.tools)===c(a.tools);i.push({name:"Tool interface unchanged",passed:d,detail:d?`${me(e.tools?.length??0,"tool")}: same names, parameters, types, required fields and enums.`:"Tool names or parameter schemas differ."});let u=e.messages??[],g=a.messages??[],p=0,y=u.length===g.length&&u.every((h,f)=>{let _=g[f];if(_.role!==h.role)return!1;if(_.content===h.content)return!0;let R=/^\[Same content as message (\d+) above\.\]$/.exec(_.content),I=!!R&&u[Number(R[1])-1]?.content.trim()===h.content.trim();return I&&p++,I});return u.length&&i.push({name:"Conversation unchanged",passed:y,detail:y?`${me(u.length,"message")} in order${p?`; ${me(p,"exact repeat")} replaced by a pointer to the first copy`:", all verbatim"}.`:"Messages were dropped, reordered or edited."}),i.push({name:"Model and examples unchanged",passed:(e.examples?.length??0)===(a.examples?.length??0),detail:"Token Lens never switches the model or drops examples on its own."}),{passed:i.every(h=>h.passed),checks:i}}var S=e=>e.toLocaleString("en-US"),fa=(e,a)=>a?Math.round(e/a*100):0;function va(e){return`${e.name}
|
|
3283
3283
|
${e.description??""}
|
|
3284
|
-
${e.parameters?JSON.stringify(e.parameters):""}`}function
|
|
3284
|
+
${e.parameters?JSON.stringify(e.parameters):""}`}function Sa(e,a=[]){if(e&&typeof e=="object")for(let[i,n]of Object.entries(e))i==="description"&&typeof n=="string"?a.push(n):Sa(n,a);return a}function ya(e){let a=(e.description??"").replace(/\s+/g," ").trim().split(/(?<=[.!?])\s/)[0]??"";return a.length>100?`${a.slice(0,97).trimEnd()}...`:a}function yi(e){let a=e.map(n=>`- ${n.name}${ya(n)?`: ${ya(n)}`:""}`).join(`
|
|
3285
3285
|
`),i=e.map(n=>n.name);return{tools:[{name:"get_tool_schema",description:`Get the full definition (description and parameters) of a tool before calling it. Available tools:
|
|
3286
|
-
${a}`,parameters:{type:"object",properties:{tool_name:{type:"string",enum:i}},required:["tool_name"]}},{name:"invoke_tool",description:"Call a tool by name with arguments that match the schema from get_tool_schema.",parameters:{type:"object",properties:{tool_name:{type:"string",enum:i},tool_input:{type:"object"}},required:["tool_name","tool_input"]}}],schemas:Object.fromEntries(e.map(n=>[n.name,n]))}}var wi=8,Si=2e3,_i=/\b\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2})?)?|\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|\b(?:today is|current (?:date|time)|timestamp)\b|\b(?:user|customer|account|session|request)[ _-]?(?:name|id)\s*[:=]/i;function
|
|
3286
|
+
${a}`,parameters:{type:"object",properties:{tool_name:{type:"string",enum:i}},required:["tool_name"]}},{name:"invoke_tool",description:"Call a tool by name with arguments that match the schema from get_tool_schema.",parameters:{type:"object",properties:{tool_name:{type:"string",enum:i},tool_input:{type:"object"}},required:["tool_name","tool_input"]}}],schemas:Object.fromEntries(e.map(n=>[n.name,n]))}}var wi=8,Si=2e3,_i=/\b\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2})?)?|\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b|\b(?:today is|current (?:date|time)|timestamp)\b|\b(?:user|customer|account|session|request)[ _-]?(?:name|id)\s*[:=]/i;function Ai(e){let a=[],i=[],n=!1;for(let t of e.split(`
|
|
3287
3287
|
`))/^\s*```/.test(t)&&(n=!n),(!n&&_i.test(t)?i:a).push(t);return i.length?e.trimEnd().split(`
|
|
3288
3288
|
`).slice(-i.length).join(`
|
|
3289
3289
|
`)===i.join(`
|
|
@@ -3291,9 +3291,9 @@ ${a}`,parameters:{type:"object",properties:{tool_name:{type:"string",enum:i}},re
|
|
|
3291
3291
|
`).trimEnd()}
|
|
3292
3292
|
|
|
3293
3293
|
${i.join(`
|
|
3294
|
-
`)}`,moved:i}:{text:e,moved:i}}var
|
|
3295
|
-
`)),n=i===void 0?{type:"object",properties:{},additionalProperties:!0}:Pe(i),r=n.type==="object"?n:{type:"object",properties:{items:n},required:["items"],additionalProperties:!1},t=a.family==="anthropic"?{tools:[{name:"return_result",description:"Return the result.",input_schema:r,strict:!0}],tool_choice:{type:"tool",name:"return_result"}}:a.family==="google"?{generationConfig:{responseMimeType:"application/json",responseSchema:r}}:{response_format:{type:"json_schema",json_schema:{name:"result",strict:!0,schema:r}}};return{fromExample:i!==void 0,setup:t}}var ya=1024;function pe(e,a){let i=typeof a=="string"?re(a):a,n=m=>m?T(m,i).tokens:0,r=n(e.system),t=(e.tools??[]).map(m=>({tool:m,tokens:n(fa(m))})),o=t.reduce((m,k)=>m+k.tokens,0),s=(e.examples??[]).map(n),l=s.reduce((m,k)=>m+k,0),c=(e.messages??[]).map(m=>({m,tokens:m.tokens??n(m.content)})),d=c.reduce((m,k)=>m+k.tokens,0),u=n(e.prompt),g=r+o+l,p=g+d+u,y=[{area:"system",label:"System prompt",tokens:r},{area:"tools",label:`Tool definitions (${t.length})`,tokens:o},{area:"examples",label:`Examples (${s.length})`,tokens:l},{area:"history",label:`Conversation (${c.length} messages)`,tokens:d},{area:"prompt",label:"Next prompt",tokens:u}].filter(m=>m.tokens>0),h=c.filter(m=>m.m.role==="user").length,f=h?Math.round(d/h):0,_=i.contextWindow-p,R=f>0?Math.max(0,Math.floor(_/f)):null,I=[],he=new Set(["prompt-caching","volatile-prefix"]),C=m=>m.saves>0&&I.push({...m,usd:(he.has(m.id)?ga(m.saves,i):F(m.saves,i)).usd});if(e.system){let m=O(e.system,{profile:i,task:"chat",level:"balanced"});C({id:"system-wording",area:"system",issue:`System prompt is ${S(r)} tokens and is re-sent on every call.`,fix:`Tighten its wording (${m.rules.join(", ")||"filler"}); meaning and constraints are kept.`,risk:"safe",saves:m.saved});let k=Ei(e.system);k.moved.length&&g>=ya&&C({id:"volatile-prefix",area:"system",issue:`The system prompt has ${k.moved.length} line${k.moved.length>1?"s":""} that change between calls (${k.moved.map(w=>`"${w.trim().slice(0,40)}"`).join(", ")}) ahead of the rest, so the provider's discount for a repeated opening can't apply.`,fix:"Move those lines to the end of the system prompt (ready to paste below): same content, so the model reads the same facts, and everything before them is billed at the cached price.",risk:"safe",saves:Math.round(g*.9)})}g>=ya&&(i.family==="anthropic"||i.family==="openai"||i.family==="google")&&C({id:"prompt-caching",area:"system",issue:`${S(g)} tokens of system prompt, tools and examples are identical on every call.`,fix:i.family==="anthropic"?"Mark the end of the tools and system prompt with cache_control so repeat calls read it from cache at a fraction of the price. The saving shown is net of the cached-read price; each cache write (when the cache is cold) costs about 25% extra on those tokens.":i.family==="openai"?"Keep this prefix byte-identical and first in every request; OpenAI caches repeated prefixes automatically and bills them at a discount.":"Use context caching for this prefix so repeat calls don't pay full price for it. The saving shown is net of the cached price, before any cache storage charge.",risk:"safe",saves:Math.round(g*.9)});let te=new Set((e.messages??[]).flatMap(m=>m.toolCalls??[]));for(let{tool:m,tokens:k}of t){let P=[m.description??"",...wa(m.parameters)].filter(Boolean).reduce((E,B)=>E+O(B,{profile:i,task:"chat",level:"balanced"}).saved,0);C({id:`tool-wording:${m.name}`,area:"tools",issue:`Tool "${m.name}" definition is ${S(k)} tokens.`,fix:"Tighten the tool and parameter descriptions; names, types and constraints are kept.",risk:"safe",saves:P})}if(t.length>=wi||t.length>=3&&o>=Si){let k=yi(e.tools??[]).tools.reduce((w,P)=>w+n(fa(P)),0);C({id:"lazy-tools",area:"tools",issue:`${t.length} tool definitions (${S(o)} tokens) are sent in full on every call, whichever tools the call uses.`,fix:`Load tool definitions on demand: send a one-line catalog plus get_tool_schema and invoke_tool (${S(k)} tokens) and return each full definition only when the agent asks for it. Same tools and model; the first use of each tool in a run adds one short lookup.`,risk:"safe",saves:o-k})}if(te.size&&h>=3){let m=t.filter(w=>!te.has(w.tool.name)),k=m.reduce((w,P)=>w+P.tokens,0);m.length&&C({id:"unused-tools",area:"tools",issue:`${m.length} of ${t.length} tools were never called in ${h} turns (${m.map(w=>w.tool.name).join(", ")}).`,fix:"Load them only for the tasks that need them, or merge them into fewer tools.",risk:"review",saves:k})}if(s.length>3||l>Math.max(1500,r)){let m=[...s].sort((k,w)=>k-w).slice(0,Math.min(3,s.length));C({id:"examples",area:"examples",issue:`${s.length} examples take ${S(l)} tokens (${ka(l,p)}% of each call).`,fix:"Keep the 2\u20133 most different examples, or shorten each to the part that shows the format.",risk:"review",saves:l-m.reduce((k,w)=>k+w,0)})}if(c.length){let m=new Map,k=0;c.forEach(({m:E,tokens:B},$)=>{let Me=E.content.trim();B>=200&&m.has(Me)?k+=B-10:m.set(Me,$)}),C({id:"duplicate-history",area:"history",issue:"The same large content appears more than once in the conversation.",fix:"Replace repeats with a pointer to the first copy.",risk:"safe",saves:k});let P=c.filter(E=>E.m.role==="tool").filter(E=>E.tokens>2e3);if(P.length){let E=P.reduce((B,$)=>B+$.tokens,0);C({id:"large-tool-results",area:"history",issue:`${P.length} tool results are over 2,000 tokens (${S(E)} in total, ${ka(E,p)}% of the context) and stay in every later call.`,fix:"Have tools return only the fields the agent uses, paginate, or replace old results with a short summary once used.",risk:"review",saves:Math.round(E*.7)})}if(d>i.contextWindow*.5||R!==null&&R<5||d>4e4){let E=c.slice(-6).reduce((B,$)=>B+$.tokens,0);C({id:"summarize-history",area:"history",issue:`History is ${S(d)} tokens and grows ~${S(f)} per turn${R!==null?`; about ${R} turns until the context is full`:""}.`,fix:"Summarize older turns into a short brief and keep the last few verbatim.",risk:"review",saves:Math.max(0,d-E-400)})}}if(e.prompt){let m=O(e.prompt,{profile:i,task:ne(e.prompt).task,level:"balanced"});C({id:"prompt-wording",area:"prompt",issue:`The next prompt is ${S(u)} tokens.`,fix:`Tighten its wording (${m.rules.join(", ")}); code and pasted material are untouched.`,risk:"safe",saves:m.saved})}let z=i.pricing?.longContext;if(z&&i.pricing&&p>=z.aboveTokens*.85){let m=p>z.aboveTokens,k=p*(z.inputPerMTok-i.pricing.inputPerMTok)/1e6,w=[...y].sort((P,E)=>E.tokens-P.tokens)[0];I.push({id:"price-threshold",area:w?.area??"history",issue:m?`This call is ${S(p)} tokens, over ${S(z.aboveTokens)}, so ${i.label} bills the whole request at $${z.inputPerMTok}/M input instead of $${i.pricing.inputPerMTok}/M (\u2248$${k.toFixed(4)} extra per call).`:`This call is ${S(p)} tokens, ${S(z.aboveTokens-p)} below ${S(z.aboveTokens)}; past that, ${i.label} bills the whole request at $${z.inputPerMTok}/M input instead of $${i.pricing.inputPerMTok}/M.`,fix:`The biggest part is ${w?.label??"the conversation"} (${S(w?.tokens??0)} tokens). Keeping the call under ${S(z.aboveTokens)} (cache or trim it, or start from a handoff brief) avoids the higher rate. Dropping content can change the answer, so check the output before you rely on it.`,risk:"review",saves:m?p-z.aboveTokens:0,usd:m?k:null})}return[e.system,e.prompt,...e.examples??[]].some(m=>m&&Ai.test(m))&&I.push({id:"structured-output",area:"output",issue:"The agent asks for JSON in words, so a reply that doesn't parse costs a retry: the whole call again.",fix:`Turn on the provider's strict JSON mode (setup below, schema ${Ti(e,i).fromExample?"taken from your example":"to fill in"}); every reply then matches the schema and no call is spent on a retry. The instructions stay as they are, so the content asked for is the same; check a few outputs once after switching.`,risk:"review",saves:0,usd:null}),I.sort((m,k)=>k.saves-m.saves),{profile:i,total:p,costPerCall:K(p,i),fixedOverhead:g,breakdown:y,growthPerTurn:f,turnsLeft:R,findings:I}}function Sa(e,a,i="balanced"){let n=pe(e,a),r=n.profile,t=(u,g=ne(u).task)=>{let p=O(u,{profile:r,task:g,level:i}).text;return ze(u,p)?p:u},o=u=>Array.isArray(u)?u.map(o):!u||typeof u!="object"?u:Object.fromEntries(Object.entries(u).map(([g,p])=>[g,g==="description"&&typeof p=="string"?t(p,"chat"):o(p)])),s={...e};if(e.system&&(s.system=t(e.system,"chat")),e.tools&&(s.tools=e.tools.map(u=>({...u,description:u.description===void 0?void 0:t(u.description,"chat"),parameters:o(u.parameters)}))),e.messages){let u=new Map;s.messages=e.messages.map((g,p)=>{let y=g.content.trim(),h=u.get(y);return h!==void 0&&T(y,r).tokens>=200?{...g,content:`[Same content as message ${h+1} above.]`}:(u.set(y,p),g)})}e.prompt&&(s.prompt=t(e.prompt));let l=new Set(["system-wording","duplicate-history","prompt-wording"]);for(let u of n.findings)(l.has(u.id)||u.id.startsWith("tool-wording:"))&&(u.applied=!0);let c=ba(e,s);if(!c.passed){for(let u of n.findings)u.applied=!1;return{spec:e,report:n,before:n.total,after:n.total,savings:F(0,r),verification:c}}let d=pe(s,r).total;return{spec:s,report:n,before:n.total,after:d,savings:F(n.total-d,r),verification:c}}function xi(e){let a={paths:[]};for(let i=0;i<e.length;i++){let n=e[i],r=()=>e[++i];n==="--model"?a.model=r():n==="--base"?a.base=r():n==="--out"?a.out=r():n==="--calls-per-month"?a.callsPerMonth=Number(r()):n==="--fail-above"?a.failAbove=Number(r()):a.paths.push(n)}return a}var Ie=(...e)=>Pi("git",e,{encoding:"utf8",maxBuffer:64<<20,stdio:["ignore","pipe","pipe"]});function Di(){let e=process.env.GITHUB_BASE_REF??process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME;return e?`origin/${e}`:"HEAD~1"}function Ea(e){let a=e?.type==="function"&&e.function?e.function:e;return!a||typeof a.name!="string"?null:{name:a.name,description:a.description,parameters:a.parameters??a.input_schema??a.inputSchema}}function Aa(e,a){if(!e.endsWith(".json"))return{system:a};let i=JSON.parse(a);if(Array.isArray(i))return{tools:i.map(Ea).filter(t=>!!t)};let n=[i.system,i.instructions,i.system_prompt].map(t=>Array.isArray(t)?t.map(o=>o?.text??"").join(`
|
|
3296
|
-
`):t).find(t=>typeof t=="string"),r=Array.isArray(i.tools)?i.tools.map(Ea).filter(t=>!!t):void 0;return{system:n,tools:r,examples:Array.isArray(i.examples)?i.examples.map(String):void 0,messages:Array.isArray(i.messages)?i.messages:void 0,prompt:typeof i.prompt=="string"?i.prompt:void 0}}var M=e=>e.toLocaleString("en-US"),Ni=e=>e>0?`+${M(e)}`:M(e),ge=e=>e===null?"n/a":e>0?`+${J(e)}`:J(e),
|
|
3294
|
+
`)}`,moved:i}:{text:e,moved:i}}var Ei=/\b(?:respond|reply|return|output|answer|format|give)\w*\b[^.\n]{0,60}\bjson\b|\bvalid json\b|\bjson (?:object|format|schema|only)\b/i;function Ci(e){for(let a=0;a<e.length;a++){let i=e[a];if(i!=="{"&&i!=="[")continue;let n=i==="{"?"}":"]",r=0;for(let t=a;t<e.length;t++)if(e[t]===i)r++;else if(e[t]===n&&--r===0){try{let o=JSON.parse(e.slice(a,t+1));if(o&&typeof o=="object")return o}catch{}break}}}function Pe(e){if(Array.isArray(e))return{type:"array",items:e.length?Pe(e[0]):{}};if(e===null)return{type:"null"};if(typeof e=="object"){let a=Object.fromEntries(Object.entries(e).map(([i,n])=>[i,Pe(n)]));return{type:"object",properties:a,required:Object.keys(a),additionalProperties:!1}}return typeof e=="number"?{type:Number.isInteger(e)?"integer":"number"}:typeof e=="boolean"?{type:"boolean"}:{type:"string"}}function Ti(e,a){let i=Ci([e.system,...e.examples??[],e.prompt].filter(Boolean).join(`
|
|
3295
|
+
`)),n=i===void 0?{type:"object",properties:{},additionalProperties:!0}:Pe(i),r=n.type==="object"?n:{type:"object",properties:{items:n},required:["items"],additionalProperties:!1},t=a.family==="anthropic"?{tools:[{name:"return_result",description:"Return the result.",input_schema:r,strict:!0}],tool_choice:{type:"tool",name:"return_result"}}:a.family==="google"?{generationConfig:{responseMimeType:"application/json",responseSchema:r}}:{response_format:{type:"json_schema",json_schema:{name:"result",strict:!0,schema:r}}};return{fromExample:i!==void 0,setup:t}}var wa=1024;function pe(e,a){let i=typeof a=="string"?re(a):a,n=m=>m?T(m,i).tokens:0,r=n(e.system),t=(e.tools??[]).map(m=>({tool:m,tokens:n(va(m))})),o=t.reduce((m,k)=>m+k.tokens,0),s=(e.examples??[]).map(n),l=s.reduce((m,k)=>m+k,0),c=(e.messages??[]).map(m=>({m,tokens:m.tokens??n(m.content)})),d=c.reduce((m,k)=>m+k.tokens,0),u=n(e.prompt),g=r+o+l,p=g+d+u,y=[{area:"system",label:"System prompt",tokens:r},{area:"tools",label:`Tool definitions (${t.length})`,tokens:o},{area:"examples",label:`Examples (${s.length})`,tokens:l},{area:"history",label:`Conversation (${c.length} messages)`,tokens:d},{area:"prompt",label:"Next prompt",tokens:u}].filter(m=>m.tokens>0),h=c.filter(m=>m.m.role==="user").length,f=h?Math.round(d/h):0,_=i.contextWindow-p,R=f>0?Math.max(0,Math.floor(_/f)):null,I=[],he=new Set(["prompt-caching","volatile-prefix"]),C=m=>m.saves>0&&I.push({...m,usd:(he.has(m.id)?ha(m.saves,i):F(m.saves,i)).usd});if(e.system){let m=O(e.system,{profile:i,task:"chat",level:"balanced"});C({id:"system-wording",area:"system",issue:`System prompt is ${S(r)} tokens and is re-sent on every call.`,fix:`Tighten its wording (${m.rules.join(", ")||"filler"}); meaning and constraints are kept.`,risk:"safe",saves:m.saved});let k=Ai(e.system);k.moved.length&&g>=wa&&C({id:"volatile-prefix",area:"system",issue:`The system prompt has ${k.moved.length} line${k.moved.length>1?"s":""} that change between calls (${k.moved.map(w=>`"${w.trim().slice(0,40)}"`).join(", ")}) ahead of the rest, so the provider's discount for a repeated opening can't apply.`,fix:"Move those lines to the end of the system prompt (ready to paste below): same content, so the model reads the same facts, and everything before them is billed at the cached price.",risk:"safe",saves:Math.round(g*.9)})}g>=wa&&(i.family==="anthropic"||i.family==="openai"||i.family==="google")&&C({id:"prompt-caching",area:"system",issue:`${S(g)} tokens of system prompt, tools and examples are identical on every call.`,fix:i.family==="anthropic"?"Mark the end of the tools and system prompt with cache_control so repeat calls read it from cache at a fraction of the price. The saving shown is net of the cached-read price; each cache write (when the cache is cold) costs about 25% extra on those tokens.":i.family==="openai"?"Keep this prefix byte-identical and first in every request; OpenAI caches repeated prefixes automatically and bills them at a discount.":"Use context caching for this prefix so repeat calls don't pay full price for it. The saving shown is net of the cached price, before any cache storage charge.",risk:"safe",saves:Math.round(g*.9)});let te=new Set((e.messages??[]).flatMap(m=>m.toolCalls??[]));for(let{tool:m,tokens:k}of t){let P=[m.description??"",...Sa(m.parameters)].filter(Boolean).reduce((A,B)=>A+O(B,{profile:i,task:"chat",level:"balanced"}).saved,0);C({id:`tool-wording:${m.name}`,area:"tools",issue:`Tool "${m.name}" definition is ${S(k)} tokens.`,fix:"Tighten the tool and parameter descriptions; names, types and constraints are kept.",risk:"safe",saves:P})}if(t.length>=wi||t.length>=3&&o>=Si){let k=yi(e.tools??[]).tools.reduce((w,P)=>w+n(va(P)),0);C({id:"lazy-tools",area:"tools",issue:`${t.length} tool definitions (${S(o)} tokens) are sent in full on every call, whichever tools the call uses.`,fix:`Load tool definitions on demand: send a one-line catalog plus get_tool_schema and invoke_tool (${S(k)} tokens) and return each full definition only when the agent asks for it. Same tools and model; the first use of each tool in a run adds one short lookup.`,risk:"safe",saves:o-k})}if(te.size&&h>=3){let m=t.filter(w=>!te.has(w.tool.name)),k=m.reduce((w,P)=>w+P.tokens,0);m.length&&C({id:"unused-tools",area:"tools",issue:`${m.length} of ${t.length} tools were never called in ${h} turns (${m.map(w=>w.tool.name).join(", ")}).`,fix:"Load them only for the tasks that need them, or merge them into fewer tools.",risk:"review",saves:k})}if(s.length>3||l>Math.max(1500,r)){let m=[...s].sort((k,w)=>k-w).slice(0,Math.min(3,s.length));C({id:"examples",area:"examples",issue:`${s.length} examples take ${S(l)} tokens (${fa(l,p)}% of each call).`,fix:"Keep the 2\u20133 most different examples, or shorten each to the part that shows the format.",risk:"review",saves:l-m.reduce((k,w)=>k+w,0)})}if(c.length){let m=new Map,k=0;c.forEach(({m:A,tokens:B},$)=>{let Me=A.content.trim();B>=200&&m.has(Me)?k+=B-10:m.set(Me,$)}),C({id:"duplicate-history",area:"history",issue:"The same large content appears more than once in the conversation.",fix:"Replace repeats with a pointer to the first copy.",risk:"safe",saves:k});let P=c.filter(A=>A.m.role==="tool").filter(A=>A.tokens>2e3);if(P.length){let A=P.reduce((B,$)=>B+$.tokens,0);C({id:"large-tool-results",area:"history",issue:`${P.length} tool results are over 2,000 tokens (${S(A)} in total, ${fa(A,p)}% of the context) and stay in every later call.`,fix:"Have tools return only the fields the agent uses, paginate, or replace old results with a short summary once used.",risk:"review",saves:Math.round(A*.7)})}if(d>i.contextWindow*.5||R!==null&&R<5||d>4e4){let A=c.slice(-6).reduce((B,$)=>B+$.tokens,0);C({id:"summarize-history",area:"history",issue:`History is ${S(d)} tokens and grows ~${S(f)} per turn${R!==null?`; about ${R} turns until the context is full`:""}.`,fix:"Summarize older turns into a short brief and keep the last few verbatim.",risk:"review",saves:Math.max(0,d-A-400)})}}if(e.prompt){let m=O(e.prompt,{profile:i,task:ne(e.prompt).task,level:"balanced"});C({id:"prompt-wording",area:"prompt",issue:`The next prompt is ${S(u)} tokens.`,fix:`Tighten its wording (${m.rules.join(", ")}); code and pasted material are untouched.`,risk:"safe",saves:m.saved})}let z=i.pricing?.longContext;if(z&&i.pricing&&p>=z.aboveTokens*.85){let m=p>z.aboveTokens,k=p*(z.inputPerMTok-i.pricing.inputPerMTok)/1e6,w=[...y].sort((P,A)=>A.tokens-P.tokens)[0];I.push({id:"price-threshold",area:w?.area??"history",issue:m?`This call is ${S(p)} tokens, over ${S(z.aboveTokens)}, so ${i.label} bills the whole request at $${z.inputPerMTok}/M input instead of $${i.pricing.inputPerMTok}/M (\u2248$${k.toFixed(4)} extra per call).`:`This call is ${S(p)} tokens, ${S(z.aboveTokens-p)} below ${S(z.aboveTokens)}; past that, ${i.label} bills the whole request at $${z.inputPerMTok}/M input instead of $${i.pricing.inputPerMTok}/M.`,fix:`The biggest part is ${w?.label??"the conversation"} (${S(w?.tokens??0)} tokens). Keeping the call under ${S(z.aboveTokens)} (cache or trim it, or start from a handoff brief) avoids the higher rate. Dropping content can change the answer, so check the output before you rely on it.`,risk:"review",saves:m?p-z.aboveTokens:0,usd:m?k:null})}return[e.system,e.prompt,...e.examples??[]].some(m=>m&&Ei.test(m))&&I.push({id:"structured-output",area:"output",issue:"The agent asks for JSON in words, so a reply that doesn't parse costs a retry: the whole call again.",fix:`Turn on the provider's strict JSON mode (setup below, schema ${Ti(e,i).fromExample?"taken from your example":"to fill in"}); every reply then matches the schema and no call is spent on a retry. The instructions stay as they are, so the content asked for is the same; check a few outputs once after switching.`,risk:"review",saves:0,usd:null}),I.sort((m,k)=>k.saves-m.saves),{profile:i,total:p,costPerCall:K(p,i),fixedOverhead:g,breakdown:y,growthPerTurn:f,turnsLeft:R,findings:I}}function _a(e,a,i="balanced"){let n=pe(e,a),r=n.profile,t=(u,g=ne(u).task)=>{let p=O(u,{profile:r,task:g,level:i}).text;return ze(u,p)?p:u},o=u=>Array.isArray(u)?u.map(o):!u||typeof u!="object"?u:Object.fromEntries(Object.entries(u).map(([g,p])=>[g,g==="description"&&typeof p=="string"?t(p,"chat"):o(p)])),s={...e};if(e.system&&(s.system=t(e.system,"chat")),e.tools&&(s.tools=e.tools.map(u=>({...u,description:u.description===void 0?void 0:t(u.description,"chat"),parameters:o(u.parameters)}))),e.messages){let u=new Map;s.messages=e.messages.map((g,p)=>{let y=g.content.trim(),h=u.get(y);return h!==void 0&&T(y,r).tokens>=200?{...g,content:`[Same content as message ${h+1} above.]`}:(u.set(y,p),g)})}e.prompt&&(s.prompt=t(e.prompt));let l=new Set(["system-wording","duplicate-history","prompt-wording"]);for(let u of n.findings)(l.has(u.id)||u.id.startsWith("tool-wording:"))&&(u.applied=!0);let c=ka(e,s);if(!c.passed){for(let u of n.findings)u.applied=!1;return{spec:e,report:n,before:n.total,after:n.total,savings:F(0,r),verification:c}}let d=pe(s,r).total;return{spec:s,report:n,before:n.total,after:d,savings:F(n.total-d,r),verification:c}}function xi(e){let a={paths:[]};for(let i=0;i<e.length;i++){let n=e[i],r=()=>e[++i];n==="--model"?a.model=r():n==="--base"?a.base=r():n==="--out"?a.out=r():n==="--calls-per-month"?a.callsPerMonth=Number(r()):n==="--fail-above"?a.failAbove=Number(r()):a.paths.push(n)}return a}var Ie=(...e)=>Pi("git",e,{encoding:"utf8",maxBuffer:64<<20,stdio:["ignore","pipe","pipe"]});function Di(){let e=process.env.GITHUB_BASE_REF??process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME;return e?`origin/${e}`:"HEAD~1"}function Ea(e){let a=e?.type==="function"&&e.function?e.function:e;return!a||typeof a.name!="string"?null:{name:a.name,description:a.description,parameters:a.parameters??a.input_schema??a.inputSchema}}function Ca(e,a){if(!e.endsWith(".json"))return{system:a};let i=JSON.parse(a);if(Array.isArray(i))return{tools:i.map(Ea).filter(t=>!!t)};let n=[i.system,i.instructions,i.system_prompt].map(t=>Array.isArray(t)?t.map(o=>o?.text??"").join(`
|
|
3296
|
+
`):t).find(t=>typeof t=="string"),r=Array.isArray(i.tools)?i.tools.map(Ea).filter(t=>!!t):void 0;return{system:n,tools:r,examples:Array.isArray(i.examples)?i.examples.map(String):void 0,messages:Array.isArray(i.messages)?i.messages:void 0,prompt:typeof i.prompt=="string"?i.prompt:void 0}}var M=e=>e.toLocaleString("en-US"),Ni=e=>e>0?`+${M(e)}`:M(e),ge=e=>e===null?"n/a":e>0?`+${J(e)}`:J(e),Ta=(e,a)=>e===null?null:e*a;function Li(e,a,i,n){let r=d=>{if(d===null)return{tokens:0,usd:0};let u=pe(Ca(e,d),n);return{tokens:u.total,usd:u.costPerCall}},t=r(a),o=r(i),s=0,l=0,c=[];if(i!==null){let d=_a(Ca(e,i),n);s=d.savings.tokens,l=d.savings.usd;for(let u of d.report.findings.slice(0,3))u.saves>0&&c.push(`${u.issue} ${u.fix} (saves ${M(u.saves)} tokens${u.usd?`, ${J(u.usd)}`:""} per call${u.risk==="review"?", review first":""})`)}return{path:e,before:t.tokens,after:o.tokens,usdBefore:t.usd,usdAfter:o.usd,canSave:s,canSaveUsd:l,fixes:c}}function Oi(e,a,i){let n=e.reduce((s,l)=>s+l.after-l.before,0),r=e.some(s=>s.usdAfter===null||s.usdBefore===null)?null:e.reduce((s,l)=>s+l.usdAfter-l.usdBefore,0),t=["### Token Lens: agent cost check","",`This change ${n>0?"adds":n<0?"removes":"keeps"} **${M(Math.abs(n))} input tokens per call** (${ge(r)} per call, ${ge(Ta(r,1e3))} per 1,000 calls`+(i?`, ${ge(Ta(r,i))} per month at ${M(i)} calls`:"")+`) on ${a.label}.`,"","| File | Before | After | Change | Per call | Same output, fewer tokens |","| --- | ---: | ---: | ---: | ---: | ---: |"];for(let s of e){let l=s.usdAfter===null||s.usdBefore===null?null:s.usdAfter-s.usdBefore;t.push(`| \`${s.path}\` | ${M(s.before)} | ${M(s.after)} | ${Ni(s.after-s.before)} | ${ge(l)} | `+(s.canSave?`\u2212${M(s.canSave)} (${J(s.canSaveUsd)})`:"\u2013")+" |")}let o=e.filter(s=>s.fixes.length);if(o.length){t.push("","**Where to trim**","");for(let s of o)for(let l of s.fixes)t.push(`- \`${s.path}\`: ${l}`)}return t.push("",`<sub>Input tokens re-sent on every call (system prompt, tools, examples), counted for ${a.label} at ${J(a.pricing?a.pricing.inputPerMTok:null)} per 1M input tokens. "Same output" fixes keep every fact, number, constraint and tool interface. Computed in this CI job; nothing was sent anywhere. [Token Lens](https://www.npmjs.com/package/@kunal_dutt/token-lens)</sub>`),t.join(`
|
|
3297
3297
|
`)+`
|
|
3298
|
-
`}function
|
|
3299
|
-
`).filter(Boolean),t=Ie("rev-parse","--show-toplevel").trim();if(!r.length)return console.log("token-lens: no agent files changed."),0;let o=r.map(c=>{let d=null;try{d=Ie("show",`${n}:${c}`)}catch{}let u=Ii(
|
|
3298
|
+
`}function Kt(e){let a=xi(e);if(!a.model||!a.paths.length)return console.error("usage: token-lens check-agent --model <the model your agent uses> [--base <ref>] [--out file.md] <pathspec>..."),2;let i=re(a.model),n=a.base??Di(),r=Ie("diff","--name-only","--diff-filter=ACMRD",n,"--",...a.paths.map(c=>`:(glob)${c}`)).split(`
|
|
3299
|
+
`).filter(Boolean),t=Ie("rev-parse","--show-toplevel").trim();if(!r.length)return console.log("token-lens: no agent files changed."),0;let o=r.map(c=>{let d=null;try{d=Ie("show",`${n}:${c}`)}catch{}let u=Ii(Aa(t,c))?Mi(Aa(t,c),"utf8"):null;try{return Li(c,d,u,i)}catch(g){return console.error(`token-lens: skipped ${c}: ${g.message}`),null}}).filter(c=>!!c),s=Oi(o,i,a.callsPerMonth);a.out?ji(a.out,s):process.stdout.write(s);let l=o.reduce((c,d)=>c+d.after-d.before,0);return a.failAbove!==void 0&&l>a.failAbove?(console.error(`token-lens: this change adds ${M(l)} tokens per call, above --fail-above ${M(a.failAbove)}.`),1):0}export{Li as checkFile,Kt as main,Ca as parseSpec,Oi as render};
|