-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path__init__.py
More file actions
483 lines (459 loc) · 13.5 KB
/
Copy path__init__.py
File metadata and controls
483 lines (459 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
"""Decisioning Platform v6.0 — Protocol-driven adopter framework.
The successor to ``adcp.server.ADCPHandler`` for adopters who want a
hybrid sync/handoff return shape and per-specialism Protocol classes
instead of inheriting + overriding methods on a base ABC. Lives inside
the existing ``adcp`` package so adopters reuse the foundation primitives
in ``adcp.signing`` / ``adcp._idempotency`` / ``adcp.server`` rather than
spinning up parallel implementations.
Quickstart::
from adcp.decisioning import (
DecisioningPlatform,
DecisioningCapabilities,
SingletonAccounts,
SalesPlatform,
create_adcp_server_from_platform,
serve,
)
from adcp.types import (
GetProductsRequest, GetProductsResponse,
CreateMediaBuyRequest, CreateMediaBuySuccess,
)
class HelloSeller(DecisioningPlatform):
capabilities = DecisioningCapabilities(
specialisms=["sales-non-guaranteed"],
channels=["display"],
pricing_models=["cpm"],
)
accounts = SingletonAccounts(account_id="hello")
def get_products(self, req: GetProductsRequest, ctx) -> GetProductsResponse:
return GetProductsResponse(products=[...])
def create_media_buy(
self, req: CreateMediaBuyRequest, ctx,
) -> CreateMediaBuySuccess:
return CreateMediaBuySuccess(media_buy_id=f"mb_{req.idempotency_key}", ...)
serve(create_adcp_server_from_platform(
platform=HelloSeller(), name="hello-seller", version="0.0.1",
))
See ``examples/hello_seller.py`` for the runnable version.
"""
from __future__ import annotations
from adcp.decisioning.account_mode import (
AccountMode,
assert_sandbox_account,
get_account_mode,
get_mock_upstream_url,
is_sandbox_or_mock_account,
)
from adcp.decisioning.account_projection import (
project_account_for_response,
project_business_entity_for_response,
to_wire_account,
to_wire_sync_accounts_row,
to_wire_sync_governance_row,
)
from adcp.decisioning.accounts import (
AccountStore,
AccountStoreList,
AccountStoreSyncGovernance,
AccountStoreUpsert,
AccountStoreUpsertRequest,
ExplicitAccounts,
FromAuthAccounts,
ResolveContext,
SingletonAccounts,
)
from adcp.decisioning.compose import (
ShortCircuit,
compose_method,
require_account_match,
require_advertiser_match,
require_org_scope,
)
from adcp.decisioning.context import (
AuthInfo,
RequestContext,
)
from adcp.decisioning.derive_packages import derive_packages_from_proposal
from adcp.decisioning.dispatch import validate_platform
from adcp.decisioning.errors import (
AccountNotFoundError,
AuthRequiredError,
BillingNotPermittedForAgentError,
MediaBuyNotFoundError,
PermissionDeniedError,
RateLimitedError,
ServiceUnavailableError,
UnsupportedFeatureError,
ValidationError,
)
from adcp.decisioning.helpers import ref_account_id
from adcp.decisioning.implementation_config import ProductConfigStore
from adcp.decisioning.media_buy_store import (
MediaBuyStore,
create_media_buy_store,
)
from adcp.decisioning.mock_ad_server import (
InMemoryMockAdServer,
MockAdServer,
)
from adcp.decisioning.oauth_passthrough import (
create_oauth_passthrough_resolver,
)
from adcp.decisioning.platform import (
GOVERNANCE_SPECIALISMS,
DecisioningCapabilities,
DecisioningPlatform,
)
from adcp.decisioning.platform_router import LazyPlatformRouter, PlatformRouter
from adcp.decisioning.property_list import (
PropertyListFetcher,
filter_products_by_property_list,
property_list_capability_enabled,
resolve_property_list,
validate_property_list_config,
)
from adcp.decisioning.proposal_manager import (
FinalizeProposalRequest,
FinalizeProposalSuccess,
MockProposalManager,
ProposalCapabilities,
ProposalManager,
SalesSpecialism,
)
from adcp.decisioning.proposal_store import (
InMemoryProposalStore,
ProposalRecord,
ProposalState,
ProposalStore,
create_dev_proposal_store,
)
from adcp.decisioning.recipe import CapabilityOverlap, Recipe
from adcp.decisioning.refine import (
RefinementOutcome,
RefinementStatus,
RefineResult,
assert_buying_mode_consistent,
build_refinement_applied,
has_refine_support,
project_refine_response,
)
from adcp.decisioning.registry import (
ApiKeyCredential,
BillingMode,
BuyerAgent,
BuyerAgentDefaultTerms,
BuyerAgentRegistry,
BuyerAgentStatus,
Credential,
HttpSigCredential,
OAuthCredential,
bearer_only_registry,
mixed_registry,
signing_only_registry,
validate_billing_for_agent,
)
from adcp.decisioning.registry_cache import (
AuditingBuyerAgentRegistry,
CachingBuyerAgentRegistry,
RateLimitedBuyerAgentRegistry,
)
from adcp.decisioning.resolve import (
CollectionList,
Format,
FormatReferenceStructuredObject,
PropertyList,
PropertyListReference,
ResourceResolver,
)
from adcp.decisioning.roster_store import (
create_roster_account_store,
)
from adcp.decisioning.serve import (
create_adcp_server_from_platform,
serve,
)
from adcp.decisioning.specialisms import (
AudiencePlatform,
BrandRightsPlatform,
CampaignGovernancePlatform,
CollectionListsPlatform,
ContentStandardsPlatform,
CreativeAdServerPlatform,
CreativeBuilderPlatform,
OwnedSignalsPlatform,
PropertyListsPlatform,
SalesPlatform,
SignalsPlatform,
)
from adcp.decisioning.state import (
GovernanceContextJWS,
Proposal,
StateReader,
WorkflowObjectType,
WorkflowStep,
)
from adcp.decisioning.state_machines import (
CREATIVE_ASSET_TRANSITIONS,
MEDIA_BUY_TRANSITIONS,
assert_creative_transition,
assert_media_buy_transition,
)
from adcp.decisioning.task_registry import (
InMemoryTaskRegistry,
TaskHandoffContext,
TaskRegistry,
TaskState,
)
from adcp.decisioning.tenant_store import create_tenant_store
from adcp.decisioning.time_budget import (
IncrementalGetProducts,
ProductsCheckpoint,
project_incomplete_response,
resolve_time_budget,
)
from adcp.decisioning.translation import (
TranslationMap,
create_translation_map,
)
from adcp.decisioning.types import (
Account,
AdcpError,
DiscoveryResult,
MaybeAsync,
SalesResult,
SyncAccountsResultRow,
SyncGovernanceEntry,
SyncGovernanceResultRow,
TaskHandoff,
WorkflowHandoff,
)
from adcp.decisioning.update_media_buy import (
SELF_SERVE_UPDATE_ACTION_MODES,
UNKNOWN_UPDATE_ACTION,
UpdateMediaBuyMutation,
decompose_update_media_buy,
disallowed_update_media_buy_mutations,
is_update_media_buy_mutation_allowed,
normalize_update_media_buy_allowed_actions,
requested_update_media_buy_actions,
)
from adcp.decisioning.upstream import (
ApiKey,
AuthContext,
DynamicBearer,
NoAuth,
StaticBearer,
UpstreamAuth,
UpstreamHttpClient,
create_upstream_http_client,
)
from adcp.decisioning.validate_capabilities import (
validate_capabilities_response_shape,
validate_capabilities_response_shape_async,
)
# Conditional import: PgTaskRegistry needs the [pg] extra. Always expose
# the name — when psycopg isn't installed we fall through to a stub class whose
# constructor raises ImportError with the install hint. Matches the pattern
# used by adcp.signing for PgReplayStore.
#
# ``PostgresTaskRegistry`` is the pre-4.4 name and remains as a deprecated
# alias through the 4.4.x line; renamed to ``PgTaskRegistry`` to match the
# ``Pg*`` convention shared with PgReplayStore / PgBuyerAgentRegistry /
# PgWebhookDeliverySupervisor.
try:
from adcp.decisioning.pg import ( # noqa: F401
PgProposalStore,
PgTaskRegistry,
PostgresTaskRegistry,
)
except ImportError: # pragma: no cover — exercised by the [pg] extra tests
from typing import ClassVar as _ClassVar
class PgTaskRegistry: # type: ignore[no-redef]
"""Stub raised when ``adcp[pg]`` isn't installed.
Attempting to instantiate raises :class:`ImportError` with the
install-hint text from :mod:`adcp.decisioning.pg.task_registry`.
"""
is_durable: _ClassVar[bool] = True
def __init__(self, *args: object, **kwargs: object) -> None:
raise ImportError(
"PgTaskRegistry requires psycopg3 and psycopg-pool. "
"Install the 'pg' extra: `pip install 'adcp[pg]'` "
"(Poetry: `poetry add 'adcp[pg]'`)."
)
# Deprecated alias preserved through 4.4.x.
PostgresTaskRegistry: type[PgTaskRegistry] = PgTaskRegistry # type: ignore[no-redef]
class PgProposalStore: # type: ignore[no-redef]
"""Stub raised when ``adcp[pg]`` isn't installed.
Attempting to instantiate raises :class:`ImportError` with the
install-hint text from :mod:`adcp.decisioning.pg.proposal_store`.
"""
is_durable: _ClassVar[bool] = True
def __init__(self, *args: object, **kwargs: object) -> None:
raise ImportError(
"PgProposalStore requires psycopg3 and psycopg-pool. "
"Install the 'pg' extra: `pip install 'adcp[pg]'` "
"(Poetry: `poetry add 'adcp[pg]'`)."
)
__all__ = [
"Account",
"AccountMode",
"AccountNotFoundError",
"AccountStore",
"AccountStoreList",
"AccountStoreSyncGovernance",
"AccountStoreUpsert",
"AccountStoreUpsertRequest",
"AdcpError",
"ApiKey",
"ApiKeyCredential",
"AuthContext",
"AudiencePlatform",
"AuditingBuyerAgentRegistry",
"AuthInfo",
"AuthRequiredError",
"BillingMode",
"BillingNotPermittedForAgentError",
"BrandRightsPlatform",
"BuyerAgent",
"BuyerAgentDefaultTerms",
"BuyerAgentRegistry",
"BuyerAgentStatus",
"CachingBuyerAgentRegistry",
"CampaignGovernancePlatform",
"CREATIVE_ASSET_TRANSITIONS",
"CollectionList",
"CollectionListsPlatform",
"ContentStandardsPlatform",
"Credential",
"CreativeAdServerPlatform",
"CreativeBuilderPlatform",
"DecisioningCapabilities",
"DecisioningPlatform",
"DiscoveryResult",
"DynamicBearer",
"ExplicitAccounts",
"Format",
"FormatReferenceStructuredObject",
"FromAuthAccounts",
"GOVERNANCE_SPECIALISMS",
"GovernanceContextJWS",
"HttpSigCredential",
"IncrementalGetProducts",
"InMemoryMockAdServer",
"InMemoryTaskRegistry",
"MEDIA_BUY_TRANSITIONS",
"MaybeAsync",
"MediaBuyNotFoundError",
"MediaBuyStore",
"MockAdServer",
"MockProposalManager",
"NoAuth",
"OAuthCredential",
"OwnedSignalsPlatform",
"PermissionDeniedError",
"PgProposalStore",
"PgTaskRegistry",
"LazyPlatformRouter",
"PlatformRouter",
"PostgresTaskRegistry",
"Proposal",
"ProposalCapabilities",
"ProposalManager",
"ProposalRecord",
"ProposalState",
"ProposalStore",
"InMemoryProposalStore",
"FinalizeProposalRequest",
"FinalizeProposalSuccess",
"CapabilityOverlap",
"create_dev_proposal_store",
"PropertyList",
"PropertyListFetcher",
"PropertyListReference",
"ProductConfigStore",
"ProductsCheckpoint",
"property_list_capability_enabled",
"PropertyListsPlatform",
"filter_products_by_property_list",
"resolve_property_list",
"validate_property_list_config",
"RefineResult",
"RefinementOutcome",
"RefinementStatus",
"assert_buying_mode_consistent",
"build_refinement_applied",
"has_refine_support",
"project_refine_response",
"RateLimitedBuyerAgentRegistry",
"RateLimitedError",
"Recipe",
"RequestContext",
"ResolveContext",
"ResourceResolver",
"SalesPlatform",
"SalesResult",
"SalesSpecialism",
"ServiceUnavailableError",
"SignalsPlatform",
"SingletonAccounts",
"SELF_SERVE_UPDATE_ACTION_MODES",
"StateReader",
"StaticBearer",
"SyncAccountsResultRow",
"SyncGovernanceEntry",
"SyncGovernanceResultRow",
"TaskHandoff",
"TaskHandoffContext",
"TaskRegistry",
"TaskState",
"TranslationMap",
"UNKNOWN_UPDATE_ACTION",
"UnsupportedFeatureError",
"UpdateMediaBuyMutation",
"UpstreamAuth",
"UpstreamHttpClient",
"ValidationError",
"WorkflowHandoff",
"WorkflowObjectType",
"WorkflowStep",
"ShortCircuit",
"assert_creative_transition",
"assert_media_buy_transition",
"assert_sandbox_account",
"get_account_mode",
"get_mock_upstream_url",
"is_sandbox_or_mock_account",
"bearer_only_registry",
"compose_method",
"create_adcp_server_from_platform",
"create_media_buy_store",
"create_oauth_passthrough_resolver",
"create_roster_account_store",
"create_tenant_store",
"create_translation_map",
"create_upstream_http_client",
"decompose_update_media_buy",
"derive_packages_from_proposal",
"disallowed_update_media_buy_mutations",
"require_account_match",
"require_advertiser_match",
"require_org_scope",
"is_update_media_buy_mutation_allowed",
"mixed_registry",
"normalize_update_media_buy_allowed_actions",
"project_account_for_response",
"project_business_entity_for_response",
"project_incomplete_response",
"ref_account_id",
"resolve_time_budget",
"requested_update_media_buy_actions",
"serve",
"signing_only_registry",
"to_wire_account",
"to_wire_sync_accounts_row",
"to_wire_sync_governance_row",
"validate_billing_for_agent",
"validate_capabilities_response_shape",
"validate_capabilities_response_shape_async",
"validate_platform",
]