sbuilder-mcp 0.105.0 → 0.106.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/CHANGELOG.vi.md +13 -0
- package/dist/tools/chrome.js +192 -13
- package/dist/tools/project.js +1 -1
- package/dist/tools/store.js +31 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,19 @@ All notable changes to this project are documented in this file.
|
|
|
6
6
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
7
7
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
8
8
|
|
|
9
|
+
## [0.106.0] - 2026-11-18
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- `sb_store` `site_template` offers the whole site as its organization's template with a `name`, `description` and gallery `categories`, attaching the site to `org_id` first when it has no organization.
|
|
13
|
+
- `sb_store` `site_template` refuses categories for an organization other than the platform organization before writing anything, and refuses `dry_run: false` without a `name`.
|
|
14
|
+
- `sb_store` `site_template_remove` withdraws a site that was offered as a template.
|
|
15
|
+
- `sb_store` `template_share` sends a saved section template to the organization's review.
|
|
16
|
+
- `sb_store` `template_save` accepts `description` and `categories` (slugs or ids), and its dry run returns `categories_available` with a prompt to name, describe and file the template under one or two categories.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- `sb_store` `template_save` with `template_id` now updates the template's name, description and categories as well as its content, and reports that the content was saved when only the metadata update fails.
|
|
20
|
+
- `sb_templates` lists `share` and `shareNote` for each template.
|
|
21
|
+
|
|
9
22
|
## [0.105.0] - 2026-11-13
|
|
10
23
|
|
|
11
24
|
### Added
|
package/CHANGELOG.vi.md
CHANGED
|
@@ -6,6 +6,19 @@ Mọi thay đổi đáng chú ý của dự án được ghi lại trong file n
|
|
|
6
6
|
Định dạng dựa trên [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
7
7
|
và dự án tuân theo [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
8
8
|
|
|
9
|
+
## [0.106.0] - 2026-11-18
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- `sb_store` `site_template` đưa cả site làm mẫu của tổ chức với `name`, `description` và `categories` của thư viện, và gắn site vào `org_id` trước khi đánh dấu nếu site chưa thuộc tổ chức nào.
|
|
13
|
+
- `sb_store` `site_template` từ chối danh mục với tổ chức không phải tổ chức nền tảng trước khi ghi gì, và từ chối `dry_run: false` khi thiếu `name`.
|
|
14
|
+
- `sb_store` `site_template_remove` gỡ site đã được đưa làm mẫu.
|
|
15
|
+
- `sb_store` `template_share` gửi section template đã lưu lên hàng duyệt của tổ chức.
|
|
16
|
+
- `sb_store` `template_save` nhận `description` và `categories` (slug hoặc id), và bản chạy thử trả về `categories_available` kèm lời dặn đặt tên, mô tả và xếp mẫu vào một hoặc hai danh mục.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- `sb_store` `template_save` với `template_id` nay cập nhật cả tên, mô tả và danh mục chứ không chỉ nội dung, và báo rõ nội dung đã được lưu khi chỉ phần cập nhật metadata bị lỗi.
|
|
20
|
+
- `sb_templates` hiện `share` và `shareNote` cho từng mẫu.
|
|
21
|
+
|
|
9
22
|
## [0.105.0] - 2026-11-13
|
|
10
23
|
|
|
11
24
|
### Added
|
package/dist/tools/chrome.js
CHANGED
|
@@ -761,20 +761,72 @@ export async function promoteGlobal(ctx, session, siteId, nodeId, kind, name, op
|
|
|
761
761
|
`${gid}" — an edit inside it now lands on every page carrying it.`,
|
|
762
762
|
};
|
|
763
763
|
}
|
|
764
|
+
/** The section-template category catalogue (enabled, named for `language`). */
|
|
765
|
+
async function sectionCategories(ctx, base, language) {
|
|
766
|
+
const got = (await request({
|
|
767
|
+
base: ctx.base,
|
|
768
|
+
method: 'GET',
|
|
769
|
+
path: `${base}/categories?locale=${encodeURIComponent(language)}`,
|
|
770
|
+
token: siteToken(ctx),
|
|
771
|
+
fetchImpl: ctx.fetchImpl,
|
|
772
|
+
}));
|
|
773
|
+
return got.categories ?? [];
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Resolve what the agent wrote — an id OR a slug — to catalogue entries. An
|
|
777
|
+
* unknown one is refused with the whole list, never dropped: a template filed
|
|
778
|
+
* under nothing is one an operator has to file by hand, the chore this exists
|
|
779
|
+
* to remove.
|
|
780
|
+
*/
|
|
781
|
+
function pickCategories(cats, wanted, what) {
|
|
782
|
+
return wanted.map((w) => {
|
|
783
|
+
const hit = cats.find((c) => c.id === w || c.slug === w);
|
|
784
|
+
if (!hit) {
|
|
785
|
+
const list = cats.map((c) => `${c.slug} (${c.name ?? c.slug})`).join(', ') || 'none — the catalogue is empty';
|
|
786
|
+
throw new Error(`sbuilder: no ${what} category "${w}". Choose from: ${list}.`);
|
|
787
|
+
}
|
|
788
|
+
return hit;
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
const catalogue = (cats) => cats.map((c) => ({ slug: c.slug, name: c.name ?? c.slug }));
|
|
764
792
|
/**
|
|
765
793
|
* Save a section on the OPEN page as a reusable section template — the editor's
|
|
766
794
|
* "Save as template". The page is untouched; `sb_template_use` places a copy.
|
|
767
795
|
*
|
|
796
|
+
* `description` and `categories` (slugs or ids from the dry run's catalogue)
|
|
797
|
+
* travel with it, so on a site of the PLATFORM organization the operator's only
|
|
798
|
+
* act in admin → Section templates is turning Listed on.
|
|
799
|
+
*
|
|
768
800
|
* With `templateId` it REWRITES that template's content instead — the editor's
|
|
769
801
|
* template edit mode. The agent's way in is the full toolset: place the template
|
|
770
802
|
* on a page with sb_template_use, edit it there, save it back over the template.
|
|
771
803
|
* The PUT is fenced on the template's `rev`, read from the list (there is no
|
|
772
804
|
* single-template GET), so an edit somebody else saved in between is refused.
|
|
805
|
+
* Name/description/categories given alongside are PATCHed after it.
|
|
773
806
|
*/
|
|
774
807
|
export async function saveTemplate(ctx, session, siteId, nodeId, name, opts) {
|
|
775
808
|
const doc = session.current();
|
|
776
809
|
const id = liftable(doc.doc, nodeId, 'template_save');
|
|
777
810
|
const base = `/api/sites/${encodeURIComponent(siteId)}/section-templates`;
|
|
811
|
+
// Read only when it is used: a plain save must not start failing because the
|
|
812
|
+
// catalogue read does.
|
|
813
|
+
const cats = opts.dryRun || opts.categories?.length ? await sectionCategories(ctx, base, opts.language ?? 'vi') : [];
|
|
814
|
+
const chosen = opts.categories?.length
|
|
815
|
+
? [...new Map(pickCategories(cats, opts.categories, 'section-template').map((c) => [c.slug, c])).values()]
|
|
816
|
+
: undefined;
|
|
817
|
+
const categoryIds = chosen?.map((c) => c.id).filter((x) => !!x);
|
|
818
|
+
const description = opts.description?.trim();
|
|
819
|
+
const document = sectionDocument(doc.doc, id);
|
|
820
|
+
const nodes = Object.keys(document.nodes).length;
|
|
821
|
+
// The dry run is where the agent CHOOSES: it gets the catalogue and the brief.
|
|
822
|
+
const choose = {
|
|
823
|
+
categories_available: catalogue(cats),
|
|
824
|
+
...(chosen ? { categories: chosen.map((c) => c.slug) } : {}),
|
|
825
|
+
...(chosen && description ? {} : {
|
|
826
|
+
write: 'Before saving, name it for what the section IS ("Hero ảnh lớn + 2 nút", not "Section 3"), write a ' +
|
|
827
|
+
'one-sentence description of what it is for, and pick 1–2 categories from categories_available that fit.',
|
|
828
|
+
}),
|
|
829
|
+
};
|
|
778
830
|
if (opts.templateId) {
|
|
779
831
|
const list = (await request({ base: ctx.base, method: 'GET', path: base, token: siteToken(ctx), fetchImpl: ctx.fetchImpl }));
|
|
780
832
|
const t = (list.sectionTemplates ?? []).find((x) => x.id === opts.templateId);
|
|
@@ -783,42 +835,169 @@ export async function saveTemplate(ctx, session, siteId, nodeId, name, opts) {
|
|
|
783
835
|
if (t.source && t.source !== 'site') {
|
|
784
836
|
throw new Error(`sbuilder: template "${opts.templateId}" is a ${t.source} template, not this site's own — save a new one instead.`);
|
|
785
837
|
}
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
|
|
838
|
+
const patch = {
|
|
839
|
+
...(name?.trim() ? { name: name.trim() } : {}),
|
|
840
|
+
...(description ? { description } : {}),
|
|
841
|
+
...(categoryIds ? { categoryIds } : {}),
|
|
842
|
+
};
|
|
789
843
|
if (opts.dryRun) {
|
|
790
|
-
return { dry_run: true, nodes, next: `Nothing was sent. Re-call with dry_run:false to replace "${t.name ?? opts.templateId}"'s content.` };
|
|
844
|
+
return { dry_run: true, nodes, ...(Object.keys(patch).length ? { would_patch: patch } : {}), ...choose, next: `Nothing was sent. Re-call with dry_run:false to replace "${t.name ?? opts.templateId}"'s content.` };
|
|
845
|
+
}
|
|
846
|
+
await request({ base: ctx.base, method: 'PUT', path: `${base}/${encodeURIComponent(opts.templateId)}/document`, token: siteToken(ctx), body: { document, rev: t.rev ?? 0 }, fetchImpl: ctx.fetchImpl });
|
|
847
|
+
// The content is saved now; a metadata failure must say so, or the agent
|
|
848
|
+
// retries the whole rewrite against a rev that has already moved.
|
|
849
|
+
let metaError;
|
|
850
|
+
if (Object.keys(patch).length) {
|
|
851
|
+
try {
|
|
852
|
+
await request({ base: ctx.base, method: 'PATCH', path: `${base}/${encodeURIComponent(opts.templateId)}`, token: siteToken(ctx), body: patch, fetchImpl: ctx.fetchImpl });
|
|
853
|
+
}
|
|
854
|
+
catch (e) {
|
|
855
|
+
metaError = e.message;
|
|
856
|
+
}
|
|
791
857
|
}
|
|
792
|
-
await request({ base: ctx.base, method: 'PUT', path, token: siteToken(ctx), body: { document, rev: t.rev ?? 0 }, fetchImpl: ctx.fetchImpl });
|
|
793
858
|
return {
|
|
794
|
-
template: { id: opts.templateId, name: t.name ?? '' },
|
|
859
|
+
template: { id: opts.templateId, name: metaError ? (t.name ?? '') : (patch.name ?? t.name ?? '') },
|
|
795
860
|
nodes,
|
|
861
|
+
...(metaError
|
|
862
|
+
? { warning: `the CONTENT was saved, but name/description/categories were not: ${metaError}. Re-run with only those fields and no node change.` }
|
|
863
|
+
: chosen ? { categories: chosen.map((c) => c.slug) } : {}),
|
|
796
864
|
next: 'Pages that placed this template earlier keep their own copy; only new placements get this content. ' +
|
|
797
|
-
'A template shared with the organization goes back to review after a content change.'
|
|
798
|
-
(name?.trim() ? ' `name` was not applied — a rewrite changes content only.' : ''),
|
|
865
|
+
'A template shared with the organization goes back to review after a content change.',
|
|
799
866
|
};
|
|
800
867
|
}
|
|
801
868
|
if (!name?.trim())
|
|
802
869
|
throw new Error('sbuilder: action:"template_save" needs name — the template\'s name in the library.');
|
|
803
|
-
const document = sectionDocument(doc.doc, id);
|
|
804
|
-
const nodes = Object.keys(document.nodes).length;
|
|
805
870
|
if (opts.dryRun) {
|
|
806
|
-
return { dry_run: true, nodes, next: 'Nothing was sent. Re-call with dry_run:false to save it.' };
|
|
871
|
+
return { dry_run: true, nodes, would_save: { name: name.trim(), ...(description ? { description } : {}) }, ...choose, next: 'Nothing was sent. Re-call with dry_run:false to save it.' };
|
|
807
872
|
}
|
|
808
873
|
const made = (await request({
|
|
809
874
|
base: ctx.base,
|
|
810
875
|
method: 'POST',
|
|
811
876
|
path: base,
|
|
812
877
|
token: siteToken(ctx),
|
|
813
|
-
body: { name: name.trim(), document },
|
|
878
|
+
body: { name: name.trim(), ...(description ? { description } : {}), document, ...(categoryIds ? { categoryIds } : {}) },
|
|
814
879
|
fetchImpl: ctx.fetchImpl,
|
|
815
880
|
}));
|
|
816
881
|
const tid = made.sectionTemplate?.id;
|
|
817
882
|
if (typeof tid !== 'string' || !tid)
|
|
818
883
|
throw new Error('sbuilder: the platform created no section template.');
|
|
884
|
+
// The create answers what IS filed (a filing failure does not fail it), so a
|
|
885
|
+
// shortfall is read off the answer rather than assumed from the request.
|
|
886
|
+
const filed = made.sectionTemplate?.categoryIds ?? [];
|
|
887
|
+
const missed = categoryIds && filed.length < categoryIds.length;
|
|
819
888
|
return {
|
|
820
889
|
template: { id: tid, name: name.trim() },
|
|
821
890
|
nodes,
|
|
822
|
-
|
|
891
|
+
...(chosen ? { categories: chosen.filter((c) => c.id && filed.includes(c.id)).map((c) => c.slug) } : {}),
|
|
892
|
+
...(missed ? { warning: 'the template was saved but its categories were NOT filed — re-run with template_id and categories to file them.' } : {}),
|
|
893
|
+
next: 'Place a copy with sb_template_use; sb_templates lists it. On a site of the platform organization it now ' +
|
|
894
|
+
'waits in admin → Section templates, where an operator turns Listed on.',
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Offer the WHOLE SITE as its organization's starting template — every page it
|
|
899
|
+
* has comes along when someone starts from it. With `orgId` the site is first
|
|
900
|
+
* attached to that organization (owner only). `categories` are platform gallery
|
|
901
|
+
* slugs (the dry run lists them), filed with the mark, so an operator's only act
|
|
902
|
+
* in admin → Templates is the listing switch. The server refuses categories for
|
|
903
|
+
* a site outside the platform organization rather than filing them into nothing.
|
|
904
|
+
*/
|
|
905
|
+
export async function markSiteTemplate(ctx, siteId, name, opts) {
|
|
906
|
+
const sitePath = `/api/sites/${encodeURIComponent(siteId)}`;
|
|
907
|
+
const get = async (path) => (await request({ base: ctx.base, method: 'GET', path, token: siteToken(ctx), fetchImpl: ctx.fetchImpl }));
|
|
908
|
+
const { site } = await get(sitePath);
|
|
909
|
+
const description = opts.description?.trim();
|
|
910
|
+
const orgId = site?.orgId || undefined;
|
|
911
|
+
if (opts.orgId && orgId && orgId !== opts.orgId) {
|
|
912
|
+
throw new Error(`sbuilder: this site already belongs to organization ${orgId}; detach it in the dashboard before offering it to ${opts.orgId}.`);
|
|
913
|
+
}
|
|
914
|
+
const attach = opts.orgId && !orgId ? opts.orgId : undefined;
|
|
915
|
+
if (!orgId && !attach) {
|
|
916
|
+
throw new Error('sbuilder: this site belongs to no organization, and a template is an organization\'s — pass org_id (the platform organization\'s, for the public gallery).');
|
|
917
|
+
}
|
|
918
|
+
const org = (attach ?? orgId);
|
|
919
|
+
const listed = await get(`/api/templates/categories?locale=${encodeURIComponent(opts.language ?? 'vi')}&orgId=${encodeURIComponent(org)}`);
|
|
920
|
+
const cats = listed.categories ?? [];
|
|
921
|
+
// Only the platform org's templates reach the gallery; refusing HERE keeps a
|
|
922
|
+
// mark from landing with a filing the server would then reject.
|
|
923
|
+
if (opts.categories?.length && !listed.fileable) {
|
|
924
|
+
throw new Error(`sbuilder: organization ${org} is not the platform organization, so its templates have no gallery categories — drop categories (its members see the template on their own shelf).`);
|
|
925
|
+
}
|
|
926
|
+
const chosen = opts.categories?.length
|
|
927
|
+
? [...new Map(pickCategories(cats, opts.categories, 'template').map((c) => [c.slug, c])).values()]
|
|
928
|
+
: undefined;
|
|
929
|
+
const pages = await get(`${sitePath}/pages`).catch(() => ({ pages: undefined }));
|
|
930
|
+
const state = {
|
|
931
|
+
site: site?.name,
|
|
932
|
+
organization: attach ?? orgId,
|
|
933
|
+
pages: pages.pages?.map((p) => p.name ?? p.slug),
|
|
934
|
+
...(site?.isTemplate ? { already_template: { name: site.templateName, description: site.templateDescription } } : {}),
|
|
823
935
|
};
|
|
936
|
+
if (!opts.dryRun && !name?.trim()) {
|
|
937
|
+
throw new Error('sbuilder: action:"site_template" needs name — run it as a dry run first to read the pages and the categories, then name it.');
|
|
938
|
+
}
|
|
939
|
+
if (opts.dryRun) {
|
|
940
|
+
return {
|
|
941
|
+
...(opts.dryRun ? { dry_run: true } : {}),
|
|
942
|
+
...state,
|
|
943
|
+
...(attach ? { would_attach_to: attach } : {}),
|
|
944
|
+
would_mark: { name: name?.trim(), description, categories: chosen?.map((c) => c.slug) },
|
|
945
|
+
...(listed.fileable
|
|
946
|
+
? { categories_available: catalogue(cats) }
|
|
947
|
+
: { categories_available: [], note: 'not the platform organization — no gallery categories; the template goes on its members\' shelf' }),
|
|
948
|
+
write: 'Name the template for the business it starts ("Shop thời trang nữ", not "Template 1"), write ONE sentence ' +
|
|
949
|
+
'on who it is for and what it comes with (read `pages`), and pick 1–2 categories from categories_available. ' +
|
|
950
|
+
'Then re-call with dry_run:false.',
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
if (attach) {
|
|
954
|
+
await request({ base: ctx.base, method: 'PUT', path: `${sitePath}/org`, token: siteToken(ctx), body: { orgId: attach }, fetchImpl: ctx.fetchImpl });
|
|
955
|
+
}
|
|
956
|
+
try {
|
|
957
|
+
await request({
|
|
958
|
+
base: ctx.base,
|
|
959
|
+
method: 'POST',
|
|
960
|
+
path: `${sitePath}/template`,
|
|
961
|
+
token: siteToken(ctx),
|
|
962
|
+
body: { name: name.trim(), ...(description ? { description } : {}), ...(chosen ? { categories: chosen.map((c) => c.slug) } : {}) },
|
|
963
|
+
fetchImpl: ctx.fetchImpl,
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
catch (e) {
|
|
967
|
+
// Say what already happened: the attach (if any) stands, and a refused
|
|
968
|
+
// filing means the mark itself landed.
|
|
969
|
+
const msg = e.message;
|
|
970
|
+
const done = [attach ? `the site WAS attached to ${attach}` : '', /categories_not_filed|marked as a template/.test(msg) ? 'it IS marked as a template' : '']
|
|
971
|
+
.filter(Boolean)
|
|
972
|
+
.join('; ');
|
|
973
|
+
throw new Error(done ? `${msg} (${done} — re-run site_template to retry the rest)` : msg);
|
|
974
|
+
}
|
|
975
|
+
return {
|
|
976
|
+
template: { site_id: siteId, name: name.trim(), ...(description ? { description } : {}), ...(chosen ? { categories: chosen.map((c) => c.slug) } : {}) },
|
|
977
|
+
...(attach ? { attached_to: attach } : {}),
|
|
978
|
+
next: 'Publish every page first — the gallery card shows the published storefront. On the platform organization an ' +
|
|
979
|
+
'operator now turns it on in admin → Templates (one switch); in any other organization it is on its members\' shelf already.',
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
/** Withdraw the site from its organization's templates (gallery listing goes with it). */
|
|
983
|
+
export async function unmarkSiteTemplate(ctx, siteId, dryRun) {
|
|
984
|
+
const path = `/api/sites/${encodeURIComponent(siteId)}/template`;
|
|
985
|
+
if (dryRun)
|
|
986
|
+
return { dry_run: true, would_delete: path, next: 'Sites already started from it keep their copy. Re-call with dry_run:false.' };
|
|
987
|
+
await request({ base: ctx.base, method: 'DELETE', path, token: siteToken(ctx), fetchImpl: ctx.fetchImpl });
|
|
988
|
+
return { withdrawn: siteId, next: 'It is off the organization\'s shelf and the gallery; site_template marks it again.' };
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Offer one of this site's section templates to its ORGANIZATION's shelf — the
|
|
992
|
+
* review queue a reviewer approves from. (The platform org's own templates need
|
|
993
|
+
* no review: an operator lists them in admin.)
|
|
994
|
+
*/
|
|
995
|
+
export async function shareTemplate(ctx, siteId, templateId, dryRun) {
|
|
996
|
+
if (!templateId)
|
|
997
|
+
throw new Error('sbuilder: action:"template_share" needs template_id — sb_templates lists them.');
|
|
998
|
+
const path = `/api/sites/${encodeURIComponent(siteId)}/section-templates/${encodeURIComponent(templateId)}/share`;
|
|
999
|
+
if (dryRun)
|
|
1000
|
+
return { dry_run: true, would_post: path, next: 'Re-call with dry_run:false to send it for review.' };
|
|
1001
|
+
const got = (await request({ base: ctx.base, method: 'POST', path, token: siteToken(ctx), fetchImpl: ctx.fetchImpl }));
|
|
1002
|
+
return { shared: templateId, share: got.sectionTemplate?.share ?? 'pending', next: 'A reviewer of the organization approves or rejects it; sb_templates shows its state.' };
|
|
824
1003
|
}
|
package/dist/tools/project.js
CHANGED
|
@@ -14,7 +14,7 @@ export const PAGE_FIELDS = [
|
|
|
14
14
|
'id', 'name', 'slug', 'path', 'isHomepage', 'type', 'status', 'updatedAt', 'publishedAt',
|
|
15
15
|
];
|
|
16
16
|
export const TEMPLATE_FIELDS = [
|
|
17
|
-
'id', 'name', 'description', 'categoryIds', 'source', 'listed', 'updatedAt',
|
|
17
|
+
'id', 'name', 'description', 'categoryIds', 'source', 'listed', 'share', 'shareNote', 'updatedAt',
|
|
18
18
|
];
|
|
19
19
|
export const MEDIA_FIELDS = [
|
|
20
20
|
'id', 'name', 'url', 'mediaType', 'contentType', 'sizeBytes', 'width', 'height', 'folderId', 'state',
|
package/dist/tools/store.js
CHANGED
|
@@ -44,7 +44,7 @@ import { siteFor } from './context.js';
|
|
|
44
44
|
import { withFreshIds } from '../domains/site/ids.js';
|
|
45
45
|
import { addPlaced, saveRefusal, siteChrome, wearChrome } from './page.js';
|
|
46
46
|
import { addSubtree } from '../domains/site/builder.js';
|
|
47
|
-
import { attachGlobal, buildChrome, detachGlobal, promoteGlobal, saveTemplate } from './chrome.js';
|
|
47
|
+
import { attachGlobal, buildChrome, detachGlobal, markSiteTemplate, promoteGlobal, saveTemplate, shareTemplate, unmarkSiteTemplate, } from './chrome.js';
|
|
48
48
|
import { bindMenu } from './menu.js';
|
|
49
49
|
import { attachOverlay, ensureCartDrawer, relocalizeCartDrawer } from './overlay.js';
|
|
50
50
|
import { installApp } from './app.js';
|
|
@@ -568,7 +568,9 @@ export function registerStoreTools(server, ctx, session) {
|
|
|
568
568
|
'wrongly build a second one. action:"global_promote" turns a section on the open page ' +
|
|
569
569
|
'(node_id) into a NEW shared section (global_kind header|footer|custom, default custom) and ' +
|
|
570
570
|
'leaves the page referencing it; action:"template_save" saves one as a section template ' +
|
|
571
|
-
'(name).
|
|
571
|
+
'(name; template_share sends one to the org\'s review). site_template offers the whole site as its org\'s ' +
|
|
572
|
+
'template (org_id attaches first; site_template_remove withdraws). ' +
|
|
573
|
+
'Dry run returns the plan.',
|
|
572
574
|
inputSchema: {
|
|
573
575
|
action: z.enum([
|
|
574
576
|
'checkout',
|
|
@@ -583,6 +585,9 @@ export function registerStoreTools(server, ctx, session) {
|
|
|
583
585
|
'global_detach',
|
|
584
586
|
'global_promote',
|
|
585
587
|
'template_save',
|
|
588
|
+
'site_template',
|
|
589
|
+
'site_template_remove',
|
|
590
|
+
'template_share',
|
|
586
591
|
]),
|
|
587
592
|
site_id: z.string().optional(),
|
|
588
593
|
language: z.enum(['vi', 'en']).optional().describe('Copy language, default vi'),
|
|
@@ -611,6 +616,15 @@ export function registerStoreTools(server, ctx, session) {
|
|
|
611
616
|
.describe('action:"menu" — the menu node; "global_promote"/"template_save" — the section; "form" — a node of the open page to place it in'),
|
|
612
617
|
global_kind: z.enum(['header', 'footer', 'custom']).optional(),
|
|
613
618
|
template_id: z.string().optional().describe('action:"template_save" — overwrite this template\'s content'),
|
|
619
|
+
description: z
|
|
620
|
+
.string()
|
|
621
|
+
.optional()
|
|
622
|
+
.describe('template_save/site_template: one sentence, what it is for'),
|
|
623
|
+
categories: z
|
|
624
|
+
.array(z.string())
|
|
625
|
+
.optional()
|
|
626
|
+
.describe('template_save/site_template: slugs from the dry run'),
|
|
627
|
+
org_id: z.string().optional(),
|
|
614
628
|
menu_id: z.string().optional(),
|
|
615
629
|
kind: z
|
|
616
630
|
.enum(['popup', 'quickview'])
|
|
@@ -642,7 +656,7 @@ export function registerStoreTools(server, ctx, session) {
|
|
|
642
656
|
dry_run: z.boolean().optional(),
|
|
643
657
|
},
|
|
644
658
|
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
|
|
645
|
-
}, async ({ action, site_id: given, language, page_name, headline, template, name, footer, node_id, menu_id, kind, overlay_id, list_id, app_key, global_id, global_kind, template_id, relocalize, settings, dry_run, }) => {
|
|
659
|
+
}, async ({ action, site_id: given, language, page_name, headline, template, name, footer, node_id, menu_id, kind, overlay_id, list_id, app_key, global_id, global_kind, template_id, description, categories, org_id, relocalize, settings, dry_run, }) => {
|
|
646
660
|
const siteId = siteFor(ctx, given);
|
|
647
661
|
if (action === 'global_attach' || action === 'global_detach') {
|
|
648
662
|
// THE COMPOSED STAMP IS NEVER THE CALLER'S TO WRITE. A page references
|
|
@@ -659,7 +673,20 @@ export function registerStoreTools(server, ctx, session) {
|
|
|
659
673
|
return text(await promoteGlobal(ctx, session, siteId, node_id, global_kind ?? 'custom', name, { dryRun: dry_run !== false }));
|
|
660
674
|
}
|
|
661
675
|
if (action === 'template_save') {
|
|
662
|
-
return text(await saveTemplate(ctx, session, siteId, node_id, name, {
|
|
676
|
+
return text(await saveTemplate(ctx, session, siteId, node_id, name, {
|
|
677
|
+
dryRun: dry_run !== false,
|
|
678
|
+
templateId: template_id,
|
|
679
|
+
description,
|
|
680
|
+
categories,
|
|
681
|
+
language,
|
|
682
|
+
}));
|
|
683
|
+
}
|
|
684
|
+
if (action === 'site_template_remove')
|
|
685
|
+
return text(await unmarkSiteTemplate(ctx, siteId, dry_run !== false));
|
|
686
|
+
if (action === 'template_share')
|
|
687
|
+
return text(await shareTemplate(ctx, siteId, template_id, dry_run !== false));
|
|
688
|
+
if (action === 'site_template') {
|
|
689
|
+
return text(await markSiteTemplate(ctx, siteId, name, { dryRun: dry_run !== false, description, categories, orgId: org_id, language }));
|
|
663
690
|
}
|
|
664
691
|
if (action === 'app') {
|
|
665
692
|
if (!app_key) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sbuilder-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.106.0",
|
|
4
4
|
"description": "MCP server that designs and operates a Store Builder site — pages, data, theme and publish — through the platform's own API and live-edit protocol.",
|
|
5
5
|
"mcpName": "io.github.vuluu2k/sbuilder-mcp",
|
|
6
6
|
"type": "module",
|