@@ -1330,41 +1330,66 @@ export function acpToolCallDiffPatch(content: unknown): string | undefined {
13301330 . join ( "\n" ) ;
13311331}
13321332
1333- function pathFromToolCall ( toolCall : AcpToolCallState ) : string | undefined {
1333+ function resolvedPathInfo (
1334+ toolCall : AcpToolCallState ,
1335+ ) : { readonly path : string ; readonly fromQuery : boolean } | undefined {
13341336 const locations = toolCall . data . locations ;
13351337 if ( Array . isArray ( locations ) ) {
13361338 for ( const location of locations ) {
13371339 const path = unknownRecord ( location ) ?. path ;
13381340 if ( typeof path === "string" && path . trim ( ) . length > 0 ) {
1339- return path . trim ( ) ;
1341+ return { path : path . trim ( ) , fromQuery : false } ;
13401342 }
13411343 }
13421344 }
13431345 const rawInput = unknownRecord ( toolCall . data . rawInput ) ;
1344- for ( const key of [ "path" , "filePath" , "file_path" , "url" , "query" , "pattern" ] ) {
1346+ for ( const key of [ "path" , "filePath" , "file_path" , "url" ] ) {
1347+ const candidate = rawInput ?. [ key ] ;
1348+ if ( typeof candidate === "string" && candidate . trim ( ) . length > 0 ) {
1349+ return { path : candidate . trim ( ) , fromQuery : false } ;
1350+ }
1351+ }
1352+ for ( const key of [ "query" , "pattern" ] ) {
13451353 const candidate = rawInput ?. [ key ] ;
13461354 if ( typeof candidate === "string" && candidate . trim ( ) . length > 0 ) {
1347- return candidate . trim ( ) ;
1355+ return { path : candidate . trim ( ) , fromQuery : true } ;
13481356 }
13491357 }
13501358 return undefined ;
13511359}
13521360
1361+ function pathFromToolCall ( toolCall : AcpToolCallState ) : string | undefined {
1362+ return resolvedPathInfo ( toolCall ) ?. path ;
1363+ }
1364+
13531365function acpBackendWebSearch (
13541366 rawInput : Record < string , unknown > | undefined ,
1355- rawOutput : Record < string , unknown > | undefined ,
1367+ rawOutput : unknown ,
1368+ title ?: string | null ,
13561369) :
13571370 | { readonly query : string | undefined ; readonly results : OrchestrationV2WebSearchResult [ ] }
13581371 | undefined {
13591372 const variant = typeof rawInput ?. variant === "string" ? rawInput . variant . toLowerCase ( ) : "" ;
1360- const action = unknownRecord ( rawOutput ?. action ) ;
1361- if ( variant !== "xsearch" && variant !== "websearch" && action ?. type !== "search" ) {
1373+ const rawOutputRecord = unknownRecord ( rawOutput ) ;
1374+ const action = unknownRecord ( rawOutputRecord ?. action ) ;
1375+ const isWebSearchTitle =
1376+ / ^ \s * (?: w e b s e a r c h | s e a r c h t h e w e b | (?: r u n (?: n i n g ) ? \s + ) ? (?: w e b _ s e a r c h | s e a r c h _ w e b ) \s * $ ) / iu. test (
1377+ title ?? "" ,
1378+ ) ;
1379+ const isWebSearchVariant = [
1380+ "xsearch" ,
1381+ "websearch" ,
1382+ "web_search" ,
1383+ "search_web" ,
1384+ "web-search" ,
1385+ ] . includes ( variant ) ;
1386+ if ( ! isWebSearchVariant && action ?. type !== "search" && ! isWebSearchTitle ) {
13621387 return undefined ;
13631388 }
13641389 let args : Record < string , unknown > | undefined ;
1365- if ( typeof rawOutput ?. input === "string" ) {
1390+ if ( typeof rawOutputRecord ?. input === "string" ) {
13661391 try {
1367- args = unknownRecord ( JSON . parse ( rawOutput . input ) ) ;
1392+ args = unknownRecord ( JSON . parse ( rawOutputRecord . input ) ) ;
13681393 } catch {
13691394 args = undefined ;
13701395 }
@@ -1373,17 +1398,46 @@ function acpBackendWebSearch(
13731398 . filter ( ( [ , value ] ) => typeof value === "string" || typeof value === "number" )
13741399 . map ( ( [ key , value ] ) => `${ key } : ${ value } ` )
13751400 . join ( ", " ) ;
1376- const query = [ action ?. query , args ?. query , argsText ]
1401+ const query = [
1402+ action ?. query ,
1403+ args ?. query ,
1404+ rawInput ?. query ,
1405+ rawInput ?. search_query ,
1406+ rawInput ?. q ,
1407+ argsText ,
1408+ ]
13771409 . find ( ( value ) : value is string => typeof value === "string" && value . trim ( ) . length > 0 )
13781410 ?. trim ( ) ;
13791411 const urls = new Set < string > ( ) ;
13801412 for ( const source of Array . isArray ( action ?. sources ) ? action . sources : [ ] ) {
13811413 const url = unknownRecord ( source ) ?. url ;
13821414 if ( typeof url === "string" && url . trim ( ) . length > 0 ) urls . add ( url . trim ( ) ) ;
13831415 }
1416+ if ( urls . size === 0 ) {
1417+ for ( const match of textFromUnknown ( rawOutput ) ?. matchAll ( / h t t p s ? : \/ \/ [ ^ \s < > " ] + / gu) ?? [ ] ) {
1418+ urls . add ( trimCitationUrl ( match [ 0 ] ) ) ;
1419+ }
1420+ }
13841421 return { query, results : [ ...urls ] . map ( ( url ) => ( { url } ) ) } ;
13851422}
13861423
1424+ // Prose citations end in punctuation or a closing bracket that is not part of the URL.
1425+ function trimCitationUrl ( raw : string ) : string {
1426+ let url = raw ;
1427+ for ( ; ; ) {
1428+ const trimmed = url . replace ( / [ . , ; : ] + $ / u, "" ) ;
1429+ const close = trimmed . at ( - 1 ) ;
1430+ const open = close === ")" ? "(" : close === "]" ? "[" : undefined ;
1431+ if ( open && close && trimmed . split ( open ) . length < trimmed . split ( close ) . length ) {
1432+ url = trimmed . slice ( 0 , - 1 ) ;
1433+ } else if ( trimmed === url ) {
1434+ return url ;
1435+ } else {
1436+ url = trimmed ;
1437+ }
1438+ }
1439+ }
1440+
13871441function providerRequestKind ( kind : string | "unknown" ) : ProviderRequestKind {
13881442 switch ( kind ) {
13891443 case "execute" :
@@ -4579,12 +4633,19 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
45794633 } ;
45804634 break ;
45814635 case "search" : {
4582- const backendSearch = acpBackendWebSearch ( rawInputRecord , rawOutputRecord ) ;
4636+ const backendSearch = acpBackendWebSearch (
4637+ rawInputRecord ,
4638+ rawOutput ,
4639+ typeof toolCall . data . title === "string" ? toolCall . data . title : title ,
4640+ ) ;
45834641 if ( backendSearch !== undefined ) {
4584- const label = nonEmptyText ( toolCall . data . title , title ?? "Web search" ) . replace (
4585- / : \s * $ / u,
4586- "" ,
4587- ) ;
4642+ const label = nonEmptyText ( toolCall . data . title , title ?? "Web search" )
4643+ . replace ( / : \s * $ / u, "" )
4644+ // Antigravity titles the call "Running search_web".
4645+ . replace (
4646+ / ^ \s * (?: r u n (?: n i n g ) ? \s + ) ? (?: w e b _ s e a r c h | s e a r c h _ w e b ) \s * $ / iu,
4647+ "Web search" ,
4648+ ) ;
45884649 turnItem = {
45894650 ...base ,
45904651 title :
@@ -4601,6 +4662,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
46014662 } ;
46024663 break ;
46034664 }
4665+ const pathIsQuery = resolvedPathInfo ( toolCall ) ?. fromQuery === true ;
46044666 turnItem = {
46054667 ...base ,
46064668 title :
@@ -4611,7 +4673,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
46114673 } ) ?? title ,
46124674 type : "file_search" ,
46134675 ...( path === undefined ? { } : { pattern : path } ) ,
4614- ...( path === undefined
4676+ ...( path === undefined ||
4677+ ( pathIsQuery && textFromUnknown ( rawOutput ) === undefined )
46154678 ? { }
46164679 : {
46174680 results : [
0 commit comments