@adport/mcp 0.11.1 → 0.12.0
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 +1 -1
- package/dist/{chunk-FVSA7WDE.js → chunk-FKKOEMUR.js} +625 -44
- package/dist/chunk-FKKOEMUR.js.map +1 -0
- package/dist/index.js +1 -1
- package/package.json +16 -16
- package/dist/chunk-FVSA7WDE.js.map +0 -1
|
@@ -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.
|
|
25
|
+
version: "0.12.0",
|
|
26
26
|
description: "adport MCP server \u2014 the open control plane for paid media",
|
|
27
27
|
license: "Apache-2.0",
|
|
28
28
|
type: "module",
|
|
@@ -472,7 +472,7 @@ var RECORD_UI_STYLES = String.raw`
|
|
|
472
472
|
var RECORD_UI_SCRIPT = String.raw`
|
|
473
473
|
let recordPages=null;
|
|
474
474
|
function recordPagesIgnoreEcho(data) {
|
|
475
|
-
return !!recordPages?.busy && data?._adport?.view===
|
|
475
|
+
return !!recordPages?.busy && data?._adport?.view===recordPages.meta.view && galleryMatches(data._adport,recordPages.meta) && galleryScope(data._adport)===recordPages.scope;
|
|
476
476
|
}
|
|
477
477
|
function providerMarks(values,meta,label='Platforms') {
|
|
478
478
|
const providers=[...new Set(arr(values).filter(value=>typeof value==='string'&&value))];
|
|
@@ -527,13 +527,46 @@ var RECORD_UI_SCRIPT = String.raw`
|
|
|
527
527
|
const provider=nativeProvider!==meta.provider?nativeProvider:undefined;
|
|
528
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>';
|
|
529
529
|
}
|
|
530
|
+
function entityRecordTable(tool) {
|
|
531
|
+
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||'');
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function entityFields(row,meta) {
|
|
535
|
+
const item=object(row?.campaign)?row.campaign:object(row?.ad_group)?row.ad_group:row||{};
|
|
536
|
+
const name=item.name??item.Name??item.campaign_name??item.adgroup_name??item.id??item.Id;
|
|
537
|
+
const status=item.effective_status??item.status??item.Status??item.delivery_status??item.configured_status??
|
|
538
|
+
item.displayStatus??item.systemStatus??item.secondary_status??item.operation_status??item.entity_status;
|
|
539
|
+
const scope=/(?:campaigns|campaign_groups)$/.test(meta.tool)?item.account_id??item.ad_account_id??item.advertiser_id??meta.accountId:
|
|
540
|
+
item.campaign_name??item.campaign_id??item.campaignId??item.CampaignId??item.parent_id??meta.accountId;
|
|
541
|
+
const native=item.dailyBudget??item.DailyBudget??item.daily_budget??(meta.provider==='tiktok'?item.budget:undefined);
|
|
542
|
+
const daily=object(native?.value)?native.value:native;
|
|
543
|
+
const minor=meta.provider==='meta'?2:0;
|
|
544
|
+
const currency=currencyOf(item)||currencyOf({currency:item.currency_code??item.currencyCode??meta.currency});
|
|
545
|
+
const moneyField=(value,scale)=> {
|
|
546
|
+
const amount=nativeReportDecimal(object(value)?value.amount??value.Amount??value.value:value,scale);
|
|
547
|
+
return amount===null?null:amount+' '+(currencyOf(object(value)?value:{})||currency||'account units');
|
|
548
|
+
};
|
|
549
|
+
const dailyMicros=item.daily_budget_micros??item.daily_budget_amount_local_micro??item.daily_spend_cap??item.budget?.daily_spend_limit_micros;
|
|
550
|
+
const totalMicros=item.lifetime_budget_micros??item.total_budget_amount_local_micro??item.lifetime_spend_cap??item.budget?.lifetime_spend_limit_micros;
|
|
551
|
+
const value=moneyField(dailyMicros,6)??moneyField(daily,minor)??moneyField(totalMicros,6)??moneyField(item.lifetime_budget,minor)??
|
|
552
|
+
moneyField(item.bid_micros??item.bid_amount_local_micro,6)??moneyField(item.bidAmount??item.bid??item.bid_amount,minor);
|
|
553
|
+
return [name,workflowLabel(status),scope,value];
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const entityHeaders=['Name','Status','Scope','Budget or bid'];
|
|
557
|
+
function recordEntryMarkup(row,index,meta,table) {
|
|
558
|
+
if(!table)return recordRow(row,index,meta);
|
|
559
|
+
return '<tr role="row">'+entityFields(row,meta).map((value,i)=>
|
|
560
|
+
workflowCell(entityHeaders[i],esc(workflowText(value)||(i===0?'Record '+(index+1):'—')),i===0)).join('')+'</tr>';
|
|
561
|
+
}
|
|
562
|
+
|
|
530
563
|
function renderRecordPages(message='') {
|
|
531
564
|
const pages=recordPages,area=app.querySelector('[data-record-pages]');if(!pages||!area)return;
|
|
532
565
|
const next=pages.rows.length<1000 && galleryNext(pages.meta);
|
|
533
566
|
let status=area.querySelector('[role="status"]');if(!status){status=document.createElement('p');status.className='operation-note';status.setAttribute('role','status');area.prepend(status);}status.textContent=message;status.hidden=!message;
|
|
534
567
|
let button=area.querySelector('[data-record-more]');
|
|
535
568
|
if(next){if(!button){button=document.createElement('button');button.type='button';button.className='media-button';button.dataset.recordMore='';button.addEventListener('click',loadRecordPage);area.append(button);}button.textContent=pages.busy?'Loading…':'Load more';button.setAttribute('aria-disabled',String(!!pages.busy));}
|
|
536
|
-
else if(button){const focused=button===document.activeElement;button.remove();if(focused)app.querySelector('[data-record-list]')?.focus({preventScroll:true});}
|
|
569
|
+
else if(button){const focused=button===document.activeElement;button.remove();if(focused)(app.querySelector('[data-record-list]')?.closest('[role=region]'))?.focus({preventScroll:true});}
|
|
537
570
|
}
|
|
538
571
|
async function loadRecordPage() {
|
|
539
572
|
const pages=recordPages,args=pages && galleryNext(pages.meta);if(!pages||pages.busy||!args||pages.rows.length>=1000)return;
|
|
@@ -543,15 +576,16 @@ var RECORD_UI_SCRIPT = String.raw`
|
|
|
543
576
|
const response=await callTool(pages.meta.tool,args,60000),value=resultData(response),meta=value?._adport,rows=recordEntries(recordPayload(value));
|
|
544
577
|
hostResults.add(JSON.stringify(value));if(hostResults.size>16)hostResults.delete(hostResults.values().next().value);
|
|
545
578
|
if(recordPages!==pages){state.hasLocalResult=true;return;}
|
|
546
|
-
if(response?.isError||value?.error||!Array.isArray(rows)||!meta||meta.view!==
|
|
579
|
+
if(response?.isError||value?.error||!Array.isArray(rows)||!meta||meta.view!==pages.meta.view||!galleryMatches(meta,pages.meta)||galleryScope(meta)!==pages.scope||!object(meta.refresh?.arguments)||galleryStable(meta.refresh.arguments)!==key||!rows.length&&(value.truncated!==false||galleryNext(meta)))throw new Error('The next page could not be confirmed.');
|
|
547
580
|
const root=app.querySelector('[data-record-list]');if(!root)return;
|
|
581
|
+
const displayMeta=currencyOf(value)?{...meta,currency:currencyOf(value)}:meta;
|
|
548
582
|
let added=0;
|
|
549
583
|
rows.forEach((row,index)=>{
|
|
550
584
|
const identity=object(row)&&(typeof row.id==='string'&&row.id||typeof row.id==='number'&&Number.isSafeInteger(row.id))?'id:'+String(row.id):key+':'+index;
|
|
551
585
|
const previous=pages.items.get(identity);
|
|
552
|
-
if(previous){if(galleryStable(previous.row)!==galleryStable(row)){const template=document.createElement('template');template.innerHTML=
|
|
586
|
+
if(previous){if(galleryStable(previous.row)!==galleryStable(row)){const template=document.createElement('template');template.innerHTML=recordEntryMarkup(row,previous.index,displayMeta,pages.table);const node=template.content.firstElementChild;previous.node.replaceWith(node);previous.node=node;previous.row=row;pages.rows[previous.index]=row;}return;}
|
|
553
587
|
if(pages.rows.length>=1000)return;
|
|
554
|
-
const template=document.createElement('template');template.innerHTML=
|
|
588
|
+
const template=document.createElement('template');template.innerHTML=recordEntryMarkup(row,pages.rows.length,displayMeta,pages.table);const node=template.content.firstElementChild;
|
|
555
589
|
pages.items.set(identity,{row,index:pages.rows.length,node});pages.rows.push(row);root.append(node);added++;
|
|
556
590
|
});
|
|
557
591
|
pages.seen.add(key);pages.meta={...meta,...(!added||pages.rows.length>=1000?{next:undefined}:{})};pages.data=value;
|
|
@@ -570,11 +604,16 @@ var RECORD_UI_SCRIPT = String.raw`
|
|
|
570
604
|
const parent=object(data.parent)?Object.entries(data.parent).filter(([key])=>/_id$/.test(key)).map(([key,value])=>human(key.replace(/_id$/,''))+' '+value).join(' · '):'';
|
|
571
605
|
const scope=[parent,typeof data.parent_id==='string'&&!parent?data.parent_id:'',meta.accountId].filter(Boolean).join(' · ');
|
|
572
606
|
const clean=object(data)?Object.fromEntries(Object.entries(data).filter(([key])=>key!=='_adport'&&!(key==='creatives'&&meta.view==='records'))):data;
|
|
573
|
-
const
|
|
607
|
+
const table=Array.isArray(entries)&&entityRecordTable(meta.tool)&&rows.every(object);
|
|
608
|
+
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('');
|
|
610
|
+
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
|
+
'<tbody data-record-list role="rowgroup">'+markup+'</tbody></table></div>':
|
|
612
|
+
'<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>';
|
|
574
613
|
app.innerHTML=chrome(operationHeader(title,scope,meta.provider)+'<div class="record-notes">'+notices(data)+'</div>'+content+(rows.length>1000?'<p class="operation-note">Showing 1,000 of '+rows.length+' records. The full response is in Details.</p>':'')+'<div data-record-pages></div><details data-record-details><summary>Details'+(entries?' · '+entries.length+' results':'')+'</summary><pre>'+esc(JSON.stringify(clean,null,2))+'</pre></details>','');
|
|
575
|
-
if(
|
|
576
|
-
recordPages={scope:galleryScope(meta),meta,data,rows:rows.slice(0,1000),items:new Map(),seen:new Set([galleryStable(meta.refresh.arguments)]),busy:false};
|
|
577
|
-
const nodes=app.querySelectorAll('[data-record-list]
|
|
614
|
+
if(Array.isArray(entries)&&rows.length&&galleryNext(meta)){
|
|
615
|
+
recordPages={scope:galleryScope(meta),meta,data,table,rows:rows.slice(0,1000),items:new Map(),seen:new Set([galleryStable(meta.refresh.arguments)]),busy:false};
|
|
616
|
+
const nodes=app.querySelectorAll('[data-record-list]>*');recordPages.rows.forEach((row,index)=>{const identity=object(row)&&(typeof row.id==='string'&&row.id||typeof row.id==='number'&&Number.isSafeInteger(row.id))?'id:'+String(row.id):galleryStable(meta.refresh.arguments)+':'+index;recordPages.items.set(identity,{row,index,node:nodes[index]});});
|
|
578
617
|
renderRecordPages();
|
|
579
618
|
}
|
|
580
619
|
}
|
|
@@ -650,15 +689,41 @@ var INSIGHT_UI_STYLES = String.raw`
|
|
|
650
689
|
.insight-action span { color:var(--muted); margin-right:5px }
|
|
651
690
|
`;
|
|
652
691
|
var INSIGHT_UI_SCRIPT = String.raw`
|
|
653
|
-
function
|
|
654
|
-
const
|
|
655
|
-
|
|
692
|
+
function appleRecommendationMoney(value) {
|
|
693
|
+
const amount=nativeReportDecimal(value?.amount),currency=currencyOf(value||{});
|
|
694
|
+
return amount===null?null:amount+' '+(currency||'account units');
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function renderAppleRecommendations(data,meta) {
|
|
698
|
+
const items=workflowRows(data.result);
|
|
699
|
+
const recommendations=items.map(item=>{
|
|
700
|
+
const budget=item.suggestedDailyBudgetAmount!=null;
|
|
701
|
+
const current=appleRecommendationMoney(budget?item.dailyBudget:item.bidStrategy?.bidAmount);
|
|
702
|
+
const proposed=appleRecommendationMoney(budget?item.suggestedDailyBudgetAmount:item.recommendedTargetCPA);
|
|
703
|
+
const entity=item.campaignName?item.campaignName:item.campaignId!=null?'Campaign '+item.campaignId:'Apple Ads recommendation';
|
|
704
|
+
const label=budget?'Daily budget':item.recommendedTargetCPA!=null?'Target CPA':'Native recommendation';
|
|
705
|
+
return {provider:'apple',title:entity+' · '+label,detail:current?'Current '+current:'',recommendation:proposed||''};
|
|
706
|
+
});
|
|
707
|
+
const args=readPageArgs(meta,'data-recommendations-next');
|
|
708
|
+
renderInsights({...data,recommendations,truncated:false},data,
|
|
709
|
+
readPageMarkup(args,'data-recommendations-next','data-recommendations-status'));
|
|
710
|
+
bindReadPage(meta,args,'data-recommendations-next','data-recommendations-status',value=>Array.isArray(value.result));
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function renderInsights(data,native,footer='') {
|
|
714
|
+
const items=data.finding?[data.finding]:workflowRows(data.findings||data.recommendations||data.results||data.entries);
|
|
715
|
+
const coverage=[
|
|
716
|
+
typeof data.evaluatedAccounts==='number'?data.evaluatedAccounts+' evaluated accounts':null,
|
|
717
|
+
data.range?.start&&data.range?.end?data.range.start+' – '+data.range.end:null
|
|
718
|
+
].filter(Boolean).join(' · ');
|
|
719
|
+
const body=notices(data)+workflowNote(coverage)+(items.length?'<div class="insight-list" role="region" aria-label="Recommendations" tabindex="0">'+items.map(item=>{
|
|
656
720
|
const reason=typeof item.detail==='string'?item.detail:typeof item.description==='string'?item.description:'';
|
|
657
721
|
const suggestion=typeof item.recommendation==='string'?item.recommendation:'';
|
|
722
|
+
const scope=item.accountId?'<p>Account '+esc(item.accountId)+'</p>':'';
|
|
658
723
|
const status=item.status&&item.status!=='open'?item.status:item.severity||item.status||'';
|
|
659
|
-
return '<article class="insight"><div class="insight-heading">'+(item.provider?logo(item.provider):'')+'<strong>'+esc(item.title||item.summary||item.rule||'Finding')+'</strong>'+(status?'<span class="pill '+(/critical|high/i.test(status)?'danger':'neutral')+'">'+esc(status)+'</span>':'')+'</div>'+(reason?'<p class="insight-reason">'+esc(reason)+'</p>':'')+(suggestion?'<p class="insight-action"><span>Suggested</span>'+esc(suggestion)+'</p>':'')+'</article>';
|
|
660
|
-
}).join('')+'</div><details><summary>Details · '+items.length+' findings</summary><pre>'+esc(JSON.stringify(items,null,2))+'</pre></details>':'<div class="empty">No recommendations were returned.</div>');
|
|
661
|
-
app.innerHTML=chrome(body,items.length+' recommendation'+(items.length===1?'':'s'));
|
|
724
|
+
return '<article class="insight"><div class="insight-heading">'+(item.provider?logo(item.provider):'')+'<strong>'+esc(item.title||item.summary||item.rule||'Finding')+'</strong>'+(status?'<span class="pill '+(/critical|high/i.test(status)?'danger':'neutral')+'">'+esc(status)+'</span>':'')+'</div>'+scope+(reason?'<p class="insight-reason">'+esc(reason)+'</p>':'')+(suggestion?'<p class="insight-action"><span>Suggested</span>'+esc(suggestion)+'</p>':'')+'</article>';
|
|
725
|
+
}).join('')+'</div><details><summary>Details · '+items.length+' findings</summary><pre>'+esc(JSON.stringify(native||items,null,2))+'</pre></details>':'<div class="empty">No recommendations were returned.</div>');
|
|
726
|
+
app.innerHTML=chrome(body+footer,items.length+' recommendation'+(items.length===1?'':'s'));
|
|
662
727
|
}
|
|
663
728
|
`;
|
|
664
729
|
|
|
@@ -1346,20 +1411,520 @@ var NATIVE_REPORT_UI_SCRIPT = String.raw`
|
|
|
1346
1411
|
const missingGoals=arr(data.not_returned_goal_ids).filter(id=>!arr(data.errors).some(error=>error?.goal_id===id&&error?.error_code));
|
|
1347
1412
|
const absent=missingGoals.length?'<p class="notice">No summary returned for goal'+(missingGoals.length===1?'':'s')+' '+missingGoals.map(esc).join(', ')+'.</p>':'';
|
|
1348
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);
|
|
1349
|
-
const pageArgs=['ga4_report','gsc_search_analytics'].includes(meta.tool)?
|
|
1414
|
+
const pageArgs=['ga4_report','gsc_search_analytics'].includes(meta.tool)?readPageArgs(meta,'data-report-next'):null;
|
|
1350
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'}:{});
|
|
1351
|
-
|
|
1416
|
+
const analytics=['ga4','gsc'].includes(provider),range=payload?.date_range;
|
|
1417
|
+
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>','');
|
|
1352
1419
|
chart.mount();
|
|
1353
|
-
|
|
1420
|
+
bindReadPage(meta,pageArgs,'data-report-next','data-report-page-status',value=>Array.isArray(recordPayload(value)?.rows));
|
|
1421
|
+
}
|
|
1422
|
+
`;
|
|
1423
|
+
|
|
1424
|
+
// src/workflow-ui.ts
|
|
1425
|
+
import { MEDIA_PREPARATION_TOOLS, MEDIA_UPLOAD_TOOLS } from "@adport/core";
|
|
1426
|
+
var WORKFLOW_UI_STYLES = String.raw`
|
|
1427
|
+
.workflow-list { display:grid; gap:0; max-height:430px; overflow:auto; scrollbar-width:thin }
|
|
1428
|
+
.workflow-item { min-width:0; padding:10px 0; border-bottom:1px solid var(--line); overflow-wrap:anywhere }
|
|
1429
|
+
.workflow-item h3 { margin:0; font-size:12px }
|
|
1430
|
+
.workflow-heading { display:flex; align-items:baseline; justify-content:space-between; flex-wrap:wrap; gap:8px }
|
|
1431
|
+
.workflow-item p { margin:5px 0 0; color:var(--muted); font-size:11px; line-height:1.55 }
|
|
1432
|
+
.workflow-item .record-fields { margin-top:6px }
|
|
1433
|
+
.workflow-item .media-button { margin-top:8px }
|
|
1434
|
+
.workflow-timeline { list-style:none; padding-left:12px; border-left:1px solid var(--line) }
|
|
1435
|
+
.workflow-arms { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,200px),1fr)); gap:12px }
|
|
1436
|
+
.workflow-scroll { overflow:auto; max-height:430px; scrollbar-width:thin; margin-top:8px }
|
|
1437
|
+
.workflow-table { width:100%; border-collapse:collapse; font-size:11px }
|
|
1438
|
+
.workflow-table th,.workflow-table td { padding:8px; border-bottom:1px solid var(--line); text-align:left; overflow-wrap:anywhere }
|
|
1439
|
+
.workflow-table thead th { position:sticky; top:0; z-index:1; background:var(--paper); color:var(--muted); font-weight:500 }
|
|
1440
|
+
.workflow-table tbody th { font-weight:600 }
|
|
1441
|
+
.workflow-link { color:var(--ink); text-underline-offset:2px }
|
|
1442
|
+
.workflow-cell-label { display:none }
|
|
1443
|
+
:root[data-theme="dark"] .workflow-item .pill:not(.neutral):not(.warn) { color:#70c9a1 }
|
|
1444
|
+
:root[data-theme="dark"] .workflow-item .pill.warn { color:#f0bb67 }
|
|
1445
|
+
@media (max-width:480px) {
|
|
1446
|
+
.workflow-stack,.workflow-stack tbody,.workflow-stack tr { display:block }
|
|
1447
|
+
.workflow-stack thead { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%) }
|
|
1448
|
+
.workflow-stack tbody tr { border-bottom:1px solid var(--line); padding:7px 0 }
|
|
1449
|
+
.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) }
|
|
1452
|
+
}
|
|
1453
|
+
`;
|
|
1454
|
+
var WORKFLOW_UI = String.raw`
|
|
1455
|
+
const uploadPreviewTools=new Set(${JSON.stringify([...MEDIA_UPLOAD_TOOLS])});
|
|
1456
|
+
const preparePreviewTools=new Set(${JSON.stringify([...MEDIA_PREPARATION_TOOLS])});
|
|
1457
|
+
const workflowRows=value=>arr(value).filter(object);
|
|
1458
|
+
const workflowText=value=>typeof value==='string'&&value.trim()?value:typeof value==='number'&&Number.isFinite(value)?String(value):'';
|
|
1459
|
+
const workflowLabel=value=>workflowText(value)?human(String(value).replace(/^[A-Z][A-Z0-9_]+$/,word=>word.toLowerCase())):'';
|
|
1460
|
+
const workflowNote=value=>workflowText(value)?'<p class="operation-note">'+esc(value)+'</p>':'';
|
|
1461
|
+
const workflowEmpty=value=>'<p class="empty">'+esc(value)+'</p>';
|
|
1462
|
+
const workflowDetails=data=>'<details><summary>Details</summary><pre>'+esc(JSON.stringify(Object.fromEntries(Object.entries(data).filter(([key])=>key!=='_adport')),null,2))+'</pre></details>';
|
|
1463
|
+
|
|
1464
|
+
function workflowFields(pairs) {
|
|
1465
|
+
const fields=pairs.filter(([,value])=>workflowText(value));
|
|
1466
|
+
return fields.length?'<dl class="record-fields">'+fields.map(([label,value])=>'<div><dt>'+esc(label)+'</dt><dd>'+esc(value)+'</dd></div>').join('')+'</dl>':'';
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
function workflowItem(title,status,body,tag='article',tone='neutral') {
|
|
1470
|
+
return '<'+tag+' class="workflow-item"><div class="workflow-heading"><h3><strong>'+esc(title)+'</strong></h3>'+
|
|
1471
|
+
(status?'<span class="pill '+tone+'">'+esc(status)+'</span>':'')+'</div>'+body+'</'+tag+'>';
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
function workflowHeader(labels) {
|
|
1475
|
+
return '<thead role="rowgroup"><tr role="row">'+labels.map(label=>
|
|
1476
|
+
'<th role="columnheader" scope="col">'+esc(label)+'</th>').join('')+'</tr></thead>';
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
function workflowCell(label,html,heading=false) {
|
|
1480
|
+
const tag=heading?'th':'td',role=heading?'rowheader':'cell';
|
|
1481
|
+
return '<'+tag+' role="'+role+'"'+(heading?' scope="row"':'')+'>'+
|
|
1482
|
+
'<span class="workflow-cell-label" aria-hidden="true" data-label="'+esc(label)+'"></span><span>'+html+'</span></'+tag+'>';
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
function workflowTable(labels,rows,description) {
|
|
1486
|
+
if(!rows.length)return '';
|
|
1487
|
+
return '<div class="workflow-scroll" role="region" aria-label="'+esc(description)+'" tabindex="0">'+
|
|
1488
|
+
'<table class="workflow-table workflow-stack" role="table">'+workflowHeader(labels)+'<tbody role="rowgroup">'+
|
|
1489
|
+
rows.map(row=>'<tr role="row">'+row.map((value,i)=>workflowCell(labels[i],esc(workflowText(value)||'—'),i===0)).join('')+'</tr>').join('')+
|
|
1490
|
+
'</tbody></table></div>';
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
function workflowUrl(value) {
|
|
1494
|
+
try {
|
|
1495
|
+
const parsed=new URL(value);
|
|
1496
|
+
return parsed.protocol==='https:'&&!parsed.username&&!parsed.password?parsed.href:null;
|
|
1497
|
+
} catch {return null;}
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
function workflowLink(url,label,attribute='') {
|
|
1501
|
+
return url?'<p class="operation-note"><a class="workflow-link" '+attribute+' href="'+esc(url)+'" target="_blank" rel="noreferrer noopener">'+esc(label)+'</a></p>':'';
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
function workflowList(body,label) {
|
|
1505
|
+
return '<div class="workflow-list" role="region" aria-label="'+esc(label)+'" tabindex="0">'+body+'</div>';
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
function workflowDate(value) {
|
|
1509
|
+
if(typeof value!=='string'||!Number.isFinite(Date.parse(value)))return null;
|
|
1510
|
+
return value;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
function workflowMillis(value) {
|
|
1514
|
+
return typeof value==='number'&&Number.isFinite(new Date(value).getTime())?new Date(value).toISOString():null;
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
function renderAvailability(data,meta) {
|
|
1518
|
+
const settings=workflowUrl(data.manage_access_url);
|
|
1519
|
+
const access=settings&&new URL(settings).pathname==='/dashboard/agents'?settings:null;
|
|
1520
|
+
const tools=workflowRows(data.tools);
|
|
1521
|
+
const matches=typeof data.total_matches==='number'?data.total_matches:tools.length;
|
|
1522
|
+
const coverage=workflowRows(data.platforms).filter(platform=>platform.selected===true);
|
|
1523
|
+
const rows=tools.map(item=>workflowItem(item.name||'Tool',item.enabled===true?'Ready':item.enabled===false?'Blocked':'Status unavailable',
|
|
1524
|
+
workflowFields([['Platform',providerName(item.provider,meta.providerNames)],['Access',item.read_only===true?'Read-only':item.read_only===false?'Requires write access':null]])+
|
|
1525
|
+
(item.description?'<p>'+esc(item.description)+'</p>':'')+
|
|
1526
|
+
(item.enabled===false?'<p>'+arr(item.blockers).map(workflowLabel).filter(Boolean).map(esc).join(' · ')+'</p>'+
|
|
1527
|
+
arr(item.next_steps).filter(workflowText).map(step=>'<p>'+esc(step)+'</p>').join(''):''),
|
|
1528
|
+
'article',item.enabled===true?'':item.enabled===false?'warn':'neutral')).join('');
|
|
1529
|
+
const total=(data.truncated?tools.length+' of '+matches:matches)+' matching '+(matches===1?'tool':'tools');
|
|
1530
|
+
const platformDetails=coverage.length?'<details><summary>Selected platforms</summary>'+workflowFields(coverage.map(platform=>[providerName(platform.id,meta.providerNames),platform.connected===true?'Connected':platform.connected===false?'Connection required':'Status unavailable']))+'</details>':'';
|
|
1531
|
+
app.innerHTML=chrome(operationHeader('Tool availability','')+(rows?workflowList(rows,'Matching tools'):workflowEmpty('No matching tools were returned.'))+
|
|
1532
|
+
workflowLink(access,'Manage tool access ↗')+workflowNote(data.profile?'Connection profile · '+workflowLabel(data.profile):'')+platformDetails+workflowDetails(data),total);
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
function measurementTable(data,tool) {
|
|
1536
|
+
switch(tool) {
|
|
1537
|
+
case 'reddit_pixel_last_fired': {
|
|
1538
|
+
const pairs=Object.entries(object(data.last_fired_at)?data.last_fired_at:{});
|
|
1539
|
+
return workflowTable(['Event','Last received'],pairs.map(([event,time])=>[workflowLabel(event),workflowDate(time)||'Unavailable']),'Pixel event activity');
|
|
1540
|
+
}
|
|
1541
|
+
case 'pinterest_event_quality':
|
|
1542
|
+
return workflowList(workflowRows(data.items).map(item=>{
|
|
1543
|
+
const components=Object.entries(item.quality_components||{}).flatMap(([component,events])=>
|
|
1544
|
+
Object.entries(events||{}).map(([event,result])=>[
|
|
1545
|
+
workflowLabel(component)+' · '+workflowLabel(event),result?.coverage,result?.overlap,
|
|
1546
|
+
workflowRows(result?.issues).map(issue=>[issue.name,issue.reason].filter(workflowText).join(' · ')).filter(Boolean).join(' | ')
|
|
1547
|
+
]));
|
|
1548
|
+
return workflowItem(workflowLabel(item.source_platform)||'Source',workflowLabel(item.overall_status),
|
|
1549
|
+
workflowFields([['Source',workflowLabel(item.ingestion_source)],['Lookback',item.lookback_period]])+
|
|
1550
|
+
workflowTable(['Component and event','Coverage','Overlap','Issues'],components,'Event quality components'));
|
|
1551
|
+
}).join(''),'Source diagnostics');
|
|
1552
|
+
case 'openai_conversion_events':
|
|
1553
|
+
return workflowTable(['Event','Channel','Event time','Received'],workflowRows(data.events).map(item=>[
|
|
1554
|
+
item.event_type ?? item.event_name,item.api_channel,workflowDate(item.event_time),workflowDate(item.received_at)
|
|
1555
|
+
]),'Sampled events');
|
|
1556
|
+
case 'tiktok_pixel_event_stats':
|
|
1557
|
+
return workflowTable(['Pixel','Event','Reported count','Last activity'],workflowRows(data.list).map(item=>[
|
|
1558
|
+
item.pixel_name ?? item.pixel_id,item.event_name ?? item.event_type ?? item.event,
|
|
1559
|
+
item.event_count ?? item.count,workflowDate(item.last_event_time ?? item.last_fired_at)
|
|
1560
|
+
]),'Pixel observations');
|
|
1561
|
+
case 'spotify_dataset_diagnostics':
|
|
1562
|
+
return workflowList(workflowRows(data.datasources).map(source=>workflowItem(source.datasource_id,workflowLabel(source.datasource_type),
|
|
1563
|
+
workflowFields([['Interval',workflowLabel(source.granularity)]])+
|
|
1564
|
+
workflowTable(['Interval start','Event','Count','Last activity'],workflowRows(source.timeseries).flatMap(bucket=>{
|
|
1565
|
+
const time=workflowMillis(bucket.timestamp);
|
|
1566
|
+
const events=workflowRows(bucket.event_counts);
|
|
1567
|
+
return events.length?events.map(event=>[time,event.name,event.event_count,workflowMillis(event.last_activity_ms)]):[[time,'All reported events',bucket.total,null]];
|
|
1568
|
+
}),'Reported activity')
|
|
1569
|
+
)).join(''),'Dataset sources');
|
|
1570
|
+
default:return '';
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
function renderMeasurement(data,meta) {
|
|
1575
|
+
const tool=meta.tool,period=data.date_range;
|
|
1576
|
+
const subject=[data.pixel_id?'Pixel '+data.pixel_id:null,data.dataset_id?'Dataset '+data.dataset_id:null,
|
|
1577
|
+
object(period)?[period.start_date??period.start,period.end_date??period.end].filter(workflowText).join(' – '):period].filter(workflowText).join(' · ');
|
|
1578
|
+
let body=measurementTable(data,tool);
|
|
1579
|
+
if(tool==='meta_custom_conversion_stats') {
|
|
1580
|
+
const rows=workflowRows(data.stats).flatMap(bucket=>workflowRows(bucket.data).map(entry=>({
|
|
1581
|
+
date:workflowDate(bucket.timestamp),entry
|
|
1582
|
+
})));
|
|
1583
|
+
// Named, explicitly numeric metrics are charted per native series. Bucket
|
|
1584
|
+
// payloads remain separate even if multiple series report the same date.
|
|
1585
|
+
const records=rows.map(({date,entry},i)=>{
|
|
1586
|
+
const group=Object.entries(entry).filter(([key,value])=>typeof value==='string'&&!/^(count|value)$/i.test(key)&&reportNumber(value)===null).map(([,value])=>value).join(' · ');
|
|
1587
|
+
const measure=entry.count??(/^(?:count|unmatched_count|usd_amount|unmatched_usd_amount)$/.test(data.aggregation)?entry.value:null);
|
|
1588
|
+
const count=reportNumber(measure);
|
|
1589
|
+
const unit=/_usd_amount$|^usd_amount$/.test(data.aggregation)?'USD':'';
|
|
1590
|
+
const label=unit?'Reported amount':data.aggregation==='unmatched_count'?'Unmatched count':'Reported count';
|
|
1591
|
+
return {date:date?.slice(0,10),name:date||'Bucket '+(i+1),series:group||'Reported count',context:group?[group]:[],
|
|
1592
|
+
fields:count===null?[]:[{key:'count',label,unit,value:count,display:String(measure)}]};
|
|
1593
|
+
}).filter(row=>row.fields.length);
|
|
1594
|
+
const periods=new Set(records.map(row=>row.date).filter(Boolean));
|
|
1595
|
+
const chart=periods.size>1&&records.every(row=>row.date)&&
|
|
1596
|
+
new Set(records.map(row=>JSON.stringify([row.date,row.series]))).size===records.length?reportCharts(records,{metric:'count'}):null;
|
|
1597
|
+
const args=readPageArgs(meta,'data-measurement-next');
|
|
1598
|
+
body=(chart?.html||'')+workflowTable(['Timestamp','Native values'],workflowRows(data.stats).map(bucket=>[
|
|
1599
|
+
bucket.timestamp,workflowRows(bucket.data).map(entry=>Object.entries(entry).filter(([,val])=>workflowText(val)).map(([key,val])=>workflowLabel(key)+' '+val).join(' · ')).filter(Boolean).join(' | ')
|
|
1600
|
+
]),'Native conversion buckets')+readPageMarkup(args,'data-measurement-next','data-measurement-status');
|
|
1601
|
+
app.innerHTML=chrome(operationHeader('Conversion statistics',[data.conversion_id?'Conversion '+data.conversion_id:null,workflowLabel(data.aggregation),
|
|
1602
|
+
[meta.refresh?.arguments?.start_time,meta.refresh?.arguments?.end_time].filter(workflowText).join(' – ')].filter(Boolean).join(' · '),meta.provider)+notices(data)+(body||workflowEmpty('No conversion statistics were returned.'))+workflowDetails(data),'');
|
|
1603
|
+
chart?.mount();
|
|
1604
|
+
bindReadPage(meta,args,'data-measurement-next','data-measurement-status',value=>Array.isArray(value.stats));
|
|
1605
|
+
return;
|
|
1606
|
+
}
|
|
1607
|
+
const hasRows=tool==='pinterest_event_quality'?workflowRows(data.items).length:tool==='spotify_dataset_diagnostics'?workflowRows(data.datasources).length:true;
|
|
1608
|
+
app.innerHTML=chrome(operationHeader('Measurement health',subject,meta.provider)+notices(data)+
|
|
1609
|
+
(tool==='openai_conversion_events'?workflowNote('Recent event sample. Counts cover the rows shown. (Sample size: '+arr(data.events).length+')'):'')+
|
|
1610
|
+
(body&&hasRows?body:workflowEmpty('No matching observations were returned.'))+workflowDetails(data),'');
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
function renderHistory(data,meta) {
|
|
1614
|
+
const args=readPageArgs(meta,'data-history-next');
|
|
1615
|
+
const events=workflowRows(Array.isArray(data.result)?data.result:data.events);
|
|
1616
|
+
const ordered=[...events].sort((a,b)=>(Date.parse(b.eventTime)||0)-(Date.parse(a.eventTime)||0));
|
|
1617
|
+
const rows=ordered.slice(0,1000).map(item=>workflowItem([workflowLabel(item.eventType),workflowLabel(item.entityType)].filter(Boolean).join(' · ')||'Change',null,
|
|
1618
|
+
workflowFields([['Time (UTC)',workflowDate(item.eventTime)],['Actor',item.modifiedBy],['Actor type',workflowLabel(item.userType)],['Transaction',item.transactionId],['Changes',item.count]])+
|
|
1619
|
+
(workflowRows(item.metas).length?'<details><summary>Returned entity metadata</summary><pre>'+esc(JSON.stringify(item.metas,null,2))+'</pre></details>':''),'li')).join('');
|
|
1620
|
+
app.innerHTML=chrome(operationHeader('Change history',meta.accountId,meta.provider)+notices(data)+(rows?'<ol class="workflow-list workflow-timeline">'+rows+'</ol>':workflowEmpty('No change summaries were returned.'))+
|
|
1621
|
+
(ordered.length>1000?workflowNote('Showing 1,000 changes. All returned changes are in Details.'):'' )+
|
|
1622
|
+
readPageMarkup(args,'data-history-next','data-history-status')+workflowDetails(data),ordered.length+' returned');
|
|
1623
|
+
bindReadPage(meta,args,'data-history-next','data-history-status',value=>Array.isArray(value.result));
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
function renderExperiment(data,meta) {
|
|
1627
|
+
const experiment=data.experiment,arms=workflowRows(data.arms),campaigns=workflowRows(data.campaigns),currency=currencyOf({currency:data.account?.currencyCode});
|
|
1628
|
+
const comparison=arms.map(arm=>{
|
|
1629
|
+
const linked=[...new Set([...arr(arm.campaigns),...arr(arm.inDesignCampaigns)])];
|
|
1630
|
+
const budgets=linked.map(resource=>{
|
|
1631
|
+
const value=campaigns.find(item=>item.campaign?.resourceName===resource),native=value?.budget;
|
|
1632
|
+
const micros=native?.period==='DAILY'?value.budget_micros:null;
|
|
1633
|
+
return [value?.campaign?.name||resource,workflowLabel(value?.campaign?.status),available(micros)?money(micros/1e6,currency,6):null];
|
|
1634
|
+
});
|
|
1635
|
+
return workflowItem(arm.name||'Arm',arm.control===true?'Control':arm.control===false?'Treatment':'',
|
|
1636
|
+
workflowFields([['Traffic',reportNumber(arm.trafficSplit)===null?null:arm.trafficSplit+'%']])+
|
|
1637
|
+
workflowTable(['Campaign','Status',currency?'Daily budget · '+currency:'Daily budget · account units'],budgets,'Campaigns in this arm'));
|
|
1638
|
+
}).join('');
|
|
1639
|
+
const base=data.base_campaign,daily=base?.budget?.period==='DAILY'?base.budget_micros:null;
|
|
1640
|
+
const content=object(experiment)?workflowFields([['Status',workflowLabel(experiment.status)],['Start',experiment.startDate],['End',experiment.endDate],['Account timezone',data.account?.timeZone]])+
|
|
1641
|
+
(comparison?'<div class="workflow-arms">'+comparison+'</div>':workflowEmpty('No experiment arms were returned.')):
|
|
1642
|
+
object(base)?workflowFields([['Base campaign',base.campaign?.name],['Status',workflowLabel(base.campaign?.status)],['Daily budget',available(daily)?money(daily/1e6,currency,6):null]]):
|
|
1643
|
+
workflowEmpty('No experiment or base campaign was returned.');
|
|
1644
|
+
app.innerHTML=chrome(operationHeader(experiment?.name||'Experiment comparison',meta.accountId,meta.provider)+notices(data)+content+workflowDetails(data),'Configuration');
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
function renderCatalogProcessing(data,meta) {
|
|
1648
|
+
const tool=meta.tool,rows=workflowRows(data.records);
|
|
1649
|
+
const identity=data.batch_id??data.feed_id??data.import_id??data.processing_result_id;
|
|
1650
|
+
let report='';
|
|
1651
|
+
if(tool==='reddit_catalog_import_report') {
|
|
1652
|
+
const expires=workflowDate(data.expires_at),href=data.report_available===true&&expires&&Date.parse(expires)>Date.now()?workflowUrl(data.download_url):null;
|
|
1653
|
+
report=href?workflowLink(href,'Download native report ↗','data-catalog-download')+workflowNote('Expires '+expires):workflowNote('The native report is unavailable or expired.');
|
|
1654
|
+
}
|
|
1655
|
+
const items=rows.map(item=>{
|
|
1656
|
+
const detail=item.message??item.error?.message??item.error??item.reason;
|
|
1657
|
+
const counts=Object.entries(item.product_counts??item.summary??Object.fromEntries(
|
|
1658
|
+
['added','updated','removed','errors','warnings','affected_product_count','affected_video_count'].map(key=>[key,item[key]])
|
|
1659
|
+
)).filter(([,value])=>workflowText(value));
|
|
1660
|
+
const structured=['validation_details','ingestion_details','errors','warnings','issues'].filter(key=>item[key]&&Object.keys(item[key]).length);
|
|
1661
|
+
return workflowItem(item.name||item.source_id||item.item_id||item.id||item.code||'Result',item.status??item.severity,
|
|
1662
|
+
workflowFields([['Store',item.store_code],['Updated',workflowDate(item.updated_at)],['Completed',item.completed_at],
|
|
1663
|
+
['Readback',workflowLabel(item.readback)],['Code',item.code],['Field',item.field],['Line',item.line],['Product',item.product_id],
|
|
1664
|
+
...counts.map(([key,value])=>[workflowLabel(key),value])])+
|
|
1665
|
+
workflowNote(detail)+(structured.length?'<details><summary>Provider diagnostics</summary><pre>'+esc(JSON.stringify(Object.fromEntries(structured.map(key=>[key,item[key]])),null,2))+'</pre></details>':''));
|
|
1666
|
+
}).join('');
|
|
1667
|
+
const args=readPageArgs(meta,'data-catalog-next');
|
|
1668
|
+
const summary=receiptMarkup({status:data.status})+
|
|
1669
|
+
workflowFields([['Submitted',data.submitted_items],['Terminal item outcomes',data.terminal_items]]);
|
|
1670
|
+
app.innerHTML=chrome(operationHeader('Catalog processing',identity,meta.provider)+notices(data)+summary+
|
|
1671
|
+
(data.all_items_native_successful===false?workflowNote('Some item outcomes are unsuccessful or unconfirmed.'):'')+
|
|
1672
|
+
report+(items?workflowList(items,'Catalog outcomes'):report?'':workflowEmpty('No processing records were returned.'))+
|
|
1673
|
+
workflowTable(['Severity','Field','Affected items'],['error_fields','warning_fields'].flatMap(key=>
|
|
1674
|
+
workflowRows(data.log?.[key]).map(row=>[key==='error_fields'?'Error':'Warning',row.field,row.affected_product_count??row.affected_video_count])
|
|
1675
|
+
),'Affected fields')+
|
|
1676
|
+
readPageMarkup(args,'data-catalog-next','data-catalog-status')+workflowDetails(data),'');
|
|
1677
|
+
app.querySelector('[data-catalog-download]')?.addEventListener('click',event=>{
|
|
1678
|
+
if(Date.parse(data.expires_at)>Date.now())return;
|
|
1679
|
+
event.preventDefault();
|
|
1680
|
+
const message=document.createElement('span');
|
|
1681
|
+
message.setAttribute('role','status');
|
|
1682
|
+
message.textContent='This report link expired. Request a fresh report.';
|
|
1683
|
+
event.currentTarget.replaceWith(message);
|
|
1684
|
+
});
|
|
1685
|
+
bindReadPage(meta,args,'data-catalog-next','data-catalog-status',value=>Array.isArray(value.records));
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
function distributionArguments(item,data,meta) {
|
|
1689
|
+
const tools=item.stage==='upload'?uploadPreviewTools:item.stage==='prepare'?preparePreviewTools:null;
|
|
1690
|
+
if(meta.capabilities?.can_write!==true||!meta.context?.project_id||item.ready!==true||item.available!==true||
|
|
1691
|
+
!tools?.has(item.tool)||typeof item.provider!=='string'||!item.tool.startsWith(item.provider+'_')||
|
|
1692
|
+
typeof item.account_id!=='string'||!object(item.arguments)) return null;
|
|
1693
|
+
const args=item.arguments;
|
|
1694
|
+
if(args.account_id!==item.account_id||Object.hasOwn(args,'project_id')&&args.project_id!==meta.context.project_id||
|
|
1695
|
+
Object.hasOwn(args,'pending_operation_id')||Object.hasOwn(args,'file_path')) return null;
|
|
1696
|
+
if(item.stage==='upload'&&(!data.asset?.id||!data.asset?.sha256||args.media_id!==data.asset.id||args.expected_sha256!==data.asset.sha256))return null;
|
|
1697
|
+
return {...args,project_id:meta.context.project_id};
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
let distributionReview=null;
|
|
1701
|
+
function distributionIgnoreEcho(data) {
|
|
1702
|
+
const pending=distributionReview,actual=data?._adport;
|
|
1703
|
+
return !!pending&&actual?.tool===pending.item.tool&&actual.context?.project_id===pending.args.project_id&&
|
|
1704
|
+
actual.accountId===pending.args.account_id&&samePreviewArguments(actual.approval?.arguments,pending.args);
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
function renderDistribution(data,meta) {
|
|
1708
|
+
const plan=meta.tool==='media_distribution_plan',items=workflowRows(plan?data.destinations:data.distributions);
|
|
1709
|
+
const rows=items.map((item,index)=>{
|
|
1710
|
+
const title=[providerName(item.provider,meta.providerNames),item.account_name||item.account_id].filter(Boolean).join(' · ');
|
|
1711
|
+
const status=plan?item.available===false?'Unavailable':item.ready===true?'Ready for review':'Needs input':
|
|
1712
|
+
({ACCEPTED:'Upload accepted',STARTED:'Attempt started',UNCONFIRMED:'Outcome unconfirmed',READY:'Ready'}[item.status]||workflowLabel(item.status));
|
|
1713
|
+
const metadata=plan?workflowFields([['Stage',item.stage==='prepare'?'Prepare an asset container':item.stage==='upload'?'Upload a copy':null]])+
|
|
1714
|
+
workflowNote(item.reason)+workflowNote(item.note)+workflowRows(item.problems).map(problem=>workflowNote([workflowLabel(problem.field),problem.message].filter(Boolean).join(' · '))).join(''):
|
|
1715
|
+
workflowFields([['Updated',workflowDate(item.updated_at)],['Provider resource',arr(item.resource_ids).join(', ')],['Error code',item.error_code]])+
|
|
1716
|
+
(item.status==='ACCEPTED'?workflowNote('Processing readiness is unconfirmed.'):item.status==='UNCONFIRMED'||item.status==='STARTED'?workflowNote('Check the native resource or processing status.'):'' );
|
|
1717
|
+
return workflowItem(title||'Destination',status,metadata+(plan&&distributionArguments(item,data,meta)?
|
|
1718
|
+
'<button type="button" class="media-button" data-distribution-review="'+index+'">Review '+(item.stage==='prepare'?'preparation':'upload')+'</button>':''));
|
|
1719
|
+
}).join('');
|
|
1720
|
+
const details=plan?{...data,destinations:items.map(({arguments:_arguments,fields:_fields,...item})=>item)}:data;
|
|
1721
|
+
app.innerHTML=chrome(operationHeader(plan?'Media distribution plan':'Media distribution status',data.asset?.name)+notices(data)+
|
|
1722
|
+
(rows?workflowList(rows,plan?'Eligible destinations':'Upload attempts'):workflowEmpty(plan?'No matching destinations were returned.':'No upload attempts were returned.'))+
|
|
1723
|
+
'<p class="provider-message" data-distribution-status role="status"></p>'+workflowDetails(details),'');
|
|
1724
|
+
const snapshot=state.result;
|
|
1725
|
+
app.querySelectorAll('[data-distribution-review]').forEach(button=>button.addEventListener('click',async()=>{
|
|
1726
|
+
if(distributionReview?.snapshot===snapshot||state.result!==snapshot)return;
|
|
1727
|
+
const item=items[Number(button.dataset.distributionReview)],args=distributionArguments(item,data,meta);
|
|
1728
|
+
if(!args)return;
|
|
1729
|
+
const pending={snapshot,item,args};distributionReview=pending;button.disabled=true;
|
|
1730
|
+
const indicator=app.querySelector('[data-distribution-status]');indicator.textContent='Preparing review…';
|
|
1731
|
+
try {
|
|
1732
|
+
const response=await callTool(item.tool,args,60000),value=resultData(response),actual=value?._adport;
|
|
1733
|
+
if(state.result!==snapshot){rememberHostResult(JSON.stringify(value));return;}
|
|
1734
|
+
if(response?.isError||value?.error||value.status!=='pending_validation'||value.applied!==false||
|
|
1735
|
+
typeof value.pending_operation_id!=='string'||!value.pending_operation_id||
|
|
1736
|
+
actual?.view!=='operation'||actual.provider!==item.provider||!distributionIgnoreEcho(value)) throw new Error('The upload review could not be confirmed.');
|
|
1737
|
+
rememberHostResult(JSON.stringify(value));
|
|
1738
|
+
acceptResult(response,true);
|
|
1739
|
+
} catch(error) {
|
|
1740
|
+
if(state.result===snapshot)indicator.textContent=error?.message||'Could not prepare the review.';
|
|
1741
|
+
} finally {
|
|
1742
|
+
if(distributionReview===pending)distributionReview=null;
|
|
1743
|
+
if(state.result===snapshot)button.disabled=false;
|
|
1744
|
+
}
|
|
1745
|
+
}));
|
|
1746
|
+
}
|
|
1747
|
+
`;
|
|
1748
|
+
|
|
1749
|
+
// src/planning-ui.ts
|
|
1750
|
+
var PLANNING_UI = String.raw`
|
|
1751
|
+
const forecastNames=new Set(['meta_delivery_estimate','pinterest_audience_estimate','snapchat_audience_size','spotify_audience_estimate','spotify_bid_estimate']);
|
|
1752
|
+
|
|
1753
|
+
function planningMicros(value) {
|
|
1754
|
+
const amount=nativeReportDecimal(value,6);
|
|
1755
|
+
return amount===null?null:amount+' account units';
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
function monthlyHistory(months) {
|
|
1759
|
+
const names=['JANUARY','FEBRUARY','MARCH','APRIL','MAY','JUNE','JULY','AUGUST','SEPTEMBER','OCTOBER','NOVEMBER','DECEMBER'];
|
|
1760
|
+
const points=new Map();
|
|
1761
|
+
for(const row of workflowRows(months)) {
|
|
1762
|
+
const month=names.indexOf(String(row.month).toUpperCase()), year=String(row.year);
|
|
1763
|
+
if(month<0||!/^[1-9]\d{3}$/.test(year))continue;
|
|
1764
|
+
const date=year+'-'+String(month+1).padStart(2,'0'),value=nativeReportDecimal(row.monthlySearches);
|
|
1765
|
+
points.set(date,{date,index:Number(year)*12+month,value});
|
|
1766
|
+
}
|
|
1767
|
+
return [...points.values()].sort((a,b)=>a.index-b.index).slice(-24);
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
function monthlySparkline(points) {
|
|
1771
|
+
const valid=points.filter(point=>point.value!==null && Number.isFinite(Number(point.value)) && Number(point.value)>=0);
|
|
1772
|
+
if(!valid.length)return '—';
|
|
1773
|
+
const width=96,height=22,start=points[0].index,span=Math.max(1,points.at(-1).index-start),max=Math.max(1,...valid.map(point=>Number(point.value)));
|
|
1774
|
+
let path='',previous=null;
|
|
1775
|
+
const dots=[];
|
|
1776
|
+
for(const point of valid) {
|
|
1777
|
+
const x=3+(point.index-start)/span*(width-6),y=height-3-Number(point.value)/max*(height-6);
|
|
1778
|
+
const adjacent=previous===point.index-1;
|
|
1779
|
+
path+=(adjacent?' L':' M')+x.toFixed(2)+' '+y.toFixed(2);
|
|
1780
|
+
dots.push('<circle cx="'+x+'" cy="'+y+'" r="2" fill="var(--orange)"/>');
|
|
1781
|
+
previous=point.index;
|
|
1782
|
+
}
|
|
1783
|
+
const label=points.map(point=>point.date+': '+(point.value??'unavailable')).join(', ');
|
|
1784
|
+
return '<svg width="'+width+'" height="'+height+'" viewBox="0 0 '+width+' '+height+'" role="img" aria-label="'+esc(label)+'"><title>'+esc(label)+'</title>'+
|
|
1785
|
+
'<path d="'+path+'" fill="none" stroke="var(--orange)" stroke-width="1.5"/>'+
|
|
1786
|
+
dots.join('')+'</svg>';
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
function planningProjection(data,meta) {
|
|
1790
|
+
const tool=meta.tool;
|
|
1791
|
+
if(/^google_keyword_(?:ideas|historical_metrics)$/.test(tool)) {
|
|
1792
|
+
return {title:'Keyword research',columns:[
|
|
1793
|
+
{key:'keyword',label:'Keyword'},{key:'volume',label:'Average monthly searches'},{key:'competition',label:'Competition'},
|
|
1794
|
+
{key:'low',label:'Low top-of-page bid'},{key:'high',label:'High top-of-page bid'},{key:'history',label:'Monthly history'}
|
|
1795
|
+
],rows:workflowRows(data.results).map(row=>{
|
|
1796
|
+
const metrics=row.keywordIdeaMetrics??row.keywordMetrics??{};
|
|
1797
|
+
return {keyword:row.text,volume:nativeReportDecimal(metrics.avgMonthlySearches),competition:workflowLabel(metrics.competition),
|
|
1798
|
+
low:planningMicros(metrics.lowTopOfPageBidMicros),high:planningMicros(metrics.highTopOfPageBidMicros),
|
|
1799
|
+
history:monthlyHistory(metrics.monthlySearchVolumes)};
|
|
1800
|
+
}),notes:['Historical estimates. Google groups close variants in historical results.']};
|
|
1801
|
+
}
|
|
1802
|
+
if(/^microsoft_keyword_(?:ideas|historical_metrics)$/.test(tool)) {
|
|
1803
|
+
return {title:'Keyword research',columns:[
|
|
1804
|
+
{key:'keyword',label:'Keyword'},{key:'competition',label:'Competition'},{key:'bid',label:'Suggested bid'},
|
|
1805
|
+
{key:'history',label:'Monthly counts (newest first)'}
|
|
1806
|
+
],rows:workflowRows(data.rows).map(row=>({
|
|
1807
|
+
keyword:row.Keyword,competition:workflowLabel(row.Competition),
|
|
1808
|
+
bid:nativeReportDecimal(row.SuggestedBid)===null?null:nativeReportDecimal(row.SuggestedBid)+' '+(currencyOf(data)||'account units'),
|
|
1809
|
+
history:arr(row.MonthlySearchCounts).slice(0,24).map(item=>nativeReportDecimal(item)??'—').join(' · ')
|
|
1810
|
+
})),notes:data.notes};
|
|
1811
|
+
}
|
|
1812
|
+
if(/^apple_(?:search_)?suggestions$/.test(tool)) {
|
|
1813
|
+
const rows=workflowRows(data.result).map(row=>({
|
|
1814
|
+
term:row.phrase??row.keyword??row.category??row.name,
|
|
1815
|
+
popularity:row.searchPopularity??row.searchPopularity1to5??row.searchPopularity1to100,
|
|
1816
|
+
position:row.rank
|
|
1817
|
+
})).filter(row=>workflowText(row.term));
|
|
1818
|
+
if(!rows.length && arr(data.result).length)return null;
|
|
1819
|
+
return {title:'Keyword suggestions',columns:[{key:'term',label:'Term or category'},{key:'popularity',label:'Native popularity'},{key:'position',label:'Native rank'}],rows};
|
|
1820
|
+
}
|
|
1821
|
+
if(tool==='microsoft_keyword_traffic_estimates') {
|
|
1822
|
+
const rows=workflowRows(data.rows).flatMap(campaign=>workflowRows(campaign.AdGroupEstimates).flatMap(group=>workflowRows(group.KeywordEstimates))).flatMap(item=>{
|
|
1823
|
+
const term=object(item.Keyword)?item.Keyword.Text:item.Keyword;
|
|
1824
|
+
return Object.entries({Minimum:item.Minimum,Maximum:item.Maximum}).filter(([,value])=>object(value)).map(([bound,value])=>({
|
|
1825
|
+
row:[term,bound].filter(workflowText).join(' · '),clicks:value.Clicks,impressions:value.Impressions,
|
|
1826
|
+
cost:nativeReportDecimal(value.TotalCost)===null?null:nativeReportDecimal(value.TotalCost)+' '+(currencyOf(data)||'account units')
|
|
1827
|
+
}));
|
|
1828
|
+
});
|
|
1829
|
+
if(!rows.length&&arr(data.rows).length)return null;
|
|
1830
|
+
return {title:'Weekly traffic estimates',columns:[{key:'row',label:'Keyword and bound'},{key:'clicks',label:'Clicks'},
|
|
1831
|
+
{key:'impressions',label:'Impressions'},{key:'cost',label:'Total cost'}],rows,notes:data.notes};
|
|
1832
|
+
}
|
|
1833
|
+
if(forecastNames.has(tool)) {
|
|
1834
|
+
const values=tool==='meta_delivery_estimate'?workflowRows(data.estimates):[object(data.value)?data.value:data];
|
|
1835
|
+
const rows=values.flatMap((value,index)=>dataFields(value)
|
|
1836
|
+
.filter(field=>/audience|size|estimate|bound|minimum|maximum|lower|upper|reach|bid|impression|dau|mau|ready|status|currency/i.test(field.label)&&workflowText(field.after))
|
|
1837
|
+
.map(field=>({estimate:(values.length>1?'Estimate '+(index+1)+' · ':'')+field.label,value:/(^|\s)micros?$/i.test(field.label)?
|
|
1838
|
+
(nativeReportDecimal(field.after,6)??'—')+' '+(currencyOf(value)||'account units'):field.after}))
|
|
1839
|
+
);
|
|
1840
|
+
if(!rows.length && values.length)return null;
|
|
1841
|
+
return {title:tool==='spotify_bid_estimate'?'Bid estimate':tool==='meta_delivery_estimate'?'Delivery estimates':'Audience estimate',
|
|
1842
|
+
columns:[{key:'estimate',label:'Native measure'},{key:'value',label:'Estimate'}],rows,
|
|
1843
|
+
notes:['Estimates reflect the selected targeting and provider assumptions.']};
|
|
1844
|
+
}
|
|
1845
|
+
return null;
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
function renderPlanning(data,meta,projected) {
|
|
1849
|
+
const planning=projected||data.planning||{};
|
|
1850
|
+
const columns=arr(planning.columns).filter(value=>typeof value?.key==='string'&&typeof value?.label==='string').slice(0,12);
|
|
1851
|
+
const rows=arr(planning.rows),pageSize=100,pages=Math.max(1,Math.ceil(rows.length/pageSize));
|
|
1852
|
+
state.planningPage=Math.max(0,Math.min(state.planningPage,pages-1));
|
|
1853
|
+
const start=state.planningPage*pageSize,shown=rows.slice(start,start+pageSize);
|
|
1854
|
+
const notes=arr(planning.notes).filter(workflowText).map(note=>'<p class="notice">'+esc(note)+'</p>').join('');
|
|
1855
|
+
const detailHeader=projected?workflowHeader(columns.map(column=>column.label)):
|
|
1856
|
+
'<thead><tr>'+columns.map(column=>'<th scope="col">'+esc(column.label)+'</th>').join('')+'</tr></thead>';
|
|
1857
|
+
const detailRows=shown.map(row=>'<tr'+(projected?' role="row"':'')+'>'+columns.map((column,i)=>{
|
|
1858
|
+
const value=row&&Object.hasOwn(row,column.key)?row[column.key]:null;
|
|
1859
|
+
const html=column.key==='history'&&Array.isArray(value)&&projected?monthlySparkline(value):esc(value==null?'—':value);
|
|
1860
|
+
return projected?workflowCell(column.label,html,i===0):'<td>'+html+'</td>';
|
|
1861
|
+
}).join('')+'</tr>').join('');
|
|
1862
|
+
const table=columns.length&&shown.length?'<div class="planning-scroll" tabindex="0" role="region" aria-label="Planning estimate table">'+
|
|
1863
|
+
(projected?'<table class="planning-table workflow-stack" role="table">':'<table class="planning-table">')+detailHeader+
|
|
1864
|
+
(projected?'<tbody role="rowgroup">':'<tbody>')+detailRows+'</tbody></table></div>':workflowEmpty('No planning values were returned for this selection.');
|
|
1865
|
+
const controls=pages>1?'<div class="planning-pages"><button type="button" data-planning-page="previous" '+(state.planningPage===0?'disabled':'')+'>Previous rows</button><span class="context">Rows '+(start+1)+'–'+(start+shown.length)+' of '+rows.length+'</span><button type="button" data-planning-page="next" '+(state.planningPage===pages-1?'disabled':'')+'>Next rows</button></div>':'';
|
|
1866
|
+
const args=readPageArgs(meta,'data-planning-next');
|
|
1867
|
+
app.innerHTML=chrome(operationHeader(planning.title||'Planning estimates',meta.accountId,meta.provider)+notices({...data,notes:arr(data.notes).filter(note=>!arr(planning.notes).includes(note)),truncated:false})+
|
|
1868
|
+
'<div data-read-page-focus tabindex="-1">'+table+controls+(data.truncated?'<p class="notice">Partial native response. More estimates may exist.</p>':'')+notes+
|
|
1869
|
+
readPageMarkup(args,'data-planning-next','data-planning-status')+workflowDetails(data)+'</div>','Read-only estimates');
|
|
1870
|
+
app.querySelectorAll('[data-planning-page]').forEach(button=>button.addEventListener('click',()=>{
|
|
1871
|
+
if(button.disabled)return;
|
|
1872
|
+
state.planningPage+=button.dataset.planningPage==='next'?1:-1;
|
|
1873
|
+
renderPlanning(data,meta,projected);
|
|
1874
|
+
}));
|
|
1875
|
+
bindReadPage(meta,args,'data-planning-next','data-planning-status',value=>!!planningProjection(value,meta)||Array.isArray(value.planning?.rows));
|
|
1876
|
+
}
|
|
1877
|
+
`;
|
|
1878
|
+
|
|
1879
|
+
// src/read-page-ui.ts
|
|
1880
|
+
var READ_PAGE_UI = String.raw`
|
|
1881
|
+
let pendingReadPage=null;
|
|
1882
|
+
let readPageHistory=null;
|
|
1883
|
+
|
|
1884
|
+
function readPageArgs(meta,selector) {
|
|
1885
|
+
const args=galleryNext(meta);
|
|
1886
|
+
const scope=galleryScope(meta);
|
|
1887
|
+
if(readPageHistory?.scope!==scope || readPageHistory.selector!==selector) {
|
|
1888
|
+
readPageHistory={scope,selector,seen:new Set()};
|
|
1889
|
+
}
|
|
1890
|
+
readPageHistory.seen.add(galleryStable(meta.refresh?.arguments));
|
|
1891
|
+
return args&&!readPageHistory.seen.has(galleryStable(args))?args:null;
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
function readPageMarkup(args,selector,statusSelector) {
|
|
1895
|
+
return args?'<div class="provider-pages"><button type="button" class="media-button" '+selector+'>Next page</button></div><p class="provider-message" '+statusSelector+' role="status"></p>':'';
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
function readPageIgnoreEcho(data) {
|
|
1899
|
+
const pending=pendingReadPage,meta=data?._adport;
|
|
1900
|
+
return !!pending&&!!meta&&galleryMatches(meta,pending.meta)&&galleryStable(meta.refresh?.arguments)===pending.key;
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
function bindReadPage(meta,args,selector,statusSelector,valid) {
|
|
1904
|
+
const button=app.querySelector('['+selector+']'),snapshot=state.result;
|
|
1354
1905
|
button?.addEventListener('click',async()=>{
|
|
1355
|
-
if(button.disabled
|
|
1356
|
-
|
|
1906
|
+
if(button.disabled||state.result!==snapshot)return;
|
|
1907
|
+
const pending={meta,key:galleryStable(args)};
|
|
1908
|
+
pendingReadPage=pending;
|
|
1909
|
+
button.disabled=true;
|
|
1910
|
+
button.textContent='Loading…';
|
|
1357
1911
|
try {
|
|
1358
|
-
const response=await callTool(meta.tool,
|
|
1359
|
-
if(state.result!==snapshot)return;
|
|
1360
|
-
if(response?.isError
|
|
1912
|
+
const response=await callTool(meta.tool,args,60000),value=resultData(response),next=value?._adport;
|
|
1913
|
+
if(state.result!==snapshot) {rememberHostResult(JSON.stringify(value));return;}
|
|
1914
|
+
if(response?.isError||value?.error||!next||next.view!==meta.view||!galleryMatches(next,meta)||
|
|
1915
|
+
galleryScope(next)!==galleryScope(meta)||galleryStable(next.refresh?.arguments)!==pending.key||!valid(value)) {
|
|
1916
|
+
throw new Error('The next page could not be confirmed.');
|
|
1917
|
+
}
|
|
1918
|
+
rememberHostResult(JSON.stringify(value));
|
|
1361
1919
|
acceptResult(response,true);
|
|
1362
|
-
|
|
1920
|
+
(app.querySelector('['+selector+']')||app.querySelector('[data-read-page-focus]'))?.focus({preventScroll:true});
|
|
1921
|
+
} catch(error) {
|
|
1922
|
+
if(state.result===snapshot) {
|
|
1923
|
+
app.querySelector('['+statusSelector+']').textContent=error?.message||'Could not load the next page.';
|
|
1924
|
+
button.disabled=false;
|
|
1925
|
+
button.textContent='Next page';
|
|
1926
|
+
}
|
|
1927
|
+
} finally {if(pendingReadPage===pending)pendingReadPage=null;}
|
|
1363
1928
|
});
|
|
1364
1929
|
}
|
|
1365
1930
|
`;
|
|
@@ -1467,8 +2032,8 @@ var REPORT_CHART_SCRIPT = String.raw`
|
|
|
1467
2032
|
`;
|
|
1468
2033
|
|
|
1469
2034
|
// src/ui.ts
|
|
1470
|
-
var ADPORT_UI_URI = "ui://adport/insight-card-
|
|
1471
|
-
var ADPORT_SUMMARY_UI_URI = "ui://adport/summary-card-
|
|
2035
|
+
var ADPORT_UI_URI = "ui://adport/insight-card-v32.html";
|
|
2036
|
+
var ADPORT_SUMMARY_UI_URI = "ui://adport/summary-card-v32.html";
|
|
1472
2037
|
var ADPORT_UI_DOMAIN = "https://app.adport.dev";
|
|
1473
2038
|
var ADPORT_UI_RESOURCE_DOMAINS = [
|
|
1474
2039
|
ADPORT_UI_DOMAIN,
|
|
@@ -1700,6 +2265,7 @@ ${RECORD_UI_STYLES}
|
|
|
1700
2265
|
${APPLE_REPORT_UI_STYLES}
|
|
1701
2266
|
${NATIVE_REPORT_UI_STYLES}
|
|
1702
2267
|
${REPORT_CHART_STYLES}
|
|
2268
|
+
${WORKFLOW_UI_STYLES}
|
|
1703
2269
|
${RECEIPT_UI_STYLES}
|
|
1704
2270
|
${INSIGHT_UI_STYLES}
|
|
1705
2271
|
${TREND_UI_STYLES}
|
|
@@ -1778,8 +2344,17 @@ ${TREND_UI_STYLES}
|
|
|
1778
2344
|
const dated=rows.some(row=>typeof row.date==='string');
|
|
1779
2345
|
const chart=dated?'<div class="report-trend"><div class="panel-head"><b>Daily '+esc(labels[metric].toLowerCase())+'</b>'+providerMarks(rows.map(row=>row.provider),meta,'Report platforms')+'</div><div data-report-trend></div><p class="operation-note">Missing or unavailable days remain gaps.</p></div>':'<div class="panel"><div class="panel-head"><b>'+esc(labels[metric])+'</b><span>Top '+ranked.length+' of '+rows.length+' rows</span></div><div class="bars">'+bars+'</div></div>';
|
|
1780
2346
|
const body=notices(data)+tabs+(rows.length ? (!currency?'<p class="notice">Currency unavailable. These values belong to this account only; no cross-account money total is calculated.</p>':'')+'<div class="kpis" role="group" aria-label="Chart metric">'+kpi('spend','Spend',spend===null?'—':money(spend,currency))+kpi('clicks','Clicks',total(rows,'clicks')===null?'—':compact(total(rows,'clicks')))+kpi('conversions','Conversions',total(rows,'conversions')===null?'—':compact(total(rows,'conversions')))+kpi('roas','ROAS',roas)+'</div>'+chart : '<div class="empty">'+(arr(data.errors).length?'Report unavailable for the requested providers.':'No rows returned for this period.')+'</div>');
|
|
2347
|
+
const table=rows.length?'<details class="report-data"><summary>Returned rows · '+rows.length+'</summary>'+
|
|
2348
|
+
workflowTable(['Entity','Platform','Date','Spend','Clicks','Conversions','ROAS'],rows.map(row=>{
|
|
2349
|
+
const metrics=row.metrics||{},revenue=rowReturn(row);
|
|
2350
|
+
return [row.entity?.name||row.entity?.id,providerName(row.provider,meta.providerNames),row.date,
|
|
2351
|
+
available(metrics.spend)?money(metrics.spend,currency,6):null,metrics.clicks,metrics.conversions,
|
|
2352
|
+
available(revenue)&&metrics.spend>0?(revenue/metrics.spend).toFixed(2)+'×':available(metrics.roas)?metrics.roas+'×':null];
|
|
2353
|
+
}),'Returned performance rows')+'</details>':'';
|
|
2354
|
+
const incomplete=data.summary?.complete===false&&!data.truncated&&arr(data.errors).length===0?
|
|
2355
|
+
'<p class="notice">Totals cover only the returned rows.</p>':'';
|
|
1781
2356
|
trendResize?.disconnect();
|
|
1782
|
-
app.innerHTML=chrome(body,period+(currency?' · '+currency:''));
|
|
2357
|
+
app.innerHTML=chrome(incomplete+body+table,period+(currency?' · '+currency:''));
|
|
1783
2358
|
if(dated)mountReportTrend(rows,metric,currency,data);
|
|
1784
2359
|
app.querySelectorAll('[data-group]').forEach(button=>button.addEventListener('click',()=>{state.reportGroup=choices[Number(button.dataset.group)].key;renderReport(data,meta);}));
|
|
1785
2360
|
app.querySelectorAll('[data-metric]').forEach(button=>button.addEventListener('click',()=>{state.reportMetric=button.dataset.metric;renderReport(data,meta);}));
|
|
@@ -1787,6 +2362,7 @@ ${TREND_UI_STYLES}
|
|
|
1787
2362
|
${OPERATION_UI_SCRIPT}
|
|
1788
2363
|
${RECEIPT_UI_SCRIPT}
|
|
1789
2364
|
${RECORD_UI_SCRIPT}
|
|
2365
|
+
${READ_PAGE_UI}
|
|
1790
2366
|
${APPLE_REPORT_UI_SCRIPT}
|
|
1791
2367
|
${NATIVE_REPORT_UI_SCRIPT}
|
|
1792
2368
|
${REPORT_CHART_SCRIPT}
|
|
@@ -1808,16 +2384,8 @@ ${MEDIA_UPLOAD_UI}
|
|
|
1808
2384
|
${MEDIA_LIBRARY_UI}
|
|
1809
2385
|
${CREATIVE_UI_SCRIPT}
|
|
1810
2386
|
${PROVIDER_GALLERY_UI}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
state.planningPage=Math.max(0,Math.min(state.planningPage,pages-1));
|
|
1814
|
-
const start=state.planningPage*pageSize, shown=rows.slice(start,start+pageSize);
|
|
1815
|
-
const notes=arr(planning.notes).filter(v=>typeof v==='string').map(v=>'<p class="notice">'+esc(v)+'</p>').join('');
|
|
1816
|
-
const table=columns.length&&shown.length?'<div class="planning-scroll" tabindex="0" role="region" aria-label="Planning estimate table"><table class="planning-table"><thead><tr>'+columns.map(v=>'<th scope="col">'+esc(v.label)+'</th>').join('')+'</tr></thead><tbody>'+shown.map(row=>'<tr>'+columns.map(column=>{const value=row&&Object.hasOwn(row,column.key)?row[column.key]:null;return '<td>'+esc(value==null?'—':value)+'</td>';}).join('')+'</tr>').join('')+'</tbody></table></div>':'<div class="empty">No planning values were returned for this selection.</div>';
|
|
1817
|
-
const controls=pages>1?'<div class="planning-pages"><button type="button" data-planning-page="previous" '+(state.planningPage===0?'disabled':'')+'>Previous rows</button><span class="context">Rows '+(start+1)+'–'+(start+shown.length)+' of '+rows.length+'</span><button type="button" data-planning-page="next" '+(state.planningPage===pages-1?'disabled':'')+'>Next rows</button></div>':'';
|
|
1818
|
-
app.innerHTML=chrome(operationHeader(planning.title || 'Planning estimates','',meta.provider)+table+controls+(data.truncated?'<p class="notice">Partial native response. More estimates may exist.</p>':'')+notes,'Read-only estimates');
|
|
1819
|
-
app.querySelectorAll('[data-planning-page]').forEach(button=>button.addEventListener('click',()=>{if(button.disabled)return;state.planningPage+=button.dataset.planningPage==='next'?1:-1;renderPlanning(data,meta);}));
|
|
1820
|
-
}
|
|
2387
|
+
${WORKFLOW_UI}
|
|
2388
|
+
${PLANNING_UI}
|
|
1821
2389
|
function render(result) {
|
|
1822
2390
|
cancelHold();clearTimeout(expiryTimer);trendResize?.disconnect();
|
|
1823
2391
|
let data=resultData(result);
|
|
@@ -1837,6 +2405,19 @@ ${PROVIDER_GALLERY_UI}
|
|
|
1837
2405
|
if (meta.view === 'accounts') return renderAccounts(data,meta);
|
|
1838
2406
|
if (meta.view === 'report') return renderReport(data,meta);
|
|
1839
2407
|
if (meta.view === 'operation') {renderOperation(data,meta);providerGalleryReviewControls(data,meta);return;}
|
|
2408
|
+
if (meta.tool === 'capabilities_list') return renderAvailability(data,meta);
|
|
2409
|
+
if (meta.tool === 'apple_change_history') return renderHistory(data,meta);
|
|
2410
|
+
if (meta.tool === 'apple_recommendations') return renderAppleRecommendations(data,meta);
|
|
2411
|
+
if (meta.tool === 'google_experiment_context') return renderExperiment(data,meta);
|
|
2412
|
+
if (['media_distribution_plan','media_distributions'].includes(meta.tool)) return renderDistribution(data,meta);
|
|
2413
|
+
if (['reddit_pixel_last_fired','pinterest_event_quality','meta_custom_conversion_stats','tiktok_pixel_event_stats',
|
|
2414
|
+
'spotify_dataset_diagnostics','openai_conversion_events'].includes(meta.tool)) return renderMeasurement(data,meta);
|
|
2415
|
+
if (['pinterest_feed_processing_results','pinterest_feed_item_issues','pinterest_catalog_item_batch_status',
|
|
2416
|
+
'pinterest_reconcile_catalog_item_batch','pinterest_local_inventory_batch_status','pinterest_reconcile_local_inventory_batch',
|
|
2417
|
+
'reddit_catalog_imports','reddit_catalog_import_issues','reddit_catalog_import_report','tiktok_catalog_feed_log',
|
|
2418
|
+
'tiktok_catalog_product_log','tiktok_catalog_video_log'].includes(meta.tool)) return renderCatalogProcessing(data,meta);
|
|
2419
|
+
const projected=planningProjection(data,meta);
|
|
2420
|
+
if (projected) return renderPlanning(data,meta,projected);
|
|
1840
2421
|
if (meta.view === 'records') return renderRecords(data,meta);
|
|
1841
2422
|
if (meta.view === 'receipt') return renderReceipt(data,meta);
|
|
1842
2423
|
if (meta.view === 'creatives') return renderCreatives(data,meta);
|
|
@@ -1851,13 +2432,13 @@ ${PROVIDER_GALLERY_UI}
|
|
|
1851
2432
|
function acceptResult(result,local=false) {
|
|
1852
2433
|
if (!result || typeof result !== 'object') return;
|
|
1853
2434
|
const incoming=resultData(result);
|
|
1854
|
-
if(!local && (providerGalleryIgnoreEcho(incoming) || mediaLibraryIgnoreEcho(incoming) || recordPagesIgnoreEcho(incoming))) return;
|
|
2435
|
+
if(!local && (providerGalleryIgnoreEcho(incoming) || mediaLibraryIgnoreEcho(incoming) || recordPagesIgnoreEcho(incoming) || readPageIgnoreEcho(incoming) || distributionIgnoreEcho(incoming))) return;
|
|
1855
2436
|
if(!local && (app.querySelector('[data-media-gallery]') && uploads.items.length>0 && ['media_prepare_upload','media_finalize_upload','media_get'].includes(incoming?._adport?.tool || result._meta?.adport?.tool) || mediaLibrary?.loading && incoming?._adport?.tool==='media_list' && mediaLibraryProject(incoming,incoming._adport)===mediaLibrary.project)) return;
|
|
1856
2437
|
const fingerprint=JSON.stringify(incoming);
|
|
1857
2438
|
// Host state updates can echo an old tool result after a local edit/apply.
|
|
1858
2439
|
if (!local && state.hasLocalResult && hostResults.has(fingerprint)) return;
|
|
1859
2440
|
if (local) state.hasLocalResult=true;
|
|
1860
|
-
else rememberHostResult(fingerprint);
|
|
2441
|
+
else {rememberHostResult(fingerprint);readPageHistory=null;}
|
|
1861
2442
|
clearTimeout(resultWait);
|
|
1862
2443
|
// ChatGPT can deliver the same result through both supported bridges.
|
|
1863
2444
|
// Do not reset an open disclosure when the second copy arrives.
|
|
@@ -1930,7 +2511,7 @@ ${PROVIDER_GALLERY_UI}
|
|
|
1930
2511
|
|
|
1931
2512
|
// src/index.ts
|
|
1932
2513
|
var PROVIDER_IDS = ["ga4", "gsc", "gtm", "google", "meta", "tiktok", "apple", "microsoft", "reddit", "snapchat", "spotify", "pinterest", "linkedin", "x", "openai"];
|
|
1933
|
-
var ADPORT_UI_RESOURCE_URIS = [ADPORT_UI_URI, "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];
|
|
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"];
|
|
1934
2515
|
var DEFAULT_MCP_ICONS = [{
|
|
1935
2516
|
src: "https://app.adport.dev/icon.svg?brand=orange-dot-v2",
|
|
1936
2517
|
mimeType: "image/svg+xml",
|
|
@@ -1957,7 +2538,7 @@ function createMcpUiServer({ name = "adport", version = package_default.version,
|
|
|
1957
2538
|
function registerUiResources(server, uiDomain, uiResourceDomains, uiConnectDomains) {
|
|
1958
2539
|
const summaryDomains = uiResourceDomains.filter((domain) => domain === ADPORT_UI_DOMAIN || uiConnectDomains.includes(domain));
|
|
1959
2540
|
for (const uri of ADPORT_UI_RESOURCE_URIS) {
|
|
1960
|
-
const summary = uri === ADPORT_SUMMARY_UI_URI;
|
|
2541
|
+
const summary = uri === ADPORT_SUMMARY_UI_URI || uri === "ui://adport/summary-card-v30.html";
|
|
1961
2542
|
const resourceMeta = {
|
|
1962
2543
|
ui: {
|
|
1963
2544
|
...uiDomain ? { domain: uiDomain } : {},
|
|
@@ -2008,7 +2589,7 @@ function createMcpServer({ runtime, catalog = { profile: "full", providers: null
|
|
|
2008
2589
|
if (scopes && !scopes.includes(requiredScope) && !scopeDenial) continue;
|
|
2009
2590
|
const view = tool.presentation ?? viewForTool(tool.name, tool.annotations.readOnly ?? false);
|
|
2010
2591
|
const resourceUri = productionOnly && view !== "creatives" ? ADPORT_SUMMARY_UI_URI : ADPORT_UI_URI;
|
|
2011
|
-
const canRefresh = (view === "creatives" || view === "records"
|
|
2592
|
+
const canRefresh = tool.annotations.readOnly && (view === "creatives" || view === "records" || tool.pagination !== void 0);
|
|
2012
2593
|
const canPage = canRefresh && tool.pagination !== void 0;
|
|
2013
2594
|
const wrapOutput = !!tool.output && !(tool.output instanceof z.ZodObject);
|
|
2014
2595
|
const output = productionOnly && tool.output === writeOutput ? hostedWriteOutput : tool.output;
|
|
@@ -2149,4 +2730,4 @@ export {
|
|
|
2149
2730
|
createMcpServer,
|
|
2150
2731
|
runStdioServer
|
|
2151
2732
|
};
|
|
2152
|
-
//# sourceMappingURL=chunk-
|
|
2733
|
+
//# sourceMappingURL=chunk-FKKOEMUR.js.map
|