Skip to content

feat(examples): add comprehensive editV2 operation examples#33

Open
hnshah wants to merge 2 commits intoEveryInc:mainfrom
hnshah:examples/multi-step-workflow
Open

feat(examples): add comprehensive editV2 operation examples#33
hnshah wants to merge 2 commits intoEveryInc:mainfrom
hnshah:examples/multi-step-workflow

Conversation

@hnshah
Copy link
Copy Markdown

@hnshah hnshah commented Mar 23, 2026

Problem

The directory currently has only one example () showing basic bridge usage with comments. There are no examples demonstrating:

  • The recommended editV2 editing approach
  • All 6 block-level operations
  • Multi-step workflows with revision tracking
  • Proper error handling and idempotency
  • Real-world document building patterns

Solution

This PR adds two comprehensive TypeScript examples that demonstrate all editV2 capabilities.

1. multi-step-workflow.ts

What it shows:

  • ✅ Creating a document with initial structure
  • ✅ Sequential edits with proper baseRevision tracking
  • ✅ Batch operations (multiple blocks in one request)
  • ✅ Real-world use case (building a project plan)
  • ✅ Proper idempotency key usage
  • ✅ Error handling

Run with:

npm run demo:workflow

Output:

📝 Multi-Step Document Builder
==============================
1️⃣  Creating project plan document...
   ✅ Document created: abc123
2️⃣  Fetching document state...
   📄 Current revision: 1
3️⃣  Adding project timeline section...
   ✅ Timeline added (revision 2)
4️⃣  Enhancing overview section...
   ✅ Overview enhanced (revision 3)
5️⃣  Completing next steps section...
   ✅ Next steps completed (revision 4)
✅ Document build complete!

2. editv2-operations.ts

What it tests:

  • replace_block - Update single block
  • insert_after - Add blocks after reference
  • insert_before - Add blocks before reference
  • delete_block - Remove block
  • find_replace_in_block - Text replacement in a block
  • replace_range - Replace multiple consecutive blocks

Run with:

npm run demo:operations

Output:

🧪 Testing Proof SDK editV2 Operations
======================================
✅ All editV2 operations working!

📊 Summary:
   - replace_block: ✅
   - insert_after: ✅
   - insert_before: ✅
   - delete_block: ✅
   - find_replace_in_block: ✅
   - replace_range: ✅

Benefits

For developers:

  • Shows proper editV2 usage (the recommended editing approach per docs)
  • Demonstrates all operation types with working code
  • Real-world patterns (not just API reference)
  • Can copy-paste as starting points for their own code

For contributors:

  • Examples can serve as validation tests
  • Reference implementation for proper error handling
  • Shows idempotency patterns

For documentation:

  • Living examples that are tested against the actual server
  • TypeScript code that matches the project's stack
  • Runnable demos for README/docs

Testing

Both examples run successfully against a local Proof SDK server:

# Terminal 1: Start server
npm run serve

# Terminal 2: Run examples
npm run demo:workflow   # ✅ Builds complete document (4 revisions)
npm run demo:operations # ✅ All 6 operations pass

Files Changed

  • apps/proof-example/examples/multi-step-workflow.ts (+169 lines)
  • apps/proof-example/examples/editv2-operations.ts (+230 lines)
  • apps/proof-example/package.json (added 2 new scripts)
  • apps/proof-example/README.md (documented new examples)

Related

hnshah added 2 commits March 23, 2026 08:49
Fixes EveryInc#22

The editV2() method was missing from the agent bridge client, and there
was a field name mismatch between what developers might expect and what
the server actually accepts.

Server expects:
- baseRevision (number)
- operations (array of ops)

This adds:
- EditV2Input interface with correct field names
- EditV2BlockOp union type covering all 6 operation types
- editV2() client method that POSTs to /documents/:slug/edit/v2
- Idempotency-Key header support (automatically set from input.idempotencyKey)

All field names now match the server implementation in server/agent-edit-v2.ts.
Adds two new example scripts demonstrating all editV2 capabilities:

1. multi-step-workflow.ts
   - Shows sequential document building
   - Demonstrates revision tracking
   - Batch operations (multiple blocks in one request)
   - Real-world use case (project plan creation)

2. editv2-operations.ts
   - Comprehensive test of all 6 block operations
   - replace_block, insert_after, insert_before
   - delete_block, find_replace_in_block, replace_range
   - Error handling for each operation
   - Validates final document state

Benefits:
- Currently only 1 example exists (basic bridge usage)
- These show recommended editV2 approach in practice
- TypeScript examples using the bridge client
- Proper idempotency and error handling patterns
- Can be run as validation tests

Run with:
  npm run demo:workflow
  npm run demo:operations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant