Commit Graph

1601 Commits

Author SHA1 Message Date
github-actions[bot] 3c32e469d8 style: auto-fix formatting 2026-04-15 13:10:36 +02:00
Jordan Ritter 8ebbba20df fix: handle anyOf/oneOf/ in JSON schema to Zod conversion (#2220) 2026-04-15 13:10:35 +02:00
Jordan Ritter 92730856b5 fix: widen openai peer dep range to include v6.x
The compatibility layer correctly handles v6 (same API surface as v5),
but the version range ^5.0.0 excluded v6.x. Changed to >=5.0.0 so
users on the latest openai SDK don't get peer dependency warnings.
2026-04-15 13:10:34 +02:00
Jordan Ritter 614e4cf815 fix: replace unsafe type casts with proper type guards for OpenAI v4/v5 compat
- Remove all `as any`, `as Function`, and `as Record<string, unknown>` casts
  from production code in the OpenAI compatibility layer
- Introduce typed `OpenAIV4Beta` interface and `hasV4BetaChat` type guard
  for safe runtime detection of v4 vs v5 clients
- Extract `retrieveThreadRun` and `submitToolOutputsStream` helper functions
  into utils.ts with properly typed generic signatures, moving the v4/v5
  dispatch logic out of the assistant adapter
- Give `getChatCompletionsForStreaming` an explicit return type so callers
  no longer need secondary casts
- Update tests to exercise the new helpers directly instead of
  duplicating dispatch logic inline
2026-04-15 13:10:34 +02:00
Jordan Ritter 1a458d1dcf test: add OpenAI SDK v4/v5 compatibility tests (#1979)
Cover isOpenAIV5 detection, getChatCompletionsForStreaming dispatch,
and named-path-param calling conventions for runs.retrieve and
submitToolOutputsStream.
2026-04-15 13:10:32 +02:00
Jordan Ritter 020588e357 fix: support OpenAI SDK v5 in adapter and assistant adapter (#1979)
OpenAI SDK v5 removed beta.chat (promoted to chat.completions) and
changed multi-path-param methods to use named params (e.g.
runs.retrieve(runId, { thread_id }) instead of positional args).

- Add isOpenAIV5() detection and getChatCompletionsForStreaming() helper
- Migrate OpenAIAdapter to use helper for streaming completions
- Migrate OpenAIAssistantAdapter runs.retrieve() and
  submitToolOutputsStream() to branch on SDK version
- Add openai ^4.85.1 || ^5.0.0 to peerDependencies
2026-04-15 13:10:32 +02:00
Jordan Ritter 856ec88b22 fix: update blockquote nested paragraph selector after p-to-div change
The blockquote.copilotKitMarkdownElement p selector targeted literal <p>
elements inside blockquotes, but paragraphs now render as <div> after
the hydration fix. Updated to target .copilotKitParagraph class instead.

Also removes unused import and adds a regression test for this selector.
2026-04-15 13:10:31 +02:00
Jordan Ritter 3bb12d12ec fix: update CSS selectors to match div-based paragraph component
The p tag was changed to div to fix hydration errors, but CSS selectors
still targeted p.copilotKitMarkdownElement. Updated to use the
.copilotKitParagraph class selector so paragraph styling (line-height,
font-size, margin) applies correctly to the new div element.
2026-04-15 13:10:30 +02:00
Jordan Ritter 7403aba8a3 fix: use div instead of p tag in Markdown to prevent hydration errors (#2234) 2026-04-15 13:10:30 +02:00
Jordan Ritter 7b5275e8db fix: scope dark theme CSS variables in colors.css
Same bug pattern as console.css and input.css: bare `.dark,` was a
standalone selector leaking all --copilot-kit-* CSS custom properties
onto any element with a .dark class. Also removed broken `:root`
pseudo-element from `body[style*="color-scheme: dark"] :root` — :root
cannot be a descendant of body, so this selector never matched.

Fix: drop standalone `.dark,` (redundant with `html.dark` and
`body.dark`) and remove the non-functional `:root` descendant.
2026-04-15 13:10:29 +02:00
github-actions[bot] 13c2ccae78 style: auto-fix formatting 2026-04-15 13:10:27 +02:00
Jordan Ritter db2ed5e19a fix: scope .dark CSS selectors to CopilotKit elements (#2920) 2026-04-15 13:10:27 +02:00
Jordan Ritter 362a04e1cc fix: resolve agent factory functions in V1 CopilotRuntime constructor
The V1 CopilotRuntime constructor did `{...endpointAgents, ...agents}`
which silently spread a factory function to `{}`, losing all agents.
Anyone using the V1 API with a factory function got zero agents and no
error. This wraps factory functions so endpoint agents are merged at
resolution time instead of construction time.
2026-04-15 13:10:24 +02:00
Alem Tuzlak b875258b22 docs(vscode-extension): add README with setup, usage, and CI/CD instructions 2026-04-15 13:10:07 +02:00
Alem Tuzlak 18b88a5112 feat(vscode-extension): wire up full extension with sidebar, preview panel, and file watcher 2026-04-15 13:07:19 +02:00
Alem Tuzlak 3c5333fee1 feat(vscode-extension): add debounced file watcher for component and fixture files 2026-04-15 13:06:19 +02:00
Alem Tuzlak ae823c9272 feat(vscode-extension): add WebviewPanel with message bridge and CSP 2026-04-15 13:05:06 +02:00
Alem Tuzlak 6adf209bdc feat(vscode-extension): add webview React app with bridge, fixture picker, and error overlay 2026-04-15 13:03:05 +02:00
Alem Tuzlak 5d02b8bad8 feat(vscode-extension): add sidebar TreeDataProvider for component tree 2026-04-15 13:00:39 +02:00
Alem Tuzlak 262f87c57a feat(vscode-extension): add component scanner for catalog discovery 2026-04-15 12:59:29 +02:00
Alem Tuzlak 954e0251a9 feat(vscode-extension): add fixture validator with oxc-parser 2026-04-15 12:56:51 +02:00
Alem Tuzlak ddce45b370 feat(vscode-extension): add Rolldown-based catalog bundler 2026-04-15 12:54:21 +02:00
Alem Tuzlak bdb44e5016 feat(vscode-extension): scaffold package with manifest and build config 2026-04-15 12:51:35 +02:00
Markus Ecker 0f02aae198 fix: align A2UI schema format with v0.9 spec and improve path binding prompts
- Replace custom { name, props } schema format with spec-aligned inline
  catalog format (allOf + properties) so the LLM sees the same flat
  structure it must produce — eliminates "props" nesting confusion.
- Restructure generation prompts: inline literal values are the default,
  path binding is a narrow schema-driven exception for form inputs.
- Export InlineCatalogSchema type from a2ui-renderer.
2026-04-15 12:28:13 +02:00
Markus Ecker abd0d5c11c fix: add path binding schema rule to A2UI generation prompts
LLMs sometimes use path bindings (e.g. {"path": "/chartData"}) on
component properties that only accept literal values, causing silent
render failures. The new guideline tells the LLM to check the schema's
anyOf type before using path bindings.
2026-04-15 11:51:05 +02:00
Jordan Ritter aff9350f17 fix: pass toolCallId to useRenderTool render components (#3741) 2026-04-14 16:24:45 -07:00
Jordan Ritter d534ccc7a0 fix: call onChange("") after send in controlled input mode (#3593) 2026-04-14 16:24:28 -07:00
Jordan Ritter 78c65a8a38 fix: ensure tool_result and tool_use messages stay paired after token trimming (#2450) 2026-04-14 16:23:34 -07:00
Jordan Ritter 97acd2e4d9 fix: add Zod v4 compatibility for schema-to-JSON conversion
Detect Zod v4 schemas by checking for a toJSONSchema() method on the
schema object. When present, call it directly instead of routing through
zod-to-json-schema (which cannot handle Zod v4 internals).

Priority order:
1. Standard JSON Schema V1 (~standard.jsonSchema.input)
2. Zod v4 native (schema.toJSONSchema())
3. Zod v3 fallback (injected zodToJsonSchema)

Removes the dead vendor === "zod4" check (Zod v4 reports "zod") and
the _def duck-typing fallback (unnecessary with toJSONSchema detection).

Closes #3636
2026-04-14 16:15:58 -07:00
Jordan Ritter a7cf38211c fix: add configurable maxInputTokens to OpenAI and Anthropic adapters (#2405) 2026-04-14 16:11:39 -07:00
Jordan Ritter a46218557c fix: add remarkPlugins/rehypePlugins passthrough support (#2296) 2026-04-14 15:55:08 -07:00
Jordan Ritter bcea46771b fix: handle urlTransform=null correctly in Markdown component
The truthiness check swallowed null, which is a valid value in
react-markdown that explicitly disables the default URL sanitizer.
Changed to an explicit undefined check.
2026-04-14 15:53:40 -07:00
Jordan Ritter 0c4383d74c fix: add satisfies constraint and improve test coverage for onAfterRequest
- Add `satisfies OnAfterRequestOptions` for compile-time type safety (consistent with onBeforeRequest)
- Replace `(m: any)` casts with type predicates and explicit `as unknown as Message[]`
- Add TODO comment for hardcoded empty properties
- Expand test to verify all 6 fields of OnAfterRequestOptions
- Add edge case tests for undefined messages and missing threadId/runId
2026-04-14 15:48:12 -07:00
Jordan Ritter 8aa369b58f fix: preserve nullable semantics and add Zod support for null-union types
- Mark parameters as optional when null is present in the type union
- Add matching null-union handling to convertJsonSchemaToZodSchema
- Add 7 tests covering null-union edge cases for both converters
2026-04-14 15:47:40 -07:00
Jordan Ritter f403105ad9 fix: only set hasReceivedContent for processed content blocks
Move hasReceivedContent flag inside each content block type handler
so that skipped unknown tool_use blocks do not prevent the fallback
response mechanism from activating. Add tests for unknown tool
skipping behavior.
2026-04-14 15:47:27 -07:00
Maxim 5058d195cc refactor: test hygiene for web-inspector spec
Extract shared helpers to reduce duplication and centralize unavoidable
casts. Add simulateSetState to mock controller to eliminate double-casts
in the new onStateChanged test. Promote mockClipboard to describe scope
to remove navigator clipboard cast in assertion. Add try/catch error
handling to syncAgentMessages and syncAgentState.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 00:43:49 +02:00
Jordan Ritter 4bd57af65d test: add tests for array content normalization in TOOL_CALL_RESULT
Cover the MCP adapter scenario where content arrives as an array of
{type:"text", text:string} objects, and verify non-text parts are
filtered out during normalization.
2026-04-14 15:41:25 -07:00
Jordan Ritter afc36a3da9 fix: mock navigator in clipboard test for Node 20 compatibility 2026-04-14 15:11:35 -07:00
Maxim df199123da fix: inspector syncs state on direct agent.setState()
When using selfManagedAgents, calling agent.setState() directly only
fires onStateChanged — the inspector subscribed to onStateSnapshotEvent
(pipeline-only) but not onStateChanged, leaving the "Current State"
panel permanently stale. Add onStateChanged handler mirroring the
existing onMessagesChanged pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 00:08:53 +02:00
Jordan Ritter 39b4ea6ecc docs: clarify client-side debug prop behavior
Updated JSDoc and troubleshooting docs to accurately describe that
the client-side debug prop forwards config to the AG-UI transport
layer, not CopilotKit's own logging. Removed fabricated console.debug
output examples that don't exist.
2026-04-14 14:58:44 -07:00
Jordan Ritter 295a1e609e fix: sync debug prop changes at runtime in CopilotKitProvider
debug was only read at construction time. Added setDebug() to
CopilotKitCore and added it to the provider's prop-sync useEffect
so runtime changes to the debug prop take effect.
2026-04-14 14:58:33 -07:00
Jordan Ritter fde4e0b424 fix: cache pino debug logger on runtime instead of creating per-request
createLogger() was called on every request when debug was enabled,
instantiating a new pino + pino-pretty stream each time. Now creates
a single logger in the runtime constructor and passes it to handlers.
Added test verifying pre-created logger is reused.
2026-04-14 14:58:22 -07:00
Jordan Ritter 6689de4522 fix: thread debug config through to ProxiedCopilotRuntimeAgent
Debug config was silently dropped because ProxiedCopilotRuntimeAgentConfig
had no debug field. Now stores it in the constructor, resolves it in
AgentRegistry before passing, and clone() preserves it. Added 6 tests
verifying the full threading chain.
2026-04-14 14:58:09 -07:00
Jordan Ritter 971a8165aa fix: default verbose to false when debug: true to prevent PII exposure
When users pass the boolean shorthand `debug: true`, verbose previously
defaulted to true, logging full event payloads including user messages,
tool args, and state snapshots. Now defaults to false — users must
explicitly opt in with `debug: { verbose: true }`.
2026-04-14 14:57:22 -07:00
Jordan Ritter 2438896409 fix: respect user expand/collapse intent in reasoning message (#3897)
## Summary

- **Component bug fix:** `CopilotChatReasoningMessage` auto-collapse
`useEffect` unconditionally called `setIsOpen(false)` when streaming
ended, overriding any manual expand/collapse the user had performed.
Added a `userToggledRef` that tracks explicit clicks so the effect only
auto-collapses when the user hasn't interacted.
- **Flaky test fix:** `CopilotChat.e2e.test.tsx` reasoning toggle test
used `fireEvent.click` without `act()`, causing React 18 to defer the
state update through its scheduler. This raced with `waitFor` polling on
slow CI runners (Node 20.x/22.x), producing nondeterministic failures
across multiple PRs.

## Test plan

- [x] Existing reasoning message tests pass with both fixes applied
- [x] Pre-commit hooks (lint, format, test, build) pass
- [ ] Verify intermittent CI failures on unit (20.x/22.x) no longer
reproduce

Note: This fixes the intermittent unit test failures that have been
appearing across multiple unrelated PRs.
2026-04-14 14:35:38 -07:00
Jordan Ritter 1e0de53a25 fix: add null check for navigator.clipboard across all copy-to-clipboard calls (#2114) (#3813)
Fixes #2114

Red-green tested locally.
2026-04-14 14:31:13 -07:00
Jordan Ritter 5aa158da03 fix: surface TOAST/BANNER errors when showDevConsole=false (#3789)
## Summary
- Fixes #2431
- The `routeError` function in `copilot-messages.tsx` returned early
when `showDevConsole=false`, suppressing ALL errors including
user-visible ones (TOAST and BANNER visibility)
- Now only `DEV_ONLY` and `SILENT` errors are suppressed in production;
`TOAST` and `BANNER` errors are always surfaced to the chat UI
- Also fixes the non-GraphQL error handler which had the same
early-return bug

## Test plan
- [x] Added `error-visibility-prod.test.tsx` covering TOAST, DEV_ONLY,
and SILENT visibility behavior
- [x] All 1073 existing react-core tests pass
- [x] Build passes
2026-04-14 14:26:17 -07:00
Jordan Ritter 0106b1bf19 fix: remove unstable key on CodeBlock to prevent flickering during streaming (#3826)
## Summary

- Removes the `key` prop from `CodeBlock` in `Markdown.tsx` entirely
- The original `Math.random()` key caused React to remount the component
on every render, producing visible flickering
- A content-based key (language + content prefix) still changes every
streaming token, causing the same problem
- Without an explicit key, React uses positional identity — stable
across re-renders while content streams in

Closes #2669

## Test plan

- [x] `@copilotkit/react-ui` tests pass
- [x] `@copilotkit/react-ui` build succeeds
- [ ] Manual: verify code blocks no longer flicker during streaming in
chat UI
2026-04-14 14:26:13 -07:00
Jordan Ritter 2c45e24e90 fix: handle anyOf/oneOf/$ref/null in JSON schema to Zod conversion (#3849)
## Summary
- Handle `anyOf`, `oneOf`, `$ref`, and null type entries when converting
JSON schema to Zod schemas
- Prevents runtime errors when LLM tool parameters use union types or
nullable fields

Closes #2220

---
*Split from #3847*
2026-04-14 14:26:09 -07:00
Jordan Ritter 1e5c0ba9ec fix: support OpenAI SDK v5 by falling back from openai.beta to openai.chat.completions (#1979) (#3810)
Fixes #1979

## Summary

- Add `isOpenAIV5()` detection helper that checks whether `beta.chat`
was removed (v5 promoted it to `chat.completions`)
- Add `getChatCompletionsForStreaming()` helper that routes to the
correct completions namespace per SDK version
- Migrate `OpenAIAdapter` to use the new helper instead of direct
`beta.chat.completions` access
- Migrate `OpenAIAssistantAdapter` `runs.retrieve()` and
`submitToolOutputsStream()` to use v5 named path params (e.g.
`retrieve(runId, { thread_id })` instead of positional
`retrieve(threadId, runId)`)
- Add `openai` to peerDependencies with `^4.85.1 || ^5.0.0` range
- Add 11 unit tests covering v4/v5 detection, streaming dispatch, and
named path param calling conventions

## Notes

The remaining `openai.beta.threads.*` calls (`threads.create`,
`messages.create`, `runs.stream`) do NOT need migration because:
1. `beta.threads` still exists in v5 (only `beta.chat` was removed)
2. These methods have single path params, so their signatures are
unchanged

## Test plan

- [x] All 11 v5 compat tests pass (`nx run @copilotkit/runtime:test`)
- [x] Runtime package builds successfully (`nx run
@copilotkit/runtime:build`)
- [x] Pre-commit hooks pass (lint, format, publint, attw)
2026-04-14 14:26:05 -07:00