Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions docs/src/loaders/skills-loader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Loader } from "astro/loaders";
import { readdir, readFile } from "node:fs/promises";
import { join } from "node:path";
import { basename, join, relative, resolve, sep } from "node:path";

const SKILLS_DIR = join(new URL(".", import.meta.url).pathname, "../../../use-crystallize/skills");

Expand Down Expand Up @@ -40,6 +40,31 @@ function parseFrontmatter(content: string) {
};
}

function referenceAnchor(file: string) {
return `ref-${file.replace(/\.md$/, "")}`;
}

// A skill page inlines SKILL.md and every references/*.md into one document, so the
// relative .md links between those files (`references/x.md`, `../SKILL.md#y`,
// `../mutation/SKILL.md`) resolve to URLs that were never built. Point each link that
// lands on a skill file at where that file ended up: a reference is the anchor above
// its section, a SKILL.md is the top of its skill page.
function rewriteSkillLinks(markdown: string, fromDir: string, currentSkill: string): string {
return markdown.replace(/\]\(([^)\s#]+\.md)(#[^)\s]*)?\)/g, (link, path: string, hash = "") => {
if (/^([a-z]+:|\/)/i.test(path)) return link;

const [skill, ...rest] = relative(SKILLS_DIR, resolve(fromDir, path)).split(sep);
const page = skill === currentSkill ? "" : `/ai/skills/${skill}/`;
if (rest.length === 1 && rest[0] === "SKILL.md") {
return `](${page}${hash || (page ? "" : "#_top")})`;
}
if (rest.length === 2 && rest[0] === "references") {
return `](${page}${hash || `#${referenceAnchor(rest[1])}`})`;
}
return link;
});
}

async function readReferences(skillDir: string): Promise<string> {
const refsDir = join(skillDir, "references");
try {
Expand All @@ -49,7 +74,8 @@ async function readReferences(skillDir: string): Promise<string> {
if (!file.endsWith(".md")) continue;
const content = await readFile(join(refsDir, file), "utf-8");
const { body } = parseFrontmatter(content);
parts.push(body.trim());
const linked = rewriteSkillLinks(body.trim(), refsDir, basename(skillDir));
parts.push(`<div id="${referenceAnchor(file)}"></div>\n\n${linked}`);
}
if (parts.length > 0) {
return "\n\n---\n\n## Reference Details\n\n" + parts.join("\n\n");
Expand Down Expand Up @@ -86,7 +112,7 @@ export function skillsLoader(): Loader {

const { name, description, body } = parseFrontmatter(content);
const references = await readReferences(join(SKILLS_DIR, dir));
const fullBody = body.trim() + references;
const fullBody = rewriteSkillLinks(body.trim(), join(SKILLS_DIR, dir), dir) + references;
const rendered = await renderMarkdown(fullBody);

store.set({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
"skills": ["payments"],
"expected": ["payments/vipps-mobilepay", "payments/stripe"]
},
{
"task": "accept iDEAL and Bancontact through Mollie in our Crystallize checkout",
"skills": ["payments"],
"expected": ["payments/mollie"]
},
{
"task": "let business customers pay by invoice with Two, including a company lookup at checkout",
"skills": ["payments"],
"expected": ["payments/two"]
},
{
"task": "create a product shape through the API with a paragraph collection and a grid relation",
"skills": ["content-model"],
Expand Down
155 changes: 125 additions & 30 deletions use-crystallize/skills/js-api-client/SKILL.md

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions use-crystallize/skills/mutation/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,17 @@ const api = createClient({
accessTokenSecret: "...",
});

// Use pimApi for Core API mutations
const result = await api.pimApi(mutationString, variables);
// Core API mutations (api.crystallize.com/@tenant)
const result = await api.nextPimApi(mutationString, variables);

// Shop API mutations: one caller per endpoint, the Shop API token is fetched for you
await api.shopCartApi(cartMutation, variables); // /cart
await api.shopOrderApi(orderMutation, variables); // /order (js-api-client 7.5+)
```

For checkout, prefer the helpers: `createCartManager` (`hydrate`, `place`) and `createShopOrderManager`
(`createFromCart`, `addPayments`, `setPayments`, `addToStage`).

## Output Format

When generating mutations for the user, produce:
Expand Down
764 changes: 572 additions & 192 deletions use-crystallize/skills/payments/SKILL.md

Large diffs are not rendered by default.

663 changes: 454 additions & 209 deletions use-crystallize/skills/payments/references/adyen.md

Large diffs are not rendered by default.

498 changes: 319 additions & 179 deletions use-crystallize/skills/payments/references/dintero.md

Large diffs are not rendered by default.

736 changes: 534 additions & 202 deletions use-crystallize/skills/payments/references/klarna.md

Large diffs are not rendered by default.

489 changes: 489 additions & 0 deletions use-crystallize/skills/payments/references/mollie.md

Large diffs are not rendered by default.

530 changes: 334 additions & 196 deletions use-crystallize/skills/payments/references/montonio.md

Large diffs are not rendered by default.

673 changes: 453 additions & 220 deletions use-crystallize/skills/payments/references/qliro.md

Large diffs are not rendered by default.

506 changes: 306 additions & 200 deletions use-crystallize/skills/payments/references/quickpay.md

Large diffs are not rendered by default.

550 changes: 349 additions & 201 deletions use-crystallize/skills/payments/references/razorpay.md

Large diffs are not rendered by default.

517 changes: 325 additions & 192 deletions use-crystallize/skills/payments/references/stripe.md

Large diffs are not rendered by default.

469 changes: 469 additions & 0 deletions use-crystallize/skills/payments/references/two.md

Large diffs are not rendered by default.

621 changes: 376 additions & 245 deletions use-crystallize/skills/payments/references/vipps-mobilepay.md

Large diffs are not rendered by default.

Loading