@letterstory/cli 0.177.85 → 0.177.86
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/lib/cli.mjs +7 -1
- package/lib/commands/visits.mjs +151 -1
- package/package.json +1 -1
package/lib/cli.mjs
CHANGED
|
@@ -90,7 +90,7 @@ import {
|
|
|
90
90
|
import { fetchParkedSections, withoutParked } from "./parked.mjs";
|
|
91
91
|
|
|
92
92
|
// Matches cli/package.json; publish-cli.yml rewrites both to the published version.
|
|
93
|
-
export const VERSION = "0.177.
|
|
93
|
+
export const VERSION = "0.177.86";
|
|
94
94
|
|
|
95
95
|
/** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
|
|
96
96
|
export const EXIT_PAYMENT_REQUIRED = 3;
|
|
@@ -99,6 +99,8 @@ export const EXIT_PAYMENT_REQUIRED = 3;
|
|
|
99
99
|
// can't accidentally swallow the id as --json's value. Every `type: "bool"` flag (and its
|
|
100
100
|
// `negate` spelling) in a command's ARGS map must be listed; boolean-flags.test.ts enforces it.
|
|
101
101
|
export const BOOLEAN_FLAGS = new Set([
|
|
102
|
+
// visits transact add folder|page: leave it out of the set.
|
|
103
|
+
"uncheck",
|
|
102
104
|
"clear-choice",
|
|
103
105
|
// models list: say whether each trained model's server is up now.
|
|
104
106
|
"serving",
|
|
@@ -2061,6 +2063,10 @@ Visits (Visitors: AI agents reading your site, and AI answers sending people to
|
|
|
2061
2063
|
visits health --site <id> Staff: how far to trust a site's numbers, each check and its fix
|
|
2062
2064
|
visits connect vercel|cloudflare [--site <id>] Send the host's request logs (no code to deploy)
|
|
2063
2065
|
visits connectors | disconnect <id> The site's host connectors
|
|
2066
|
+
visits transact [on|off] [--site <id>|--host <h>] Transact: agents' questions answered from your sources, cited
|
|
2067
|
+
visits transact add folder <path> [--uncheck] | page <url> [--uncheck] | site <host> | file <path> | text --title <t> --text <t>
|
|
2068
|
+
visits transact source <source-id>|--folder <path> | remove <id> | test "<question>"
|
|
2069
|
+
visits transact asks [--since 7d] [--limit <n>] What agents asked, answered, and asks per agent visit
|
|
2064
2070
|
|
|
2065
2071
|
Sim (Simulations: a free, simulated copy of your API for agents, and what they did with it):
|
|
2066
2072
|
sim [list] Your simulations and their URLs
|
package/lib/commands/visits.mjs
CHANGED
|
@@ -19,7 +19,16 @@
|
|
|
19
19
|
// letterstory visits connect vercel|cloudflare send the host's request logs (no code to deploy)
|
|
20
20
|
// letterstory visits connectors | disconnect <id>
|
|
21
21
|
// letterstory visits shortcut [mod+e | default] your own key for Letter Edit's card (⌘L by default)
|
|
22
|
+
// letterstory visits transact [on|off] [--host acme.com] Transact: agents' questions answered from your sources, cited
|
|
23
|
+
// letterstory visits transact add folder /blog [--uncheck] | page <url> [--uncheck] | site docs.acme.com
|
|
24
|
+
// letterstory visits transact add file ./faq.pdf | text --title Support --text "…"
|
|
25
|
+
// letterstory visits transact source <source-id> | --folder /docs
|
|
26
|
+
// letterstory visits transact remove <source-id>
|
|
27
|
+
// letterstory visits transact test "What does it cost?"
|
|
28
|
+
// letterstory visits transact asks [--since 7d] [--limit 50]
|
|
22
29
|
|
|
30
|
+
import { readFileSync } from "node:fs";
|
|
31
|
+
import { basename } from "node:path";
|
|
23
32
|
import { CliError } from "../client.mjs";
|
|
24
33
|
import { flagStr, printResult, argsFromFlags } from "./shared.mjs";
|
|
25
34
|
|
|
@@ -86,6 +95,62 @@ export const ARGS = {
|
|
|
86
95
|
path: "path",
|
|
87
96
|
purpose: { flag: "purpose", enum: PURPOSES },
|
|
88
97
|
},
|
|
98
|
+
visitors_set_modules: {
|
|
99
|
+
site_id: "site",
|
|
100
|
+
agent_visitors: { internal: "visits transact on|off switches transact only" },
|
|
101
|
+
editor: { internal: "visits transact on|off switches transact only" },
|
|
102
|
+
transact: { value: (flags, positionals) => ({ on: true, off: false })[positionals[0]] },
|
|
103
|
+
},
|
|
104
|
+
visitors_get_transact: { site_id: "site", host: "host" },
|
|
105
|
+
visitors_add_transact_source: {
|
|
106
|
+
site_id: "site",
|
|
107
|
+
kind: {
|
|
108
|
+
positional: 0,
|
|
109
|
+
label: "kind (folder | page | site | file | text)",
|
|
110
|
+
required: true,
|
|
111
|
+
enum: ["folder", "page", "site", "file", "text"],
|
|
112
|
+
},
|
|
113
|
+
path: {
|
|
114
|
+
value: (flags, positionals) =>
|
|
115
|
+
positionals[0] === "folder" || (positionals[0] === "page" && !/^https?:/i.test(positionals[1] ?? ""))
|
|
116
|
+
? positionals[1]
|
|
117
|
+
: undefined,
|
|
118
|
+
},
|
|
119
|
+
url: {
|
|
120
|
+
value: (flags, positionals) =>
|
|
121
|
+
positionals[0] === "page" && /^https?:/i.test(positionals[1] ?? "") ? positionals[1] : undefined,
|
|
122
|
+
},
|
|
123
|
+
host: {
|
|
124
|
+
value: (flags, positionals) => (positionals[0] === "site" ? positionals[1] : flagStr(flags.host)),
|
|
125
|
+
},
|
|
126
|
+
checked: { flag: "uncheck", type: "bool", invert: true },
|
|
127
|
+
title: "title",
|
|
128
|
+
text: "text",
|
|
129
|
+
file_name: {
|
|
130
|
+
value: (flags, positionals) => (positionals[0] === "file" ? basename(positionals[1] ?? "") : undefined),
|
|
131
|
+
},
|
|
132
|
+
content_base64: {
|
|
133
|
+
value: (flags, positionals) =>
|
|
134
|
+
positionals[0] === "file" && positionals[1]
|
|
135
|
+
? readFileSync(positionals[1]).toString("base64")
|
|
136
|
+
: undefined,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
visitors_get_transact_source: {
|
|
140
|
+
site_id: "site",
|
|
141
|
+
source_id: { positional: 0, label: "source id" },
|
|
142
|
+
folder: "folder",
|
|
143
|
+
limit: { flag: "limit", type: "num" },
|
|
144
|
+
},
|
|
145
|
+
visitors_test_transact: {
|
|
146
|
+
site_id: "site",
|
|
147
|
+
question: { positional: 0, label: "question", required: true },
|
|
148
|
+
},
|
|
149
|
+
visitors_remove_transact_source: {
|
|
150
|
+
site_id: "site",
|
|
151
|
+
source_id: { positional: 0, label: "source id", required: true },
|
|
152
|
+
},
|
|
153
|
+
visitors_list_transact_asks: { site_id: "site", days, limit: { flag: "limit", type: "num" } },
|
|
89
154
|
visitors_export: {
|
|
90
155
|
site_id: "site",
|
|
91
156
|
days,
|
|
@@ -147,9 +212,11 @@ export async function cmdVisits(ctx) {
|
|
|
147
212
|
return visitsDisconnect(rest);
|
|
148
213
|
case "shortcut":
|
|
149
214
|
return visitsShortcut(rest);
|
|
215
|
+
case "transact":
|
|
216
|
+
return visitsTransact(rest);
|
|
150
217
|
default:
|
|
151
218
|
throw new CliError(
|
|
152
|
-
"Usage: visits [list|citations|people|who|compare|export|sites|domain|pages|health|connect|connectors|disconnect|shortcut]"
|
|
219
|
+
"Usage: visits [list|citations|people|who|compare|export|sites|domain|pages|health|connect|connectors|disconnect|shortcut|transact]"
|
|
153
220
|
);
|
|
154
221
|
}
|
|
155
222
|
}
|
|
@@ -237,6 +304,89 @@ async function visitsDisconnect(ctx) {
|
|
|
237
304
|
return 0;
|
|
238
305
|
}
|
|
239
306
|
|
|
307
|
+
/** Transact on a site, as the CLI prints it: its state and URL, the folders, then everything else chosen. */
|
|
308
|
+
function transactLines(t) {
|
|
309
|
+
const state = { off: "off", unproven: "on, served once the site is proven", on: "on" }[t.state] ?? t.state;
|
|
310
|
+
const lines = [`Transact: ${state}`];
|
|
311
|
+
if (t.url) lines.push(` ${t.url}`, ` MCP ${t.mcp_url}`);
|
|
312
|
+
lines.push("", `${t.host ?? "This site"} (${t.read} of ${t.in_set} pages read):`);
|
|
313
|
+
if (!t.folders.length) lines.push(" no pages mapped yet");
|
|
314
|
+
for (const f of t.folders)
|
|
315
|
+
lines.push(
|
|
316
|
+
` [${f.checked ? "x" : " "}] ${f.path === "/" ? "/ (home)" : f.path} ${f.pages} ${f.pages === 1 ? "page" : "pages"} cited ${f.times_cited}${f.failed ? ` ${f.failed} failed` : ""}${f.by_default ? "" : " (yours)"}${f.id ? ` ${f.id}` : ""}`
|
|
317
|
+
);
|
|
318
|
+
if (t.sources.length) lines.push("", "Added:");
|
|
319
|
+
for (const s of t.sources) {
|
|
320
|
+
const what = s.snapshot ? `snapshot, ${s.chars} characters` : `${s.pages} ${s.pages === 1 ? "page" : "pages"}`;
|
|
321
|
+
lines.push(` ${s.id} ${s.kind} ${s.title} ${what} cited ${s.times_cited}`);
|
|
322
|
+
}
|
|
323
|
+
return lines;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** `visits transact`: read it; `on` / `off`; `add <kind> …`; `source <id>`; `remove <id>`; `test "…"`; `asks`. */
|
|
327
|
+
async function visitsTransact(ctx) {
|
|
328
|
+
const { flags, io } = ctx;
|
|
329
|
+
const sub = ctx.positionals[0];
|
|
330
|
+
const rest = { ...ctx, positionals: ctx.positionals.slice(1) };
|
|
331
|
+
if (sub === "on" || sub === "off") {
|
|
332
|
+
const result = await call(ctx, "visitors_set_modules");
|
|
333
|
+
printResult(io, flags, result, (r) => `Transact ${r.modules.transact ? "on" : "off"}`);
|
|
334
|
+
return 0;
|
|
335
|
+
}
|
|
336
|
+
if (sub === "add") {
|
|
337
|
+
const result = await call(rest, "visitors_add_transact_source");
|
|
338
|
+
printResult(io, flags, result, (r) => `Saved: ${r.source_id}`);
|
|
339
|
+
return 0;
|
|
340
|
+
}
|
|
341
|
+
if (sub === "source") {
|
|
342
|
+
const result = await call(rest, "visitors_get_transact_source");
|
|
343
|
+
printResult(io, flags, result, (r) =>
|
|
344
|
+
[
|
|
345
|
+
`${r.total} pages`,
|
|
346
|
+
...r.pages.map(
|
|
347
|
+
(p) =>
|
|
348
|
+
` [${p.in_set ? "x" : " "}] ${p.path} ${p.error ? `failed: ${p.error}` : p.read_at ? `read ${p.read_at.slice(0, 16)}` : "not read"}`
|
|
349
|
+
),
|
|
350
|
+
].join("\n")
|
|
351
|
+
);
|
|
352
|
+
return 0;
|
|
353
|
+
}
|
|
354
|
+
if (sub === "remove") {
|
|
355
|
+
const result = await call(rest, "visitors_remove_transact_source");
|
|
356
|
+
printResult(io, flags, result, () => "Removed");
|
|
357
|
+
return 0;
|
|
358
|
+
}
|
|
359
|
+
if (sub === "test") {
|
|
360
|
+
const result = await call(rest, "visitors_test_transact");
|
|
361
|
+
printResult(io, flags, result, (r) =>
|
|
362
|
+
[
|
|
363
|
+
r.answer,
|
|
364
|
+
...r.citations.map((c) => ` [${c.n}] ${c.title}${c.url ? ` ${c.url}` : ""}: "${c.quote}"`),
|
|
365
|
+
].join("\n")
|
|
366
|
+
);
|
|
367
|
+
return 0;
|
|
368
|
+
}
|
|
369
|
+
if (sub === "asks") {
|
|
370
|
+
const result = await call(rest, "visitors_list_transact_asks");
|
|
371
|
+
printResult(io, flags, result, (r) => {
|
|
372
|
+
const c = r.counts;
|
|
373
|
+
const visits = c.agent_visits === null ? "" : `, ${c.agent_visits} AI agent visits`;
|
|
374
|
+
const lines = [
|
|
375
|
+
`${c.asks} asks since ${r.since.slice(0, 10)}: ${c.answered} answered, ${c.agents} agents${visits}`,
|
|
376
|
+
];
|
|
377
|
+
for (const a of r.asks)
|
|
378
|
+
lines.push(` ${a.created_at.slice(0, 16)} ${a.test ? "test" : a.agent} ${a.outcome} ${a.question}`);
|
|
379
|
+
return lines.join("\n");
|
|
380
|
+
});
|
|
381
|
+
return 0;
|
|
382
|
+
}
|
|
383
|
+
if (sub !== undefined)
|
|
384
|
+
throw new CliError("Usage: visits transact [on|off|add <kind>|source <id>|remove <id>|test|asks]");
|
|
385
|
+
const result = await call(ctx, "visitors_get_transact");
|
|
386
|
+
printResult(io, flags, result, (t) => transactLines(t).join("\n"));
|
|
387
|
+
return 0;
|
|
388
|
+
}
|
|
389
|
+
|
|
240
390
|
const PURPOSE_LABELS = {
|
|
241
391
|
live: "answering a user",
|
|
242
392
|
index: "search index",
|