Skip to content

refactor: use common LDValueConverter and LDContextEncoder in AI SDK#188

Draft
mattrmc1 wants to merge 3 commits into
mainfrom
mmccarthy/AIC-2940/impl-common-context-encoder
Draft

refactor: use common LDValueConverter and LDContextEncoder in AI SDK#188
mattrmc1 wants to merge 3 commits into
mainfrom
mmccarthy/AIC-2940/impl-common-context-encoder

Conversation

@mattrmc1

@mattrmc1 mattrmc1 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Switches the AI SDK (server-ai) to consume the shared LDValueConverter and LDContextEncoder from common (com.launchdarkly.sdk) and removes the SDK's internal copies. This is a behavior-preserving refactor — the interpolation and config-parsing output are unchanged; the logic now lives in one shared place.

⚠️ Merge order — do not merge before #187 is merged and released

This PR depends on the common utilities added in #187. Because common is a separately published artifact, #188 can only merge to main after:

  1. feat: add LDValueConverter and LDContextEncoder to common #187 is merged, and
  2. a common release containing LDValueConverter + LDContextEncoder is published, and
  3. the AI SDK resolves that released common version.

Merging this before that release would leave server-ai referencing common symbols that aren't in a published artifact yet. Do not merge until the release dependency is satisfied.

Changes

  • Interpolator — the private contextToMap / singleContextToMap methods are removed; the ldctx template variable is now built via LDContextEncoder.encode(context). The interpolation policy is unchanged (no HTML escaping, missing/null → empty string, ldctx merged last so it always wins).
// before
merged.put("ldctx", contextToMap(context));
// after
merged.put("ldctx", LDContextEncoder.encode(context));
  • AIConfigParser — now imports and uses com.launchdarkly.sdk.LDValueConverter (for model.parameters, model.custom, and tool parameters / customParameters) instead of the SDK-local copy.
  • Removed the AI SDK's internal LDValueConverter and its LDValueConverterTest; that coverage now lives in common.

Migration

None. All changes are internal to server-ai; the public API and the rendered output (config maps and ldctx template values) are unchanged.

Test plan

  • server-ai module builds and tests pass against the released common version
  • InterpolatorTest — existing cases still pass (interpolation parity preserved), including single- and multi-kind ldctx rendering
  • AIConfigParser behavior unchanged for model.parameters / model.custom / tool params
  • Shared converter/encoder coverage verified in common (LDValueConverterTest, LDContextEncoderTest)

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.

1 participant