@adport/mcp 0.12.0 → 0.12.2

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/dist/bin.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  assembleRuntime,
4
4
  runStdioServer
5
- } from "./chunk-FKKOEMUR.js";
5
+ } from "./chunk-LLAXR25X.js";
6
6
 
7
7
  // src/bin.ts
8
8
  var includeRawTools = process.argv.includes("--raw-api-tools");
@@ -22,7 +22,7 @@ import { createOpenAIModule } from "@adport/provider-openai";
22
22
  // package.json
23
23
  var package_default = {
24
24
  name: "@adport/mcp",
25
- version: "0.12.0",
25
+ version: "0.12.2",
26
26
  description: "adport MCP server \u2014 the open control plane for paid media",
27
27
  license: "Apache-2.0",
28
28
  type: "module",
@@ -438,8 +438,192 @@ var TREND_UI_SCRIPT = String.raw`
438
438
  }
439
439
  `;
440
440
 
441
+ // src/record-collection-ui.ts
442
+ var RECORD_COLLECTION_STYLES = String.raw`
443
+ .collection-heading { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:.65rem 1rem; margin:.35rem 0 .85rem }
444
+ .collection-heading .operation-heading { margin:0 }
445
+ .collection-filter { min-width:0; width:12rem; max-width:100%; padding:.45rem .65rem; border:1px solid var(--line); border-radius:.5rem; background:var(--soft); color:var(--ink); font:inherit; font-size:.8rem }
446
+ .collection-filter::placeholder { color:var(--muted) }
447
+ .collection-filter:focus-visible,.collection-scroll:focus-visible { outline:2px solid var(--orange); outline-offset:2px }
448
+ .collection-scroll { overflow:auto; max-height:24rem; scrollbar-width:thin; border:1px solid var(--line); border-radius:.65rem }
449
+ .collection-scroll .workflow-table { font-size:.8125rem; line-height:1.4; font-variant-numeric:tabular-nums }
450
+ .collection-scroll .workflow-table :is(td,th) { padding:.48rem .7rem }
451
+ .collection-scroll .workflow-table thead th { background:var(--soft); font-size:.75rem; font-weight:600 }
452
+ .collection-scroll .workflow-table tbody th { font-weight:600 }
453
+ .collection-scroll .workflow-table tbody tr:last-child > * { border-bottom:0 }
454
+ .collection-scroll .workflow-table tr[hidden] { display:none }
455
+ @media (pointer:coarse) { .collection-filter { min-height:44px; font-size:1rem } }
456
+ @media (max-width:480px) {
457
+ .collection-filter { flex:1 1 9rem }
458
+ .collection-scroll .workflow-table:not(.workflow-stack) :is(td,th) { padding:.45rem .5rem }
459
+ .collection-scroll .workflow-stack tbody :is(td,th) { padding:.2rem .65rem }
460
+ .collection-scroll .workflow-stack tbody th { display:block }
461
+ .collection-scroll .workflow-stack tbody th .workflow-cell-label { display:none }
462
+ }
463
+ `;
464
+ var RECORD_COLLECTION_UI = String.raw`
465
+ function recordLabel(path) {
466
+ const words = human(path.replace(/([A-Z]+)([A-Z][a-z])/g,'$1 $2')).toLowerCase();
467
+ return human(words).replace(/\b(?:id|url|sku|iso)\b/gi, word => word.toUpperCase());
468
+ }
469
+
470
+ function recordLeaf(path) { return recordLabel(path.split('.').at(-1)).toLowerCase(); }
471
+
472
+ function recordVisibleFields(row) {
473
+ return dataFields(row).filter(({label}) =>
474
+ !/(?:hash|token|secret|password|authorization|credential|pending operation|snapshot|resource receipt|preview url|preview cover url|logo url|pixel code)/i.test(label) &&
475
+ !/^(?:notes?|actions)$/i.test(label));
476
+ }
477
+
478
+ const recordRank = {name:0, qualifiedName:1, value:2, code:3, other:4, id:5, resource:6};
479
+ function recordFieldPriority(path) {
480
+ const leaf = recordLeaf(path);
481
+ if (/^(?:name|display name|descriptive name|title|label|search term|keyword(?: text)?)$/.test(leaf) ||
482
+ (leaf === 'text' && /keyword/i.test(path))) return recordRank.name;
483
+ if (leaf === 'resource name') return recordRank.resource;
484
+ if (/ name$/.test(leaf)) return recordRank.qualifiedName;
485
+ if (leaf === 'value') return recordRank.value;
486
+ if (/(?:^| )code$/.test(leaf)) return recordRank.code;
487
+ if (/(?:^| )id$/.test(leaf)) return recordRank.id;
488
+ return recordRank.other;
489
+ }
490
+
491
+ // Use the shortest unambiguous suffix, e.g. "Name" or "Campaign name" and "Ad group name".
492
+ function recordColumnLabels(paths) {
493
+ const parts = paths.map(path => path.split('.'));
494
+ return new Map(paths.map((path, i) => {
495
+ let depth = 1;
496
+ const label = () => recordLabel(parts[i].slice(-depth).join(' '));
497
+ while (depth < parts[i].length && parts.some((other, j) =>
498
+ i !== j && recordLabel(other.slice(-depth).join(' ')) === label())) depth++;
499
+ return [path, label()];
500
+ }));
501
+ }
502
+
503
+ function recordCollection(rows, meta, total) {
504
+ // A provider cursor may return a different projection on the next page.
505
+ // Its incremental cards keep their identity, focus and scroll position.
506
+ if (!rows.length || (rows.length === 1 && meta.tool !== 'google_gaql') || meta.pagination) return null;
507
+ const columns = new Map(), values = [];
508
+ for (const row of rows) {
509
+ if (!object(row) || (row.provider && row.provider !== meta.provider) || (providerSvg[row.platform] && row.platform !== meta.provider)) return null;
510
+ const fields = recordVisibleFields(row);
511
+ if (!fields.length || fields.some(field => Array.isArray(field.after))) return null;
512
+ const cells = new Map();
513
+ for (const {path, after} of fields) {
514
+ if (path === 'provider' && after === meta.provider) continue;
515
+ cells.set(path, after);
516
+ columns.set(path, (columns.get(path) || 0) + 1);
517
+ }
518
+ if (columns.size > 12) return null;
519
+ values.push(cells);
520
+ }
521
+ let paths = [...columns.keys()];
522
+ const shared = paths.filter(path => columns.get(path) === rows.length);
523
+ if (!shared.length || (shared.length * 2 < paths.length && !shared.some(path => recordFieldPriority(path) <= recordRank.value))) return null;
524
+ const root = paths[0].split('.')[0];
525
+ const oneResource = paths.every(path => path.startsWith(root + '.'));
526
+ const geo = oneResource && recordLabel(root) === 'Geo target constant';
527
+ const language = oneResource && recordLabel(root) === 'Language constant';
528
+ const types = paths.filter(path => /^(?:target type|type)$/.test(recordLeaf(path)));
529
+ const type = types.length === 1 ? types[0] : null;
530
+ const kind = type && values[0].get(type);
531
+ const sameType = typeof kind === 'string' && kind.trim() && rows.length === total && values.every(row => row.get(type) === kind);
532
+ const countries = geo && sameType && type.split('.').length === 2 && recordLeaf(type) === 'target type' && kind.toLowerCase() === 'country';
533
+ const summarizeType = sameType && paths.length > 1 && (countries || rows.length > 1);
534
+ // Google also returns a resource name for some queries. Omit it only when
535
+ // it is the same prefix plus the exact ID that is already visible.
536
+ paths = paths.filter(path => {
537
+ if (summarizeType && path === type) return false;
538
+ if (recordLeaf(path) !== 'resource name') return true;
539
+ const id = paths.find(other => other.split('.').slice(0,-1).join('.') === path.split('.').slice(0,-1).join('.') && recordLeaf(other) === 'id');
540
+ if (!id) return true;
541
+ const first = String(values[0].get(path) ?? ''), prefix = first.slice(0, first.lastIndexOf('/') + 1);
542
+ return !prefix || !values.every(row => row.get(id) != null && row.get(path) === prefix + row.get(id));
543
+ });
544
+ if (!paths.length) return null;
545
+ paths.sort((a,b) => recordFieldPriority(a) - recordFieldPriority(b));
546
+ const distinct = new Map(paths.map(path => [path, new Set(values.map(row => row.get(path)).filter(value => value != null && value !== '')).size]));
547
+ const names = paths.filter(path => recordFieldPriority(path) <= recordRank.value);
548
+ const identifiers = paths.filter(path => recordFieldPriority(path) !== recordRank.other && recordLeaf(path) !== 'currency code');
549
+ // Display a distinguishing name first. A repeated name can still sit beside its unique ID.
550
+ const primary = names.find(path => distinct.get(path) === rows.length) ||
551
+ names.find(path => distinct.get(path) > 1 && values.every(row => row.get(path) != null && row.get(path) !== '')) ||
552
+ identifiers.find(path => distinct.get(path) === rows.length) ||
553
+ identifiers.find(path => distinct.get(path) > 1) || names.find(path => distinct.get(path)) || paths[0];
554
+ paths = [primary, ...paths.filter(path => path !== primary)];
555
+ const labels = recordColumnLabels(paths);
556
+ let title;
557
+ if (geo || language) {
558
+ title = countries ? 'Countries' : geo ? 'Target locations' : 'Languages';
559
+ for (const path of paths) {
560
+ if (path.split('.').length !== 2) continue;
561
+ const leaf = recordLeaf(path);
562
+ if (leaf === 'name') labels.set(path, countries ? 'Country' : geo ? 'Location' : 'Language');
563
+ if (geo && leaf === 'id') labels.set(path,'Target ID');
564
+ if (geo && leaf === 'target type') labels.set(path,'Type');
565
+ }
566
+ } else if (oneResource && meta.tool === 'google_gaql') {
567
+ title = recordLabel(root).replace(/ (?:constant|view)$/i,'') + ' results';
568
+ }
569
+ const subject = summarizeType && !countries ? 'Type · ' + kind : '';
570
+ return {paths, labels, values, title, subject};
571
+ }
572
+
573
+ function recordCollectionTable(collection, meta, title) {
574
+ const {paths, labels, values} = collection;
575
+ const scales = paths.map(recordAmountScale);
576
+ const headers = paths.map((path,i) => scales[i] ? labels.get(path).replace(/ (?:micros|cents)$/i,'') : labels.get(path));
577
+ const currencyPaths = paths.filter(recordCurrencyField);
578
+ const rows = values.map(cells => {
579
+ const currency = recordCurrency(currencyPaths.map(path => cells.get(path)),meta);
580
+ return '<tr role="row">' + paths.map((path,i) => {
581
+ const value = cells.get(path);
582
+ return workflowCell(headers[i], value == null || value === '' ? '—' : recordValue(value,path,currency,scales[i]), i === 0);
583
+ }).join('') + '</tr>';
584
+ });
585
+ return '<div class="collection-scroll" role="region" aria-label="Returned records" tabindex="0"><table class="workflow-table' +
586
+ (paths.length > 3 ? ' workflow-stack' : '') + '" role="table" aria-label="' + esc(title) + '">' + workflowHeader(headers) +
587
+ '<tbody id="record-collection-rows" role="rowgroup">' + rows.join('') + '</tbody></table></div>';
588
+ }
589
+
590
+ function renderRecordCollection(data, meta, collection, title, scope, clean, total) {
591
+ const shown = collection.values.length;
592
+ const count = total + (total === 1 ? ' result' : ' results');
593
+ const search = shown >= 15 ? '<input class="collection-filter" type="search" aria-label="Filter shown results" aria-controls="record-collection-rows" placeholder="Filter results" autocomplete="off">' : '';
594
+ const heading = collection.title || title;
595
+ const subject = [scope,collection.subject].filter(Boolean).join(' · ');
596
+ app.innerHTML = chrome('<div class="collection-heading">' + operationHeader(heading,subject,meta.provider) + search + '</div>' +
597
+ notices(data) + recordCollectionTable(collection,meta,heading) + '<p class="operation-note" data-collection-empty hidden>No matching results.</p>' +
598
+ (shown < total ? workflowNote('Showing ' + shown.toLocaleString() + ' of ' + total.toLocaleString() + ' results. The full response is in Details.') : '') +
599
+ '<details><summary>Details</summary><pre>' + esc(JSON.stringify(clean,null,2)) + '</pre></details>',count);
600
+ if (!search) return;
601
+ const input = app.querySelector('.collection-filter'), context = app.querySelector('.context'), empty = app.querySelector('[data-collection-empty]');
602
+ const original = context.textContent;
603
+ const entries = [...app.querySelectorAll('#record-collection-rows tr')].map(node => ({
604
+ node, text: [...node.cells].map(cell => cell.textContent).join(' ').toLowerCase()
605
+ }));
606
+ context.setAttribute('role','status');
607
+ function filter() {
608
+ const query = input.value.trim().toLowerCase();
609
+ let matched = 0;
610
+ for (const {node,text} of entries) {
611
+ node.hidden = !text.includes(query);
612
+ if (!node.hidden) matched++;
613
+ }
614
+ empty.hidden = matched !== 0;
615
+ context.textContent = query ? (syntheticResult ? 'Synthetic demo · ' : '') + matched + ' of ' + shown + ' shown' : original;
616
+ }
617
+ input.addEventListener('input',filter);
618
+ input.addEventListener('keydown',event => {
619
+ if (event.key === 'Escape' && input.value) { event.preventDefault(); input.value = ''; filter(); }
620
+ });
621
+ }
622
+ `;
623
+
441
624
  // src/record-ui.ts
442
625
  var RECORD_UI_STYLES = String.raw`
626
+ ${RECORD_COLLECTION_STYLES}
443
627
  .record-list { display:grid; max-height:400px; overflow:auto; scrollbar-width:thin }
444
628
  .record-row { min-width:0; padding:10px 0; border-bottom:1px solid var(--line) }
445
629
  .record-heading { display:flex; align-items:baseline; justify-content:space-between; gap:10px; min-width:0 }
@@ -470,6 +654,7 @@ var RECORD_UI_STYLES = String.raw`
470
654
  }
471
655
  `;
472
656
  var RECORD_UI_SCRIPT = String.raw`
657
+ ${RECORD_COLLECTION_UI}
473
658
  let recordPages=null;
474
659
  function recordPagesIgnoreEcho(data) {
475
660
  return !!recordPages?.busy && data?._adport?.view===recordPages.meta.view && galleryMatches(data._adport,recordPages.meta) && galleryScope(data._adport)===recordPages.scope;
@@ -505,27 +690,49 @@ var RECORD_UI_SCRIPT = String.raw`
505
690
  if(!object(payload))return null;
506
691
  if(['name','value','title','id','saved_audience_name','saved_audience_id','pixel_name','pixel_id','capi_connection_id'].some(key=>Object.hasOwn(payload,key)&&!object(payload[key])&&!Array.isArray(payload[key])))return null;
507
692
  const ignored=/^(_adport|notes|warnings|errors|actions|creatives|fields|media|resourceIds|resource_ids)$/;
508
- const keys=['items','results','records','campaigns','ad_groups','ad_sets','ads','keywords','audiences','accounts','projects','assets','data'];
693
+ const keys=['items','results','records','rows','campaigns','ad_groups','ad_sets','ads','keywords','audiences','accounts','projects','assets','data'];
509
694
  const key=keys.find(key=>Array.isArray(payload[key])) ?? Object.keys(payload).find(key=>!ignored.test(key)&&Array.isArray(payload[key]));
510
695
  return key?payload[key]:null;
511
696
  }
512
- function recordValue(value,key,currency) {
513
- if(typeof value==='number'&&Number.isFinite(value)&&/micros$|cents$/i.test(key))return esc(money(value/(/cents$/i.test(key)?100:1e6),currency,6));
697
+ function recordAmountScale(path) {
698
+ const leaf=recordLeaf(path), label=/^(micros|cents)$/.test(leaf)?recordLabel(path).toLowerCase():leaf;
699
+ if(!/\b(?:budget|amount|price|cost|bid|spend|revenue|fee)\b/.test(label))return 0;
700
+ return /\bmicros$/.test(leaf)?6:/\bcents$/.test(leaf)?2:0;
701
+ }
702
+ function recordCurrencyField(path) { return /^(?:currency|currency code)$/.test(recordLeaf(path)); }
703
+ function recordCurrency(values,meta) {
704
+ const codes=new Set(values.filter(value=>typeof value==='string'&&/^[A-Z]{3}$/.test(value)));
705
+ if(!codes.size)return currencyOf(meta);
706
+ return codes.size===1?[...codes][0]:null;
707
+ }
708
+ function recordValue(value,key,currency,scale=recordAmountScale(key)) {
709
+ if(scale) {
710
+ const amount=nativeReportDecimal(value,scale);
711
+ if(amount!==null)return esc(currency?new Intl.NumberFormat(state.host.locale||'en',{style:'currency',currency,maximumFractionDigits:6}).format(amount):amount+' account units');
712
+ }
514
713
  return valueHTML(value,true);
515
714
  }
516
715
  function recordRow(value,index,meta) {
517
716
  if(!object(value))return '<article class="record-row">'+valueHTML(value,true)+'</article>';
518
- const fields=dataFields(value).filter(field=>!/(?:hash|token|secret|password|authorization|pending operation|snapshot)/i.test(field.label));
519
- const name=fields.find(field=>/^(name|display name|title|value|keyword|keyword text|campaign name|ad group name|ad name|creative name|account name|audience name|saved audience name|pixel name)$/i.test(field.label));
520
- const id=fields.find(field=>/^(id|resource name|saved audience id|pixel id|capi connection id)$/i.test(field.label));
521
- const status=fields.find(field=>/^(status|state|delivery status|archived)$/i.test(field.label));
522
- const currency=currencyOf(value)||(/^[A-Z]{3}$/.test(value.currency_code||'')?value.currency_code:currencyOf(meta));
523
- const chosen=fields.filter(field=>!/^note$|^notes$|^actions$|preview url|preview cover url|logo url/i.test(field.label)&&field!==name&&field!==status&&!/^(id|saved audience id|pixel id|pixel code|capi connection id|account id|provider|resource name|currency|currency code)$/i.test(field.label));
717
+ const fields=recordVisibleFields(value);
718
+ const identities=fields.filter(field=>(typeof field.after==='string'&&field.after.trim())||typeof field.after==='number')
719
+ .sort((a,b)=>recordFieldPriority(a.path)-recordFieldPriority(b.path));
720
+ const name=identities.find(field=>recordFieldPriority(field.path)<=recordRank.code && recordLeaf(field.path)!=='currency code');
721
+ const id=identities.find(field=>recordFieldPriority(field.path)>=recordRank.id);
722
+ const status=fields.find(field=>/^(status|state|delivery status|archived)$/.test(recordLeaf(field.path)));
723
+ const currency=recordCurrency(fields.filter(field=>recordCurrencyField(field.path)).map(field=>field.after),meta);
724
+ const chosen=fields.filter(field=>field!==(name||id)&&field!==status&&!/^(id|saved audience id|pixel id|capi connection id|account id|provider|resource name|currency|currency code)$/.test(recordLeaf(field.path)));
524
725
  chosen.sort((a,b)=>{const priority=field=>/match type|scope|budget|bid|size|type|rule|frequency/i.test(field.label)?0:1;return priority(a)-priority(b);});
525
- const label=name?.after ?? id?.after ?? 'Record '+(index+1);
726
+ const displayed=chosen.slice(0,4), labels=recordColumnLabels(displayed.map(field=>field.path));
727
+ const label=name?.after ?? id?.after ?? (displayed.length?null:'Record '+(index+1));
526
728
  const nativeProvider=typeof value.provider==='string'?value.provider:typeof value.platform==='string'&&providerSvg[value.platform]?value.platform:undefined;
527
729
  const provider=nativeProvider!==meta.provider?nativeProvider:undefined;
528
- return '<article class="record-row"><div class="record-heading"><div class="record-name">'+(provider?'<span role="img" aria-label="'+esc(providerName(provider,meta.providerNames||{}))+'">'+logo(provider)+'</span>':'')+'<strong>'+esc(label)+'</strong></div>'+(status?'<span>'+esc(status.label==='Archived'&&typeof status.after==='boolean'?(status.after?'Archived':'Unarchived'):status.after)+'</span>':'')+'</div>'+(chosen.length?'<dl class="record-fields">'+chosen.slice(0,4).map(field=>/^(providers|platforms)$/i.test(field.label)&&Array.isArray(field.after)?'<div><dd>'+providerMarks(field.after,meta)+'</dd></div>':'<div><dt>'+esc(/micros$|cents$/i.test(field.label)?field.label.replace(/ (?:micros|cents)$/i,'')+' · '+(currency||'account units'):field.label)+'</dt><dd>'+recordValue(field.after,field.label.replaceAll(' ','_'),currency)+'</dd></div>').join('')+'</dl>':'')+'</article>';
730
+ const heading=label!=null||provider||status?'<div class="record-heading"><div class="record-name">'+(provider?'<span role="img" aria-label="'+esc(providerName(provider,meta.providerNames||{}))+'">'+logo(provider)+'</span>':'')+(label!=null?'<strong>'+esc(label)+'</strong>':'')+'</div>'+(status?'<span>'+esc(recordLeaf(status.path)==='archived'&&typeof status.after==='boolean'?(status.after?'Archived':'Unarchived'):status.after)+'</span>':'')+'</div>':'';
731
+ return '<article class="record-row">'+heading+(displayed.length?'<dl class="record-fields">'+displayed.map(field=>{
732
+ if(/^(providers|platforms)$/i.test(field.label)&&Array.isArray(field.after))return '<div><dd>'+providerMarks(field.after,meta)+'</dd></div>';
733
+ const label=labels.get(field.path);
734
+ return '<div><dt>'+esc(recordAmountScale(field.path)?label.replace(/ (?:micros|cents)$/i,''):label)+'</dt><dd>'+recordValue(field.after,field.path,currency)+'</dd></div>';
735
+ }).join('')+'</dl>':'')+'</article>';
529
736
  }
530
737
  function entityRecordTable(tool) {
531
738
  return /^(?:google|meta|apple|microsoft|tiktok|linkedin|pinterest|reddit|snapchat|spotify|openai|x)_(?:list_)?(?:campaigns|campaign_groups|adgroups|ad_groups|ad_sets|adsets|line_items|adsquads)$/.test(tool||'');
@@ -600,13 +807,16 @@ var RECORD_UI_SCRIPT = String.raw`
600
807
  if(meta.tool==='apple_report')return renderAppleReport(data,meta);
601
808
  if(nativeReportTools.has(meta.tool)&&(meta.tool!=='google_gaql'||arr(recordPayload(data)?.rows).some(row=>object(row?.metrics)&&Object.keys(row.metrics).length)))return renderNativeReport(data,meta);
602
809
  const payload=recordPayload(data),entries=recordEntries(payload),rows=entries ?? [payload];
603
- const title=human(String(meta.tool||'Results').replace(/^(?:google|meta|tiktok|apple|microsoft|reddit|snapchat|spotify|pinterest|linkedin|x)_/,'').replace(/^(?:list|get)_/,'').replace(/_(?:list|get)$/,'').replaceAll('_',' '));
810
+ const title=meta.tool==='google_gaql'?'Google Ads query results':human(String(meta.tool||'Results').replace(/^(?:google|meta|tiktok|apple|microsoft|reddit|snapchat|spotify|pinterest|linkedin|openai|x)_/,'').replace(/^(?:list|get)_/,'').replace(/_(?:list|get)$/,'').replaceAll('_',' '));
604
811
  const parent=object(data.parent)?Object.entries(data.parent).filter(([key])=>/_id$/.test(key)).map(([key,value])=>human(key.replace(/_id$/,''))+' '+value).join(' · '):'';
605
812
  const scope=[parent,typeof data.parent_id==='string'&&!parent?data.parent_id:'',meta.accountId].filter(Boolean).join(' · ');
606
813
  const clean=object(data)?Object.fromEntries(Object.entries(data).filter(([key])=>key!=='_adport'&&!(key==='creatives'&&meta.view==='records'))):data;
607
814
  const table=Array.isArray(entries)&&entityRecordTable(meta.tool)&&rows.every(object);
608
815
  const displayMeta=currencyOf(data)?{...meta,currency:currencyOf(data)}:meta;
609
- const markup=rows.slice(0,1000).map((row,index)=>recordEntryMarkup(row,index,displayMeta,table)).join('');
816
+ const shown=rows.slice(0,1000);
817
+ const collection=entries&&!table&&recordCollection(shown,meta,rows.length);
818
+ if(collection)return renderRecordCollection(data,displayMeta,collection,title,scope,clean,rows.length);
819
+ const markup=shown.map((row,index)=>recordEntryMarkup(row,index,displayMeta,table)).join('');
610
820
  const content=rows.length?table?'<div class="workflow-scroll" role="region" aria-label="Returned records" tabindex="0"><table class="workflow-table workflow-stack" role="table">'+workflowHeader(entityHeaders)+
611
821
  '<tbody data-record-list role="rowgroup">'+markup+'</tbody></table></div>':
612
822
  '<div class="record-list" data-record-list role="region" aria-label="Returned records" tabindex="0">'+markup+'</div>':'<p class="operation-note">No results returned.</p>';
@@ -1032,7 +1242,7 @@ var OPERATION_UI_SCRIPT = String.raw`
1032
1242
  if (!object(value) || depth>8) return [];
1033
1243
  return Object.entries(value).filter(([key])=>!['_adport','data_source','pending_operation_id'].includes(key)).flatMap(([key,item])=>{
1034
1244
  const path=prefix?prefix+'.'+key:key;
1035
- return object(item)?dataFields(item,path,depth+1):[{label:human(path),after:item}];
1245
+ return object(item)?dataFields(item,path,depth+1):[{path,label:human(path),after:item}];
1036
1246
  });
1037
1247
  }
1038
1248
  function valueHTML(value,compact=false) {
@@ -1289,6 +1499,118 @@ var APPLE_REPORT_UI_SCRIPT = String.raw`
1289
1499
  }
1290
1500
  `;
1291
1501
 
1502
+ // src/gaql-report-ui.ts
1503
+ var GAQL_REPORT_UI = String.raw`
1504
+ const gaqlEntities = new Map([
1505
+ ['searchTermView.searchTerm', 'Search term'], ['campaignSearchTermView.searchTerm', 'Search term'],
1506
+ ['adGroupCriterion.keyword.text', 'Keyword'], ['segments.keyword.info.text', 'Keyword'],
1507
+ ['adGroupAd.ad.name', 'Ad'], ['adGroupAd.ad.id', 'Ad ID'],
1508
+ ['asset.name', 'Asset'], ['asset.id', 'Asset ID'], ['assetGroup.name', 'Asset group'], ['assetGroup.id', 'Asset group ID'],
1509
+ ['adGroup.name', 'Ad group'], ['adGroup.id', 'Ad group ID'], ['campaign.name', 'Campaign'], ['campaign.id', 'Campaign ID'],
1510
+ ['customer.descriptiveName', 'Account'], ['customer.id', 'Account ID']
1511
+ ]);
1512
+
1513
+ function gaqlDimensions(row) {
1514
+ const {metrics, ...dimensions} = row;
1515
+ return new Map(dataFields(dimensions)
1516
+ .filter(({path, after}) => after != null && !Array.isArray(after) && String(after).trim() &&
1517
+ !/(?:currency(?:_?code)?$|token|secret|password|authorization)/i.test(path))
1518
+ .map(({path, after}) => [path, String(after)]));
1519
+ }
1520
+
1521
+ function gaqlDimensionLabel(path) {
1522
+ if (gaqlEntities.has(path)) return gaqlEntities.get(path);
1523
+ if (path.endsWith('.keyword.matchType') || path.endsWith('.keyword.info.matchType')) return 'Match type';
1524
+ return human(human(path.replace(/^segments\./, '')).toLowerCase()).replace(/\bid\b/i, 'ID');
1525
+ }
1526
+
1527
+ const gaqlMoneyFormats = new Map();
1528
+ function gaqlAmount(amount, currency) {
1529
+ const locale = state.host.locale || 'en', key = locale + '/' + (currency || '');
1530
+ if (!gaqlMoneyFormats.has(key)) {
1531
+ const digits = currency ? new Intl.NumberFormat(locale, {style:'currency', currency}).resolvedOptions().maximumFractionDigits : 2;
1532
+ gaqlMoneyFormats.set(key, {
1533
+ format: new Intl.NumberFormat(locale, {minimumFractionDigits:digits, maximumFractionDigits:digits}),
1534
+ unit: 10 ** -digits
1535
+ });
1536
+ }
1537
+ const {format, unit} = gaqlMoneyFormats.get(key);
1538
+ if (Number(amount) !== 0 && Math.abs(Number(amount)) < unit) {
1539
+ return Number(amount) < 0 ? '>' + format.format(-unit) : '<' + format.format(unit);
1540
+ }
1541
+ return format.format(amount);
1542
+ }
1543
+
1544
+ function gaqlHasTrend(points, dimensions, paths) {
1545
+ // A dated series must refer to the same returned entity and breakdown on every date.
1546
+ if (points.length > 366 || new Set(points.map(point => point.date)).size < 2) return false;
1547
+ const series = new Map(), observations = new Set();
1548
+ const seriesPaths = paths.filter(path => path !== 'segments.date');
1549
+ return points.every((point, i) => {
1550
+ if (!point.date) return false;
1551
+ const identity = JSON.stringify(seriesPaths.map(path => dimensions[i].get(path)));
1552
+ const observation = JSON.stringify([point.series, point.date]);
1553
+ if (observations.has(observation) || (series.has(point.series) && series.get(point.series) !== identity)) return false;
1554
+ observations.add(observation);
1555
+ series.set(point.series, identity);
1556
+ return true;
1557
+ }) && series.size <= 3;
1558
+ }
1559
+
1560
+ function gaqlReportTable(records, points) {
1561
+ const dimensions = records.map(record => record?.gaqlDimensions || new Map());
1562
+ const paths = [...new Set(dimensions.flatMap(row => [...row.keys()]))];
1563
+ const fields = [...new Set(points.flatMap(row => row.fields.map(field => field.key)))];
1564
+ const first = records[0];
1565
+ const commonEntity = first?.gaqlEntity && records.every(row => row?.gaqlEntity === first.gaqlEntity);
1566
+ if (points.length <= 8 && fields.length === 1 && commonEntity && !points.some(point => point.date) &&
1567
+ new Set(points.map(point => point.name)).size === points.length) return null;
1568
+ const monetary = fields.some(key => nativeReportMoneyField(key, 'google'));
1569
+ const currencies = new Set(records.map(row => row?.currency || ''));
1570
+ if ((!monetary || currencies.size === 1) && gaqlHasTrend(points, dimensions, paths)) return null;
1571
+
1572
+ const varies = path => dimensions.some(row => row.get(path) !== dimensions[0].get(path));
1573
+ const varying = paths.filter(varies);
1574
+ const identifiers = [...gaqlEntities.keys()].filter(path => varying.includes(path));
1575
+ const names = identifiers.filter(path => !path.endsWith('.id'));
1576
+ const columns = [...new Set([...names, ...identifiers, ...varying])].filter(path => !path.endsWith('.resourceName'));
1577
+ const distinct = keys => new Set(dimensions.map(row => JSON.stringify(keys.map(key => row.get(key))))).size;
1578
+ let identities = distinct(columns);
1579
+ for (const path of varying.filter(path => path.endsWith('.resourceName'))) {
1580
+ const withResource = distinct([...columns, path]);
1581
+ if (withResource > identities) { columns.push(path); identities = withResource; }
1582
+ }
1583
+ const primary = columns.shift() ?? (records.length === 1 ? first?.gaqlEntity : undefined);
1584
+ const metrics = fields.sort((a, b) => reportMetricPriority(a) - reportMetricPriority(b));
1585
+ const mixed = monetary && currencies.size > 1;
1586
+ const currency = currencies.size === 1 ? first?.currency : null;
1587
+ const headers = [primary ? gaqlDimensionLabel(primary) : 'Row', ...metrics.map(key =>
1588
+ nativeReportLabel(key) + (currency && nativeReportMoneyField(key, 'google') ? ' · ' + currency : '')),
1589
+ ...(mixed ? ['Currency'] : []), ...columns.map(gaqlDimensionLabel)];
1590
+ const values = points.map((point, i) => [
1591
+ primary ? dimensions[i].get(primary) : i + 1,
1592
+ ...metrics.map(key => {
1593
+ const field = point.fields.find(field => field.key === key);
1594
+ return field?.shortDisplay ?? field?.display;
1595
+ }),
1596
+ ...(mixed ? [records[i]?.currency] : []), ...columns.map(path => dimensions[i].get(path))
1597
+ ]);
1598
+ const scope = paths.filter(path => path !== primary && !varying.includes(path) &&
1599
+ (gaqlEntities.has(path) || path.startsWith('segments.')) &&
1600
+ !(path.endsWith('.id') && paths.includes(path.slice(0, -2) + 'name')))
1601
+ .map(path => gaqlEntities.has(path) && !path.endsWith('.id') ? dimensions[0].get(path) :
1602
+ gaqlDimensionLabel(path) + ' ' + dimensions[0].get(path));
1603
+ if (monetary && currencies.has('')) scope.push('Currency unavailable');
1604
+ return {
1605
+ title: gaqlEntities.has(primary) ? gaqlDimensionLabel(primary).replace(/ ID$/, '') + ' performance' : 'Google Ads query results',
1606
+ subject: [...new Set(scope)].join(' · '),
1607
+ html: (identities < records.length ?
1608
+ workflowNote('Some rows have identical labels. Include a more specific name, ID or segment to distinguish them.') : '') +
1609
+ workflowTable(headers, values, 'Google Ads query results')
1610
+ };
1611
+ }
1612
+ `;
1613
+
1292
1614
  // src/native-report-ui.ts
1293
1615
  var NATIVE_REPORT_TOOLS = [
1294
1616
  "ga4_report",
@@ -1312,6 +1634,7 @@ var NATIVE_REPORT_UI_STYLES = String.raw`
1312
1634
  `;
1313
1635
  var NATIVE_REPORT_UI_SCRIPT = String.raw`
1314
1636
  const nativeReportTools=new Set(${JSON.stringify(NATIVE_REPORT_TOOLS)});
1637
+ ${GAQL_REPORT_UI}
1315
1638
  function nativeReportDecimal(value,scale=0) {
1316
1639
  const text=typeof value==='number'&&Number.isFinite(value)?String(value):typeof value==='string'?value:'';
1317
1640
  if(!/^-?\d+(?:\.\d+)?$/.test(text))return null;
@@ -1324,7 +1647,7 @@ var NATIVE_REPORT_UI_SCRIPT = String.raw`
1324
1647
  const known={spend:'Spend',costMicros:'Spend',conversionsValue:'Conversion value',impressions:'Impressions',clicks:'Clicks',conversion:'Conversions',conversions:'Conversions',purchases:'Purchases',cpc:'CPC',cpm:'CPM',ctr:'CTR',roas:'ROAS',total_complete_payment_rate:'Purchase value',complete_payment_roas:'Purchase ROAS',lowImpressionShare:'Impression share · lower bound',highImpressionShare:'Impression share · upper bound',searchPopularity1to5:'Popularity · 1–5',searchPopularity1to100:'Popularity · 1–100',searchPopularityInGenre:'Genre popularity · 1–100',rankInGenre:'Genre rank',OverallSuccessRate:'Success rate · ratio',OverallSuccessCount:'Succeeded',SuccessCount:'Succeeded',FailureCount:'Failed',OverallUnattributedCount:'Unattributed'};
1325
1648
  return known[key]||known[key.toLowerCase()]||human(human(key).toLowerCase());
1326
1649
  }
1327
- function nativeReportRatio(key,provider) {return provider==='gsc'&&key==='ctr'||provider==='ga4'&&!key.includes(':')&&/Rate$/.test(key);}
1650
+ function nativeReportRatio(key,provider) {return (provider==='gsc'||provider==='google')&&key==='ctr'||provider==='ga4'&&!key.includes(':')&&/Rate$/.test(key);}
1328
1651
  function nativeReportMetric(key,value,provider,currency,moneyFields=[]) {
1329
1652
  if(key==='costInUsd')currency='USD';
1330
1653
  const lower=key.toLowerCase(),decimal=nativeReportDecimal(value);
@@ -1357,7 +1680,9 @@ var NATIVE_REPORT_UI_SCRIPT = String.raw`
1357
1680
  const names=provider==='microsoft'?['SearchQuery','Keyword','ConversionName','UploadDate']:provider==='apple'?['searchTerm','appName']:['ad_name','adgroup_name','adset_name','campaign_name','account_name','advertiser_name','name','entity_name'];
1358
1681
  const ids=['ad_id','adgroup_id','adset_id','campaign_id','advertiser_id','account_id','entity_id','id','GoalId','urn'];
1359
1682
  const first=(keys,sources)=>keys.flatMap(key=>sources.map(source=>source[key])).find(value=>(typeof value==='string'&&value.trim())||typeof value==='number');
1360
- const googleName=provider==='google'?[row.adGroupAd?.ad?.name,row.adGroup?.name,row.campaign?.name,row.customer?.descriptiveName,row.searchTermView?.searchTerm,row.adGroupCriterion?.keyword?.text].find(value=>typeof value==='string'&&value):null;
1683
+ const googleDimensions=provider==='google'?gaqlDimensions(row):null;
1684
+ const googleEntity=googleDimensions&&[...gaqlEntities.keys()].find(path=>googleDimensions.has(path));
1685
+ const googleName=googleDimensions?.get(googleEntity);
1361
1686
  const bucket=dimensions.conversionLagBucket??dimensions.conversionOrAdjustmentLagBucket;
1362
1687
  const analyticsName=['ga4','gsc'].includes(provider)?Object.values(dimensions).filter(value=>typeof value==='string'&&value).join(' · '):null;
1363
1688
  const name=bucket?reportBucket(bucket):googleName??analyticsName??first(names,[row,metrics,dimensions]) ?? first(ids,[row,dimensions]) ?? (provider==='google'?'Report':'Result '+(index+1));
@@ -1378,7 +1703,7 @@ var NATIVE_REPORT_UI_SCRIPT = String.raw`
1378
1703
  const priority=key=>/^(spend|impressions|clicks)$/i.test(key)?['spend','impressions','clicks'].indexOf(key.toLowerCase()):/^(conversion|conversions|purchases)$|^actions · purchase$/i.test(key)?3:4;
1379
1704
  fields.sort((a,b)=>priority(a[0])-priority(b[0]));
1380
1705
  const moneyFields=provider==='ga4'?arr(payload.metric_headers).filter(header=>header.type==='TYPE_CURRENCY').map(header=>header.name):[];
1381
- return {name,status,context,currency,moneyFields,provider,fields,native:row,date:reportDate(dimensions.stat_time_day??(provider==='ga4'&&/^\d{8}$/.test(dimensions.date||'')?dimensions.date.replace(/^(\d{4})(\d{2})(\d{2})$/,'$1-$2-$3'):dimensions.date)??(row.date_start===row.date_stop?row.date_start:null)??(row.date_range?.start===row.date_range?.end?row.date_range?.start:null)),series:googleName||(['ga4','gsc'].includes(provider)?Object.entries(dimensions).filter(([key])=>key!=='date').map(([,value])=>value).join(' · ')||'Website':name)};
1706
+ return {name,status,context,currency,moneyFields,provider,fields,gaqlDimensions:googleDimensions,gaqlEntity:googleEntity,native:row,date:reportDate(dimensions.stat_time_day??(provider==='ga4'&&/^\d{8}$/.test(dimensions.date||'')?dimensions.date.replace(/^(\d{4})(\d{2})(\d{2})$/,'$1-$2-$3'):dimensions.date)??(row.date_start===row.date_stop?row.date_start:null)??(row.date_range?.start===row.date_range?.end?row.date_range?.start:null)),series:googleName||(['ga4','gsc'].includes(provider)?Object.entries(dimensions).filter(([key])=>key!=='date').map(([,value])=>value).join(' · ')||'Website':name)};
1382
1707
  }
1383
1708
  function nativeChartRecord(record) {
1384
1709
  if(!record)return {name:'Unavailable row',context:[],fields:[]};
@@ -1387,7 +1712,9 @@ var NATIVE_REPORT_UI_SCRIPT = String.raw`
1387
1712
  const ratio=nativeReportRatio(key,record.provider);
1388
1713
  const value=record.provider==='spotify'&&String(raw)==='-5'?null:reportNumber(monetary?scaled:raw);
1389
1714
  const display=nativeReportMetric(key,raw,record.provider,record.currency,record.moneyFields);
1390
- return {key,label:key==='costInLocalCurrency'?'Spend':key==='costInUsd'?'Spend · USD':nativeReportLabel(key),value:ratio&&value!==null?value*100:value,display,unit:ratio?'%':monetary?key==='costInUsd'?'USD':record.currency||'Account units':''};
1715
+ const googleMoney=record.provider==='google'&&monetary;
1716
+ const shortDisplay=googleMoney&&scaled!==null?gaqlAmount(scaled,record.currency):undefined;
1717
+ return {key,label:key==='costInLocalCurrency'?'Spend':key==='costInUsd'?'Spend · USD':nativeReportLabel(key),value:ratio&&value!==null?value*100:value,display,shortDisplay,unit:ratio?'%':monetary?key==='costInUsd'?'USD':record.currency||(googleMoney?'Currency unavailable':'Account units'):''};
1391
1718
  });
1392
1719
  const low=record.native.lowImpressionShare,high=record.native.highImpressionShare;
1393
1720
  const range=record.provider==='apple'&&[low,high].every(value=>typeof value==='number'&&Number.isFinite(value)&&value>=0&&value<=1)&&low<=high?[low,high]:undefined;
@@ -1410,13 +1737,19 @@ var NATIVE_REPORT_UI_SCRIPT = String.raw`
1410
1737
  const errors=arr(data.errors).filter(error=>error?.error_code).map(error=>'<p class="notice">Goal '+esc(error.goal_id||'unavailable')+': '+esc(error.error_code)+'</p>').join('');
1411
1738
  const missingGoals=arr(data.not_returned_goal_ids).filter(id=>!arr(data.errors).some(error=>error?.goal_id===id&&error?.error_code));
1412
1739
  const absent=missingGoals.length?'<p class="notice">No summary returned for goal'+(missingGoals.length===1?'':'s')+' '+missingGoals.map(esc).join(', ')+'.</p>':'';
1413
- const records=entries.slice(0,1000).map((row,index)=>nativeReportRecord(row,index,meta,payload)),delay=provider==='google'&&entries.some(row=>row.segments?.conversionLagBucket||row.segments?.conversionOrAdjustmentLagBucket);
1740
+ const records=entries.slice(0,1000).map((row,index)=>nativeReportRecord(row,index,meta,payload)),delay=provider==='google'&&entries.some(row=>row?.segments?.conversionLagBucket||row?.segments?.conversionOrAdjustmentLagBucket);
1414
1741
  const pageArgs=['ga4_report','gsc_search_analytics'].includes(meta.tool)?readPageArgs(meta,'data-report-next'):null;
1415
- const chart=reportCharts(records.map(nativeChartRecord),delay?{dimension:'delay',mode:'bars',metric:records.some(record=>record?.fields.some(([key])=>key==='conversions'))?'conversions':undefined}:meta.tool==='apple_impression_share'?{metric:'Impression share',dimension:'search term'}:{});
1742
+ const points=records.map(nativeChartRecord);
1743
+ const table=provider==='google'&&!delay&&entries.length?gaqlReportTable(records,points):null;
1744
+ const entity=records[0]?.gaqlEntity;
1745
+ const dimension=entity&&records.every(row=>row?.gaqlEntity===entity)?gaqlEntities.get(entity).toLowerCase():undefined;
1746
+ const chart=table?null:reportCharts(points,delay?{dimension:'delay',mode:'bars',metric:records.some(record=>record?.fields.some(([key])=>key==='conversions'))?'conversions':undefined}:meta.tool==='apple_impression_share'?{metric:'Impression share',dimension:'search term'}:{dimension});
1416
1747
  const analytics=['ga4','gsc'].includes(provider),range=payload?.date_range;
1417
1748
  const period=analytics&&object(range)?[range.start_date??range.start,range.end_date??range.end].filter(workflowText).join(' – '):'';
1418
- app.innerHTML=chrome(operationHeader(delay?'Conversion delay':title,analytics?[meta.accountId,period].filter(Boolean).join(' · '):'',provider)+notices({...data,...(meta.tool==='linkedin_demographic_report'?{notes:[]}:{}),errors:arr(data.errors).filter(error=>!error?.error_code)})+errors+absent+'<section data-native-report data-read-page-focus tabindex="-1">'+(entries.length?chart.html:'<p class="operation-note">'+missing+'</p>')+(meta.tool==='linkedin_demographic_report'?'<p class="report-chart-foot">Approximate demographics · privacy thresholds apply</p>':'')+(entries.length>1000?'<p class="operation-note">Showing 1,000 returned rows. The full response is in Details.</p>':'')+readPageMarkup(pageArgs,'data-report-next','data-report-page-status')+'<details class="report-data"><summary>Details · '+entries.length+' results</summary>'+(entries.length?'<div class="record-list" role="region" aria-label="Native report data" tabindex="0">'+entries.slice(0,1000).map((row,index)=>nativeReportRow(row,index,meta,payload)).join('')+'</div>':'')+'<pre>'+esc(JSON.stringify(clean,null,2))+'</pre></details></section>','');
1419
- chart.mount();
1749
+ const subject=table?.subject||(analytics?[meta.accountId,period].filter(Boolean).join(' · '):'');
1750
+ const body=table?.html||(entries.length?chart.html:'<p class="operation-note">'+missing+'</p>');
1751
+ app.innerHTML=chrome(operationHeader(table?.title||(delay?'Conversion delay':title),subject,provider)+notices({...data,...(meta.tool==='linkedin_demographic_report'?{notes:[]}:{}),errors:arr(data.errors).filter(error=>!error?.error_code)})+errors+absent+'<section data-native-report data-read-page-focus tabindex="-1">'+body+(meta.tool==='linkedin_demographic_report'?'<p class="report-chart-foot">Approximate demographics · privacy thresholds apply</p>':'')+(entries.length>1000?'<p class="operation-note">Showing 1,000 returned rows. The full response is in Details.</p>':'')+readPageMarkup(pageArgs,'data-report-next','data-report-page-status')+'<details class="report-data"><summary>Details · '+entries.length+' results</summary>'+(!table&&entries.length?'<div class="record-list" role="region" aria-label="Native report data" tabindex="0">'+entries.slice(0,1000).map((row,index)=>nativeReportRow(row,index,meta,payload)).join('')+'</div>':'')+'<pre>'+esc(JSON.stringify(clean,null,2))+'</pre></details></section>',table?entries.length+(entries.length===1?' row':' rows'):'');
1752
+ chart?.mount();
1420
1753
  bindReadPage(meta,pageArgs,'data-report-next','data-report-page-status',value=>Array.isArray(recordPayload(value)?.rows));
1421
1754
  }
1422
1755
  `;
@@ -1447,8 +1780,8 @@ var WORKFLOW_UI_STYLES = String.raw`
1447
1780
  .workflow-stack thead { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%) }
1448
1781
  .workflow-stack tbody tr { border-bottom:1px solid var(--line); padding:7px 0 }
1449
1782
  .workflow-stack tbody :is(td,th) { display:grid; grid-template-columns:minmax(88px,2fr) minmax(0,3fr); gap:8px; padding:4px 0; border:0 }
1450
- .workflow-cell-label { display:block; color:var(--muted); font-weight:400 }
1451
- .workflow-cell-label::before { content:attr(data-label) }
1783
+ .workflow-stack .workflow-cell-label { display:block; color:var(--muted); font-weight:400 }
1784
+ .workflow-stack .workflow-cell-label::before { content:attr(data-label) }
1452
1785
  }
1453
1786
  `;
1454
1787
  var WORKFLOW_UI = String.raw`
@@ -1999,7 +2332,7 @@ var REPORT_CHART_SCRIPT = String.raw`
1999
2332
  const label=pretty(point.name)+(point.context?.length?' · '+point.context.join(' · '):'');
2000
2333
  const range=point.range&&point.range.every(available)?point.range:null;
2001
2334
  const fill=range?'<span class="report-bar-fill report-bar-range" style="left:'+Math.max(0,range[0]*100)+'%;width:'+Math.max(0,(range[1]-range[0])*100)+'%"></span>':'<span class="report-bar-fill" style="left:'+left.toFixed(5)+'%;width:'+width.toFixed(5)+'%"></span>';
2002
- return '<li data-chart-value="'+(value===null?'':value)+'"><div class="report-bar-label"><span title="'+esc(label)+'">'+esc(label)+'</span><strong>'+esc(point.display)+'</strong></div><div class="report-bar-track" aria-hidden="true">'+fill+(min<0?'<span class="report-bar-zero" style="left:'+(-min/span*100).toFixed(5)+'%"></span>':'')+'</div></li>';
2335
+ return '<li data-chart-value="'+(value===null?'':value)+'"><div class="report-bar-label"><span title="'+esc(label)+'">'+esc(label)+'</span><strong>'+esc(point.shortDisplay??point.display)+'</strong></div><div class="report-bar-track" aria-hidden="true">'+fill+(min<0?'<span class="report-bar-zero" style="left:'+(-min/span*100).toFixed(5)+'%"></span>':'')+'</div></li>';
2003
2336
  }).join('')+'</ol>';
2004
2337
  return '<section class="report-chart" data-report-chart><div class="report-chart-head"><b>'+esc(title)+'</b>'+(unit?'<span>'+esc(unit)+'</span>':'')+'</div>'+body+(!trend&&model.returned>shown.length?'<p class="report-chart-foot">'+shown.length+' of '+model.returned+' returned rows · all rows in Details</p>':trend&&model.returned>points.length?'<p class="report-chart-foot">'+points.length+' of '+model.returned+' dated observations · all data in Details</p>':'')+'</section>';
2005
2338
  }).join('')+(groups.size>4?'<p class="report-chart-foot">Showing four units. All returned values are in Details.</p>':'');
@@ -2032,8 +2365,8 @@ var REPORT_CHART_SCRIPT = String.raw`
2032
2365
  `;
2033
2366
 
2034
2367
  // src/ui.ts
2035
- var ADPORT_UI_URI = "ui://adport/insight-card-v32.html";
2036
- var ADPORT_SUMMARY_UI_URI = "ui://adport/summary-card-v32.html";
2368
+ var ADPORT_UI_URI = "ui://adport/insight-card-v34.html";
2369
+ var ADPORT_SUMMARY_UI_URI = "ui://adport/summary-card-v34.html";
2037
2370
  var ADPORT_UI_DOMAIN = "https://app.adport.dev";
2038
2371
  var ADPORT_UI_RESOURCE_DOMAINS = [
2039
2372
  ADPORT_UI_DOMAIN,
@@ -2086,6 +2419,7 @@ function viewForTool(name, readOnly) {
2086
2419
  function toolTitle(name) {
2087
2420
  if (name === "accounts_list") return "Show connected ad accounts";
2088
2421
  if (name === "report") return "Show advertising performance";
2422
+ if (name === "google_gaql") return "Query Google Ads";
2089
2423
  return name.split("_").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
2090
2424
  }
2091
2425
  function toolInvocationLabels(view) {
@@ -2511,7 +2845,7 @@ ${PLANNING_UI}
2511
2845
 
2512
2846
  // src/index.ts
2513
2847
  var PROVIDER_IDS = ["ga4", "gsc", "gtm", "google", "meta", "tiktok", "apple", "microsoft", "reddit", "snapchat", "spotify", "pinterest", "linkedin", "x", "openai"];
2514
- var ADPORT_UI_RESOURCE_URIS = [ADPORT_UI_URI, "ui://adport/insight-card-v31.html", "ui://adport/insight-card-v30.html", "ui://adport/insight-card-v29.html", "ui://adport/insight-card-v28.html", "ui://adport/insight-card-v27.html", "ui://adport/insight-card-v26.html", "ui://adport/insight-card-v25.html", "ui://adport/insight-card-v24.html", "ui://adport/insight-card-v23.html", "ui://adport/insight-card-v22.html", "ui://adport/insight-card-v21.html", "ui://adport/insight-card-v20.html", "ui://adport/insight-card-v19.html", "ui://adport/insight-card-v18.html", "ui://adport/insight-card-v17.html", "ui://adport/insight-card-v16.html", "ui://adport/insight-card-v15.html", "ui://adport/insight-card-v14.html", "ui://adport/insight-card-v13.html", "ui://adport/insight-card-v12.html", "ui://adport/insight-card-v11.html", "ui://adport/insight-card-v10.html", "ui://adport/insight-card-v9.html", "ui://adport/insight-card-v8.html", "ui://adport/insight-card-v7.html", "ui://adport/insight-card-v6.html", "ui://adport/insight-card-v5.html", "ui://adport/insight-card-v4.html", "ui://adport/insight-card-v3.html", "ui://adport/insight-card-v2.html", ADPORT_SUMMARY_UI_URI, "ui://adport/summary-card-v30.html"];
2848
+ var ADPORT_UI_RESOURCE_URIS = [ADPORT_UI_URI, "ui://adport/insight-card-v33.html", "ui://adport/insight-card-v32.html", "ui://adport/insight-card-v31.html", "ui://adport/insight-card-v30.html", "ui://adport/insight-card-v29.html", "ui://adport/insight-card-v28.html", "ui://adport/insight-card-v27.html", "ui://adport/insight-card-v26.html", "ui://adport/insight-card-v25.html", "ui://adport/insight-card-v24.html", "ui://adport/insight-card-v23.html", "ui://adport/insight-card-v22.html", "ui://adport/insight-card-v21.html", "ui://adport/insight-card-v20.html", "ui://adport/insight-card-v19.html", "ui://adport/insight-card-v18.html", "ui://adport/insight-card-v17.html", "ui://adport/insight-card-v16.html", "ui://adport/insight-card-v15.html", "ui://adport/insight-card-v14.html", "ui://adport/insight-card-v13.html", "ui://adport/insight-card-v12.html", "ui://adport/insight-card-v11.html", "ui://adport/insight-card-v10.html", "ui://adport/insight-card-v9.html", "ui://adport/insight-card-v8.html", "ui://adport/insight-card-v7.html", "ui://adport/insight-card-v6.html", "ui://adport/insight-card-v5.html", "ui://adport/insight-card-v4.html", "ui://adport/insight-card-v3.html", "ui://adport/insight-card-v2.html", ADPORT_SUMMARY_UI_URI, "ui://adport/summary-card-v33.html", "ui://adport/summary-card-v32.html", "ui://adport/summary-card-v30.html"];
2515
2849
  var DEFAULT_MCP_ICONS = [{
2516
2850
  src: "https://app.adport.dev/icon.svg?brand=orange-dot-v2",
2517
2851
  mimeType: "image/svg+xml",
@@ -2538,7 +2872,7 @@ function createMcpUiServer({ name = "adport", version = package_default.version,
2538
2872
  function registerUiResources(server, uiDomain, uiResourceDomains, uiConnectDomains) {
2539
2873
  const summaryDomains = uiResourceDomains.filter((domain) => domain === ADPORT_UI_DOMAIN || uiConnectDomains.includes(domain));
2540
2874
  for (const uri of ADPORT_UI_RESOURCE_URIS) {
2541
- const summary = uri === ADPORT_SUMMARY_UI_URI || uri === "ui://adport/summary-card-v30.html";
2875
+ const summary = uri.startsWith("ui://adport/summary-card-");
2542
2876
  const resourceMeta = {
2543
2877
  ui: {
2544
2878
  ...uiDomain ? { domain: uiDomain } : {},
@@ -2730,4 +3064,4 @@ export {
2730
3064
  createMcpServer,
2731
3065
  runStdioServer
2732
3066
  };
2733
- //# sourceMappingURL=chunk-FKKOEMUR.js.map
3067
+ //# sourceMappingURL=chunk-LLAXR25X.js.map