feat: allow using chat to modify page titles

This commit is contained in:
LIlGG
2025-10-11 16:36:20 +08:00
parent a672fcad1c
commit 7acc4949fb
8 changed files with 88 additions and 23 deletions

View File

@@ -96,7 +96,7 @@ export class ChatStore {
});
}
addArtifact({ messageId, name, title, id }: ArtifactCallbackData) {
async addArtifact({ messageId, name, title, id }: ArtifactCallbackData) {
const artifact = this.getArtifact(messageId, name);
if (artifact) {
return;
@@ -129,6 +129,8 @@ export class ChatStore {
artifactsByPageName.set(name, newArtifact);
this.artifacts.set(artifactsByMessageId);
const bridge = await editorBridge;
bridge.updatePageAttributes(name, { title });
}
updateArtifact({ messageId, name }: ArtifactCallbackData, state: Partial<ArtifactUpdateState>) {

View File

@@ -299,6 +299,11 @@ export class PagesStore {
switch (type) {
case 'add_page': {
const { title: pageTitle, actionIds = [] } = payload;
const oldPage = this.pages.get()[pageName];
if (oldPage) {
throw new Error(`Page ${pageName} already exists`);
}
this.pages.setKey(pageName, {
name: pageName,
title: pageTitle,
@@ -312,10 +317,12 @@ export class PagesStore {
}
case 'upsert_page': {
const { title: pageTitle, actionIds = [] } = payload;
const oldPage = this.pages.get()[pageName];
this.pages.setKey(pageName, {
name: pageName,
title: pageTitle,
actionIds,
actionIds: actionIds || oldPage?.actionIds,
content: oldPage?.content,
});
break;
}