@cloudcart/storefront-mcp 0.0.0-stage → 0.2.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.
@@ -0,0 +1,380 @@
1
+ /**
2
+ * What an assistant needs to know before writing against the Storefront API.
3
+ *
4
+ * Not a feature list — the schema carries one, and every type and field in it is
5
+ * documented. This is the set of things a competent developer gets wrong on the
6
+ * first attempt, because they follow from how the platform works rather than
7
+ * from how the schema looks.
8
+ *
9
+ * Organised by what you are building, since almost nobody builds all of it at
10
+ * once. Every claim here was checked against the deployed schema and the code
11
+ * behind it; check again when either changes.
12
+ */
13
+ export const STOREFRONT_GUIDE = `
14
+ # CloudCart Storefront API
15
+
16
+ \`POST /api/sf\` — one GraphQL endpoint for the whole storefront: catalog,
17
+ collections, search, content, metafields and metaobjects, cart, checkout,
18
+ customer accounts, orders and returns. One schema serves every client: Nitrogen
19
+ storefronts, the mobile app and others.
20
+
21
+ ## On a Nitrogen storefront
22
+
23
+ Nitrogen is CloudCart's framework for headless storefronts, and it sends the
24
+ requests: you write \`#graphql\` documents, not headers.
25
+
26
+ - The storefront's tokens and the buyer's IP go from the storefront's server.
27
+ The browser reaches the API only through the storefront's \`/api/sf\` proxy.
28
+ - The signed-in buyer's access token stays in the storefront's signed session
29
+ cookie. A document that should run for that buyer declares
30
+ \`$buyer: BuyerInput\` and \`@inContext(buyer: $buyer)\`, and the storefront
31
+ passes the buyer it read from the session.
32
+ - The checkout is the platform's: send the buyer to \`cart.checkoutUrl\`. An
33
+ order placed on the page itself — a product's one-step order — is
34
+ \`fastOrderSubmit\`. The API's own checkout steps below are for a client that
35
+ runs its own checkout, such as a mobile app.
36
+
37
+ The \`cloudcart-nitrogen\` skill shows the code for each.
38
+
39
+ ## Authentication
40
+
41
+ The storefront's access token goes in \`X-Storefront-Access-Token\`. It names the
42
+ store, so no operation takes a store argument.
43
+
44
+ A signed-in buyer is sent in one of two ways — **never in an \`Authorization\`
45
+ header**:
46
+
47
+ - \`customerAccessToken\` — the argument of \`customer\`, \`order\` and every
48
+ customer mutation; they always take it, \`@inContext\` does not replace it. An invalid or expired token gives \`null\` from a query and a
49
+ \`TOKEN_INVALID\` error from a mutation.
50
+ - \`@inContext(buyer: {customerAccessToken: …})\` on the operation — the whole
51
+ operation runs for that buyer: their customer group's prices and discounts,
52
+ and the buyer of a fast order and of the store's forms. An invalid or expired
53
+ token is ignored and the operation runs as a guest. It does not give a cart an
54
+ owner: \`buyerIdentity.customerAccessToken\` on \`cartCreate\` or
55
+ \`cartBuyerIdentityUpdate\` does. \`BuyerInput\` is \`{customerAccessToken}\`.
56
+
57
+ The token comes from \`customerLoginCodeVerify\`. On the web keep it on the server
58
+ — Nitrogen keeps it in the signed session cookie — never in a URL, browser
59
+ storage or client code.
60
+
61
+ \`@inContext(country:, language:)\` are accepted and ignored: a store serves one
62
+ country and one language.
63
+
64
+ ## Conventions that hold everywhere
65
+
66
+ **Ids are global.** \`gid://cloudcart/Product/123\`. Most single-object queries
67
+ also accept \`handle\`, which is what a URL carries — prefer it. \`node(id)\` and
68
+ \`nodes(ids)\` read a product, collection, vendor, tag, page, blog, article or
69
+ store location by its id.
70
+
71
+ **Lists are Relay connections** with \`edges\`, \`nodes\`, \`pageInfo\`. Use \`nodes\`
72
+ unless you need cursors. \`first\` and \`last\` default to 25 and a larger value is
73
+ cut to 100 on most lists (a product's \`reviews\`: 10 and 50). \`first\`/\`after\` page forward
74
+ and \`last\`/\`before\` back, except \`relatedProducts\`, which pages forward only.
75
+ Trust \`pageInfo.hasNextPage\`, not the number of nodes you got.
76
+
77
+ **Show \`formatted\`.** Every \`MoneyV2\` has \`amount\`, a decimal string for logic,
78
+ and \`formatted\`, the amount as the store writes money: its currency's symbol and
79
+ where it stands, its decimals and separators. Never format \`amount\` yourself. An
80
+ amount you add up from amounts the API gave is written with \`Shop.currencyFormat\`,
81
+ the pattern \`formatted\` is made with.
82
+
83
+ **Mutations do not throw for a business failure.** Each payload carries its
84
+ errors — \`userErrors\`, or \`customerUserErrors\` on the customer payloads — each
85
+ with a \`message\` meant for the buyer and, on most, \`field\` and \`code\`. Empty
86
+ means success. A cart payload also carries \`warnings\`: inputs that were sent and
87
+ had no effect, such as a discount code the store did not honour. A GraphQL-level
88
+ error means the request itself was malformed.
89
+
90
+ **Some fields depend on the merchant's apps.** They answer empty rather than
91
+ erroring, which is the harder failure to notice. \`introspect_graphql_schema\`
92
+ flags them.
93
+
94
+ ---
95
+
96
+ # Catalog
97
+
98
+ \`products(first, after, query, sortKey, reverse, filters, smartFacetCounts)\`
99
+ returns a \`ProductConnection\` with:
100
+
101
+ - \`nodes\` — the products
102
+ - \`totalCount\` — the real total for the query and filters, for "47 products"
103
+ - \`filters\` — the facets **for this result set**, from the store's search engine,
104
+ and \`filterCapabilities\` — whether their counts are exact and their values
105
+ complete
106
+
107
+ Build the facet sidebar from \`filters\` (on a search, \`productFilters\`); do not
108
+ hardcode facets. Each \`Filter\`
109
+ has an \`id\`, a \`label\`, a \`type\` (\`LIST\`, \`BOOLEAN\`, \`PRICE_RANGE\`, \`RANGE\`,
110
+ \`SWATCH_COLOR\`, \`SWATCH_IMAGE\`) and \`values\`, each with its \`count\` and its
111
+ \`input\`: the \`ProductFilter\` to send back when the buyer picks it. Ranges add
112
+ \`minValue\`/\`maxValue\`, \`rangeStep\` and \`decimals\`. A collection's, a vendor's
113
+ and a tag's \`products\` take the same arguments.
114
+
115
+ \`smartFacetCounts\` (default true) recounts each active facet as if its own
116
+ filter were off, so a buyer sees what another value would give. It costs one
117
+ more engine search per active filter; turn it off when you do not show those
118
+ counts.
119
+
120
+ \`ProductFilter\` accepts \`available\`, \`onSale\`, \`isNew\`, \`isFeatured\`, \`tag\`,
121
+ \`productVendor\`, \`price\`, \`variantOption\`, \`category\`, \`brandModel\` and
122
+ \`productMetafield\` (a category property's value). Send back a value's \`input\`
123
+ rather than building one.
124
+
125
+ Sort with \`ProductSortKeys\`: \`TITLE\`, \`PRICE\`, \`BEST_SELLING\`, \`CREATED_AT\`,
126
+ \`UPDATED_AT\`, \`PRODUCT_TYPE\`, \`VENDOR\`, \`RELEVANCE\`, \`ID\`. Without a \`sortKey\`
127
+ a list comes in the store's own order.
128
+
129
+ For "you may also like", \`product.relatedProducts\` pages through the merchant's
130
+ linked products, then the product's category; \`product.linkedProducts\` is the
131
+ linked ones alone. \`productRecommendations(productId | productHandle, intent)\`
132
+ gives a short list: \`RELATED\` or \`COMPLEMENTARY\`.
133
+
134
+ ## Collections
135
+
136
+ A collection is a category or a merchant's selection (a smart collection), in
137
+ one type; \`kind\` on \`collection\` and \`collections\` tells them apart. A smart
138
+ collection's id carries \`sc_\` — \`gid://cloudcart/Collection/sc_12\` — so never
139
+ parse an id as a number.
140
+
141
+ \`Collection\` gives you a whole category page: \`parent\`, \`children\`,
142
+ \`breadcrumb\`, \`productsCount\`, \`displayChildren\`, \`seo\`, \`googleTaxonomy\`,
143
+ plus \`restrictions\`, which is why a payment or shipping method may be unavailable
144
+ later in the checkout.
145
+
146
+ ## Search
147
+
148
+ \`search(query, types, productFilters, sortKey, unavailableProducts, smartFacetCounts)\`
149
+ spans products, pages and articles. Its facets are \`productFilters\`, not
150
+ \`filters\`; \`totalCount\` counts every result and \`productCount\` the products.
151
+ \`predictiveSearch(query, limit, limitScope, types)\` is the type-ahead —
152
+ products, collections, vendors, pages and articles, smaller and faster.
153
+
154
+ ---
155
+
156
+ # Cart and checkout
157
+
158
+ **The server owns every number.** Never compute a price, discount, tax or total
159
+ in the storefront. Every cart mutation returns the whole repriced cart — read the
160
+ answer, do not predict it.
161
+
162
+ **Record where the buyer came from**, early, while the landing URL still exists:
163
+ \`cartAttributionUpdate\` keeps the landing page, referrer, visitor and UTM on the
164
+ cart, and both the store's checkout (through \`checkoutUrl\`) and
165
+ \`cartSubmitForCompletion\` read it. Skip it and the order is recorded as direct
166
+ traffic. A fast order takes the same in its \`attribution\` input.
167
+
168
+ **A cart's id is \`gid://cloudcart/Cart/<key>\`**, where the key is a long random
169
+ string. It is not a row number and cannot be guessed. Keep it yourself — a
170
+ Nitrogen storefront keeps it in a cookie; there is no implicit "current cart".
171
+
172
+ ## The checkout
173
+
174
+ **\`cart.checkoutUrl\`** hands the cart to the store's own checkout, signed in as
175
+ the buyer when the request carried one. It is signed and **valid for ten
176
+ minutes**: read it right before sending the buyer, not from a page loaded long
177
+ before, or the buyer lands on a 404.
178
+
179
+ **\`fastOrderSubmit(attemptToken, input)\`** places an order from the page: one
180
+ line or bundle, the buyer's contact and consents. It answers \`COMPLETED\` with the
181
+ order, or \`FAILED\` with \`userErrors\`.
182
+
183
+ ## The API's own checkout
184
+
185
+ For a client that runs its own checkout. **There are no steps:** no mutation has
186
+ to precede another. Ask what is missing and let that drive the UI:
187
+
188
+ \`\`\`graphql
189
+ query { cartCheckoutReadiness(cartId: $id) { status missing consents { id } } }
190
+ \`\`\`
191
+
192
+ \`missing\` names what remains — \`BUYER_EMAIL\`, \`DELIVERY_ADDRESS\`,
193
+ \`DELIVERY_OPTION\`, \`DELIVERY_SLOT\`, \`PAYMENT_METHOD\`, \`CONSENTS\` and others
194
+ (\`CartCheckoutRequirement\`).
195
+
196
+ 1. \`cartCreate\` — lines, buyer identity and discount codes in one call
197
+ 2. \`cartAttributionUpdate\` — early (above)
198
+ 3. \`cartDeliveryAddressUpdate\` — a street address, a courier office or locker
199
+ (\`pickupPointId\`), a merchant shop (\`storeId\`), or a signed-in buyer's saved
200
+ address (\`addressId\`)
201
+ 4. \`cart { delivery { carriers } }\` — the couriers that can deliver there; it
202
+ **calls no courier** and is cheap
203
+ 5. \`cartDeliveryQuote(cartId, carrierHandle)\` — one courier, live. Quote the
204
+ couriers **in parallel**, so one slow courier does not hold up the rest.
205
+ 6. \`cartSelectedDeliveryOptionUpdate\` — the option's handle, plus
206
+ \`deliverySlotKey\` for a courier that delivers in slots (\`cartDeliverySlots\`)
207
+ 7. \`cart { paymentMethods }\` → \`cartPaymentMethodUpdate\`
208
+ 8. \`cartSubmitForCompletion\` with an \`attemptToken\`
209
+
210
+ \`CartSubmitStatus\` is one of three: \`COMPLETED\` — the order exists;
211
+ \`REQUIRES_REDIRECT\` with \`redirectUrl\` — send the buyer to the payment
212
+ provider; \`FAILED\` — read \`userErrors\`. The \`attemptToken\`
213
+ makes retrying safe: the same token returns the same order instead of a second
214
+ one.
215
+
216
+ ## Traps
217
+
218
+ **Delivery needs an address.** \`carriers\` is empty until the cart has one, and a
219
+ quote without one is refused.
220
+
221
+ **Payment follows delivery.** \`paymentMethods\` is empty until a shippable cart
222
+ has a delivery service chosen: the courier decides half of what is allowed. Read
223
+ it again when delivery changes.
224
+
225
+ **Line discounts are already inside the subtotal.** Only order-level discounts
226
+ appear as separate rows of \`totals\` (the \`discount.before\` group). Adding the
227
+ line ones again double-counts.
228
+
229
+ **\`totals\` and \`cost\` come from one calculation** and cannot disagree.
230
+ \`totals\` is the merchant's ordered summary, with their own labels — the right
231
+ thing to render a summary panel from. \`cost\` is the same figures as named
232
+ aggregates, for when you just need the total.
233
+
234
+ **Customizations are not variant options.** A variant option picks *which*
235
+ variant. A customization — engraving, gift wrap, a cut to size — rides along with
236
+ the line, can change its price, and is part of the line's identity: the same
237
+ variant with different answers is a **separate line**, not a larger quantity.
238
+ Read \`product.customizations\` for what a product accepts.
239
+
240
+ **Bundles are groups, not lines.** \`cartBundleAdd\` adds one line per product in
241
+ the bundle, all sharing a \`bundle.id\`. Group by it for display. A bundle is added
242
+ whole or not at all.
243
+
244
+ **A cart may have no customer.** Identity arrives at any point, in any order.
245
+ Sending only a phone or a name creates nothing — it waits on the cart until an
246
+ email or a sign-in gives it an owner.
247
+
248
+ **Record where a line came from.** If the buyer took an up-sell or cross-sell
249
+ offer, send \`upSellTriggerVariantId\` or \`crossSellId\` on the line: the line is
250
+ then priced as the offer and counted in the merchant's reporting. Without the
251
+ store's up-sell and cross-sell app they do nothing, and the line gets a warning.
252
+
253
+ ---
254
+
255
+ # Customers
256
+
257
+ Sign in with \`customerLoginCodeSend\`, then \`customerLoginCodeVerify\`, which
258
+ returns the access token. **There is deliberately no password login and no
259
+ password reset.**
260
+
261
+ \`customer(customerAccessToken)\` is the account area in one query: \`orders\`,
262
+ \`wishlist\`, \`downloads\`, \`payments\`, \`returns\`, \`addresses\`,
263
+ \`billingAddresses\`, \`defaultAddress\`, \`numberOfOrders\`, \`tags\`.
264
+
265
+ Delivery and billing addresses are separate sets with separate mutations. A
266
+ buyer can have several: a street address, one per courier office, one per
267
+ locker. Do not assume one buyer has one address.
268
+
269
+ ## Orders
270
+
271
+ \`customer.orders\` lists them, newest first, with \`totalCount\`; there is no
272
+ filter or search over them. \`order(customerAccessToken, id)\` reads one with its
273
+ lines, addresses, payments, discounts, \`totals\` and \`returnEligibility\`.
274
+
275
+ **A guest reads an order's status** with \`orderStatus(id, email)\` — the order's
276
+ \`id\` and the email it was placed with: the status, the totals, whether it is
277
+ paid, nothing that identifies the buyer. A wrong pair answers \`null\`. It is how a
278
+ client returning from a payment provider asks the store what the payment did.
279
+
280
+ ## Returns
281
+
282
+ \`returnRequestStart\` → \`returnRequestVerify\` (a code sent by email) →
283
+ \`returnRequestCreate\`. \`returnByReference(reference)\` reads one back **without
284
+ a sign-in**, by the reference from the notification email. Returns need the
285
+ merchant's returns app; without it they answer \`null\` or a \`NOT_AVAILABLE\`
286
+ error.
287
+
288
+ ---
289
+
290
+ # Content and shop
291
+
292
+ \`page\`, \`pages\`, \`blog\`, \`blogs\`, \`article\`, \`articles\`, \`policies\` and
293
+ \`menu(handle)\` are the content. \`menu\` takes a handle such as \`main\` or
294
+ \`footer\` and returns the tree.
295
+
296
+ \`shop\` gives the store's name, description, logo, primary domain, contact,
297
+ payment settings and \`currencyFormat\`. \`checkoutSettings\` says which checkout
298
+ fields exist and whether each is required, optional or hidden — build a form from
299
+ it rather than hardcoding, because it differs per merchant. \`cookieConsent\` is
300
+ the merchant's cookie banner and its consent groups; \`subscribeForms\` are their
301
+ sign-up forms.
302
+
303
+ \`storeLocations\` lists the merchant's physical shops, for a store locator and
304
+ for collect-from-shop.
305
+
306
+ ---
307
+
308
+ # Metafields and metaobjects
309
+
310
+ The merchant's own fields and content types. Only definitions whose storefront
311
+ access is \`PUBLIC_READ\` are returned; anything else answers \`null\` or an
312
+ empty list, never an error.
313
+
314
+ \`Product\`, \`Collection\` and \`Customer\` have \`metafield(namespace, key)\` and
315
+ \`metafields(identifiers: [{namespace, key}])\`. **Always pass \`namespace\`**: the
316
+ store has no app-reserved namespace, so a \`metafield(key:)\` without one finds
317
+ nothing. \`metafields\` answers one entry per identifier, in their order, \`null\`
318
+ where there is no value — read it by position. A smart collection has no
319
+ metafields.
320
+
321
+ \`value\` is always a string, whatever the \`type\` (\`boolean\`,
322
+ \`number_integer\`, \`single_line_text_field\`, \`list.product_reference\`, …); a
323
+ \`list.*\` type is a JSON array in that string, and \`list\` says which. A
324
+ reference type gives the record: \`reference\` for one,
325
+ \`references(first:)\` for a list, each a \`MetafieldReference\` — \`Product\`,
326
+ \`ProductVariant\`, \`Collection\`, \`Page\`, \`Metaobject\`, \`MediaImage\`,
327
+ \`Video\` or \`GenericFile\` — read with inline fragments. A record the storefront
328
+ does not show is \`null\` in \`reference\` and left out of \`references\`.
329
+
330
+ \`\`\`graphql
331
+ query ProductSpecs($handle: String!) {
332
+ product(handle: $handle) {
333
+ metafields(identifiers: [
334
+ {namespace: "custom", key: "material"}
335
+ {namespace: "custom", key: "care_guide"}
336
+ ]) {
337
+ key
338
+ type
339
+ value
340
+ reference { ... on MediaImage { image { url altText } } }
341
+ }
342
+ }
343
+ }
344
+ \`\`\`
345
+
346
+ A metaobject is an entry of a content type: \`metaobject(handle: {type, handle})\`
347
+ or \`metaobject(id:)\` for one, \`metaobjects(type:, first:)\` for a type's
348
+ entries (an unknown or hidden type gives an empty list). Read its values with
349
+ \`field(key:)\` or \`fields\`, which has only the fields that have a value; a
350
+ \`MetaobjectField\` has the same \`value\`, \`reference\` and \`references\` as a
351
+ metafield. \`metaobjects\` sorts by \`sortKey\` (\`id\` or \`updated_at\`) with
352
+ \`reverse\`, and filters with \`query\` on the type's filterable fields:
353
+ \`fields.color:blue\`, \`fields.year:>=2020\`, \`-fields.tags:"sale"\`. A term it
354
+ cannot filter by is ignored, not refused.
355
+
356
+ A customer's own metafields come only to that customer, through
357
+ \`customer(customerAccessToken:)\`, and only for definitions the merchant opened
358
+ to customer accounts.
359
+
360
+ These fields count toward the query's complexity: \`metafields\` one object per
361
+ identifier, \`metaobjects\` and \`references\` per item of their page. Ask for
362
+ small pages; a document over 1 000 is refused.
363
+
364
+ ---
365
+
366
+ # Analytics
367
+
368
+ \`analyticsSettings\` says which pixels the merchant runs. \`analyticsEventPublish\`
369
+ records an event and returns its \`eventId\` — fire the browser pixel's event with
370
+ that same id, or the vendor counts the conversion twice. A Nitrogen storefront
371
+ publishes its events through Nitrogen's analytics, not by hand.
372
+
373
+ ---
374
+
375
+ # Before you ship a query
376
+
377
+ Run it through \`validate_graphql_codeblocks\`. The schema is large, and close
378
+ names are easy to invent.
379
+ `.trim();
380
+ //# sourceMappingURL=storefront.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storefront.js","sourceRoot":"","sources":["../../src/prompts/storefront.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8W/B,CAAC,IAAI,EAAE,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { type GraphQLSchema, type IntrospectionQuery } from "graphql";
2
+ interface SchemaCache {
3
+ raw: IntrospectionQuery;
4
+ schema: GraphQLSchema;
5
+ types: IntrospectionType[];
6
+ queries: IntrospectionField[];
7
+ mutations: IntrospectionField[];
8
+ }
9
+ export interface IntrospectionType {
10
+ name: string;
11
+ kind: string;
12
+ description?: string | null;
13
+ fields?: IntrospectionField[] | null;
14
+ inputFields?: IntrospectionInputField[] | null;
15
+ enumValues?: IntrospectionEnumValue[] | null;
16
+ interfaces?: IntrospectionTypeRef[] | null;
17
+ }
18
+ export interface IntrospectionField {
19
+ name: string;
20
+ description?: string | null;
21
+ args?: IntrospectionArg[];
22
+ type: IntrospectionTypeRef;
23
+ }
24
+ interface IntrospectionInputField {
25
+ name: string;
26
+ description?: string | null;
27
+ type: IntrospectionTypeRef;
28
+ defaultValue?: string | null;
29
+ }
30
+ interface IntrospectionEnumValue {
31
+ name: string;
32
+ description?: string | null;
33
+ }
34
+ interface IntrospectionArg {
35
+ name: string;
36
+ description?: string | null;
37
+ type: IntrospectionTypeRef;
38
+ defaultValue?: string | null;
39
+ }
40
+ interface IntrospectionTypeRef {
41
+ kind: string;
42
+ name?: string | null;
43
+ ofType?: IntrospectionTypeRef | null;
44
+ }
45
+ export declare function loadSchema(api: string): SchemaCache;
46
+ export {};
47
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/schema/loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAAqB,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAIzF,UAAU,WAAW;IACnB,GAAG,EAAE,kBAAkB,CAAC;IACxB,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,OAAO,EAAE,kBAAkB,EAAE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AAC;CACtC;AAQD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CA8BnD"}
@@ -0,0 +1,34 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join, dirname } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { buildClientSchema } from "graphql";
5
+ const __dirname = dirname(fileURLToPath(import.meta.url));
6
+ const cache = new Map();
7
+ function getSchemaPath(api) {
8
+ return join(__dirname, "..", "..", "data", `${api}.json`);
9
+ }
10
+ export function loadSchema(api) {
11
+ const existing = cache.get(api);
12
+ if (existing)
13
+ return existing;
14
+ const path = getSchemaPath(api);
15
+ const raw = JSON.parse(readFileSync(path, "utf-8"));
16
+ const introspection = raw.data;
17
+ const schema = buildClientSchema(introspection);
18
+ const schemaType = introspection.__schema;
19
+ const allTypes = schemaType.types.filter((t) => !t.name.startsWith("__"));
20
+ const queryTypeName = schemaType.queryType?.name ?? "Query";
21
+ const mutationTypeName = schemaType.mutationType?.name ?? "Mutation";
22
+ const queryType = allTypes.find((t) => t.name === queryTypeName);
23
+ const mutationType = allTypes.find((t) => t.name === mutationTypeName);
24
+ const result = {
25
+ raw: introspection,
26
+ schema,
27
+ types: allTypes.filter((t) => t.name !== queryTypeName && t.name !== mutationTypeName),
28
+ queries: queryType?.fields ?? [],
29
+ mutations: mutationType?.fields ?? [],
30
+ };
31
+ cache.set(api, result);
32
+ return result;
33
+ }
34
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/schema/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAA+C,MAAM,SAAS,CAAC;AAEzF,MAAM,SAAS,GAAG,OAAO,CAA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,CAAC,IAAI,KAAK,gBAAgB,CAAC,CAAC;IAEvE,MAAM,MAAM,GAAgB;QAC1B,GAAG,EAAE,aAAa;QAClB,MAAM;QACN,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,IAAI,CAAC,CAAC,IAAI,KAAK,gBAAgB,CAAC;QACtF,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,EAAE;QAChC,SAAS,EAAE,YAAY,EAAE,MAAM,IAAI,EAAE;KACtC,CAAC;IAEF,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,17 @@
1
+ type FilterKind = "all" | "types" | "queries" | "mutations";
2
+ type Mode = "full" | "compact";
3
+ export interface IntrospectInput {
4
+ query: string;
5
+ filter?: FilterKind[];
6
+ conversationId: string;
7
+ api?: string;
8
+ mode?: Mode;
9
+ }
10
+ export declare function introspectSchema(input: IntrospectInput): {
11
+ content: {
12
+ type: "text";
13
+ text: string;
14
+ }[];
15
+ };
16
+ export {};
17
+ //# sourceMappingURL=introspect-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspect-schema.d.ts","sourceRoot":"","sources":["../../src/tools/introspect-schema.ts"],"names":[],"mappings":"AAGA,KAAK,UAAU,GAAG,KAAK,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC;AAC5D,KAAK,IAAI,GAAG,MAAM,GAAG,SAAS,CAAC;AAE/B,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAsID,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe;;;;;EA6ItD"}