Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ jobs:
"/brand/mcp"
"/inventory-adserver/mcp"
"/inventory-content/mcp"
"/adserver-us/mcp"
"/mcp"
)
# Build curl args once. Omit the Authorization header when the secret
Expand Down
1 change: 1 addition & 0 deletions server/src/training-agent/inventory-sim/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ export { toAdcpForecast, type AdcpDeliveryForecast, type ForecastRange } from '.
export { ENGINE_VERSION } from './version.js';
export { ADSERVER_SEASON } from './seeds/adserver-season.js';
export { CONTENT_SEASON } from './seeds/content-season.js';
export { ADSERVER_US_SEASON } from './seeds/adserver-us-season.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* Season seed for a US ad server: three publishers, Northstar, Meridian and
* Harbor, each selling run of site 300x250 display. Northstar sells in an
* open first-price auction; Meridian and Harbor sell guaranteed at a fixed CPM.
* Sales regions are the three US regions. The rng_seed is shared with the
* other ad server season on purpose, so the two seasons' noise is correlated.
*/
import type { SeasonSeed } from '../types.js';

// The publishers' domains use the reserved .example suffix like the other ad server season.
const NORTHSTAR_DOMAIN = 'northstar.example';
const MERIDIAN_DOMAIN = 'meridian.example';
const HARBOR_DOMAIN = 'harbor.example';

export const ADSERVER_US_SEASON: SeasonSeed = {
seed_id: 'adserver-us-2027',
rng_seed: 'adserver-2027-v1',
start_date: '2026-11-01',
days: 730,
currency: 'USD',
regions: [
{ region_id: 'us_northeast', country: 'US', name: 'US Northeast', share: 0.35 },
{ region_id: 'us_south', country: 'US', name: 'US South', share: 0.35 },
{ region_id: 'us_west', country: 'US', name: 'US West', share: 0.3 },
],
audience_profiles: [
{ profile_id: 'young_urban', name: 'Young urban', share: 0.3, rate_multipliers: { click_rate: 1.3, conversion_rate: 0.8 } },
{ profile_id: 'families', name: 'Families', share: 0.25 },
{ profile_id: 'professionals', name: 'Professionals', share: 0.3, rate_multipliers: { viewability: 1.05, conversion_rate: 1.3 } },
{ profile_id: 'retirees', name: 'Retirees', share: 0.15, rate_multipliers: { click_rate: 0.7, completion_rate: 1.1 } },
],
segments: [
{ segment_id: 'sports_fans', name: 'Sports fans', profile_ids: ['young_urban', 'professionals'] },
{ segment_id: 'household_decision_makers', name: 'Household decision makers', profile_ids: ['families', 'professionals'] },
{ segment_id: 'news_loyalists', name: 'News loyalists', profile_ids: ['professionals', 'retirees'] },
],
properties: [
{ property_id: 'northstar_site', name: 'Northstar', domain: NORTHSTAR_DOMAIN, publisher_id: 'northstar' },
{ property_id: 'meridian_site', name: 'Meridian', domain: MERIDIAN_DOMAIN, publisher_id: 'meridian' },
{ property_id: 'harbor_site', name: 'Harbor', domain: HARBOR_DOMAIN, publisher_id: 'harbor' },
],
placements: [
{
placement_id: 'northstar',
name: 'Northstar run of site',
channel: 'display',
property_ids: ['northstar_site'],
formats: ['display_300x250'],
base_daily_impressions: 500_000,
floor_cpm: 2,
rates: { viewability: 0.7, click_rate: 0.0028, completion_rate: 0, conversion_rate: 0.02 },
reporting_lag_days: 0,
},
{
placement_id: 'meridian',
name: 'Meridian run of site',
channel: 'display',
property_ids: ['meridian_site'],
formats: ['display_300x250'],
base_daily_impressions: 320_000,
floor_cpm: 2,
rates: { viewability: 0.7, click_rate: 0.0035, completion_rate: 0, conversion_rate: 0.025 },
reporting_lag_days: 0,
},
{
placement_id: 'harbor',
name: 'Harbor run of site',
channel: 'display',
property_ids: ['harbor_site'],
formats: ['display_300x250'],
base_daily_impressions: 200_000,
floor_cpm: 2,
rates: { viewability: 0.7, click_rate: 0.0038, completion_rate: 0, conversion_rate: 0.03 },
reporting_lag_days: 0,
},
],
products: [
{
product_id: 'northstar_auction',
name: 'Northstar auction',
description: 'Run of site 300x250 display across Northstar. Sold in an open auction, first-price, above the 2 CPM floor.',
delivery_type: 'non_guaranteed',
placement_ids: ['northstar'],
},
{
product_id: 'meridian_guaranteed',
name: 'Meridian guaranteed',
description: 'Guaranteed run of site 300x250 display across Meridian at a fixed 5 CPM, with an impression goal.',
delivery_type: 'guaranteed',
placement_ids: ['meridian'],
rate_cpm: 5,
},
{
product_id: 'harbor_guaranteed',
name: 'Harbor guaranteed',
description: 'Guaranteed run of site 300x250 display across Harbor at a fixed 6 CPM, with an impression goal.',
delivery_type: 'guaranteed',
placement_ids: ['harbor'],
rate_cpm: 6,
},
],
traffic: {
weekday_shape: [0.8, 1.05, 1.1, 1.1, 1.05, 1, 0.85],
trend_per_day: 0.0002,
truth_daily_sigma: 0.03,
},
forecast_error: {
channel_sigma: { display: 0.06, olv: 0.06 },
ar1_phi: 0.85,
lead_time_tau_days: 14,
lead_time_horizon_days: 60,
log_clip: 0.6931471805599453,
cell_kappa: 3.08,
cell_min_impressions: 100,
publishers: [
{ publisher_id: 'northstar', bias: -0.02 },
{ publisher_id: 'meridian', bias: -0.02 },
{ publisher_id: 'harbor', bias: -0.02 },
],
},
events: [],
};
95 changes: 72 additions & 23 deletions server/src/training-agent/tenants/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
* sold as exclusive sponsorships of the installments scheduled in a
* package's flight. Installments run, are postponed or are cancelled on
* their dates, and each builds its audience over its channel's curve.
* - `/adserver-us` — an ad server of the same kind as `/inventory-adserver`
* with its own season: run of site 300x250 display on three US publishers,
* Northstar in an open auction, Meridian and Harbor guaranteed at a fixed
* CPM, sold in US regions.
*
* Their `comply_test_controller` serves `sandbox_clock` (get, start and advance
* the caller's sandbox clock), `simulation_truth` (a sandbox readout of what
Expand All @@ -27,7 +31,7 @@
*/

import type { TenantConfig } from '@adcp/sdk/server';
import { ADSERVER_SEASON, CONTENT_SEASON, type SeasonSeed } from '../inventory-sim/engine/index.js';
import { ADSERVER_SEASON, ADSERVER_US_SEASON, CONTENT_SEASON, type SeasonSeed } from '../inventory-sim/engine/index.js';
import { InventoryPlatform, type InventoryTenantProfile } from '../inventory-sim/platform.js';
import { readSeasonFile } from '../inventory-sim/season-file.js';
import { TRAINING_FORMAT_LABELS } from '../product-factory.js';
Expand All @@ -46,32 +50,67 @@ import { SALES_COMPLY_INPUT_SCHEMA, createPrincipalScopedSeedCache, seedAccountA

export const INVENTORY_ADSERVER_TENANT_ID = 'inventory-adserver';
export const INVENTORY_CONTENT_TENANT_ID = 'inventory-content';
export const INVENTORY_ADSERVER_US_TENANT_ID = 'adserver-us';

const logger = createLogger('training-agent-inventory-tenants');

interface InventoryTenantEntry {
id: string;
kind: 'adserver' | 'content';
/** Env var naming the season file that replaces the tenant's shipped season. */
seasonFileEnv: string;
shipped: SeasonSeed;
label: string;
/** MCP server name reported on initialize. Default: the platform's. */
serverName?: string;
/** Prefix of the tenant's signing key id. Default: the platform's. */
kidPrefix?: string;
}

const INVENTORY_TENANTS: readonly InventoryTenantEntry[] = [
{
id: INVENTORY_ADSERVER_TENANT_ID,
kind: 'adserver',
seasonFileEnv: 'TRAINING_AGENT_INVENTORY_ADSERVER_SEASON_FILE',
shipped: ADSERVER_SEASON,
label: 'Training agent — inventory: ad server',
},
{
id: INVENTORY_CONTENT_TENANT_ID,
kind: 'content',
seasonFileEnv: 'TRAINING_AGENT_INVENTORY_CONTENT_SEASON_FILE',
shipped: CONTENT_SEASON,
label: 'Training agent — inventory: content',
},
{
// The id is part of every stored market document's key; it is final once deployed.
id: INVENTORY_ADSERVER_US_TENANT_ID,
kind: 'adserver',
seasonFileEnv: 'TRAINING_AGENT_INVENTORY_ADSERVER_US_SEASON_FILE',
shipped: ADSERVER_US_SEASON,
label: 'Ad server: Northstar, Meridian and Harbor',
serverName: 'northstar-meridian-harbor-adserver',
kidPrefix: '',
},
];

/** Env var naming the season file that replaces a tenant's shipped season. */
export const INVENTORY_SEASON_FILE_ENV: Readonly<Record<string, string>> = {
[INVENTORY_ADSERVER_TENANT_ID]: 'TRAINING_AGENT_INVENTORY_ADSERVER_SEASON_FILE',
[INVENTORY_CONTENT_TENANT_ID]: 'TRAINING_AGENT_INVENTORY_CONTENT_SEASON_FILE',
};

const SHIPPED_SEASONS: Readonly<Record<string, SeasonSeed>> = {
[INVENTORY_ADSERVER_TENANT_ID]: ADSERVER_SEASON,
[INVENTORY_CONTENT_TENANT_ID]: CONTENT_SEASON,
};

function seasonFor(tenantId: string, env: NodeJS.ProcessEnv): SeasonSeed {
const envVar = INVENTORY_SEASON_FILE_ENV[tenantId];
export const INVENTORY_SEASON_FILE_ENV: Readonly<Record<string, string>> = Object.fromEntries(
INVENTORY_TENANTS.map(tenant => [tenant.id, tenant.seasonFileEnv]),
);

function seasonFor(tenant: InventoryTenantEntry, env: NodeJS.ProcessEnv): SeasonSeed {
const envVar = tenant.seasonFileEnv;
const file = env[envVar]?.trim();
if (!file) return SHIPPED_SEASONS[tenantId];
if (!file) return tenant.shipped;
let seed: SeasonSeed;
try {
seed = readSeasonFile(file, { formats: TRAINING_FORMAT_LABELS });
} catch (error) {
const reason = error instanceof Error ? error.message : String(error);
throw new Error(`${envVar}=${file}: ${reason}`, { cause: error });
}
logger.info(`${tenantId}: season ${seed.seed_id} from ${file}`);
logger.info(`${tenant.id}: season ${seed.seed_id} from ${file}`);
return seed;
}

Expand All @@ -80,8 +119,9 @@ function seasonFor(tenantId: string, env: NodeJS.ProcessEnv): SeasonSeed {
* file throws, naming the env var and the path. */
export function resolveInventoryTenantProfiles(env: NodeJS.ProcessEnv): Record<string, InventoryTenantProfile> {
const profiles: Record<string, InventoryTenantProfile> = {};
for (const tenantId of Object.keys(SHIPPED_SEASONS)) {
profiles[tenantId] = { tenantId, seed: seasonFor(tenantId, env) };
for (const tenant of INVENTORY_TENANTS) {
const seed = seasonFor(tenant, env);
profiles[tenant.id] = { tenantId: tenant.id, seed };
}
return profiles;
}
Expand All @@ -91,10 +131,17 @@ export const INVENTORY_TENANT_PROFILES: Readonly<Record<string, InventoryTenantP

export const INVENTORY_TENANT_IDS: readonly string[] = Object.keys(INVENTORY_TENANT_PROFILES);

const LABELS: Readonly<Record<string, string>> = {
[INVENTORY_ADSERVER_TENANT_ID]: 'Training agent — inventory: ad server',
[INVENTORY_CONTENT_TENANT_ID]: 'Training agent — inventory: content',
};
/** Inventory tenants that are ad servers, whichever season they run. */
export const INVENTORY_ADSERVER_KIND_TENANT_IDS: readonly string[] =
INVENTORY_TENANTS.filter(tenant => tenant.kind === 'adserver').map(tenant => tenant.id);

const TENANT_ENTRIES: Readonly<Record<string, InventoryTenantEntry>> = Object.fromEntries(
INVENTORY_TENANTS.map(tenant => [tenant.id, tenant]),
);

export function isAdserverKindTenant(tenantId: string): boolean {
return INVENTORY_ADSERVER_KIND_TENANT_IDS.includes(tenantId);
}

export function isInventoryTenant(tenantId: string): boolean {
return INVENTORY_TENANT_IDS.includes(tenantId);
Expand Down Expand Up @@ -189,7 +236,8 @@ export function buildInventoryTenantConfig(
): { tenantId: string; config: TenantConfig } {
const profile = INVENTORY_TENANT_PROFILES[tenantId];
if (!profile) throw new Error(`Unknown inventory tenant ${tenantId}`);
const material = getTenantSigningMaterial(tenantId);
const entry = TENANT_ENTRIES[tenantId];
const material = getTenantSigningMaterial(tenantId, entry.kidPrefix);
const platform = new InventoryPlatform(profile);
// Project the seed's own formats too, so canonical creatives in them
// (inline on create_media_buy) map to the formats this tenant serves.
Expand All @@ -199,10 +247,11 @@ export function buildInventoryTenantConfig(
config: {
agentUrl: `${host}/${tenantId}`,
signingKey: material.signingKey,
label: LABELS[tenantId] ?? tenantId,
label: entry.label,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
platform: platform as any,
serverOptions: {
...(entry.serverName === undefined ? {} : { name: entry.serverName }),
legacyCreativeFormatConverter: projection.legacyFormatConverter,
canonicalFormatLegacyResolver: projection.canonicalFormatLegacyResolver,
legacyHandlers: {
Expand Down
21 changes: 10 additions & 11 deletions server/src/training-agent/tenants/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import { grantFor, grantPermits, loadSandbox } from '../account-sandbox.js';
import { projectCollectionCapabilities } from '../collections/capabilities.js';
import { supportsCollections33 } from '../collections/card-catalog.js';
import { SEED_COLLECTION_SCENARIO } from '../collections/seed-collection.js';
import { INVENTORY_ADSERVER_TENANT_ID, INVENTORY_COMPLY_SCENARIOS, INVENTORY_TENANT_PROFILES, handleInventorySandboxClock, handleInventorySimulationTruth, handleInventoryWinShareCut, isInventoryTenant } from './inventory.js';
import { INVENTORY_COMPLY_SCENARIOS, INVENTORY_TENANT_IDS, INVENTORY_TENANT_PROFILES, handleInventorySandboxClock, handleInventorySimulationTruth, handleInventoryWinShareCut, isAdserverKindTenant, isInventoryTenant } from './inventory.js';
import { SIMULATION_TRUTH_SCENARIO } from '../inventory-sim/truth-scenario.js';
import { PLACE_CATALOG_VERSION, placeSystem, placeType, resolveGeoPlaces } from '../inventory-sim/geo-places.js';
import { SANDBOX_CLOCK_SCENARIO } from '../inventory-sim/sandbox-clock.js';
Expand All @@ -113,8 +113,7 @@ const TENANT_PROTOCOLS: Readonly<Record<string, readonly string[]>> = {
'creative-builder': ['creative'],
brand: ['brand'],
si: ['sponsored_intelligence'],
'inventory-adserver': ['media_buy'],
'inventory-content': ['media_buy'],
...Object.fromEntries(INVENTORY_TENANT_IDS.map(id => [id, ['media_buy']])),
};

const OPERATOR_UNIT_BRIDGE_TENANTS = new Set([
Expand Down Expand Up @@ -1237,10 +1236,10 @@ function stripContentLengthOnWriteHead(res: Response): void {
};
}

/** Declares the ad server's place system under `execution.targeting.geo_places`,
/** Declares an ad server's place system under `execution.targeting.geo_places`,
* beside whatever targeting the SDK declared. */
function advertiseGeoPlaces(mediaBuy: Record<string, unknown>): void {
const seed = INVENTORY_TENANT_PROFILES[INVENTORY_ADSERVER_TENANT_ID].seed;
function advertiseGeoPlaces(mediaBuy: Record<string, unknown>, tenantId: string): void {
const seed = INVENTORY_TENANT_PROFILES[tenantId].seed;
const system = placeSystem();
const type = placeType(system);
const countries: Record<string, string[]> = {};
Expand All @@ -1260,7 +1259,7 @@ function advertiseGeoPlaces(mediaBuy: Record<string, unknown>): void {
current_version: PLACE_CATALOG_VERSION,
supported_versions: [PLACE_CATALOG_VERSION],
resolver: {
url: `${base}/${INVENTORY_ADSERVER_TENANT_ID}/geo-places`,
url: `${base}/${tenantId}/geo-places`,
auth: 'none',
protocol: 'adcp_geo_place_resolver_v1',
},
Expand Down Expand Up @@ -1684,8 +1683,8 @@ function projectTenantCapabilities(
...(structured.compliance_testing && typeof structured.compliance_testing === 'object' ? structured.compliance_testing : {}),
scenarios: [...INVENTORY_COMPLY_SCENARIOS],
};
if (tenantId === INVENTORY_ADSERVER_TENANT_ID && structured.media_buy && typeof structured.media_buy === 'object') {
advertiseGeoPlaces(structured.media_buy);
if (isAdserverKindTenant(tenantId) && structured.media_buy && typeof structured.media_buy === 'object') {
advertiseGeoPlaces(structured.media_buy, tenantId);
}
}
// Every tenant: a release whose capabilities schema closes the scenario
Expand Down Expand Up @@ -1943,8 +1942,8 @@ export function mountTenantRoutes(
...(tenantId === 'governance' ? governanceMw : tenantId === 'sales' ? salesMw : mw),
tenantMcpHandler(holder, tenantId, middleware.storyboardCompat, undefined, previewHolder),
);
if (tenantId === INVENTORY_ADSERVER_TENANT_ID) {
// The place resolver the ad server's capabilities advertise. Public: it
if (isAdserverKindTenant(tenantId)) {
// The place resolver an ad server's capabilities advertise. Public: it
// publishes the seed's region catalogue and nothing per caller.
parent.get(`/${tenantId}/geo-places`, (req, res) => {
setCORSHeaders(res);
Expand Down
Loading
Loading