Repository navigation
Keep extra elements - #1181
Keep extra elements#1181
Conversation
WalkthroughUpdates push_agent.ts to use a shallow-copied array, preserve non-array input fields in outputs, and adds a new sample. Also bumps agents/vanilla_agents package version from 2.0.7 to 2.0.8. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant PushAgent
participant Array as arrayCopy
participant Output
Client->>PushAgent: inputs { array, item(s), arrayKey?, ...rest }
PushAgent->>Array: arrayCopy = [...array]
PushAgent->>Array: push(item or items)
PushAgent->>Output: result = { ...rest, [arrayKey||"array"]: arrayCopy }
PushAgent-->>Client: result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
agents/vanilla_agents/src/array_agents/push_agent.ts (4)
15-15: Use slice/spread for shallow copy instead of map.
.map(x => x)is slower and less idiomatic for cloning.- const arrayCopy = array.map((item: any) => item); // shallow copy + const arrayCopy = array.slice(); // shallow copy + // or: const arrayCopy = [...array];
17-17: Minor: simplify bulk push for readability/perf.
Prefer spreading when appending multiple items.if (item !== undefined) { arrayCopy.push(item); } - if (items) { - items.forEach((item) => { - arrayCopy.push(item); - }); - } + if (items?.length) { + arrayCopy.push(...items); + }Also applies to: 21-21
26-28: arrayKey branch now overwrites any existing key in rest; confirm this is desired and document it.
Ifrestalready contains a property equal toparams.arrayKey, it will be overridden by the array (last-write wins). If that’s intended, consider adding a short note in description/samples.I can add a sample and a short note to pushAgentInfo documenting this precedence.
77-81: Great sample; add analogous sample for arrayKey + extra fields and align schema docs.
To fully exercise the new behavior when arrayKey is provided, include a sample that preserves extra fields, and clarify output schema allows extra properties.samples: [ ... + { + inputs: { array: [1, 2], item: 3, data: { example: "hello" } }, + params: { arrayKey: "test" }, + result: { test: [1, 2, 3], data: { example: "hello" } }, + },Also consider updating
outputschema to explicitly permit pass-through props:output: { type: "object", properties: { array: { type: "array" }, }, + additionalProperties: true, },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
agents/vanilla_agents/package.json(1 hunks)agents/vanilla_agents/src/array_agents/push_agent.ts(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build (22.x)
- GitHub Check: build (24.x)
🔇 Additional comments (2)
agents/vanilla_agents/package.json (1)
3-3: Version bump looks fine; ensure release hygiene.
No functional changes here. If this publishes a behavior change (outputs now preserve extra fields), ensure CHANGELOG and tags reflect it.agents/vanilla_agents/src/array_agents/push_agent.ts (1)
31-33: Default return path: pass-through extras + updated array — LGTM.
This aligns with “Keep extra elements.” No functional concern here.
| const extra_message = " Set inputs: { array: :arrayNodeId, item: :itemNodeId }"; | ||
| arrayValidate("pushAgent", namedInputs, extra_message); | ||
| const { item, items } = namedInputs; | ||
| const { item, items, array, ...rest } = namedInputs; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Good: preserving extra input fields; adjust return type to match runtime shape.
With rest spread into outputs, the arrayKey branch can return non-array fields (e.g., data). The current return type GraphAIArray | Record<string, unknown[]> is too narrow for that case.
Apply this diff to relax the return type:
-export const pushAgent: AgentFunction<{ arrayKey?: string }, GraphAIArray | Record<string, unknown[]>, GraphAIArrayWithOptionalItemAndItems> = async ({
+export const pushAgent: AgentFunction<{ arrayKey?: string }, Record<string, unknown>, GraphAIArrayWithOptionalItemAndItems> = async ({Optionally tighten later with a dedicated union type that reflects both:
- default case: { array: unknown[] } & Record<string, unknown>
- arrayKey case: Record<string, unknown> (keyed by params.arrayKey)
Committable suggestion skipped: line range outside the PR's diff.
Summary by CodeRabbit