Commit Graph

1227 Commits

Author SHA1 Message Date
Martha Schumann e814e91030 test: add unit tests for ThreadStoreRegistry, thread handlers, and hook lifecycle
- New ThreadStoreRegistry suite (8 tests) covers register/get round-trip,
  replacement on duplicate id, unregister no-op, and subscriber events for
  both register and unregister
- handle-threads suite gains handleClearThreads (InMemory path + intelligence
  path) and handleGetThreadMessages (InMemory, unknown thread, intelligence
  delegation, 422 fallback) describe blocks
- in-memory-runner suite: clearThreads() in beforeEach fixes GLOBAL_STORE
  isolation; vacuous empty-array test replaced with a meaningful post-clear
  assertion
- use-threads suite: new test asserts registerThreadStore is called on mount
  and unregisterThreadStore is called on unmount

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 15:43:28 -07:00
Martha Schumann 0ee11987e3 feat(web-inspector): add Threads tab with early-access gate and thread store integration
Wires the new Angular Custom Elements into the web inspector's Threads tab.
The tab is hidden behind an early-access gate (isEarlyAccessUser check);
_demoMode defaults to false. The inspector registers its own per-agentId
thread store unless one is already registered by useThreads(), preventing
accidental overwrites for apps that use both.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 15:43:28 -07:00
Martha Schumann 0e913ea33e feat(web-inspector-angular): new Angular Custom Elements package for thread UI
Exports cpk-thread-list, cpk-thread-details, and cpk-empty-events as
Custom Elements so the thread panel UI works in any framework (Angular,
React, plain HTML). Components use RxJS observables and Angular signals
internally, then render via defineElements() to register as standard
Web Components.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 15:43:28 -07:00
Martha Schumann 14ae28cfd1 feat(inspector): add thread store registry, runtime handlers, and useThreads hook
- CopilotKitCore gains a ThreadStoreRegistry (register/unregister by agentId)
  and a new onAgentRunStarted subscriber event so the inspector can subscribe
  before agent.runAgent() snapshots the subscriber list
- Runtime gains handleListThreads, handleUpdateThread, handleArchiveThread,
  handleDeleteThread, handleSubscribeToThreads, and handleGetThreadMessages
  handlers; all mutations are authenticated via identifyUser (request body
  userId is ignored)
- InMemoryAgentRunner now stores thread history for the local-dev fallback
  path; debug console.log removed; InMemoryThread uses literal types for
  constant-value fields (organizationId: "", createdById: "", archived: false)
- useThreads hook registers its store with CopilotKitCore on mount and
  unregisters on unmount so the inspector can read thread state

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 15:43:27 -07:00
Nathan 🔶 Tarbert 8a651db6d9 fix: inspector not receiving AG-UI events from per-thread agent clones
useAgent() returns per-thread clones that are not in the agent registry.
The inspector only subscribed to registry agents via onAgentsChanged, so
it never received events from clones — resulting in an empty event panel.

Add onAgentRunStarted subscriber event that fires before connectAgent()
and runAgent(), passing the actual agent instance (which may be a clone).
The inspector subscribes to that agent, matching the existing StateManager
pattern (subscribeAgentToStateManager).
2026-04-13 17:58:10 -04:00
Jordan Ritter 5e9fec77ba 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-13 14:38:22 -07:00
Jordan Ritter 8244b0f31f fix: guard clipboard calls and only show copied state on success (#2114)
Add null checks for navigator.clipboard across all copy-to-clipboard
calls to prevent TypeError in non-localhost environments where the
Clipboard API is unavailable. The copied indicator now only appears
after a confirmed successful write, preventing false positive UX
feedback when the clipboard API is missing or the write fails.
2026-04-13 09:16:11 -07:00
Jordan Ritter b53844c8c3 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-13 09:11:28 -07:00
Jordan Ritter 0b26088586 fix: clone visited-refs set to prevent false circular-ref detection across sibling branches
The shared visitedRefs Set was mutated in place, so when two sibling
properties referenced the same $def (e.g. billing and shipping both
referencing Address), the second resolution was incorrectly flagged as
circular. Clone the set before recursing so each branch has its own
ancestry path. Added regression test that fails without this fix.
2026-04-13 09:08:54 -07:00
Jordan Ritter 6bf84f3cec 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-13 09:07:38 -07:00
Jordan Ritter ac0ceda748 fix: replace tautological test with real unit tests for error visibility
Extract getErrorSuppression as a pure testable function from the
routeError closure. Replace the mock-only test that only proved mock
wiring with 12 real assertions covering all visibility x isDev
combinations against the actual logic.
2026-04-13 09:05:38 -07:00
Jordan Ritter 18552b561f fix: add circular $ref cycle detection in JSON schema to Zod conversion
Recursive JSON schemas that reference themselves via $ref would cause
infinite recursion and stack overflow. This adds a visited set that
tracks which $ref paths have been seen during resolution. When a cycle
is detected, it breaks with z.any() and logs a console.warn so users
get feedback. Also adds console.warn for the generic z.any() fallback
on unsupported schema types.

Adds tests for circular refs, non-circular $ref resolution, anyOf with
$ref variants, integer type, null type, and unsupported type warning.
2026-04-13 08:30:33 -07:00
Jordan Ritter 23ea810c5a fix: remove unstable key on CodeBlock to prevent flickering during streaming
The original Math.random() key caused React to remount the CodeBlock on
every render. The PR's content-based key (language + content prefix) still
changed every streaming token, causing the same flickering. Removing the
key entirely lets React use positional identity, which is stable across
re-renders while content streams in.

Closes #2669
2026-04-13 08:28:28 -07:00
Jordan Ritter 4e10f1344a 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-13 08:27:19 -07:00
Jordan Ritter 7998a46659 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-13 08:25:22 -07:00
Alem Tuzlak f55cd5f7e2 Merge remote-tracking branch 'origin/main' into worktree-nested-tinkering-quail
# Conflicts:
#	packages/runtime/src/v2/runtime/handlers/get-runtime-info.ts
2026-04-13 15:03:54 +02:00
Ran Shemtov 9788c07dcc Merge branch 'main' into fix/issue-1921 2026-04-13 15:01:32 +02:00
Ran Shemtov 454ba9b17a Merge branch 'main' into fix/issue-1936 2026-04-13 14:58:03 +02:00
Ran Shemtov ced35df1b2 Merge branch 'main' into fix/issue-1921 2026-04-13 14:56:05 +02:00
Ran Shemtov 7a7955a440 Merge branch 'main' into fix/issue-2941 2026-04-13 14:50:24 +02:00
Alem Tuzlak 4b279cee64 fix: address code review findings on capabilities
- Restore getCapabilities() return type to Promise<AgentCapabilities>
  with ?? {} fallback, honoring AbstractAgent base class contract
- Simplify type annotation in get-runtime-info.ts to explicit
  AgentCapabilities | undefined instead of complex Awaited<ReturnType<...>>
- Add console.warn logging to per-agent capabilities error catch block
- Fix useCapabilities JSDoc to accurately describe behavior during
  runtime handshake
- Add test for empty capabilities object {} (truthy, included in response)
- Update error isolation test to verify warning is logged
2026-04-13 14:49:50 +02:00
Ran Shemtov dcfd7da220 Merge branch 'main' into fix/issue-3499 2026-04-13 14:43:42 +02:00
github-actions[bot] a6fb46b555 style: auto-fix formatting 2026-04-13 09:23:53 +00:00
Alem Tuzlak ee926b8628 fix: address capabilities review feedback
- Add per-agent error isolation in /info handler so a single
  getCapabilities() failure doesn't 500 the whole endpoint
- Normalize getCapabilities() to return undefined (not {}) when no
  capabilities are set, matching the sync getter
- Replace instanceof ProxiedCopilotRuntimeAgent with duck-type check
  in useCapabilities hook for extensibility
- Add JSDoc warning about shallow-merge behavior on capabilities config
- Add useCapabilities hook tests (5 cases covering both branches)
- Add per-agent error isolation test for get-runtime-info
2026-04-13 11:22:22 +02:00
Alem Tuzlak 327d134ecd Merge remote-tracking branch 'origin/main' into worktree-nested-tinkering-quail
# Conflicts:
#	packages/angular/package.json
#	packages/core/package.json
#	packages/demo-agents/package.json
#	packages/react-core/package.json
#	packages/runtime/package.json
#	packages/shared/package.json
#	packages/sqlite-runner/package.json
#	packages/web-inspector/package.json
#	pnpm-lock.yaml
2026-04-13 11:12:25 +02:00
Jordan Ritter d1c3708050 fix: batch useAgent forceUpdate calls via microtask to prevent scroll jumping (#3499)
When useAgent subscribes to multiple update types (OnMessagesChanged,
OnStateChanged, OnRunStatusChanged), each event fires forceUpdate()
independently. During streaming this causes dozens of re-renders per
second, leading to brief content height fluctuations that trigger
scroll jumping in use-stick-to-bottom.

Coalesce OnStateChanged and OnRunStatusChanged notifications using
queueMicrotask so multiple synchronous events within the same tick
produce a single React re-render. OnMessagesChanged retains its
existing behavior (direct or throttled).
2026-04-12 16:19:55 -07:00
Jordan Ritter 6c4162c2d0 fix: support per-request agent factory function (#2941)
Add AgentsFactory type that accepts a function receiving request context,
enabling multi-tenant and request-scoped agent configuration. The agents
option now accepts a static record, a Promise, or a factory function.
2026-04-12 16:09:41 -07:00
Jordan Ritter 2cf4021eaa fix: skip content_block_delta events for unknown tool_use blocks
When mode is null (unknown tool skipped), content_block_delta events
with input_json_delta would still call sendActionExecutionArgs using
the previous valid tool call ID, corrupting its arguments.
2026-04-12 15:31:50 -07:00
github-actions[bot] 45d4e36280 style: auto-fix formatting 2026-04-12 22:27:35 +00:00
github-actions[bot] 65b8f05e8d style: auto-fix formatting 2026-04-12 22:26:58 +00:00
github-actions[bot] c4d50a3ec7 style: auto-fix formatting 2026-04-12 22:26:58 +00:00
Jordan Ritter f94367ffd7 fix: support dynamic headers function prop for auth token refresh (#2779) 2026-04-12 15:25:17 -07:00
Jordan Ritter 49be36eeb9 fix: scope .dark CSS selectors to CopilotKit elements (#2920) 2026-04-12 15:24:54 -07:00
Jordan Ritter fac52dbf9b fix: handle anyOf/oneOf/ in JSON schema to Zod conversion (#2220) 2026-04-12 15:24:46 -07:00
Jordan Ritter 39a9eb81ca fix: preserve jsonSchema structure in MCP tool parameter extraction (#1936)
extractParametersFromSchema now preserves enum values as structured
data on string parameters, recursively extracts nested object
attributes, and converts object arrays to object[] type with
attributes. This ensures complex MCP tool schemas survive the
Parameter[] -> Zod conversion without losing nested structure.
2026-04-12 15:17:02 -07:00
Jordan Ritter 00b14e54ba fix: pass urlTransform prop through to ReactMarkdown (#1921)
The Markdown component accepted components but not urlTransform,
preventing users from customizing URL sanitization. Added urlTransform
as an optional prop with passthrough to MemoizedReactMarkdown.
2026-04-12 15:16:55 -07:00
Jordan Ritter 0099c1d3e2 fix: honor Retry-After header on 429 responses (#3637)
Parse Retry-After as seconds or HTTP-date and use it as the retry delay
instead of exponential backoff. Throw if the server requests a wait
longer than maxRetryAfterSeconds (60s default) to avoid hanging.
2026-04-12 15:16:35 -07:00
Jordan Ritter 3aadfb34f4 fix: prevent "Unknown provider" regression for LangChainAdapter (#3217)
When getLanguageModel() returns null and provider/model are undefined
(as with LangChainAdapter), the code constructed "undefined/undefined"
as a model string, causing a cryptic "Unknown provider" error.

Now checks each source of model info explicitly and throws a clear
error message directing users to provide an explicit agents config
when using adapters that don't expose model metadata.
2026-04-12 15:16:34 -07:00
Jordan Ritter 6afe64b3ef fix: forward credentials on all agent registration paths (#3141)
applyCredentialsToAgents/applyCredentialsToAgent were defined but never
called from initialize(), setAgents__unsafe_dev_only(), or
addAgent__unsafe_dev_only(). Only remote agents received credentials
via constructor. Local agents now receive credentials alongside headers.
2026-04-12 15:16:34 -07:00
Jordan Ritter 41e7d70bbe fix: add IME composition guard in CopilotChatInput (#3318)
Skip keydown handling during IME composition (e.g. CJK input) by
checking isComposing/keyCode 229, and guard textarea measurement
from resetting value mid-composition.
2026-04-12 15:10:28 -07:00
Jordan Ritter 2e85fd6428 fix: show loading indicator during tool execution (#3055)
The loading spinner only appeared when the last message had role "user".
During tool execution the last message can have role "tool", hiding the
indicator. Now also show it when the trailing message is a tool result.
2026-04-12 15:09:37 -07:00
Jordan Ritter 18b0d7a831 fix: normalize array content in TOOL_CALL_RESULT for MCP adapters (#2922)
langchain-mcp-adapters sends tool call result content as an array of
{type:"text", text:string} objects. Extract and join text parts so
downstream consumers always receive a plain string.
2026-04-12 15:09:33 -07:00
Jordan Ritter 6b653d6580 fix: wrap Button with forwardRef to fix DropdownMenuTrigger ref warning (#2947)
Radix UI's asChild pattern requires the child component to forward
refs. The Button component was a plain function, causing a React
warning when nested inside DropdownMenuTrigger. Converted to
React.forwardRef so the ref is properly passed through to the
underlying DOM element.
2026-04-12 15:05:28 -07:00
Jordan Ritter 6b360916b9 fix: always generate unique message IDs in LangChain adapter (#2929)
GoogleGenerativeAI returns "0" as lc_kwargs.id for every message,
which is truthy and bypassed the randomId() fallback. All streamed
messages then shared the same ID, breaking message deduplication.
Now we always use randomId() for new message streams.
2026-04-12 15:05:20 -07:00
Jordan Ritter f07501bbb8 fix: skip version check when showDevConsole is false (#2751)
checkForUpdates() fired unconditionally on mount, making a network
request even when the dev console was disabled. Now the useEffect
short-circuits when showDevConsole is false.
2026-04-12 15:05:06 -07:00
Jordan Ritter 1dcaf752d4 fix: handle null-union types in convertJsonSchemaToParameter (#2651)
JSON schemas from tools like Zod can produce union types like
["string", "null"]. The switch statement only handles single type
strings, causing these to fall through silently. Now we detect
Array.isArray(schema.type), filter out "null", and recurse with
the resolved scalar type.
2026-04-12 15:04:51 -07:00
Jordan Ritter 7e02057885 fix: skip unknown tool_use blocks in Anthropic adapter to prevent crashes (#2504) 2026-04-12 15:02:45 -07:00
Jordan Ritter 859304a770 fix: use div instead of p tag in Markdown to prevent hydration errors (#2234) 2026-04-12 15:01:34 -07:00
Jordan Ritter f278eda07d fix: export CopilotModal and CopilotModalProps from react-ui (#2194) 2026-04-12 14:59:37 -07:00
Jordan Ritter 3528a1f200 fix: ensure TextMessageOutput.id is never null by falling back to randomId() (#2118) 2026-04-12 14:59:03 -07:00