@letterstory/cli 0.177.189 → 0.177.190
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 +2 -1
- package/lib/commands/visits.mjs +57 -2
- package/package.json +1 -1
package/lib/cli.mjs
CHANGED
|
@@ -93,7 +93,7 @@ import {
|
|
|
93
93
|
import { fetchParkedSections, withoutParked } from "./parked.mjs";
|
|
94
94
|
|
|
95
95
|
// Matches cli/package.json; publish-cli.yml rewrites both to the published version.
|
|
96
|
-
export const VERSION = "0.177.
|
|
96
|
+
export const VERSION = "0.177.190";
|
|
97
97
|
|
|
98
98
|
/** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
|
|
99
99
|
export const EXIT_PAYMENT_REQUIRED = 3;
|
|
@@ -102,6 +102,7 @@ export const EXIT_PAYMENT_REQUIRED = 3;
|
|
|
102
102
|
// can't accidentally swallow the id as --json's value. Every `type: "bool"` flag (and its
|
|
103
103
|
// `negate` spelling) in a command's ARGS map must be listed; boolean-flags.test.ts enforces it.
|
|
104
104
|
export const BOOLEAN_FLAGS = new Set([
|
|
105
|
+
"supporting",
|
|
105
106
|
"share-website",
|
|
106
107
|
"connections-only",
|
|
107
108
|
"suggestions",
|
package/lib/commands/visits.mjs
CHANGED
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
// letterstory visits transact [on|off] [--host acme.com] Transact: agents' questions answered from your sources, cited
|
|
26
26
|
// letterstory visits transact add folder /answers | page <url> | site https://docs.acme.com/answers
|
|
27
27
|
// letterstory visits transact add text --text "Knowledge agents should know" [--title "Question?"] [--ask <id>]
|
|
28
|
+
// letterstory visits transact add text --prompt "Add our documentation at https://docs.acme.com/"
|
|
29
|
+
// letterstory visits transact add text --file guide.md --title "Setup guide" [--approve] [--source <id>]
|
|
30
|
+
// letterstory visits transact add text --supporting --title "Setup guide" --text "Reviewed public facts"
|
|
28
31
|
// letterstory visits transact source <source-id> | --folder /docs | --section /blog
|
|
29
32
|
// letterstory visits transact search "sso" the knowledge base and the site's pages, as an ask searches them
|
|
30
33
|
// letterstory visits transact remove <source-id>
|
|
@@ -35,8 +38,38 @@
|
|
|
35
38
|
// letterstory visits transact site [publish|unpublish] [--domain ask.acme.com | --domain none] [--remove <slug>] [--dismiss "<question>"] [--forget <address>] [--check-link] the Agent Site tab
|
|
36
39
|
|
|
37
40
|
import { CliError } from "../client.mjs";
|
|
41
|
+
import { closeSync, fstatSync, openSync, readSync } from "node:fs";
|
|
38
42
|
import { flagBool, flagStr, printResult, argsFromFlags } from "./shared.mjs";
|
|
39
43
|
|
|
44
|
+
function supportingFile(file) {
|
|
45
|
+
if (typeof file !== "string" || !/\.(?:txt|md|markdown)$/i.test(file))
|
|
46
|
+
throw new CliError("Choose a text or Markdown file.");
|
|
47
|
+
const fd = openSync(file, "r");
|
|
48
|
+
try {
|
|
49
|
+
const stat = fstatSync(fd);
|
|
50
|
+
const limit = 80_000; // Four UTF-8 bytes per allowed character; the server enforces the text limit too.
|
|
51
|
+
if (!stat.isFile() || stat.size > limit) throw new CliError("File exceeds 80,000 bytes.");
|
|
52
|
+
const bytes = Buffer.alloc(limit + 1);
|
|
53
|
+
let used = 0;
|
|
54
|
+
while (used < bytes.length) {
|
|
55
|
+
const n = readSync(fd, bytes, used, bytes.length - used);
|
|
56
|
+
if (!n) break;
|
|
57
|
+
used += n;
|
|
58
|
+
}
|
|
59
|
+
if (used > limit) throw new CliError("File exceeds 80,000 bytes.");
|
|
60
|
+
let text;
|
|
61
|
+
try {
|
|
62
|
+
text = new TextDecoder("utf-8", { fatal: true }).decode(bytes.subarray(0, used));
|
|
63
|
+
} catch {
|
|
64
|
+
throw new CliError("Choose a UTF-8 text file.");
|
|
65
|
+
}
|
|
66
|
+
if (text.includes("\0") || text.length > 20_000) throw new CliError("Choose text within 20,000 characters.");
|
|
67
|
+
return text;
|
|
68
|
+
} finally {
|
|
69
|
+
closeSync(fd);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
40
73
|
const PURPOSES = ["live", "index", "training", "automated_browser", "unknown"];
|
|
41
74
|
const PATH_KINDS = ["page", "agent_file", "site_file", "asset"];
|
|
42
75
|
|
|
@@ -128,6 +161,17 @@ export const ARGS = {
|
|
|
128
161
|
enum: ["folder", "page", "site", "text"],
|
|
129
162
|
},
|
|
130
163
|
ask_id: "ask",
|
|
164
|
+
directory: {
|
|
165
|
+
value: (flags) => (flags.file || flags.prompt || flags.supporting || flags.prepare ? false : undefined),
|
|
166
|
+
},
|
|
167
|
+
prepare: {
|
|
168
|
+
value: (flags) => {
|
|
169
|
+
const { prepare, approve, prompt, file } = flags;
|
|
170
|
+
if (approve && (prepare || prompt)) throw new CliError("Review the prompt before approving its text.");
|
|
171
|
+
return prepare || prompt || (file && !approve) ? true : undefined;
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
prompt: "prompt",
|
|
131
175
|
source_id: "source",
|
|
132
176
|
path: {
|
|
133
177
|
value: (flags, positionals) =>
|
|
@@ -149,7 +193,13 @@ export const ARGS = {
|
|
|
149
193
|
},
|
|
150
194
|
checked: { flag: "uncheck", type: "bool", invert: true },
|
|
151
195
|
title: "title",
|
|
152
|
-
text:
|
|
196
|
+
text: {
|
|
197
|
+
value: (flags) => {
|
|
198
|
+
const { file, text } = flags;
|
|
199
|
+
if (file && text) throw new CliError("Choose --file or --text.");
|
|
200
|
+
return file ? supportingFile(file) : flagStr(text);
|
|
201
|
+
},
|
|
202
|
+
},
|
|
153
203
|
},
|
|
154
204
|
visitors_get_transact_source: {
|
|
155
205
|
site_id: "site",
|
|
@@ -400,7 +450,12 @@ async function visitsTransact(ctx) {
|
|
|
400
450
|
}
|
|
401
451
|
if (sub === "add") {
|
|
402
452
|
const result = await call(rest, "visitors_add_transact_source");
|
|
403
|
-
printResult(io, flags, result, (r) =>
|
|
453
|
+
printResult(io, flags, result, (r) => {
|
|
454
|
+
if (!r.preview) return `Saved: ${r.source_id}`;
|
|
455
|
+
return r.preview.kind === "text"
|
|
456
|
+
? r.preview.title + "\n\n" + r.preview.text
|
|
457
|
+
: (r.preview.url ?? r.preview.message);
|
|
458
|
+
});
|
|
404
459
|
return 0;
|
|
405
460
|
}
|
|
406
461
|
if (sub === "source") {
|