feat(nodejs): add Session.searchMessages() to query session history (#2376) - #2378
Open
Anvith433 wants to merge 1 commit into
Open
feat(nodejs): add Session.searchMessages() to query session history (#2376)#2378Anvith433 wants to merge 1 commit into
Anvith433 wants to merge 1 commit into
Conversation
Add an async searchMessages(query, options?) method to CopilotSession that
fetches conversation history via getEvents() and filters it in memory.
- query may be a string (case-insensitive substring by default, or exact
case via { caseSensitive: true }) or a RegExp (case sensitivity governed
by its own i flag; the caller's RegExp is never mutated and its g/y
lastIndex statefulness is neutralized).
- options.eventType restricts results to a single event type.
- Matching runs only over the string leaf values nested in event.data, so
searches hit message/tool/error content rather than object keys, ids, or
timestamps. Results preserve history order.
Also export SearchMessagesOptions on the public API surface and add 20 unit
tests covering string/RegExp matching, case sensitivity, eventType
filtering, nested-data matching, order preservation, and edge cases.
Implements the feature requested in github#2376.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the feature requested in #2376 — an async
searchMessages()method onCopilotSessionfor querying inside a session's history, for the Node.js/TypeScript SDK.query— astring(case-insensitive substring by default; exact case via{ caseSensitive: true }) or aRegExp(case sensitivity governed by its owniflag).options.eventType— restrict results to a single event type (e.g."assistant.message"). Typed asSessionEventType | (string & {})for autocomplete while still accepting any string.SessionEvent[]in history order.Design notes
getEvents()and filters in memory.event.data(message text, tool output, error messages, nested attachment fields). Structural fields (type,id,timestamp) and object keys are intentionally not searched, so a query matches content rather than field names or UUIDs.RegExpquery, the pattern is cloned with the statefulg/yflags stripped, so repeated.test()calls never depend on a sharedlastIndexand the caller'sRegExpis never mutated.eventTypefilter).Testing
npm test -- test/session-search-messages.test.ts→ 20/20 pass (string/RegExp matching, case sensitivity,eventTypefiltering, nested-datamatching,lastIndexsafety, caller'sRegExpnot mutated, order preservation, edge cases).npm run typecheck→ clean.npm run lint→ 0 errors.Scope / alignment
I read CONTRIBUTING.md and understand that (a) feature work should be discussed with the team first, and (b) features need to be maintained in sync across all supported languages. This PR is a Node.js-first implementation opened against the existing open enhancement issue #2376 as a concrete starting point for that discussion.
If the team is open to this feature, I'm happy to:
If it's not aligned with the roadmap, feel free to close — no worries at all, and thanks for the great SDK.
🤖 Generated with Claude Code