Skip to content

feat(rich-text): add AI patch finalization API and harden BlockIdExtension (FCT-50714)#3781

Open
mjh-sakh wants to merge 5 commits intomainfrom
aoskin/20260325-one-onboarding-policy-co-creation
Open

feat(rich-text): add AI patch finalization API and harden BlockIdExtension (FCT-50714)#3781
mjh-sakh wants to merge 5 commits intomainfrom
aoskin/20260325-one-onboarding-policy-co-creation

Conversation

@mjh-sakh
Copy link
Copy Markdown

@mjh-sakh mjh-sakh commented Mar 27, 2026

Description

The One assistant co-creates page documents with users. This PR adds the editor-layer requirements that make that possible:

  1. NotesTextEditorHandle.applyPageDocumentPatch() — the imperative API the frontend co-creation hook calls to apply a structured patch to the open Tiptap instance. This allows AI to work with blocks as per RFC.

  2. Null block ID population — legacy documents store some block IDs as null; patches look up blocks by ID, so null IDs silently fail without this fix. BLOCK_NODE_TYPES_SET is also exported as ReadonlySet to prevent caller mutation.

  • ⚠️ This will trigger "You have changes pending to be saved" on Policies Pages created before BlockIdExtension.
  1. Double-spinner and flicker fix in F0AiChat — the co-creation confirmation protocol uses followUp: true, which produces a tool-call-only assistant message followed immediately by a new empty message. This caused two concurrent spinners and a flickery thinking indicator. Fixed via a useDebouncedFalseEdge hook that smooths the ~10ms gap between followUp requests, and suppressed the empty placeholder when a turn already has active progress.

Implementation details

fix(rich-text): harden BlockIdExtension — populate null block IDs and export ReadonlySet
Null IDs populated via onCreate round-trip in BlockIdExtension/index.tsx.
BLOCK_NODE_TYPES_SET re-exported as ReadonlySet<string>.

feat(rich-text): add AI patch finalization API to NotesTextEditorHandle
Adds applyPageDocumentPatch(patch: PageDocumentPatch): PageDocumentPatchResult to the handle interface. Applies the patch as a Tiptap transaction. Called by factorial's usePageCoCreation hook after receiving a patch from the agent.
⚠️ The factorial frontend co-creation hook has a hard dependency on this method — the f0 package must be published before the factorial PR merges.

fix(ai-chat): suppress double spinner and followUp flicker via useDebouncedFalseEdge
New useDebouncedFalseEdge hook smooths the isLoading gap between CopilotKit followUp requests. Suppresses the empty follow-up assistant placeholder when a turn already has active progress. Debounce delay reduced from 150ms to 40ms (below the 100ms human perception threshold). Must be published before the factorial-agent PR deploys to avoid the known regression.

📦 Dependencies

Has to be merged before https://github.com/factorialco/factorial/pull/93214.

Note: there is another change that has introduced a need for creditWarning translation to frontend. It fails without it.

🏡 Context

  • 💼 Jira — Related to FCT-50714
  • Frontend implementation: factorial PR feat(pages): add page document co-creation for onboarding policies

Copilot AI review requested due to automatic review settings March 27, 2026 06:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@github-actions github-actions bot added the feat label Mar 27, 2026
@mjh-sakh mjh-sakh force-pushed the aoskin/20260325-one-onboarding-policy-co-creation branch 2 times, most recently from 33b0015 to db4a08c Compare March 27, 2026 13:32
Copilot AI review requested due to automatic review settings March 27, 2026 13:32
@github-actions github-actions bot added the react Changes affect packages/react label Mar 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

✅ No New Circular Dependencies

No new circular dependencies detected. Current count: 0

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

📦 Alpha Package Version Published

Use pnpm i github:factorialco/f0#npm/alpha-pr-3781 to install the package

Use pnpm i github:factorialco/f0#6d4097dcf016dea2787dfd491bf87eb86e0e1275 to install this specific commit

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

🔍 Visual review for your branch is published 🔍

Here are the links to:

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

Coverage Report for packages/react

Status Category Percentage Covered / Total
🔵 Lines 45.12% 10742 / 23806
🔵 Statements 44.41% 11066 / 24917
🔵 Functions 37.18% 2438 / 6556
🔵 Branches 36.58% 6875 / 18790
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/react/src/experimental/RichText/CoreEditor/Extensions/BlockIdExtension/index.tsx 74.6% 72.72% 82.35% 75.4% 72, 124-129, 161-171, 175-184
packages/react/src/experimental/RichText/NotesTextEditor/applyPageDocumentPatch.ts 98.75% 80.43% 100% 98.75% 68
packages/react/src/experimental/RichText/NotesTextEditor/index.tsx 56.25% 42.5% 44% 59.15% 104-112, 133, 181-183, 186, 192-224, 229, 237-241, 256, 262-284, 296, 331-360, 423-485
packages/react/src/experimental/RichText/NotesTextEditor/types.tsx 100% 100% 100% 100%
packages/react/src/sds/ai/F0AiChat/components/messages/MessagesContainer.tsx 6.77% 0% 0% 7.14% 48-50, 63-334, 364-383
packages/react/src/sds/ai/F0AiChat/hooks/useDebouncedFalseEdge.ts 87.5% 83.33% 100% 87.5% 21-22
packages/react/src/sds/ai/F0AiChat/utils/turnUtils.ts 97.91% 90.24% 100% 97.82% 53
Generated in workflow #12337 for commit b60c97d by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Copilot AI review requested due to automatic review settings March 28, 2026 07:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

@mjh-sakh mjh-sakh force-pushed the aoskin/20260325-one-onboarding-policy-co-creation branch from fa547ac to 05a5aa8 Compare March 28, 2026 07:48
Copilot AI review requested due to automatic review settings March 28, 2026 07:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

@mjh-sakh
Copy link
Copy Markdown
Author

build

1 similar comment
@mjh-sakh
Copy link
Copy Markdown
Author

build

Copilot AI review requested due to automatic review settings March 28, 2026 08:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@mjh-sakh
Copy link
Copy Markdown
Author

build

Copilot AI review requested due to automatic review settings March 28, 2026 10:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

@mjh-sakh mjh-sakh changed the title feat(rich-text): expose AI finalization editor API feat(rich-text): add AI patch finalization API and harden BlockIdExtension (FCT-50714) Mar 28, 2026
Copilot AI review requested due to automatic review settings March 28, 2026 13:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

@mjh-sakh mjh-sakh force-pushed the aoskin/20260325-one-onboarding-policy-co-creation branch from 3450f28 to 50d2c63 Compare March 28, 2026 17:01
Copilot AI review requested due to automatic review settings March 28, 2026 19:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

@mjh-sakh mjh-sakh marked this pull request as ready for review March 30, 2026 05:46
@mjh-sakh mjh-sakh requested a review from a team as a code owner March 30, 2026 05:46
@mjh-sakh
Copy link
Copy Markdown
Author


Note

Medium Risk
Introduces new mutation paths for the Tiptap document (insert/replace/delete by block id) and adjusts block-id generation logic, which could impact editor state integrity if edge cases are missed. Chat UI changes are low risk but affect loading/turn rendering behavior during followUp flows.

Overview
Enables AI-driven, structured edits to the rich-text editor by adding NotesTextEditorHandle.applyPageDocumentPatch() plus supporting patch types (prepend/append/insert before/after/replace block/replace content/delete) that return a {json, html} snapshot and throw a dedicated NotesTextEditorPatchTargetNotFoundError when target IDs are missing.

Hardens block ID handling: BlockIdExtension now exports BLOCK_NODE_TYPES_SET as a ReadonlySet and fixes range tracking so newly inserted blocks reliably receive fresh IDs; NotesTextEditor also normalizes legacy id: null blocks on mount and only emits onChange when IDs are actually populated.

Improves AI chat follow-up UX by debouncing the false edge of inProgress via new useDebouncedFalseEdge, suppressing redundant empty assistant placeholders, and refining analyzeTurn to avoid double spinners; adds targeted tests and ProseMirror Range rect stubs to stabilize JSDOM runs.

Written by Cursor Bugbot for commit b60c97d. This will update automatically on new commits. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat react Changes affect packages/react

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants