Repository navigation
feat: hand off artifact chats after AI artifact changes - #747
Conversation
|
Warning Review limit reached
More reviews will be available in 22 minutes and 49 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughIntroduces an artifact chat handoff system: new ChangesArtifact Chat Handoff Flow
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e867389c5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return result; | ||
| } | ||
|
|
||
| pendingHandoff = { |
There was a problem hiding this comment.
Key pending artifact handoffs by session
When two artifact-scoped AI chats are running at the same time, the second command that reaches this assignment overwrites the first session's pending handoff before its onChatFinish fires. Since the app keeps providers mounted for every session.isRunning session, concurrent turns are supported; in that case the first session finishes, sees a pending handoff for a different sourceSessionId, and never forks its continuation chat. Store pending handoffs per source session/turn instead of a single shared slot.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aee4c91f3f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return result; | ||
| } | ||
|
|
||
| pendingHandoffs.set(sourceSessionId, { |
There was a problem hiding this comment.
Clear pending handoffs when a turn is aborted
When this records a handoff, the only cleanup is in the app onChatFinish callback, but the AI slice deliberately skips that callback for aborted turns and errors. If a user cancels or a turn fails after an artifact-select/create command, the stale entry remains; a later run of the same source session can fork into that old target whenever that artifact happens to be current, even if the later turn did not change artifacts. Clear the pending entry on abort/error or tie it to the specific turn/message before forking.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
apps/sqlrooms-cli-ui/src/artifactChatHandoff.ts (1)
64-178: ⚡ Quick winAdd TSDoc to exported function.
The exported
createArtifactChatHandoffControllerfunction should have TSDoc documentation describing its purpose, parameters, and return value. As per coding guidelines, exported functions in TypeScript should include TSDoc.📝 Suggested documentation
+/** + * Creates a chat handoff controller that automatically continues AI conversations + * when commands change the active artifact. + * + * `@param` store - The room Zustand store + * `@returns` An object containing commandMiddleware and onChatFinish hooks + */ export function createArtifactChatHandoffController( store: StoreApi<RoomState>, ) {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/sqlrooms-cli-ui/src/artifactChatHandoff.ts` around lines 64 - 178, Add TSDoc documentation to the `createArtifactChatHandoffController` exported function by placing a JSDoc comment block above the function declaration. The documentation should describe the function's purpose (that it creates a controller for handling artifact chat handoffs), document the store parameter and its type (StoreApi<RoomState>), and document the return value object containing the commandMiddleware and onChatFinish properties with their types and purposes.Source: Coding guidelines
apps/sqlrooms-cli-ui/src/createDashboardCommands.ts (1)
134-160: ⚡ Quick winAvoid redundant
getState()call.At line 152,
getState()is called to retrieve the artifact title, butstatewas already obtained at line 136. Usestate.artifacts.getArtifact(artifactId)?.titleinstead to avoid the redundant state getter invocation.♻️ Suggested fix
title: - getState().artifacts.getArtifact(artifactId)?.title ?? + state.artifacts.getArtifact(artifactId)?.title ?? title ?? 'Dashboard',🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/sqlrooms-cli-ui/src/createDashboardCommands.ts` around lines 134 - 160, In the execute function, there is a redundant call to getState() within the return statement when retrieving the artifact title. The state variable has already been captured at the beginning of the function. Replace the getState().artifacts.getArtifact(artifactId)?.title expression in the title field with state.artifacts.getArtifact(artifactId)?.title to use the already-captured state variable instead of calling getState() again.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/sqlrooms-cli-ui/src/store.ts`:
- Around line 541-543: The `as any` cast on
`artifactChatHandoff.commandMiddleware` in the `createCommandProps` middleware
array is unnecessary and should be removed. Since `commandMiddleware` is already
properly typed as `RoomCommandMiddleware<RoomState>` in the artifactChatHandoff
definition, which matches the expected middleware type, TypeScript can correctly
validate the type without the cast. Simply remove the `as any` cast to let the
type system work as intended.
---
Nitpick comments:
In `@apps/sqlrooms-cli-ui/src/artifactChatHandoff.ts`:
- Around line 64-178: Add TSDoc documentation to the
`createArtifactChatHandoffController` exported function by placing a JSDoc
comment block above the function declaration. The documentation should describe
the function's purpose (that it creates a controller for handling artifact chat
handoffs), document the store parameter and its type (StoreApi<RoomState>), and
document the return value object containing the commandMiddleware and
onChatFinish properties with their types and purposes.
In `@apps/sqlrooms-cli-ui/src/createDashboardCommands.ts`:
- Around line 134-160: In the execute function, there is a redundant call to
getState() within the return statement when retrieving the artifact title. The
state variable has already been captured at the beginning of the function.
Replace the getState().artifacts.getArtifact(artifactId)?.title expression in
the title field with state.artifacts.getArtifact(artifactId)?.title to use the
already-captured state variable instead of calling getState() again.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7d20b42d-1413-4cc1-bddd-ed3b37950daa
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (16)
apps/sqlrooms-cli-ui/src/artifactChatHandoff.tsapps/sqlrooms-cli-ui/src/createDashboardCommands.tsapps/sqlrooms-cli-ui/src/store.tspackages/ai-core/README.mdpackages/ai-core/__tests__/AiSlice.onChatFinish.test.tspackages/ai-core/src/AiSlice.tspackages/ai-core/src/chatTransport.tspackages/ai/README.mdpackages/ai/__tests__/commandTools.test.tspackages/ai/package.jsonpackages/ai/src/tools/commandTools.tspackages/artifacts/README.mdpackages/artifacts/src/ai/artifactTargetChange.tspackages/artifacts/src/ai/index.tspackages/documents/src/BlockDocumentCommands.tspackages/documents/src/documentCommands.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1dbf69e603
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sourceSessionId, | ||
| sourceArtifactId, | ||
| sourceUserMessageId: getLastUserMessage( | ||
| nextState.ai.getSession(sourceSessionId)?.uiMessages ?? [], |
There was a problem hiding this comment.
Use an existing AI session lookup
When an AI execute_command creates or selects a different artifact, this line runs after the command has already switched artifacts, but AiSliceState does not expose getSession (sessions are stored under ai.config.sessions, with only getCurrentSession as a helper). In that scenario the middleware throws nextState.ai.getSession is not a function, so the tool call is reported as failed and no handoff is recorded even though the artifact change already happened.
Useful? React with 👍 / 👎.
Summary
ArtifactTargetChangemetadata shape and include it in artifact create/select command results.execute_commandand add an AI-coreonChatFinishhook for host-owned completed-turn follow-up behavior.Validation
corepack pnpm install --frozen-lockfilecorepack pnpm buildcorepack pnpm --filter @sqlrooms/ai test -- commandTools.test.ts --runInBandcorepack pnpm --filter @sqlrooms/ai-core test -- AiSlice.onChatFinish.test.ts --runInBandcorepack pnpm --filter @sqlrooms/artifacts test -- artifactAiSessions.test.ts --runInBandcorepack pnpm --filter @sqlrooms/ai typecheckcorepack pnpm --filter @sqlrooms/ai-core typecheckcorepack pnpm --filter sqlrooms-cli-app buildhttp://127.0.0.1:4174/with HTTP 200.Note: the in-app browser connector failed with a session metadata error, so full UI automation was not available. Live AI handoff interaction also depends on configured model/API credentials.
Summary by CodeRabbit
New Features
onChatFinishcallback to enable app-level logic for handling completed AI turns, supporting artifact-scoped follow-up behaviors.Documentation
onChatFinishconfiguration option.