@40rty/ams-cli 0.2.0 → 0.2.2

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.
@@ -13,12 +13,19 @@
13
13
  import { watch } from 'node:fs';
14
14
  import path from 'node:path';
15
15
  import { cwd, deployment, fail, readConfig, readConfigIfPresent, writeDotenv } from '../lib/context.mjs';
16
- import { call } from '../lib/credentials.mjs';
16
+ import { call, request } from '../lib/credentials.mjs';
17
17
  import { init } from './init.mjs';
18
18
  import { buildRelease } from './publish.mjs';
19
19
 
20
20
  const SETTLE_MS = 150;
21
21
 
22
+ /** The console of the deployment this space lives on: `FORTY_CONSOLE_URL`, else the one the api names. */
23
+ async function previewConsole(config) {
24
+ if (process.env.FORTY_CONSOLE_URL) return deployment(config).consoleUrl;
25
+ const me = await request(config.apiUrl, 'GET', '/org/me');
26
+ return me.ok && typeof me.body.consoleUrl === 'string' ? me.body.consoleUrl : deployment(config).consoleUrl;
27
+ }
28
+
22
29
  export async function dev() {
23
30
  if ((await readConfigIfPresent()) === null) await init();
24
31
  const config = await readConfig();
@@ -65,7 +72,7 @@ export async function dev() {
65
72
  await writeDotenv('FORTY_DEV_TOKEN', token);
66
73
  console.log('\n wrote FORTY_DEV_TOKEN to .env — your app previews the draft. Keep it out of version control.\n');
67
74
  } else {
68
- console.log(`\n ${deployment(config).consoleUrl}/${config.spaceSlug}?preview=${token}\n`);
75
+ console.log(`\n ${await previewConsole(config)}/${config.spaceSlug}?preview=${token}\n`);
69
76
  }
70
77
  // `--once`: store the draft and stop — for a script, or an agent, that cannot hold a watcher open.
71
78
  if (process.argv.includes('--once')) return;
@@ -67,11 +67,22 @@ async function createSpace(apiUrl, { slug, name }) {
67
67
  }
68
68
 
69
69
  /** An existing space, or `{ create: { slug, name } }` for one to make once everything else is known. */
70
+ const titleCase = (words) => words.split(/[-_\s]+/).filter(Boolean).map((w) => w[0].toUpperCase() + w.slice(1)).join(' ');
71
+
72
+ /** A person-readable name from package.json: `@hosted-test/spacefront` → "Hosted Test", not "spacefront". */
73
+ function displayName(name) {
74
+ if (typeof name !== 'string' || name === '') return undefined;
75
+ const match = /^@([^/]+)\/(.+)$/.exec(name);
76
+ if (match === null) return titleCase(name);
77
+ return titleCase(/^(spacefront|storefront|web|app|site)$/.test(match[2]) ? match[1] : match[2]);
78
+ }
79
+
70
80
  async function pickSpace(spaces, appName) {
71
81
  const wanted = option('space');
72
82
  const create = option('create');
73
83
  if (wanted !== undefined && create !== undefined) fail('pass --space OR --create, not both');
74
- if (create !== undefined) return { create: { slug: create, name: appName === undefined ? create : appName } };
84
+ // The slug the developer typed names the space better than a package name does.
85
+ if (create !== undefined) return { create: { slug: create, name: titleCase(create) } };
75
86
  if (wanted !== undefined) {
76
87
  const space = spaces.find((candidate) => candidate.slug === wanted);
77
88
  const has = spaces.length === 0 ? 'none' : spaces.map((candidate) => candidate.slug).join(', ');
@@ -115,7 +126,7 @@ async function run() {
115
126
  const manifest = JSON.parse(await readFile(path.join(cwd, 'package.json'), 'utf8'));
116
127
  const dependencies = manifest.dependencies === undefined ? {} : manifest.dependencies;
117
128
  const selfHosted = dependencies['@shopify/hydrogen'] !== undefined;
118
- const appName = typeof manifest.name === 'string' && manifest.name !== '' ? manifest.name.replace(/^@[^/]+\//, '') : undefined;
129
+ const appName = displayName(manifest.name);
119
130
 
120
131
  const me = await call(apiUrl, 'GET', '/org/me');
121
132
  const picked = await pickSpace(me.spaces, appName);
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "peerDependencies": {
16
16
  "zod": "^3.25.0"
17
17
  },
18
- "version": "0.2.0",
18
+ "version": "0.2.2",
19
19
  "homepage": "https://docs.40rty.ai",
20
20
  "license": "UNLICENSED",
21
21
  "engines": {
@@ -1,3 +1,4 @@
1
+ import {useEffect, useState} from 'react';
1
2
  import {
2
3
  SpacefrontCanvas,
3
4
  renderInline,
@@ -9,7 +10,12 @@ import {
9
10
  useThreadRows,
10
11
  } from '@40rty/ams-sdk';
11
12
 
12
- /** The page: a header, the canvas the agent composes onto, and the conversation. */
13
+ /**
14
+ * The page: a header, the canvas the agent composes onto, and the AMS island —
15
+ * the floating composer every 40rty spacefront is recognised by. Its shape is
16
+ * fixed (grip, latest answer, field, round send stamp, suggestion chips, a pill
17
+ * when folded); its look comes from the brand tokens in `styles.css`.
18
+ */
13
19
  export function Shell() {
14
20
  const session = useFourtySession();
15
21
  const [draft, setDraft] = useComposerDraft();
@@ -18,9 +24,34 @@ export function Shell() {
18
24
  const goHome = useGoHome();
19
25
  const {cart} = useCart();
20
26
  const chips = session.suggestions ? session.suggestions.actions : [];
27
+ const latest = rows.length > 0 ? rows[rows.length - 1] : undefined;
28
+
29
+ const [threadOpen, setThreadOpen] = useState(false);
30
+ const [folded, setFolded] = useState(false);
31
+
32
+ // Folds to the pill while the visitor scrolls down the canvas, back on scroll up.
33
+ useEffect(() => {
34
+ let last = window.scrollY;
35
+ const onScroll = () => {
36
+ const y = window.scrollY;
37
+ if (Math.abs(y - last) > 24) {
38
+ setFolded(y > last && y > 120);
39
+ last = y;
40
+ }
41
+ };
42
+ window.addEventListener('scroll', onScroll, {passive: true});
43
+ return () => window.removeEventListener('scroll', onScroll);
44
+ }, []);
45
+
46
+ const send = (text: string) => {
47
+ if (text.trim() === '') return;
48
+ session.sendMessage(text);
49
+ setDraft('');
50
+ setFolded(false);
51
+ };
21
52
 
22
53
  return (
23
- <div className="flex min-h-screen flex-col bg-paper text-ink antialiased">
54
+ <div className="min-h-screen bg-paper text-ink antialiased">
24
55
  <header className="sticky top-0 z-40 flex h-16 items-center justify-between border-b border-ink/10 bg-paper/90 px-6 backdrop-blur md:px-10">
25
56
  <button type="button" className="font-semibold" onClick={goHome}>
26
57
  __LABEL__
@@ -30,51 +61,96 @@ export function Shell() {
30
61
  </a>
31
62
  </header>
32
63
 
33
- <div className="grid flex-grow lg:grid-cols-[1fr_24rem]">
34
- <main className="min-w-0">
35
- <SpacefrontCanvas />
36
- </main>
64
+ <main className="min-w-0 pb-56">
65
+ <SpacefrontCanvas />
66
+ </main>
37
67
 
38
- <aside className="flex flex-col gap-6 border-l border-ink/10 p-6 lg:sticky lg:top-16 lg:h-[calc(100vh-4rem)]">
39
- <div className="grid grow content-start gap-4 overflow-y-auto">
40
- {isEmpty && <p className="text-ink/60">Tell us what you’re looking for.</p>}
41
- {rows.map((row) => (
42
- <div key={row.key} className="grid gap-1">
43
- <p className="text-sm text-ink/60">{row.visitorText}</p>
44
- <p>{renderInline(row.prose, row.key)}</p>
68
+ <div className="pointer-events-none fixed inset-x-0 bottom-4 z-40 flex justify-center px-4">
69
+ {folded ? (
70
+ <button
71
+ type="button"
72
+ className="pointer-events-auto h-10 w-28 rounded-[20px] bg-ink text-paper text-sm font-semibold shadow-lg"
73
+ onClick={() => setFolded(false)}
74
+ >
75
+ Ask
76
+ </button>
77
+ ) : (
78
+ <div className="pointer-events-auto grid w-full max-w-[640px] gap-2">
79
+ {chips.length > 0 && (
80
+ <div className="flex flex-wrap justify-center gap-2">
81
+ {chips.map((chip) => (
82
+ <button
83
+ key={chip.id}
84
+ type="button"
85
+ className="rounded-full border border-ink/20 bg-paper px-3 py-1 text-sm hover:border-accent"
86
+ onClick={() => selectChip(chip)}
87
+ >
88
+ {chip.label}
89
+ </button>
90
+ ))}
45
91
  </div>
46
- ))}
47
- {session.error && <p className="text-accent">{session.error}</p>}
48
- </div>
92
+ )}
49
93
 
50
- <div className="flex flex-wrap gap-2">
51
- {chips.map((chip) => (
52
- <button key={chip.id} type="button" className="rounded-full border border-ink/20 px-3 py-1 text-sm" onClick={() => selectChip(chip)}>
53
- {chip.label}
94
+ <div className="overflow-hidden rounded-2xl bg-paper text-ink shadow-[0_0_0_1px_rgb(var(--color-ink)/.14),0_6px_16px_-4px_rgb(var(--color-ink)/.26),0_20px_44px_-12px_rgb(var(--color-ink)/.36)]">
95
+ <button
96
+ type="button"
97
+ aria-label="Fold the assistant"
98
+ className="flex w-full justify-center py-2"
99
+ onClick={() => setFolded(true)}
100
+ >
101
+ <span className="h-1 w-8 rounded-full bg-ink/40" />
54
102
  </button>
55
- ))}
56
- </div>
57
103
 
58
- <form
59
- className="flex gap-3"
60
- onSubmit={(event) => {
61
- event.preventDefault();
62
- if (draft.trim() === '') return;
63
- session.sendMessage(draft);
64
- setDraft('');
65
- }}
66
- >
67
- <input
68
- className="w-full border-b border-ink/20 bg-transparent py-2 outline-none focus:border-ink"
69
- placeholder="Ask anything…"
70
- value={draft}
71
- onChange={(event) => setDraft(event.target.value)}
72
- />
73
- <button type="submit" className="rounded bg-ink px-4 text-paper disabled:opacity-50" disabled={session.isRunning}>
74
- Ask
75
- </button>
76
- </form>
77
- </aside>
104
+ <div className={`px-4 text-sm ${threadOpen ? 'grid max-h-64 gap-3 overflow-y-auto pb-2' : ''}`} aria-live="polite">
105
+ {session.error ? (
106
+ <p className="text-accent">{session.error}</p>
107
+ ) : session.isRunning ? (
108
+ <p className="animate-pulse text-ink/50">Pulling that together…</p>
109
+ ) : threadOpen ? (
110
+ rows.map((row) => (
111
+ <div key={row.key} className="grid gap-1">
112
+ <p className="text-ink/60">{row.visitorText}</p>
113
+ <p>{renderInline(row.prose, row.key)}</p>
114
+ </div>
115
+ ))
116
+ ) : isEmpty ? (
117
+ <p className="text-ink/60">Tell us what you’re looking for.</p>
118
+ ) : (
119
+ latest && (
120
+ <button type="button" className="line-clamp-2 text-left text-ink/70" onClick={() => setThreadOpen(true)}>
121
+ {renderInline(latest.prose, latest.key)}
122
+ </button>
123
+ )
124
+ )}
125
+ </div>
126
+
127
+ <form
128
+ className="flex items-center gap-2 px-3 pb-3 pt-2"
129
+ onSubmit={(event) => {
130
+ event.preventDefault();
131
+ send(draft);
132
+ }}
133
+ >
134
+ <input
135
+ className="min-w-0 flex-1 bg-transparent px-3 py-2 outline-none"
136
+ aria-label="Ask"
137
+ placeholder="Ask anything…"
138
+ value={draft}
139
+ onChange={(event) => setDraft(event.target.value)}
140
+ onFocus={() => setThreadOpen(false)}
141
+ />
142
+ <button
143
+ type="submit"
144
+ aria-label="Send"
145
+ className="grid h-[34px] w-[34px] shrink-0 place-items-center rounded-full bg-ink text-paper disabled:opacity-40"
146
+ disabled={session.isRunning || draft.trim() === ''}
147
+ >
148
+ ↑
149
+ </button>
150
+ </form>
151
+ </div>
152
+ </div>
153
+ )}
78
154
  </div>
79
155
  </div>
80
156
  );