Skip to content

feat: array override ops (array_append, array_prepend, array_insert)#1481

Merged
looplj merged 3 commits into
looplj:unstablefrom
paopaoandlingyia:feat/array-override-ops
Apr 25, 2026
Merged

feat: array override ops (array_append, array_prepend, array_insert)#1481
looplj merged 3 commits into
looplj:unstablefrom
paopaoandlingyia:feat/array-override-ops

Conversation

@paopaoandlingyia

Copy link
Copy Markdown
Contributor

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:

Op Use
array_append insert value(s) at the end of the target array
array_prepend insert value(s) at the start of the target array
array_insert insert value(s) at a specific position (op.index)

Two new optional fields on OverrideOperation:

Field Default Notes
index (*int) required for array_insert negative values count from the end; out-of-range values are clamped to [0, len]
splat (*bool) true when the rendered value is a JSON array, spread its elements into the target; set false to insert as a single nested element

Behavior

  • If path doesn't exist, a new array is created with the value(s).
  • If path exists but isn't an array, the operation is skipped with a warning.
  • Multiple array ops on the same path are additive — each runs against the current state.
  • Array ops on headers are not supported and will be rejected by the validator.
  • Template rendering ({{.Model}}, {{index .Metadata "key"}} etc.) is supported in value, same as set.

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.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@looplj

looplj commented Apr 25, 2026

Copy link
Copy Markdown
Owner

感谢 PR,帮忙确认下是否本地验证过

@paopaoandlingyia

Copy link
Copy Markdown
Contributor Author

感谢 PR,帮忙确认下是否本地验证过

已本地验证过:新增 array ops 单测、biz override 校验相关测试、以及 orchestrator override 相关用例均通过;本地也做过一次构建检查,未发现问题。

@looplj looplj merged commit 9d7a919 into looplj:unstable Apr 25, 2026
4 checks passed
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