Skip to content

feat(server): definePlatform/defineSalesPlatform helpers — fix req: unknown in typed-platform handlers - #1240

Merged
bokelley merged 3 commits into
mainfrom
claude/issue-1235-define-platform-helpers
May 1, 2026
Merged

bokelley merged 3 commits into
mainfrom
claude/issue-1235-define-platform-helpers

Conversation

@bokelley

@bokelley bokelley commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1235

Summary

Fixes the TypeScript contextual-typing gap that caused handler method parameters to resolve as req: unknown when a DecisioningPlatform (or sub-interface) was built as an object literal and passed directly to createAdcpServerFromPlatform. A sales_social matrix validation run produced 16 manual as { ... } coercions in a 743-line server.ts; this PR eliminates the need for all of them.

Root cause: createAdcpServerFromPlatform<P>(platform: P & ...) infers P from the argument instead of using the constraint for contextual typing. TypeScript can't backpropagate parameter types into nested method bodies from a generic constraint.

Fix (non-breaking): Ten pure identity functions — one per platform sub-interface — that force a concrete parameter type at the call site:

// Before — req: unknown, 16 manual as-casts
createAdcpServerFromPlatform({
  sales: {
    syncEventSources: async (req, ctx) => {
      const sources = ((req as { event_sources?: unknown[] }).event_sources ?? []) as Array<{ ... }>;
    }
  }
}, opts);

// After — req: SyncEventSourcesRequest ✓, ctx.account.ctx_metadata: SocialMeta ✓
createAdcpServerFromPlatform({
  sales: defineSalesPlatform({
    syncEventSources: async (req, ctx) => {
      const sources = req.event_sources ?? [];  // no cast
    }
  }),
  audiences: defineAudiencePlatform({
    syncAudiences: async (audiences, ctx) => { ... },  // audiences: Audience[] ✓
  }),
}, opts);

The class pattern with explicit property-type annotations (sales: SalesPlatform = { ... }) continues to work unchanged. These helpers are the object-literal escape hatch.

Also: The skills/build-seller-agent/specialisms/sales-social.md had a note describing handler-bag grouping for the legacy createAdcpServer path. This actively steered LLM adopters toward the v5 lower-level path (where all req parameters are unknown) rather than the typed platform surface. Replaced with the createAdcpServerFromPlatform method-mapping table, a TCtxMeta note, and a concrete two-sub-object code example.

Note on the signature-change suggestion from #1235

The issue suggested changing AudiencePlatform.syncAudiences(audiences: Audience[], ctx) to (req: SyncAudiencesRequest, ctx). This would be a breaking change (existing implementations and the canonical example at examples/decisioning-platform-identity-graph.ts:127 would need updating). The identity-helper approach in this PR solves the core DX problem without breaking existing adopters. The signature change is flagged in the triage comment on #1235 for @bokelley to decide whether to pursue as a separate major-bump PR.

What was tested

  • npx tsc --project tsconfig.lib.json --noEmit — no new type errors (pre-existing TS2688/TS5107 env errors unrelated to these changes)
  • npx tsc --noEmit — clean (same)
  • npm run format:check — passed
  • node_modules not present in this environment; npm test and build:lib could not run. TypeScript compilation serves as the primary gate for a type-level-only change.

Pre-PR review

  • dx-expert: approved after two blockers fixed — (1) removed sync_catalogs from sales-social method table (it's a retail-media extension, not a social requirement), (2) changed "or" to "and" for defineSalesPlatform + defineAudiencePlatform and added concrete two-sub-object example
  • code-reviewer: approved after two fixups — (1) removed sync_catalogs from sales-social prose "Additional tools" list (method table was already correct; prose was contradicting it), (2) added type-check coverage in decisioning.type-checks.ts — two positive identity assertions and one negative verifying that a wrong method shape is rejected

Triage-managed PR. This bot does not currently iterate on
review comments or PR conversation threads (only on the source
issue). To unblock:

  • Push fixup commits directly: gh pr checkout →
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See adcp#3121
for context.

Session: https://claude.ai/code/session_01BfQUoDUmf4gh9Ff1ETnW6v


Generated by Claude Code

claude added 2 commits May 1, 2026 21:31
…yped object-literal adoption

Closes #1235

Fixes TypeScript's contextual-typing gap when building a DecisioningPlatform
as an object literal. `createAdcpServerFromPlatform<P extends DecisioningPlatform<any,any>>`
infers P from the argument instead of applying contextual types backward,
leaving nested handler parameters as `req: unknown`. This caused 16 manual
as-casts in the sales_social matrix validation run.

New `definePlatform<TConfig, TCtxMeta>()` and `defineSalesPlatform<TCtxMeta>()`
(plus one per remaining specialism) are pure identity functions that force the
concrete interface type at the call site, giving TypeScript the annotation it
needs to resolve req/ctx parameters throughout the handler body.

Also removes the misleading `createAdcpServer` handler-grouping note from
skills/build-seller-agent/specialisms/sales-social.md — it described the legacy
v5 handler-bag path (where all requests are unknown) and steered LLM adopters
away from the typed platform surface. Replaced with the createAdcpServerFromPlatform
method-mapping table and a note that declaring TCtxMeta eliminates ctx_metadata casts.

https://claude.ai/code/session_01BfQUoDUmf4gh9Ff1ETnW6v
Per pre-PR review:
1. Remove sync_catalogs from the core sales-social method table — it's a
   retail-media extension (sales-catalog-driven) not a sales-social requirement.
   LLMs seeing it in the table would generate unnecessary syncCatalogs stubs.
2. Change "or" to "and" (defineSalesPlatform AND defineAudiencePlatform) and
   add a concrete two-sub-object code snippet so LLMs see both wrappers used
   together rather than choosing one and dropping the other.

https://claude.ai/code/session_01BfQUoDUmf4gh9Ff1ETnW6v
…heck coverage

Address pre-PR review on #1240:

- Drop sync_catalogs from the sales-social prose list — the method table
  was already correct, but the prose contradicted it. sync_catalogs is a
  retail-media extension (sales-catalog-driven), not a sales-social
  requirement; LLMs reading the prose would generate unnecessary
  syncCatalogs stubs.
- Add type-level coverage in decisioning.type-checks.ts: two positive
  identity assertions and one negative, covering definePlatform and
  defineSalesPlatform contextual-typing behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants