Commit ad2ac08
feat: AICONF config types & LDAIClient methods (AIC-2663) (#173)
**Requirements**
- [x] I have added test coverage for new or changed functionality
- [x] I have followed the repository's [pull request submission
guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests)
- [x] I have validated my changes against all supported platform
versions
**Related issues**
[AIC-2663](https://launchdarkly.atlassian.net/browse/AIC-2663) — Step 3:
AICONF config types & `LDAIClient` methods. Part of epic
[AIC-2629](https://launchdarkly.atlassian.net/browse/AIC-2629).
> **Stacked on #172** (`feat/AIC-2695/ai-sdk-vendor-mustache`), which is
stacked on #171. It builds on the data model + parser (#171) and the
vendored-Mustache `Interpolator` (#172). Base retargets up the stack as
each merges.
**Describe the solution you've provided**
Implements the public AI Config types and the `LDAIClient` retrieval
methods that evaluate a flag, validate its mode, interpolate prompt
templates, and return a typed config. The behavior mirrors the JS
reference the spec points to.
- **Config types** — `.NET`-style two-hierarchy design (`AIConfig` /
`AIConfigDefault` bases): `AICompletionConfig`(+messages),
`AIAgentConfig`(+instructions), `AIJudgeConfig`(+evaluationMetricKey)
result types plus parallel `*Default` builder types, and
`AIAgentConfigRequest` for batch agent retrieval. A generic base builder
keeps the `*Default` builders DRY.
- **`LDAIClient` methods** — `completionConfig`, `agentConfig`,
`agentConfigs`, `judgeConfig`:
- serialize the caller default to a flag value (tagged with the
requested `mode`) and pass it through `jsonValueVariation`, so an absent
flag yields the default and the eval event records the correct default;
- **mode validation**: a mismatch logs a single warning and returns a
disabled config of the requested type — never a config that would NPE
the caller;
- interpolate messages/instructions via the vendored-Mustache
`Interpolator`, exposing the context as `{{ldctx}}`;
- fire the spec'd usage events (`$ld:ai:usage:completion-config`,
`:agent-config`, `:agent-configs`, `:judge-config`) and emit
`$ld:ai:sdk:info` once at construction, **guarded** so an uninitialized
client can't throw from the constructor.
- `evaluationMetricKey` resolves to the first non-blank entry (handled
by the #171 parser).
**Key decisions**
- **Synchronous API (no `CompletableFuture`).** Matches the core Java
server SDK's blocking style and sidesteps Android API-level/threading
concerns. `variation` is in-memory after init, so `agentConfigs` fan-out
parallelism buys ~nothing while adding real complexity. Resolves the
ticket's async-surface question.
- **No per-field merge** of missing model/provider/instructions from the
default (matches JS).
- **Tracking deferred to Step 4 (AIC-2664).** `LDAIConfigTracker` is a
placeholder interface with an internal no-op; configs expose
`createTracker()` so Step 4 fills in behavior without reshaping the
public config types.
- **Construction**: `new LDAIClientImpl(ldClient)` (interface
`LDAIClient` is provided for mocking/DI). A second constructor accepts
an `LDLogger`.
**Thread-safety** — `LDAIClientImpl` holds only the thread-safe base
client, a logger, and one shared `Interpolator` (thread-safe template
cache); every returned config is immutable.
**Tests** — `LDAIClientImplTest` (17 cases) covers usage events,
SDK-info emission + constructor guard, typed retrieval,
interpolation/`ldctx`, mode-mismatch (disabled + single warning, no
NPE), default semantics (absent → default; no per-field merge), and
`agentConfigs` ordering/count. `LDValueConverterTest` extended for the
new inverse conversion. `./gradlew clean build` green (checkstyle +
Javadoc + all tests).
**Describe alternatives you've considered**
- **Single unified config type** (default == result) — rejected; the
ticket and sibling SDKs intentionally separate the caller-supplied
default from the retrieved result (which carries the key + tracker +
interpolated content).
- **Async `CompletableFuture` surface** — rejected for a server SDK (see
decision above).
**Additional context**
`AISdkInfo.VERSION` is currently a constant kept in step with
`gradle.properties`; wiring it to a generated/build-time version can be
a follow-up.
Made with [Cursor](https://cursor.com)
[AIC-2663]:
https://launchdarkly.atlassian.net/browse/AIC-2663?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[AIC-2629]:
https://launchdarkly.atlassian.net/browse/AIC-2629?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> New public SDK API on the flag-evaluation path; incorrect defaults,
mode handling, or interpolation would affect how apps load AI configs in
production, though scope is additive with guarded telemetry.
>
> **Overview**
> Adds the **public AI Config retrieval surface** for the Java server AI
SDK: immutable `AICompletionConfig`, `AIAgentConfig`, and
`AIJudgeConfig` types (plus matching `*Default` builders and
`AIAgentConfigRequest` for batch agents), wired through **`LDAIClient` /
`LDAIClientImpl`**.
>
> `LDAIClientImpl` evaluates flags via `jsonValueVariation` with a null
sentinel, parses variations, **validates mode** (mismatch → disabled
config + warning), and **interpolates** messages/instructions (including
`{{ldctx}}`). Absent flags return the caller default with interpolation
and **no per-field merge** from defaults when a variation is present. It
emits **`$ld:ai:sdk:info`** at construction (failure-safe) and
**`$ld:ai:usage:*`** metrics per method; **`LDAIConfigTracker`** is a
placeholder with a no-op implementation until a later step.
>
> The README now documents constructing `LDAIClientImpl` from `LDClient`
and calling `completionConfig`. **`LDAIClientImplTest`** covers usage
events, interpolation, mode mismatch, default semantics, and ordered
`agentConfigs`.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
ac6b827. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 32732ea commit ad2ac08
16 files changed
Lines changed: 1666 additions & 2 deletions
File tree
- lib/sdk/server-ai
- src
- main/java/com/launchdarkly/sdk/server/ai
- internal
- test/java/com/launchdarkly/sdk/server/ai
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 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 | + | |
23 | 48 | | |
24 | 49 | | |
25 | 50 | | |
| |||
Lines changed: 66 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
Lines changed: 132 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
Lines changed: 107 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments