Commit Graph

1601 Commits

Author SHA1 Message Date
Ran Shemtov 2afc3c380e Merge branch 'main' into claude/explore-agentcore-cli-a25GL 2026-04-06 13:59:33 +02:00
Ran Shem Tov 1bf2bad15b fix(cli): add fixture tests for configureAgentCore config.yaml patching 2026-04-06 13:58:34 +02:00
Alem Tuzlak a528d488ef Merge branch 'main' into fix/CPK-7154-agent-text-wiped-multiple-tool-calls 2026-04-06 11:48:09 +02:00
Alem Tuzlak 0dbb1b9a96 fix(tests): simplify assistantMsg function signature and streamline toolCall usage in tests 2026-04-06 11:39:51 +02:00
Alem Tuzlak 2fc548f3a8 fix(react-core): enhance message handling by introducing isToolMessage utility and refactoring tests for clarity 2026-04-06 10:36:52 +02:00
Tyler Slaton 9c940dcaac Merge branch 'main' into claude/rebase-against-main-PGEp1 2026-04-05 21:46:05 -07:00
Claude ca2d081f8c fix: use preventScroll on focus calls so autoFocus opt-in doesn't scroll page
When users explicitly set autoFocus={true}, the textarea now focuses
with { preventScroll: true } so the page doesn't jump. Also applies
to the modal-open focus path. Added tests verifying default no-focus
behavior and that opt-in focus uses preventScroll.

https://claude.ai/code/session_01LPiJ8GcUNtWdS2W6MYSE4b
2026-04-05 00:39:36 +00:00
Martha Schumann 4a44b6641f fix(react-core): preserve assistant text when multiple tool calls wipe content in same turn (CPK-7154)
During streaming, the same message ID can arrive multiple times as tool calls are appended.
The previous "keep last" dedup lost any text content that was streamed before the first tool call,
because later entries carry empty content. Replace with a merge strategy: for assistant messages,
recover non-empty content from earlier occurrences while keeping the latest toolCalls accumulation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 09:17:13 -07:00
Claude f41133d356 fix: change autoFocus default to false in CopilotChatInput
Prevents the chat input from stealing focus on mount by default.
Users can opt-in via the autoFocus prop (e.g. input={{ autoFocus: true }}).

https://claude.ai/code/session_01LPiJ8GcUNtWdS2W6MYSE4b
2026-04-04 02:13:01 +00:00
Claude 7426486199 fix: remove scrollIntoView on chat input focus that forces page scroll
The v2 CopilotChatInput had a useEffect that called scrollIntoView()
whenever the textarea received focus. Combined with autoFocus defaulting
to true, this caused the entire page to scroll to the chat component on
load - the same bug that was previously fixed in v1.

https://claude.ai/code/session_01LPiJ8GcUNtWdS2W6MYSE4b
2026-04-04 02:07:38 +00:00
Claude 2171c7b855 test: address review feedback on LangGraph tests
- Python: extract track_parent_dispatches() context manager, eliminating
  repeated boilerplate; import AGUIBase directly instead of __bases__[0]
- Python: use named constants for "copilotkit_exit" and "Exit" strings
  with comments explaining why they're literals (source uses them too)
- TS runtime: extract withMockedParentMerge() helper using vi.spyOn for
  automatic cleanup instead of manual try/finally prototype patching
- TS runtime: add makeCustomEvent() factory to centralise as-any casts
- TS runtime: use CustomEventNames constants for all custom event tests
- TS runtime: fix misleading comment on empty string content test
- TS runtime: add callPrivate() docstring noting the any trade-off

https://claude.ai/code/session_01BPMn7zhadhapfyyD8kYeAH
2026-04-03 23:12:52 +00:00
Claude d849fae68b test: add LangGraph integration unit tests + dead code annotations
- Python SDK: 18 new tests for LangGraphAGUIAgent (custom event handling,
  emit filtering, state merging, copilotkit namespace)
- TypeScript SDK: 25 new tests for copilotkitCustomizeConfig and
  convertActionsToDynamicStructuredTools
- TypeScript Runtime: 27 new tests for event-source helpers
  (shouldEmitToolCall, getCurrentMessageId, getCurrentContent, etc.)
- TypeScript Runtime: expanded dispatch-event-filtering tests with
  custom event dispatch (manually_emit_message/tool_call/state, exit)
  and langGraphDefaultMergeState tests
- Dead code annotations: LangGraphAgent class and use_function_call=True
  branch annotated with TODO(ran-review) for Ran to verify

https://claude.ai/code/session_01BPMn7zhadhapfyyD8kYeAH
2026-04-03 22:44:09 +00:00
Martha Schumann 4bc77088b0 fix(chat): fix virtualization, slot memoization, and ToolMessage casts
- Change ScrollElementContext to carry HTMLElement | null state (not a ref)
  so CopilotChatMessageView re-renders reactively when the scroll container
  first mounts. Removes the one-shot useLayoutEffect that silently kept
  virtualization disabled in the default autoScroll path (hasMounted gate
  in ScrollView deferred the Provider past the one-shot read window).

- Lift resolveSlotComponent calls out of renderMessageBlock into useMemo.
  When a slot was passed as a CSS class string, resolveSlotComponent
  returned a new { className } object on every call, defeating
  MemoizedAssistantMessage's slotProps reference-equality check and
  causing all completed messages to re-render on every parent update.

- Add deduplicatedMessages.length to scrollToIndex deps so the virtualizer
  stays at the bottom as new messages arrive during streaming.

- Replace four as-any ToolMessage casts in the memoized comparator with
  typed inline type predicates using the ToolMessage import from @ag-ui/core.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 14:02:03 -07:00
Martha Schumann 95b3eabf0e chore(perf): remove perf page, bench file, and dev-only window globals
The /perf demo page and .bench.tsx file were useful during development but
add noise to the PR. Removing them keeps the diff focused on the library
changes. Also removes the __perfScrollEl / __perfMsgCount window globals
that only existed to serve the perf page's polling mechanism.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 13:24:33 -07:00
Martha Schumann 7184cfb855 Merge remote-tracking branch 'origin/main' into feat/CPK-7190-chat-performance 2026-04-03 13:21:52 -07:00
Martha Schumann 7b90bdb532 fix(chat): revert toolResultMap comparator — breaks HITL sequential tool-call rendering
The pre-computed toolResultMap in MemoizedAssistantMessage's comparator caused
HITL tests to fail: after responding to one tool call, the second tool call's
status would not transition from 'inProgress' to 'complete'.

Root cause: when executingToolCallIds context updates (removing the completed
tool call from the set), CopilotChatToolCallsView re-renders via useCopilotKit()
context subscription. At that point it holds stale `messages` props (MemoizedAssistantMessage
hasn't re-rendered yet), so messages.find(tc.id) returns undefined. The timing
window between the context update and the messages re-render caused the status
to briefly show inProgress. In the old code the same O(n) messages.filter() scan
was used, which is proven correct. Reverting to that approach.

Keeps all other perf improvements: deduplicatedMessages useMemo, virtualization,
resolveSlotComponent helper, NODE_ENV-gated dev globals.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 13:06:48 -07:00
Martha Schumann 848205f89b perf(chat): memoize dedup map, O(1) tool-result comparator, TanStack Virtual, perf page & tests
Addresses review findings from PR #3611:
- toolResultMap: pre-compute id→content Map via useMemo so MemoizedAssistantMessage
  comparator does O(k) lookups instead of O(n) linear scans
- resolveSlotComponent<T>() helper eliminates repeated slot-resolution boilerplate
- NODE_ENV gate on __perfMsgCount / __perfScrollEl (no production window pollution)
- hasScrolledToBottomRef → dep-based [shouldVirtualize, firstMessageId] in useLayoutEffect
- Merged duplicate virtual/flat render return paths; removed dead null-guards in comparator
- AssistantMessage type import + cast in fingerprint (CopilotChat.tsx)
- perf page: private → protected, lastScrollTop=NaN, STABLE_POLLS_REQUIRED constant,
  agent as any with version-mismatch comment (ag-ui 0.0.46 vs 0.0.48)
- snapshot test: act+tick flush instead of sentinel message (Observable subscription
  ends after RUN_FINISHED so new events are dropped)
- .bench.tsx extension comment: not picked up by vitest CI glob

Pre-existing test failures in use-human-in-the-loop.e2e.test.tsx (2 tests) and
@copilotkit/sqlite-runner + @copilotkit/runtime are on main; unrelated to this PR.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 12:42:47 -07:00
Maxim 208f9bc32f fix: restore .d.ts declaration files for legacy moduleResolution consumers
Copies .d.cts → .d.ts after each tsdown build so consumers on
moduleResolution "node" (e.g. DocuSign) can resolve types without
changing their tsconfig. Also points the "types" field back to .d.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 20:55:45 +02:00
Martha Schumann 453b156533 Merge remote-tracking branch 'origin/main' into feat/CPK-7190-chat-performance 2026-04-03 11:53:39 -07:00
Martha Schumann 468062c3c3 perf(react-core): add TanStack Virtual + two-phase animation measurement
- Add @tanstack/react-virtual to react-core deps; activate useVirtualizer
  in CopilotChatMessageView when message count exceeds 50 (VIRTUALIZE_THRESHOLD).
  Only visible items are mounted; total scrollable height is maintained via
  an absolutely-positioned container div.
- Add scroll-element-context.ts to pass the scroll container ref from
  CopilotChatView down to CopilotChatMessageView without circular imports.
- Expose window.__perfScrollEl (scroll container) and window.__perfMsgCount
  (committed message count) for programmatic perf measurement.
- Update /perf demo page with two-phase timing: phase 1 measures event emit
  time, phase 2 waits for all messages committed + scroll position stable
  (animation settled). PerfPanel now shows emit / render+anim / total.

Benchmark results (MacBook, dev build):
  Load 50  [anim]:    emit 305ms  render+anim 1433ms  total 1739ms
  Load 100 [anim]:    emit 752ms  render+anim 1578ms  total 2331ms
  Load 500 [anim]:    emit 14.2s  render+anim 1783ms  total 16.0s
  Load 50  [noAnim]:  emit 299ms  render+anim  182ms  total  481ms
  Load 100 [noAnim]:  emit 771ms  render+anim  161ms  total  931ms
  Load 500 [noAnim]:  emit 13.9s  render+anim  199ms  total 14.1s

Key findings:
- React render cost is now O(1) in message count (161-199ms flat).
  Virtualization fully decouples DOM work from history size.
- Animation (StickToBottom spring scroll-to-bottom) adds ~1.4-1.8s
  regardless of message count; this is a fixed cost on every history load.
- The remaining bottleneck for large histories is event emit time (~5.6ms
  per TEXT_MESSAGE_CHUNK through AbstractAgent). This is upstream of React
  and tracked separately.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 11:52:19 -07:00
Martha Kelly Schumann 7407e55aa7 Merge branch 'main' into claude/rebase-against-main-PGEp1 2026-04-03 10:12:31 -07:00
Ran Shemtov 6670cdeb91 Merge branch 'main' into claude/remove-endpoint-flag-xd3G1 2026-04-03 19:06:30 +02:00
Martha Kelly Schumann f2c860a777 Merge branch 'main' into fix/a2ui-root-strict-mode 2026-04-03 10:05:41 -07:00
Ran Shemtov 1b7496a516 Merge branch 'main' into claude/explore-agentcore-cli-a25GL 2026-04-03 19:03:19 +02:00
Alem Tuzlak e77588a062 chore: fix formatting 2026-04-03 18:50:14 +02:00
Tyler Slaton 180b719d50 Revert "fix: add types conditions to package exports for proper TypeScript resolution"
This reverts commit 499bca09ad.
2026-04-03 09:42:01 -07:00
Alem Tuzlak 5c7c894969 fix(runtime): address PR review findings for fetch-based runtime
- RouteInfo: discriminated union replaces interface with optional fields,
  eliminating 8 non-null assertions and enabling TypeScript narrowing
- Dispatch: consolidated dispatchMultiRoute and dispatchSingleRoute into
  single dispatchRoute function, removing parallel switch statements
- Hooks: multi-route 404/405 now throw Response to flow through onResponse
  hooks, matching single-route behavior
- Hono CORS: explicit `cors: true` default instead of relying on
  toFetchCorsConfig(undefined) returning {} (confusing truthy path)
- Tests: replaced 22 `platform as any` casts with MockIntelligencePlatform
  interface; removed unused CopilotKitIntelligence imports
2026-04-03 18:41:33 +02:00
Alem Tuzlak 9a6ee39d96 chore(runtime): update package config, CI workflows, and docs
- Add package.json exports for v2/{express,hono,node} subpaths
- Add elysia devDependency and tsdown entry points
- Exclude bun integration tests from vitest config
- Update CI workflows to include runtime-servers test job
- Add runtime-server-adapter docs page
- Add changeset for the fetch-based runtime feature
2026-04-03 18:41:27 +02:00
Alem Tuzlak 7355c9b380 test(runtime): add unit and integration tests for fetch-based runtime
Comprehensive test coverage for the new fetch handler layer:
- Unit tests for fetch-handler, fetch-cors, fetch-router, hooks
- Adapter tests for Express and Hono bridges
- Node.js native HTTP handler tests
- Integration test suites for single and multi-endpoint setups
  across Express, Hono, Node, and Bun/Elysia servers
- Edge case and backward compatibility tests
2026-04-03 18:41:26 +02:00
Alem Tuzlak 1a45d3cb3a feat(runtime): add Express, Hono, and Node.js adapters for fetch handler
Bridge the framework-agnostic fetch handler to specific frameworks:
- Express adapter via express-fetch-bridge.ts (converts req/res to fetch)
- Hono adapter (thin wrapper, Hono already uses Request/Response)
- Node.js native HTTP adapter via node-fetch-handler.ts
- Re-export entry points at @copilotkit/runtime/v2/{express,hono,node}

Simplifies existing Express and Hono endpoints by delegating to the
shared fetch core instead of duplicating routing and CORS logic.
2026-04-03 18:41:24 +02:00
Alem Tuzlak 971c3dc1b5 feat(runtime): add fetch-based core handler, CORS, hooks, and router
Introduce the framework-agnostic fetch handler layer:
- fetch-handler.ts: single Request→Response pipeline for all routes
- fetch-cors.ts: CORS preflight and response header handling
- fetch-router.ts: path-based routing for multi-endpoint setups
- hooks.ts: lifecycle hooks (onBeforeRequest, onAfterResponse, onError)

Also migrates handler error responses from Response.json() to
new Response(JSON.stringify(...)) for broader runtime compatibility
(Node.js <20, CF Workers, Deno).
2026-04-03 18:40:29 +02:00
Alem Tuzlak 83fffea5e8 refactor(runtime): move runtime internals into core/ directory
Move middleware-sse-parser.ts, middleware.ts, and runtime.ts into
a new core/ subdirectory to make room for the fetch-based handler
layer. Updates all import paths in handlers and existing tests.
2026-04-03 18:40:28 +02:00
Tyler Slaton 4f1f132d41 fix: address issues with licensing, formatting and types (#3597) 2026-04-03 09:38:41 -07:00
Ran Shem Tov d1f57e6b37 feat(cli): provide a clean scaffolded agentcore project per framework 2026-04-03 17:36:37 +02:00
Claude 92ebd74011 fix: resolve a2ui-root CustomElementRegistry error under React Strict Mode
`@a2ui/lit` registers the "a2ui-root" custom element via Lit's
@customElement decorator as a side effect when its UI module loads.
React Strict Mode double-mounts components, and since
customElements.define() is irreversible, the second mount throws:
"the name a2ui-root has already been used with this registry"

Several a2ui-renderer files used value imports from "@a2ui/lit" when
only types were needed, pulling in the full module tree including
the custom element registration. Changed to `import type` where
possible and switched to the narrower `@a2ui/lit/0.8` subpath
(core.js only, no UI/custom element registration) where value
access is needed.

https://claude.ai/code/session_01CUPfWAF8EmLieEasaepAgp
2026-04-03 15:00:46 +00:00
Ran Shemtov 92039cba79 feat(cli): clean up scaffolded agentcore projects
After downloading the agentcore template, remove files that don't apply
to the selected framework: the other agent directory, the other deploy
script, and the terraform infra. Rename the remaining deploy script to
deploy.sh for a single obvious entry point.

https://claude.ai/code/session_01LeSq6n4oGs8FocDSnSV6c7
2026-04-03 13:55:43 +00:00
Ran Shem Tov 92447be772 chore: fix formatting 2026-04-03 15:46:03 +02:00
Ran Shem Tov 9c0b134bdb fix(cli): harden configureAgentCore template configuration
- Throw if config.yaml.example is missing (was silent no-op)
- Validate pattern/stack_name_base keys exist before replacing (was silent miss)
- Preserve trailing YAML comments via \S+(.*) regex pattern

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 15:45:50 +02:00
Claude 552e3bb713 feat(cli): add agentcore-langgraph and agentcore-strands framework options
Add two new framework options to `cpk create` that scaffold AgentCore-based
projects with either LangGraph or Strands. Both download the agentcore
example template and auto-configure config.yaml with the correct agent
pattern and stack name suffix.

https://claude.ai/code/session_01LeSq6n4oGs8FocDSnSV6c7
2026-04-03 15:45:50 +02:00
Ran Shem Tov ba7691b453 chore: fix formatting 2026-04-03 15:20:58 +02:00
Ran Shem Tov 3b6a060423 chore: refresh web inspector css 2026-04-03 15:20:44 +02:00
Ran Shem Tov 6fa01fb8a1 test: add edge case coverage and fix auto-detect status check
- Fix fetchRuntimeInfoAutoDetect in agent.ts to use 2xx-only check
  (was checking only 404/405, now aligns with agent-registry.ts)
- Remove duplicate JSDoc block on fetchRuntimeInfoAutoDetect
- Add 7 edge case tests: 500/403/405/network-error/both-fail scenarios
- Add 4 tests for useSingleEndpoint->runtimeTransport ternary mapping
- Update Angular test stubs to use "auto" default (was "rest")

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 15:20:44 +02:00
Claude 0a65f70f85 feat: auto-detect single-endpoint transport from runtime info response
Instead of requiring users to explicitly set transport: "single", the
client now auto-detects the transport mode by trying REST (GET /info)
first and falling back to single-endpoint (POST with { method: "info" })
if the REST probe returns 404/405 or fails. The explicit flag is kept
for backward compatibility.

https://claude.ai/code/session_016xtYN15TY2BaBviryTcVyY
2026-04-03 15:20:44 +02:00
Ran Shem Tov aae2c5cee1 chore: use latest ag-ui langgraph version 2026-04-03 14:57:45 +02:00
Martha Schumann f955dd37dd perf(react-core): reduce wasted re-renders in CopilotChat with 100+ messages
Replace full JSON.stringify(agent.messages) memo dep with a lightweight
fingerprint (length + last-id + last-content + last tool-call args) so only
the in-flight message is serialized on each render instead of the whole array.

Wrap deduplicatedMessages in useMemo([messages]) so the Map is not
reconstructed on every render cycle.

Add generateMessages(n) factory to test-helpers for perf-focused tests, a
vitest bench for the dedup map at 100/1000 messages, and three regression
tests that assert completed messages do not re-render when new messages or
state snapshots arrive.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 15:40:35 -07:00
Tyler Slaton ac54391d0f fix: only create license checker for Intelligence runtime, not SSE
createLicenseChecker was called unconditionally in BaseCopilotRuntime,
printing the "No license token configured" banner even for open-source
SSE-mode users who don't use any licensed features. Moved it to
CopilotIntelligenceRuntime only.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 14:56:31 -07:00
Tyler Slaton 499bca09ad fix: add types conditions to package exports for proper TypeScript resolution
All @copilotkit/* packages were missing type declarations in their exports
map. This meant TypeScript couldn't resolve types for subpath imports like
@copilotkit/react-core/v2 without manual tsconfig paths workarounds
pointing to dist .d.ts files (which no longer exist after the tsup to
tsdown migration).

Uses nested conditional exports to map .d.mts for ESM and .d.cts for CJS
consumers, satisfying both attw and TypeScript module resolution under
nodenext and bundler modes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 14:56:09 -07:00
Tyler Slaton 9dc688be2e fix: stop barrel-exporting license-verifier through shared to avoid bundling Node crypto into client
@copilotkit/shared was doing `export * from "@copilotkit/license-verifier"`,
which pulled the entire license-verifier bundle (including Node's `crypto`)
into any client-side consumer. This caused "Module not found: Can't resolve
'crypto'" errors for users bundling @copilotkit/react-core for the browser.

Now shared only re-exports types (erased at compile time) and a client-safe
`createLicenseContextValue` inlined without crypto. Runtime imports
`createLicenseChecker` and `getLicenseWarningHeader` directly from
`@copilotkit/license-verifier`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 14:55:58 -07:00
Maxim a2386017b4 Merge branch 'main' into feat/useagent-throttle-ms 2026-04-02 19:04:53 +02:00
Maxim 3f1c16881e fix: replace as any cast with typed RunAgentInput factory in throttle tests
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 18:46:35 +02:00