Skip to content

refactor(agent-client): move polymorphic linkage read into the lib [PRD-493]#1654

Merged
matthv merged 6 commits into
mainfrom
fix/prd-493-polymorphic-linkage-in-agent-client
Jun 11, 2026
Merged

refactor(agent-client): move polymorphic linkage read into the lib [PRD-493]#1654
matthv merged 6 commits into
mainfrom
fix/prd-493-polymorphic-linkage-in-agent-client

Conversation

@matthv

@matthv matthv commented Jun 10, 2026

Copy link
Copy Markdown
Member

What

Follow-up to #1647 (merged). Review feedback: the polymorphic linkage read belongs in agent-client (the lib that centralises agent calls), not hand-rolled in the workflow-executor adapter.

Before

AgentClientAgentPort.resolvePolymorphicType did a manual fetch — rebuilding the URL, minting the token, serialising the projection query by hand — bypassing agent-client.

After

  • HttpRequester.query gains a raw option returning the undeserialized JSON:API body (the deserializer drops relationship type, the polymorphic discriminator).
  • Collection.getRelationLinkage(id, relation) reads a to-one relation's raw linkage { type, id } via a <relation>@@@id projection, reusing QuerySerializer, the by-id route and the client's auth. Returns null when there is no linked record.
  • AgentClientAgentPort.resolvePolymorphicType now delegates to it — no hand-rolled fetch/URL/token.

Tests

  • agent-client collection.test.ts: new getRelationLinkage cases (raw projection, composite ids, null). 70 pass.
  • executor agent-client-agent-port.test.ts: resolvePolymorphicType asserts delegation (no fetch spy). 131 pass.
  • Builds + lint clean. No behaviour change.

Refs PRD-493

Note

Move polymorphic linkage resolution into agent-client library

  • Adds a raw option to HttpRequester.query and Collection.getOne in agent-client that returns the undeserialized JSON:API body, preserving relationship type fields.
  • Rewrites AgentClientAgentPort.resolvePolymorphicType in agent-client-agent-port.ts to use getOne({ raw: true }) instead of constructing a manual fetch call to the agent URL.
  • Extracts polymorphic linkage from body.data.relationships[relation].data and returns { type, id } or null.

Changes since #1654 opened

  • Renamed the raw option to skipDeserialization across agent-client package [9bbb98d]
  • Updated AgentClientAgentPort.resolvePolymorphicType to use the renamed option [9bbb98d]

Macroscope summarized c2a0cdf.

…RD-493]

The workflow-executor adapter hand-rolled a fetch (URL building, token, query
params) to read a polymorphic relation's raw JSON:API linkage. That's exactly
what agent-client exists to centralise. Move it into the lib:

- HttpRequester.query gains a `raw` option to return the undeserialized body
  (the deserializer drops relationship `type`, the polymorphic discriminator).
- Collection.getRelationLinkage(id, relation) reads the linkage { type, id }
  via a `<relation>@@@id` projection, reusing QuerySerializer + auth.
- AgentClientAgentPort.resolvePolymorphicType now just delegates to it — no
  more hand-rolled fetch/URL/token.

Tests updated on both sides (agent-client + executor adapter).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@linear-code

linear-code Bot commented Jun 10, 2026

Copy link
Copy Markdown

PRD-493

matthv and others added 3 commits June 10, 2026 17:52
@qltysh

qltysh Bot commented Jun 11, 2026

Copy link
Copy Markdown

Qlty


Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (2)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
packages/agent-client/src/http-requester.ts50.0%54
Coverage rating: A Coverage rating: A
...ages/workflow-executor/src/adapters/agent-client-agent-port.ts100.0%
Total66.7%
🤖 Increase coverage with AI coding...
In the `fix/prd-493-polymorphic-linkage-in-agent-client` branch, add test coverage for this new code:

- `packages/agent-client/src/http-requester.ts` -- Line 54

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

…method [PRD-493]

Review feedback:
- reuse getOne (add a `raw` option) rather than a dedicated getRelationLinkage;
- keep agent-client generic — return the raw JSON:API body and let the consumer
  extract the polymorphic linkage, instead of baking { type, id } parsing into the lib;
- serialization stays in QuerySerializer (getOne -> serialize -> formatFields).

The executor adapter reads the raw body via getOne(..., { raw: true }) and parses
data.relationships.<rel>.data itself. Validated e2e (Image -> User / Product).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread packages/agent-client/src/domains/collection.ts Outdated
Comment thread packages/agent-client/src/domains/collection.ts Outdated
…-493]

Review feedback (Scra3): rename the `raw` query/getOne option to the more
explicit `skipDeserialization`, and drop the now-redundant comment on getOne.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@matthv matthv merged commit ed50344 into main Jun 11, 2026
30 checks passed
@matthv matthv deleted the fix/prd-493-polymorphic-linkage-in-agent-client branch June 11, 2026 09:32
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