Skip to content

Commit bf339d2

Browse files
Milkdown Editor (#459)
1 parent 6aa7091 commit bf339d2

8 files changed

Lines changed: 2155 additions & 199 deletions

File tree

libraries/python/assistant-extensions/assistant_extensions/document_editor/_inspector.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,14 @@ async def get(self, context: ConversationContext) -> AssistantConversationInspec
123123
if not document:
124124
return AssistantConversationInspectorStateDataModel(data={"content": "No current document."})
125125

126+
is_readonly = await self._controller.is_read_only(context)
127+
126128
return AssistantConversationInspectorStateDataModel(
127-
data=document.model_dump(mode="json"),
128-
json_schema=document.model_json_schema(),
129-
ui_schema=_get_document_editor_ui_schema(
130-
await self._controller.is_read_only(context),
131-
await self._controller.list_documents(context),
132-
),
129+
data={
130+
"markdown_content": document.content,
131+
"filename": document.filename,
132+
"readonly": is_readonly,
133+
}
133134
)
134135

135136
async def set(
@@ -142,13 +143,18 @@ async def set(
142143
if await self._controller.is_read_only(context):
143144
return
144145

145-
try:
146-
model = DocumentFileStateModel.model_validate(data)
147-
except ValidationError:
148-
logger.exception("invalid data for DocumentFileStateModel")
149-
return
150-
151-
await self._controller.write_active_document(context, model.content)
146+
# The data comes in with 'markdown_content' but our model expects 'content'
147+
if "markdown_content" in data:
148+
content = data["markdown_content"]
149+
# If filename is present but we don't need to modify it, we can just get the content
150+
await self._controller.write_active_document(context, content)
151+
else:
152+
try:
153+
model = DocumentFileStateModel.model_validate(data)
154+
await self._controller.write_active_document(context, model.content)
155+
except ValidationError:
156+
logger.exception("invalid data for DocumentFileStateModel")
157+
return
152158

153159

154160
class ReadonlyDocumentFileStateInspector:
@@ -189,7 +195,11 @@ async def get(self, context: ConversationContext) -> AssistantConversationInspec
189195
return AssistantConversationInspectorStateDataModel(data={"content": "No current document."})
190196

191197
return AssistantConversationInspectorStateDataModel(
192-
data={"content": f"```markdown\n_Filename: {document.filename}_\n\n{document.content}\n```"}
198+
data={
199+
"markdown_content": document.content,
200+
"filename": document.filename,
201+
"readonly": True, # Always read-only for this inspector
202+
},
193203
)
194204

195205

workbench-app/.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
"levelname",
186186
"levelno",
187187
"listbox",
188+
"Milkdown",
188189
"msal",
189190
"multimodel",
190191
"nonchat",

workbench-app/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
"@lexical/utils": "^0.17.1",
3939
"@microsoft/fetch-event-source": "^2.0.1",
4040
"@microsoft/microsoft-graph-client": "^3.0.7",
41+
"@milkdown/crepe": "^7.7.0",
42+
"@milkdown/kit": "^7.7.0",
43+
"@milkdown/react": "^7.7.0",
44+
"@milkdown/theme-nord": "^7.7.0",
4145
"@reduxjs/toolkit": "^1.9.7",
4246
"@rjsf/core": "^5.21.1",
4347
"@rjsf/fluentui-rc": "^5.21.1",

0 commit comments

Comments
 (0)