feat: array override ops (array_append, array_prepend, array_insert)#1481
Conversation
Add three array operations to the channel override pipeline so users can inject items into existing JSON arrays (e.g. system, messages, tools) without replacing them. - array_append / array_prepend insert at the end / start of the target - array_insert places the value at op.index, supporting negative indexes (counted from the end) and clamping out-of-range positions to [0, len] - when the rendered value is a JSON array, splat (default true) spreads its elements into the target; set splat=false to insert the array as a single nested element - creates a new array when path does not exist; logs a warning and skips when path exists but is not an array - headers reject array ops; merge logic treats them as additive (multiple array ops on the same path are meaningful) GraphQL: index/splat exposed via OverrideOperation type and input.
Surface array_append/prepend/insert in the channel override dialog with a numeric index input (revealed for array_insert) and a splat checkbox (defaults to true). Header op dropdown stays restricted to set/delete/ rename/copy. Form validation requires path for all array ops and an explicit index for array_insert. Update the zod schema, channel + override-template GraphQL queries (so round-tripping through edit forms preserves the new fields), i18n keys in en + zh, and the Request Override guide in both languages with a worked example for prepending Anthropic system items (with cache_control) before the user's original content.
GraphQL returns null (not undefined) for unset nullable fields, so a plain z.optional() rejected the response and broke loading any channel that had a non-array override op saved (set/delete/rename/copy). Switch to z.nullish() so both null and undefined are accepted, matching the existing pattern used for autoTrimedModelPrefixes in the same schema.
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
Code Review
This pull request introduces new array manipulation operations (array_append, array_prepend, and array_insert) for request body overrides in AxonHub. These operations allow users to inject items into existing arrays at specific positions or ends, with support for optional spreading of JSON array values via a new splat parameter. The changes include updates to the documentation, frontend UI components, GraphQL schema, backend validation logic, and comprehensive unit tests to ensure correct behavior and edge-case handling. I have no feedback to provide as the implementation appears complete and well-tested.
|
感谢 PR,帮忙确认下是否本地验证过 |
已本地验证过:新增 array ops 单测、biz override 校验相关测试、以及 orchestrator override 相关用例均通过;本地也做过一次构建检查,未发现问题。 |
Motivation
The current four override operations (
set,delete,rename,copy) have no way to inject items into an existing JSON array without overwriting it — there is no array prepend / append / insert primitive.What's added
Three new body override operations:
array_appendarray_prependarray_insertop.index)Two new optional fields on
OverrideOperation:index(*int)array_insert[0, len]splat(*bool)truefalseto insert as a single nested elementBehavior
pathdoesn't exist, a new array is created with the value(s).pathexists but isn't an array, the operation is skipped with a warning.{{.Model}},{{index .Metadata "key"}}etc.) is supported invalue, same asset.