Skip to content

fix(tsagentspec): accept plugin components nested inside builtin components - #259

Open
fede-kamel wants to merge 1 commit into
oracle:mainfrom
fede-kamel:fix/ts-nested-custom-components
Open

fix(tsagentspec): accept plugin components nested inside builtin components#259
fede-kamel wants to merge 1 commit into
oracle:mainfrom
fede-kamel:fix/ts-nested-custom-components

Conversation

@fede-kamel

Copy link
Copy Markdown
Member

Fixes #219.

Root cause

Every component-container field of the builtin TypeScript components (Agent.tools/toolboxes/transforms/llmConfig, ToolNode.tool, AgentNode.agent, LlmNode.llmConfig, the Flow node union, MCP clientTransport, OCI clientConfig, transform llm/datastore, Oracle datastore connectionConfig) was a closed z.discriminatedUnion of the builtin schemas. A plugin could serialize and deserialize its own component, but the builtin factory then re-validated the parent against the closed union and threw ZodError: Invalid discriminator value. Registering a replacement plugin for the builtin parent is not possible because duplicate component types are rejected.

Changes

  • src/component.ts: ComponentTypeName is derived from a runtime BUILTIN_COMPONENT_TYPE_NAMES list; new isBuiltinComponentTypeName, CustomComponentSchema (base fields validated, extra fields passed through, builtin type names refused) and openComponentUnion(union), a Zod transform that dispatches on componentType: builtin names go through the original union (so a wrong-kind builtin still fails with the same message), any other registered name goes through CustomComponentSchema.
  • Applied at every field listed above and to the registered lazy NodeUnion; factory option types widened accordingly. New symbols exported from src/index.ts.
  • tests/serialization/nested-custom-components.test.ts: the scenario of the issue (custom transform, toolbox and tool inside an Agent; custom node and custom tool inside a Flow/ToolNode) through both the factories and the serializer round trip, plus a check that a wrong-kind builtin is still rejected. Six of the seven tests fail on main. tests/component-registry.test.ts asserts the name list matches the schema map.
  • Changelog entry (TypeScript SDK) under Bug fixes.

Behaviour change to be aware of

Public output types widen from e.g. Tool[] to (Tool | CustomComponent)[], which is the honest type of the values now accepted. Consumers narrowing on componentType literals keep working for builtin names.

Verification

From tsagentspec/: npm test 51 files / 745 tests passed (737 on main), npm run lint clean, npm run build succeeds.

…onents

Component fields of builtin components were typed with closed Zod
discriminated unions of the builtin component schemas, so a plugin
component (e.g. a FunctionTransform in an Agent's transforms, or a
ConnectorToolBox in its toolboxes) was rejected with "Invalid
discriminator value" both by the factories and, after the nested
component had been deserialized by its plugin, by the builtin Agent
deserialization. Documents produced by the serializer with custom
plugins could therefore not be read back (oracle#219).

component.ts now derives ComponentTypeName from a runtime list of the
builtin component type names and adds openComponentUnion(): builtin
component types are still validated by the builtin union, while
components with a non-builtin componentType are validated against
CustomComponentSchema (base component fields only, other fields kept).
The helper is applied to every component-container field: Agent
llmConfig/tools/toolboxes/transforms, SpecializedAgent additionalTools,
ToolNode tool, AgentNode agent, LlmNode llmConfig, the Flow node
references, MCPTool/MCPToolBox clientTransport, OciGenAiConfig
clientConfig, the summarization transforms' llm/datastore and the
Oracle datastore connectionConfig. Factories accept the same components
so construction and deserialization stay symmetric, and a builtin
component of the wrong kind is rejected exactly as before.

Fixes oracle#219.

Signed-off-by: Federico Kamelhar <federico.kamelhar@oracle.com>
@fede-kamel
fede-kamel requested a review from a team September 11, 2026 16:22
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tsagentspec] Custom components nested inside builtin components can't be deserialized (closed Zod unions)

1 participant