@@ -3,7 +3,6 @@ import { encode } from 'gpt-tokenizer'
33
44/**
55 * Estimates token counts for a batch of texts using gpt-tokenizer.
6- * TODO: ensure we aren't falling back to catch branch
76 */
87function estimateTokensBatch ( texts : string [ ] ) : number [ ] {
98 try {
@@ -15,7 +14,6 @@ function estimateTokensBatch(texts: string[]): number[] {
1514
1615/**
1716 * Calculates approximate tokens saved by pruning the given tool call IDs.
18- * Uses pre-fetched messages to avoid duplicate API calls.
1917 * TODO: Make it count message content that are not tool outputs. Currently it ONLY covers tool outputs and errors
2018 */
2119export const calculateTokensSaved = (
@@ -57,9 +55,6 @@ export function formatTokenCount(tokens: number): string {
5755 return tokens . toString ( ) + ' tokens'
5856}
5957
60- /**
61- * Checks if a session is a subagent session by looking for a parentID.
62- */
6358export async function isSubAgentSession ( client : any , sessionID : string ) : Promise < boolean > {
6459 try {
6560 const result = await client . session . get ( { path : { id : sessionID } } )
@@ -68,47 +63,3 @@ export async function isSubAgentSession(client: any, sessionID: string): Promise
6863 return false
6964 }
7065}
71-
72- /**
73- * Finds the current agent from messages by scanning backward for user messages.
74- */
75- export function findCurrentAgent ( messages : any [ ] ) : string | undefined {
76- for ( let i = messages . length - 1 ; i >= 0 ; i -- ) {
77- const msg = messages [ i ]
78- const info = msg . info
79- if ( info ?. role === 'user' ) {
80- return info . agent || 'build'
81- }
82- }
83- return undefined
84- }
85-
86- /**
87- * Builds a list of tool call IDs from messages.
88- */
89- export function buildToolIdList ( messages : WithParts [ ] ) : string [ ] {
90- const toolIds : string [ ] = [ ]
91- for ( const msg of messages ) {
92- if ( msg . parts ) {
93- for ( const part of msg . parts ) {
94- if ( part . type === 'tool' && part . callID && part . tool ) {
95- toolIds . push ( part . callID )
96- }
97- }
98- }
99- }
100- return toolIds
101- }
102-
103- /**
104- * Prunes numeric tool IDs to valid tool call IDs based on the provided tool ID list.
105- */
106- export function getPruneToolIds ( numericToolIds : number [ ] , toolIdList : string [ ] ) : string [ ] {
107- const pruneToolIds : string [ ] = [ ]
108- for ( const index of numericToolIds ) {
109- if ( ! isNaN ( index ) && index >= 0 && index < toolIdList . length ) {
110- pruneToolIds . push ( toolIdList [ index ] )
111- }
112- }
113- return pruneToolIds
114- }
0 commit comments