Skip to content

feat: add note_manager — create/get/list notes via API#8

Open
DophinL wants to merge 3 commits intop697:mainfrom
DophinL:feat/note-manager
Open

feat: add note_manager — create/get/list notes via API#8
DophinL wants to merge 3 commits intop697:mainfrom
DophinL:feat/note-manager

Conversation

@DophinL
Copy link
Copy Markdown

@DophinL DophinL commented Mar 6, 2026

Summary

Add note_manager.py to support creating and reading YouMind notes (thoughts) via API.

Changes

scripts/note_manager.py (new)

  • create — create a note with plain text content, optional title and board association (POST /api/v1/createThoughtWithPlain)
  • get — fetch a note by ID (POST /api/v1/getThought)
  • list — list all notes in the space (POST /api/v1/listThoughts)

scripts/api_client.py

  • Added create_note(), get_note(), list_notes() methods

SKILL.md

  • Added Note Commands section with usage examples

Usage

# Create a note attached to a board
python3 scripts/run.py note_manager.py create --content "My note" --title "Title" --board-id <board-id>

# AI-generated title
python3 scripts/run.py note_manager.py create --content "My note" --board-id <board-id> --gen-title

# Get / list
python3 scripts/run.py note_manager.py get --id <note-id>
python3 scripts/run.py note_manager.py list

Verified

Tested locally against production API — returns NoteDto with type: "note" as expected.

DophinL added 2 commits March 6, 2026 21:08
Add note_manager.py to manage YouMind notes (thoughts) via API:
- create: POST /api/v1/createThoughtWithPlain — plain text, optional title/board
- get: POST /api/v1/getThought — fetch note by ID
- list: POST /api/v1/listThoughts — list all notes in the space

Also add Note API methods to api_client.py and update SKILL.md docs.
…napi

Adds support for creating craft documents (type: page, the rich-text
Document type in YouMind's board UI), distinct from plain notes (type: note).

## Changes

### scripts/api_client.py
- Added create_craft(board_id, content_plain, title) method
- Uses POST /openapi/v1/createDocument which accepts plain text content
  and converts to Yjs format server-side (same pattern as createThoughtWithPlain)
- Returns PageDto with type='page'

### scripts/note_manager.py
- Added create-craft subcommand
- --content, --title, --board-id (required) flags

### SKILL.md
- Added Note vs Craft explanation (type: note vs type: page)
- Added Craft Document Commands section with usage examples

## Background

createThoughtWithPlain (POST /api/v1/createThoughtWithPlain) always creates
type='note'. To create a craft document (type='page'), use
POST /openapi/v1/createDocument with content as a plain text string —
the OpenApiContentInterceptor handles Yjs conversion server-side.

Verified locally against production API — returns PageDto with type='page'.
@DophinL
Copy link
Copy Markdown
Author

DophinL commented Mar 10, 2026

新增:create_craft() — 创建 Craft 文档 (type: page)

在原有 note 支持基础上,追加了创建 craft document(即看板里的「Document」类型)的接口。

背景

createThoughtWithPlain 固定返回 type: note,无法创建 craft document。
研究了后端代码后发现:

  • POST /api/v1/createPage 需要客户端提供 Yjs binary base64(content.raw),纯 Python 难以生成
  • POST /openapi/v1/createDocument 使用了 OpenApiContentInterceptor接受 plain text string,服务端自动通过 createBase64ByPlainText 转换为 Yjs 格式

所以 create_craft()/openapi/v1/createDocument,和 createThoughtWithPlain 同样的思路,但返回 type: page(craft document)。

使用方式

# Python API
result = client.create_craft(
    board_id='<board-id>',
    content_plain='Your document content',
    title='Document Title',
)
# result['type'] == 'page'
# CLI
python3 scripts/run.py note_manager.py create-craft \
  --content "Your document content" \
  --title "Document Title" \
  --board-id <board-id>

已在生产 API 验证,返回 PageDto with type: 'page'

…64.mjs)

Previously create_craft() sent plain text to /openapi/v1/createDocument without
proper Yjs conversion, causing markdown to render as raw text (## not a heading,
| table | not a table).

## Root Cause
- POST /api/v1/createPage expects content: { raw: <yjs-base64>, plain: string }
- The Yjs binary requires running the full tiptap + y-prosemirror pipeline
- /openapi/v1/createDocument has no @OpenApiContentFields decorator on createPage,
  so the OpenApiContentInterceptor does NOT convert plain text to Yjs

## Fix: client-side markdown → Yjs conversion
Added scripts/md_to_base64.mjs — a Node.js script that runs locally:
  Markdown → HTML (markdown-it) → Tiptap JSON (@tiptap/html) → Yjs binary (y-prosemirror) → base64

create_craft() now:
1. Calls md_to_base64.mjs via subprocess with the markdown content
2. Uses the resulting Yjs base64 as content.raw
3. Calls POST /api/v1/createPage directly with { raw, plain }

## Supported markdown elements
- Headings (h1-h6)
- Bold, italic, strikethrough
- Bullet/ordered lists
- Tables
- Code blocks and inline code
- Blockquotes
- Horizontal rules

Verified locally — renders correctly in YouMind board editor.
@DophinL
Copy link
Copy Markdown
Author

DophinL commented Mar 10, 2026

路径 B 实现:客户端 Markdown → Yjs 转换

上一个 commit 修复了 markdown 不渲染的问题。

根本原因

POST /api/v1/createPagecontent.raw 需要 Yjs binary base64,而 /openapi/v1/createDocumentcreatePage handler 没有 @OpenApiContentFields 装饰器,导致之前发的 plain text string 被直接存储,markdown 完全不解析。

解决方案

新增 scripts/md_to_base64.mjs(Node.js 脚本),在客户端完成转换:

Markdown → HTML (markdown-it) → Tiptap JSON (@tiptap/html) → Yjs binary (y-prosemirror) → base64

create_craft() 通过 subprocess 调用这个脚本,拿到 Yjs base64 后直接调 POST /api/v1/createPage

渲染效果(截图验证)

标题、加粗/斜体、列表、表格、引用块、代码块全部正常渲染。


备选方案(如果 p697 愿意改后端):在 createPage 上加 @OpenApiContentFields('content'),并在 OpenApiContentInterceptor 里用 markdownToBase64 代替 createBase64ByPlainText,这样服务端统一处理,skill 端更简洁。

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