Skip to content

Keep extra elements - #1181

Merged
isamu merged 2 commits into
receptron:mainfrom
isamu:keepExtraElements
Aug 11, 2025
Merged

isamu merged 2 commits into
receptron:mainfrom
isamu:keepExtraElements

Conversation

@isamu

@isamu isamu commented Aug 11, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Output now preserves additional input fields alongside the updated array, including when a custom array key is used.
  • Bug Fixes
    • Push agent no longer mutates the original array; operations apply to a safe copy to prevent side effects.
  • Documentation
    • Added a sample illustrating propagation of extra fields in the output.
  • Chores
    • Bumped package version to 2.0.8.

@isamu
isamu requested a review from snakajima August 11, 2025 00:20
@coderabbitai

coderabbitai Bot commented Aug 11, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Updates 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

Cohort / File(s) Summary of Changes
Array push agent behavior
agents/vanilla_agents/src/array_agents/push_agent.ts
Push operations now apply to a shallow copy (arrayCopy). Output preserves extra input fields via spreading rest. Supports returning arrayCopy under provided arrayKey or default array. Adds a sample demonstrating propagation of non-array fields.
Package metadata
agents/vanilla_agents/package.json
Version bumped from 2.0.7 to 2.0.8; no other 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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • push agent dynamic key #1180 — Modifies the same push_agent.ts to add optional dynamic arrayKey and update signatures/samples; closely related behavior changes.

Suggested reviewers

  • snakajima

Poem

I hop through arrays with nimble delight,
Copy, then push—keeping inputs tight.
Rest fields ride along, no byte left behind,
Version hops a notch—2.0.8 aligned.
Thump-thump of paws, results set free,
A tidy trail of data for all to see. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai 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.

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.
If rest already contains a property equal to params.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 output schema 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2bc6f7e and 7f54002.

📒 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;

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.

🛠️ 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.

@isamu
isamu merged commit a66f9eb into receptron:main Aug 11, 2025
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.

1 participant