@40rty/ams-cli 0.5.14 → 0.5.16

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.
@@ -69,7 +69,10 @@ async function derivedName(config) {
69
69
  }
70
70
 
71
71
  /** Why a search that ran found nothing — the one cause we see over and over. */
72
- export const ZERO_RESULTS_HINT = 'unpublished/dev stores are not in Shopify\'s global catalog, which the agent searches — publish the store (remove its password) and make sure its products are on the Shop channel';
72
+ export const ZERO_RESULTS_HINT = 'unpublished/dev stores are not in Shopify\'s global catalog — publish the store (remove its password) and put its products on the Shop channel, or search the store\'s own catalog instead: `forty connect --search storefront`';
73
+
74
+ /** Where the agent's catalog search runs: Shopify's Global catalog (by shop id), or the store's own Storefront search. */
75
+ const SEARCH_MODES = ['global', 'storefront'];
73
76
 
74
77
  /** `forty connect` — attach this app's store to the space. What the space renders is not decided here. */
75
78
  export async function connect() {
@@ -90,21 +93,31 @@ export async function connect() {
90
93
  const token = present(binding.token);
91
94
  if (domain === undefined || token === undefined) fail('no store: pass --from <the store\'s live URL> (reads its public Storefront token), or set PUBLIC_STORE_DOMAIN and PUBLIC_STOREFRONT_API_TOKEN (or SHOPIFY_STORE_DOMAIN and SHOPIFY_STOREFRONT_ACCESS_TOKEN) in .env, or pass --domain and --token');
92
95
  const host = domain.replace(/^https?:\/\//, '').replace(/\/+$/, '');
93
- // Catalog search runs ONLY through Shopify's Global catalog, scoped by the
94
- // store's id — and mock.shop is not in it, so a spacefront on it could never
95
- // find a product.
96
- if (host === 'mock.shop') fail('mock.shop is not supported: the agent searches through Shopify\'s Global catalog, which does not index it — connect a real store');
96
+ // `--search global` (default): Shopify's Global catalog, scoped by the
97
+ // store's shop id, with the store's own search beside it. `--search
98
+ // storefront`: the store's own Storefront search only — for a store Global
99
+ // does not index (a dev store, mock.shop, a Storefront-shaped mock API).
100
+ const search = option('search') === undefined ? 'global' : option('search');
101
+ if (!SEARCH_MODES.includes(search)) fail(`--search must be one of ${SEARCH_MODES.join(', ')} (got "${search}")`);
102
+ if (host === 'mock.shop' && search === 'global') fail('mock.shop is not in Shopify\'s Global catalog — connect it with `--search storefront`');
97
103
 
98
104
  const store = await askStore(host, token);
99
- const shopId = present(binding.shopId) !== undefined ? present(binding.shopId) : store.shopId;
100
- if (shopId === undefined) {
101
- fail(`could not work out ${host}'s shop id, and without it the agent cannot search the catalog (search runs through Shopify's Global catalog, by shop id) — set SHOP_ID in .env to the number in gid://shopify/Shop/<n>`);
105
+ const settings = { hosting: { embedded: true, headless: true }, storefrontAccessToken: token };
106
+ let shopId;
107
+ if (search === 'global') {
108
+ shopId = present(binding.shopId) !== undefined ? present(binding.shopId) : store.shopId;
109
+ if (shopId === undefined) {
110
+ fail(`could not work out ${host}'s shop id, which Global catalog search is scoped by — set SHOP_ID in .env to the number in gid://shopify/Shop/<n>, or search the store's own catalog: \`--search storefront\``);
111
+ }
112
+ settings.globalShopId = shopId;
113
+ // The store's market: Global search ranks by ship-to country and defaults to the US.
114
+ if (store.marketCountry !== undefined) settings.marketCountry = store.marketCountry;
115
+ } else {
116
+ // An empty value removes a shop id an earlier `forty connect` stored, so
117
+ // catalog search routes to the store's own search.
118
+ settings.globalShopId = '';
102
119
  }
103
120
 
104
- const settings = { hosting: { embedded: true, headless: true }, storefrontAccessToken: token, globalShopId: shopId };
105
- // The store's market: Global search ranks by ship-to country and defaults to the US.
106
- if (store.marketCountry !== undefined) settings.marketCountry = store.marketCountry;
107
-
108
121
  const body = { platform: 'shopify', platformConfig: { platform: 'shopify', domain: host, config: settings }, vertical: 'ecommerce' };
109
122
  // The agent greets visitors by the space's name: a name `forty init` derived
110
123
  // (from the slug or package.json) gives way to the store's own.
@@ -112,7 +125,8 @@ export async function connect() {
112
125
  if (rename !== undefined && rename !== store.shopName) body.name = store.shopName;
113
126
  const result = await call(config.apiUrl, 'PUT', `/org/spaces/${config.spaceSlug}/storefront`, body);
114
127
  if (body.name !== undefined) console.log(`space "${result.slug}" is now named "${body.name}" (was "${rename}", derived by \`forty init\`)`);
115
- console.log(`space "${result.slug}" is connected to ${host} (shop ${shopId}${store.marketCountry === undefined ? '' : `, market ${store.marketCountry}`}) — \`forty dev\` to work on it`);
128
+ const how = search === 'global' ? `shop ${shopId}, Global catalog search${store.marketCountry === undefined ? '' : `, market ${store.marketCountry}`}` : 'the store\'s own catalog search';
129
+ console.log(`space "${result.slug}" is connected to ${host} (${how}) — \`forty dev\` to work on it`);
116
130
 
117
131
  // Connected is not searchable: run the agent's own search once, for a product the store just named.
118
132
  const probe = await probeSearch(config, store.sampleTitle);
@@ -16,8 +16,8 @@ import { findCredential, request } from '../lib/credentials.mjs';
16
16
  import { agenticFramework, agenticWiringProblems } from '../lib/agentic.mjs';
17
17
  import { askStore, probeSearch, ZERO_RESULTS_HINT } from './connect.mjs';
18
18
 
19
- /** What the ecommerce vertical requires a source to draw, and what the agent speaks through. */
20
- const REQUIRED_TYPES = ['productGrid', 'collectionList'];
19
+ /** What a space bound to a store requires a source to draw, and what the agent speaks through. */
20
+ const STORE_TYPES = ['productGrid', 'collectionList'];
21
21
  const REQUIRED_RENDERERS = ['agentText', 'turn'];
22
22
 
23
23
  async function exists(file) {
@@ -117,10 +117,10 @@ export async function doctor() {
117
117
  // ── The repo ──
118
118
  const hasCatalog = await exists(config.catalog);
119
119
  check(hasCatalog, `catalog file ${config.catalog} exists`);
120
+ let types = [];
120
121
  if (hasCatalog) {
121
122
  check(!/from ['"]react['"]/.test(await readFile(path.join(cwd, config.catalog), 'utf8')), 'the catalog file does not import React');
122
- const types = Object.keys(await loadCatalog(config.catalog));
123
- for (const type of REQUIRED_TYPES) check(types.includes(type), `the catalog declares "${type}"`);
123
+ types = Object.keys(await loadCatalog(config.catalog));
124
124
  }
125
125
  if (selfHosted) {
126
126
  const componentsFile = path.join(path.dirname(config.catalog), 'components.tsx');
@@ -143,11 +143,14 @@ export async function doctor() {
143
143
  // platform's own components, and the brand's only in a preview.
144
144
  const released = space.componentSources.length === 1 && space.componentSources[0] === config.sourceId;
145
145
  console.log(released ? `- visitors see ${config.sourceId}` : `- not released yet: visitors see ${space.componentSources.join(', ')} — \`forty publish\` when ready`);
146
- if (selfHosted) {
147
- // The agent's tools need BOTH: the token for the store, the shop id for catalog search (Shopify's Global catalog).
148
- const where = space.domain === undefined ? 'no store' : space.domain;
149
- check(space.hasStorefrontToken === true, `the space's store (${where}) has a storefront token`, 'run `forty connect`');
150
- check(space.hasGlobalShopId === true, `the space's store (${where}) has a shop id, so catalog search works`, 'run `forty connect`');
146
+ // Only a space with a store has products and collections to draw.
147
+ if (hasCatalog && space.domain !== undefined) {
148
+ for (const type of STORE_TYPES) check(types.includes(type), `the catalog declares "${type}"`);
149
+ }
150
+ if (selfHosted && space.domain !== undefined) {
151
+ // The agent's tools read the store with its token. Whether catalog search
152
+ // works (Global by shop id, or the store's own) is the search check below.
153
+ check(space.hasStorefrontToken === true, `the space's store (${space.domain}) has a storefront token`, 'run `forty connect`');
151
154
  }
152
155
  if (space.domain !== undefined) await searchCheck(config, check);
153
156
  }
@@ -17,12 +17,13 @@ export async function buildRelease(config) {
17
17
  version = '0.0.0';
18
18
  console.log('package.json has no "version" — releasing as 0.0.0');
19
19
  }
20
+ const catalog = await loadCatalog(config.catalog);
20
21
  const release = {
21
22
  sourceId: config.sourceId,
22
23
  label: config.label,
23
24
  version,
24
- catalog: catalogToWire(await loadCatalog(config.catalog)),
25
- manifests: await loadManifests(config.manifests),
25
+ catalog: catalogToWire(catalog),
26
+ manifests: await loadManifests(config.manifests, Object.keys(catalog)),
26
27
  };
27
28
  if (config.bundle !== undefined) {
28
29
  release.bundle = await buildBundle(config.bundle);
package/bin/forty.mjs CHANGED
@@ -17,7 +17,9 @@
17
17
  // forty releases the package's release history, and which one is live
18
18
  // forty rollback make an earlier release live again (`forty rollback 3`)
19
19
  // forty connect attach this app's store to the space (`--from <store url>`
20
- // reads its public Storefront token off the live page)
20
+ // reads its public Storefront token off the live page;
21
+ // `--search storefront` searches the store's own catalog
22
+ // instead of Shopify's Global one)
21
23
  // forty origin add let a deployed site's origin call the api (CORS)
22
24
  // forty domain add serve the space on your own domain; prints the DNS records
23
25
  // forty feedback report a problem to the 40rty team
package/bin/lib/build.mjs CHANGED
@@ -189,16 +189,26 @@ function bundleAssets(outputs) {
189
189
  * types from (`node_modules/@40rty/ams-ui/dist/conversation/manifests`). The
190
190
  * first folder that has a file wins it — the same layering a brand in the
191
191
  * platform's repository gets from `layerCatalogsFileAccess`.
192
+ *
193
+ * `declared` (the catalog's types) filters the KIT folders only: a brand that
194
+ * drops a kit block must not ship its manifest, which the platform refuses.
195
+ * The brand's own folder is never filtered, so an orphan it wrote still fails.
192
196
  */
193
- export async function loadManifests(dirs) {
197
+ export async function loadManifests(dirs, declared) {
194
198
  const out = {};
195
- for (const dir of (Array.isArray(dirs) ? dirs : [dirs])) {
199
+ const folders = Array.isArray(dirs) ? dirs : [dirs];
200
+ for (const [index, dir] of folders.entries()) {
196
201
  const root = path.resolve(cwd, dir);
197
202
  for (const entry of await readdir(root, { recursive: true, withFileTypes: true })) {
198
203
  if (!entry.isFile() || !entry.name.endsWith('.md')) continue;
199
204
  const abs = path.join(entry.parentPath, entry.name);
200
205
  const key = `catalogs/${path.relative(root, abs).split(path.sep).join('/')}`;
201
- if (!(key in out)) out[key] = await readFile(abs, 'utf8');
206
+ if (key in out) continue;
207
+ const text = await readFile(abs, 'utf8');
208
+ // A manifest names its type in its `# <type>` heading, as the platform reads it.
209
+ const type = /^#\s+(\S+)/m.exec(text)?.[1];
210
+ if (index > 0 && declared !== undefined && !declared.includes(type)) continue;
211
+ out[key] = text;
202
212
  }
203
213
  }
204
214
  return out;
package/dist/wire.js CHANGED
@@ -435,7 +435,7 @@ function partsText(parts) {
435
435
  var ModelTurnAskSchema = z11.object({
436
436
  kind: z11.enum(["choice", "open"]),
437
437
  parts: z11.array(PartSchema).min(1)
438
- }).refine((ask) => partsText(ask.parts).trim().length > 0, { message: "the question reads as nothing" }).transform((ask) => {
438
+ }).refine((ask) => partsText(ask.parts).trim().length > 0, { message: "the question reads as nothing" }).refine((ask) => /\?["'”’*)\s]*$/.test(partsText(ask.parts)), { message: "an ask is a question" }).transform((ask) => {
439
439
  const answers = ask.parts.filter((p) => typeof p !== "string").length;
440
440
  if (ask.kind === "choice" && answers >= MIN_CHOICE_ANSWERS && answers <= MAX_CHOICE_ANSWERS) return ask;
441
441
  if (ask.kind === "open" && answers === 0) return ask;
@@ -816,6 +816,7 @@ var WireCatalogEntrySchema = z21.object({
816
816
  examples: z21.array(z21.record(z21.unknown())).optional(),
817
817
  renderedBy: z21.string().optional(),
818
818
  alwaysInclude: z21.boolean().optional(),
819
+ asks: z21.boolean().optional(),
819
820
  whenToUse: z21.string().optional(),
820
821
  dontUseWhen: z21.string().optional(),
821
822
  variants: z21.string().optional(),
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "peerDependencies": {
17
17
  "zod": "^3.25.0"
18
18
  },
19
- "version": "0.5.14",
19
+ "version": "0.5.16",
20
20
  "homepage": "https://docs.40rty.ai",
21
21
  "license": "UNLICENSED",
22
22
  "engines": {