MCP takes markdown input for document version content
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -18,11 +18,14 @@ package mcp_v1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"go.gearno.de/kit/log"
|
"go.gearno.de/kit/log"
|
||||||
"go.probo.inc/probo/pkg/gid"
|
"go.probo.inc/probo/pkg/gid"
|
||||||
"go.probo.inc/probo/pkg/iam"
|
"go.probo.inc/probo/pkg/iam"
|
||||||
"go.probo.inc/probo/pkg/probo"
|
"go.probo.inc/probo/pkg/probo"
|
||||||
|
"go.probo.inc/probo/pkg/prosemirror"
|
||||||
"go.probo.inc/probo/pkg/server/api/authn"
|
"go.probo.inc/probo/pkg/server/api/authn"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,6 +35,20 @@ type Resolver struct {
|
|||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func markdownToProseMirrorJSON(markdown string) (string, error) {
|
||||||
|
node, err := prosemirror.ParseMarkdown(markdown)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("cannot parse markdown: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := json.Marshal(node)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("cannot marshal prosemirror node: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(out), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Resolver) MustAuthorize(ctx context.Context, entityID gid.GID, action iam.Action) {
|
func (r *Resolver) MustAuthorize(ctx context.Context, entityID gid.GID, action iam.Action) {
|
||||||
identity := authn.IdentityFromContext(ctx)
|
identity := authn.IdentityFromContext(ctx)
|
||||||
|
|
||||||
|
|||||||
@@ -2170,6 +2170,24 @@ func (r *Resolver) CreateDraftDocumentVersionTool(ctx context.Context, req *mcp.
|
|||||||
panic(fmt.Errorf("cannot create draft document version: %w", err))
|
panic(fmt.Errorf("cannot create draft document version: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if input.Content != nil {
|
||||||
|
content, err := markdownToProseMirrorJSON(*input.Content)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot convert markdown to prosemirror: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
draftVersion, err = svc.Documents.UpdateVersion(
|
||||||
|
ctx,
|
||||||
|
probo.UpdateDocumentVersionRequest{
|
||||||
|
ID: draftVersion.ID,
|
||||||
|
Content: &content,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot update draft document version content: %w", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil, types.CreateDraftDocumentVersionOutput{
|
return nil, types.CreateDraftDocumentVersionOutput{
|
||||||
DocumentVersion: types.NewDocumentVersion(draftVersion),
|
DocumentVersion: types.NewDocumentVersion(draftVersion),
|
||||||
}, nil
|
}, nil
|
||||||
@@ -2180,11 +2198,20 @@ func (r *Resolver) UpdateDocumentVersionTool(ctx context.Context, req *mcp.CallT
|
|||||||
|
|
||||||
svc := r.ProboService(ctx, input.DocumentVersionID)
|
svc := r.ProboService(ctx, input.DocumentVersionID)
|
||||||
|
|
||||||
|
var content *string
|
||||||
|
if input.Content != nil {
|
||||||
|
c, err := markdownToProseMirrorJSON(*input.Content)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot convert markdown to prosemirror: %w", err))
|
||||||
|
}
|
||||||
|
content = &c
|
||||||
|
}
|
||||||
|
|
||||||
documentVersion, err := svc.Documents.UpdateVersion(
|
documentVersion, err := svc.Documents.UpdateVersion(
|
||||||
ctx,
|
ctx,
|
||||||
probo.UpdateDocumentVersionRequest{
|
probo.UpdateDocumentVersionRequest{
|
||||||
ID: input.DocumentVersionID,
|
ID: input.DocumentVersionID,
|
||||||
Content: input.Content,
|
Content: content,
|
||||||
Classification: input.Classification,
|
Classification: input.Classification,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5565,6 +5565,9 @@ components:
|
|||||||
document_id:
|
document_id:
|
||||||
$ref: "#/components/schemas/GID"
|
$ref: "#/components/schemas/GID"
|
||||||
description: Document ID
|
description: Document ID
|
||||||
|
content:
|
||||||
|
type: string
|
||||||
|
description: Document content in markdown format
|
||||||
|
|
||||||
CreateDraftDocumentVersionOutput:
|
CreateDraftDocumentVersionOutput:
|
||||||
type: object
|
type: object
|
||||||
@@ -5584,7 +5587,7 @@ components:
|
|||||||
description: Document version ID
|
description: Document version ID
|
||||||
content:
|
content:
|
||||||
type: string
|
type: string
|
||||||
description: Document content
|
description: Document content in markdown format
|
||||||
classification:
|
classification:
|
||||||
$ref: "#/components/schemas/DocumentClassification"
|
$ref: "#/components/schemas/DocumentClassification"
|
||||||
description: Document classification
|
description: Document classification
|
||||||
|
|||||||
Reference in New Issue
Block a user