@elisym/cli 0.35.0 → 0.37.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.
- package/dist/index.js +202 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --no-deprecation
|
|
2
2
|
import { randomBytes, createHash } from 'node:crypto';
|
|
3
|
-
import { writeFile, readFile, realpath, stat, unlink, readdir, mkdtemp, rm, mkdir, chmod,
|
|
3
|
+
import { writeFile, readFile, realpath, stat, open, unlink, readdir, mkdtemp, rm, mkdir, chmod, rename, link } from 'node:fs/promises';
|
|
4
4
|
import { dirname, join, resolve, sep, basename, extname, relative } from 'node:path';
|
|
5
5
|
import { nip19, generateSecretKey, getPublicKey, verifyEvent } from 'nostr-tools';
|
|
6
6
|
import { bytesToHex, hexToBytes } from 'nostr-tools/utils';
|
|
7
7
|
import * as nip44 from 'nostr-tools/nip44';
|
|
8
8
|
import { finalizeEvent, generateSecretKey as generateSecretKey$1, getPublicKey as getPublicKey$1, verifyEvent as verifyEvent$1 } from 'nostr-tools/pure';
|
|
9
9
|
import Decimal2 from 'decimal.js-light';
|
|
10
|
+
import { readFileSync, constants, existsSync, readdirSync, statSync, realpathSync, renameSync, chmodSync, mkdirSync, writeFileSync, unlinkSync, appendFileSync, rmdirSync } from 'node:fs';
|
|
10
11
|
import { ReadableStream } from 'node:stream/web';
|
|
11
|
-
import { readFileSync, existsSync, readdirSync, statSync, realpathSync, renameSync, chmodSync, mkdirSync, writeFileSync, unlinkSync, appendFileSync, rmdirSync } from 'node:fs';
|
|
12
12
|
import { DEFAULTS, SolanaPaymentStrategy, validateAgentName, RELAYS, ElisymIdentity, splAssetsForNetwork, formatSol, formatAssetAmount, deleteControlCharacters, signerFromSecretKeyBase58, resolveUsdcAsset, ElisymClient, KIND_EXTERNAL_IDENTITIES, POLICY_D_TAG_PREFIX, KIND_LONG_FORM_ARTICLE, jobRequestKind, DEFAULT_KIND_OFFSET, toDTag, createBlossomTransport, generateSolanaWallet, verifyAgentIdentities, getProtocolConfig, getProtocolProgramId, calculateProtocolFee, LIMITS, makeCensor, DEFAULT_REDACT_PATHS, flattenForComparison, POLICY_T_TAG, SESSION_ID_REGEX, createSlidingWindowLimiter, excerptUntrusted, isScriptBillingExhaustedError, excerptUntrustedTail, scriptOutput, isScriptExecutionError, utf8ByteLength, readAcceptedTransports, resolveDelegationAsset, MAX_PROOF_TTL_SECS, PROOF_CLOCK_SKEW_SECS, verifyDelegationAuthProof, deriveOwnerDelegationAta, getDelegation, buildDelegatedTransfer, buildSignedPull, sendConfirmToTerminal, parseDelegatedPayment, confirmPullToTerminal, isDefinitelyUnpaid, decodeJobPayload, isLlmHealthError, BoundedSet, KIND_JOB_FEEDBACK, encodeSecretKeyBase58, GITHUB_USERNAME_REGEX, X_USERNAME_REGEX, normalizeNip05Identifier, splitNip05Identifier, clipToCodeUnits, degenerateReference, PROVIDER_REFUSED_PREFIX, PROVIDER_FAILED_MESSAGE, NATIVE_SOL, GIST_ID_REGEX, TWEET_ID_REGEX } from '@elisym/sdk';
|
|
13
13
|
import { ElisymYamlSchema, resolveInHome, resolveInProject, createAgentDir, writeYamlInitial, writeExampleSkillTemplate, writeSecrets, listAgents, loadAgent, writeYaml, agentPaths, ensureGitignoreHasX402Entries, readMediaCache, ensureGitignoreHasPrivateStateEntries, loadPoliciesFromDir, ensureGitignoreHasDelegationNoncesEntry, ensureGitignoreHasIrohEntry, ensureGitignoreHasSessionsEntry, readAgentPublic, isBlockingNodeSync, AgentNameSchema, lookupCachedUrl, newCacheEntry, isBlockingNode, writeMediaCache } from '@elisym/sdk/agent-store';
|
|
14
14
|
import { isAddress, createSolanaRpc, address, signature } from '@solana/kit';
|
|
@@ -81,7 +81,7 @@ var init_errors = __esm({
|
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
// src/commands/askr/constants.ts
|
|
84
|
-
var ASKR_COMMAND, DEADLINE_MS, ADMIN_URL, CONTACT_URL, PRICING_URL, FIND_STORE_ID_URL, UPGRADE, WIDGET_SCRIPT_URL, WIDGET_ELEMENT, API_OVERRIDE_ENV, RELAY_OVERRIDE_ENV, UNSAFE_OVERRIDE_ENV, LOCAL_HOSTS, NOT_AUTHORIZED_MESSAGE, SYNC_BUSY_MESSAGE, STORE_POLL_MS, SYNC_POLL_MS, PROBE_RETRY_MS, MIN_REAL_CALL_MS, PREVIEW_TIMEOUT_MS, NOT_AUTHORIZED_RETRY_MS, MAX_CATALOG_BODY_BYTES, MAX_AHEAD_SECS, ABSENT_WARNING_BPS, ABSENT_WARNING_COUNT, SAMPLE_SIZE, MAX_ISSUES, PROFILE_RE, DEFAULT_PROFILE, POLICY_SLUG_RE;
|
|
84
|
+
var ASKR_COMMAND, DEADLINE_MS, ADMIN_URL, CONTACT_URL, PRICING_URL, FIND_STORE_ID_URL, UPGRADE, WIDGET_SCRIPT_URL, WIDGET_ELEMENT, STORE_FILES_BASE, ASKR_SITE_URL, API_OVERRIDE_ENV, RELAY_OVERRIDE_ENV, UNSAFE_OVERRIDE_ENV, LOCAL_HOSTS, NOT_AUTHORIZED_MESSAGE, SYNC_BUSY_MESSAGE, STORE_POLL_MS, SYNC_POLL_MS, PROBE_RETRY_MS, MIN_REAL_CALL_MS, PREVIEW_TIMEOUT_MS, NOT_AUTHORIZED_RETRY_MS, MAX_CATALOG_BODY_BYTES, MAX_AHEAD_SECS, ABSENT_WARNING_BPS, ABSENT_WARNING_COUNT, SAMPLE_SIZE, MAX_ISSUES, PROFILE_RE, DEFAULT_PROFILE, POLICY_SLUG_RE;
|
|
85
85
|
var init_constants = __esm({
|
|
86
86
|
"src/commands/askr/constants.ts"() {
|
|
87
87
|
ASKR_COMMAND = "npx -y @elisym/cli@latest askr";
|
|
@@ -98,6 +98,8 @@ var init_constants = __esm({
|
|
|
98
98
|
};
|
|
99
99
|
WIDGET_SCRIPT_URL = "https://app.askr.elisym.network/widget.js";
|
|
100
100
|
WIDGET_ELEMENT = "askr-chat";
|
|
101
|
+
STORE_FILES_BASE = "https://app.askr.elisym.network/s";
|
|
102
|
+
ASKR_SITE_URL = "https://askr.elisym.network";
|
|
101
103
|
API_OVERRIDE_ENV = "ELISYM_ASKR_API";
|
|
102
104
|
RELAY_OVERRIDE_ENV = "ELISYM_ASKR_RELAY";
|
|
103
105
|
UNSAFE_OVERRIDE_ENV = "ELISYM_ASKR_UNSAFE_TEST";
|
|
@@ -493,8 +495,11 @@ function inactiveExit(view, exitCode = EXIT.LIMIT) {
|
|
|
493
495
|
fields: { status: view.status, awaitingPlan: awaitingPlanOf(view), upgrade: UPGRADE }
|
|
494
496
|
});
|
|
495
497
|
}
|
|
496
|
-
function movedExit() {
|
|
497
|
-
return new AskrExit(EXIT.REFUSED, "moved_store", {
|
|
498
|
+
function movedExit(fields) {
|
|
499
|
+
return new AskrExit(EXIT.REFUSED, "moved_store", {
|
|
500
|
+
hint: MOVED_HINT,
|
|
501
|
+
...fields === void 0 ? {} : { fields }
|
|
502
|
+
});
|
|
498
503
|
}
|
|
499
504
|
function serverMessage(result) {
|
|
500
505
|
if (result.ok) {
|
|
@@ -1261,6 +1266,7 @@ async function runInit(session, options) {
|
|
|
1261
1266
|
};
|
|
1262
1267
|
if (awaitingPlan) {
|
|
1263
1268
|
output.next = NEXT_PLAN;
|
|
1269
|
+
output.upgrade = UPGRADE;
|
|
1264
1270
|
} else if (view.status !== "active") {
|
|
1265
1271
|
output.hint = CONTACT_HINT;
|
|
1266
1272
|
}
|
|
@@ -1269,6 +1275,7 @@ async function runInit(session, options) {
|
|
|
1269
1275
|
var DEFAULT_LANGUAGE, DEFAULT_CURRENCY, LANGUAGE_RE, CURRENCY_RE, SCHEME_RE, BARE_HOST_RE, MAX_URL_CHARS, NEXT_PLAN, STOPPED_HINT;
|
|
1270
1276
|
var init_init = __esm({
|
|
1271
1277
|
"src/commands/askr/init.ts"() {
|
|
1278
|
+
init_constants();
|
|
1272
1279
|
init_errors();
|
|
1273
1280
|
init_files();
|
|
1274
1281
|
init_owner_key();
|
|
@@ -1282,7 +1289,7 @@ var init_init = __esm({
|
|
|
1282
1289
|
SCHEME_RE = /^[a-z][a-z0-9+.-]*:\/\//iu;
|
|
1283
1290
|
BARE_HOST_RE = /^[^\s/:]+\.[^\s/:]+(?::\d+)?(?:\/.*)?$/u;
|
|
1284
1291
|
MAX_URL_CHARS = 2048;
|
|
1285
|
-
NEXT_PLAN =
|
|
1292
|
+
NEXT_PLAN = `choose a plan: Free via askr plan free, only if the human chose Free; a paid plan: message us at ${CONTACT_URL} with your Store ID and the name of the plan the human chose`;
|
|
1286
1293
|
STOPPED_HINT = "report this to us with your Store ID";
|
|
1287
1294
|
}
|
|
1288
1295
|
});
|
|
@@ -1446,8 +1453,25 @@ async function readProductsFile(session, path) {
|
|
|
1446
1453
|
if (issues.length > 0) {
|
|
1447
1454
|
throw invalidFile("fix these products and run again", { issues: issues.slice(0, MAX_ISSUES) });
|
|
1448
1455
|
}
|
|
1456
|
+
const repeated = repeatedIds(items);
|
|
1457
|
+
if (repeated.length > 0) {
|
|
1458
|
+
throw invalidFile("each product needs its own d: these ids are used more than once", {
|
|
1459
|
+
repeated: repeated.slice(0, MAX_ISSUES)
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1449
1462
|
return { format: "json", items };
|
|
1450
1463
|
}
|
|
1464
|
+
function repeatedIds(items) {
|
|
1465
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1466
|
+
const repeated = /* @__PURE__ */ new Set();
|
|
1467
|
+
for (const item of items) {
|
|
1468
|
+
if (seen.has(item.d)) {
|
|
1469
|
+
repeated.add(item.d);
|
|
1470
|
+
}
|
|
1471
|
+
seen.add(item.d);
|
|
1472
|
+
}
|
|
1473
|
+
return [...repeated];
|
|
1474
|
+
}
|
|
1451
1475
|
function itemsOfCsv(session, text, currency) {
|
|
1452
1476
|
const imported = session.askr.productsFromCsv(text, currency);
|
|
1453
1477
|
if (imported.fileErrors.length > 0) {
|
|
@@ -1493,7 +1517,8 @@ async function runProducts(session, options) {
|
|
|
1493
1517
|
const file = await readProductsFile(session, options.file);
|
|
1494
1518
|
const key = await useOwnerKey(session);
|
|
1495
1519
|
const view = await readView(session);
|
|
1496
|
-
|
|
1520
|
+
const localDryRun = options.dryRun === true && view.status === "pending";
|
|
1521
|
+
if (view.status !== "active" && !localDryRun) {
|
|
1497
1522
|
throw inactiveExit(view);
|
|
1498
1523
|
}
|
|
1499
1524
|
const { config } = await readSigned(session, key.owner, key.secretKey);
|
|
@@ -1523,6 +1548,10 @@ async function runProducts(session, options) {
|
|
|
1523
1548
|
if (linkWarnings.length > 0) {
|
|
1524
1549
|
extra.urlWarnings = linkWarnings.slice(0, SAMPLE_SIZE);
|
|
1525
1550
|
}
|
|
1551
|
+
if (localDryRun) {
|
|
1552
|
+
const local = await localDiff(session, view.catalogKey, items, mode);
|
|
1553
|
+
return { exitCode: EXIT.OK, output: { ...summary, ...local, ...extra } };
|
|
1554
|
+
}
|
|
1526
1555
|
for (; ; ) {
|
|
1527
1556
|
const diff = await flow.dryRun();
|
|
1528
1557
|
if (mode === "upsert" && extra.warning === void 0) {
|
|
@@ -1566,6 +1595,22 @@ async function runProducts(session, options) {
|
|
|
1566
1595
|
};
|
|
1567
1596
|
}
|
|
1568
1597
|
}
|
|
1598
|
+
async function localDiff(session, catalogKey, items, mode) {
|
|
1599
|
+
const { listed } = await readListings(session, catalogKey);
|
|
1600
|
+
const inFile = new Set(items.map((item) => item.d));
|
|
1601
|
+
const listedIds = new Set(listed);
|
|
1602
|
+
const created = items.filter((item) => !listedIds.has(item.d)).map((item) => item.d);
|
|
1603
|
+
const hidden = mode === "replace" ? listed.filter((d) => !inFile.has(d)) : [];
|
|
1604
|
+
return {
|
|
1605
|
+
checked: "local",
|
|
1606
|
+
published: false,
|
|
1607
|
+
created: created.length,
|
|
1608
|
+
alreadyListed: items.length - created.length,
|
|
1609
|
+
hidden: hidden.length,
|
|
1610
|
+
sample: { created: created.slice(0, SAMPLE_SIZE), hidden: hidden.slice(0, SAMPLE_SIZE) },
|
|
1611
|
+
note: "the store is pending: the file is valid and nothing was published; once the plan is active, run this line again without --dry-run (the server then also checks the plan's product limit)"
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1569
1614
|
function countsOf(diff) {
|
|
1570
1615
|
return {
|
|
1571
1616
|
created: diff.created.length,
|
|
@@ -2041,6 +2086,7 @@ var init_connector = __esm({
|
|
|
2041
2086
|
// src/commands/askr/status.ts
|
|
2042
2087
|
var status_exports = {};
|
|
2043
2088
|
__export(status_exports, {
|
|
2089
|
+
BUDGET_HINT: () => BUDGET_HINT,
|
|
2044
2090
|
runStatus: () => runStatus
|
|
2045
2091
|
});
|
|
2046
2092
|
function money(value) {
|
|
@@ -2106,8 +2152,8 @@ async function probe(session, view, origin) {
|
|
|
2106
2152
|
await session.sleep(PROBE_RETRY_MS);
|
|
2107
2153
|
}
|
|
2108
2154
|
}
|
|
2109
|
-
function probeExit(session, view, probed,
|
|
2110
|
-
const fields = {
|
|
2155
|
+
function probeExit(session, view, probed, status) {
|
|
2156
|
+
const fields = { ...status, probe: probed };
|
|
2111
2157
|
switch (probed.result) {
|
|
2112
2158
|
case "ok":
|
|
2113
2159
|
return void 0;
|
|
@@ -2130,15 +2176,21 @@ function probeExit(session, view, probed, storeId) {
|
|
|
2130
2176
|
return new AskrExit(EXIT.REFUSED, "inactive", { hint: planHintOf(view), fields });
|
|
2131
2177
|
case "budget":
|
|
2132
2178
|
return new AskrExit(EXIT.LIMIT, "budget", {
|
|
2133
|
-
hint:
|
|
2134
|
-
fields
|
|
2179
|
+
hint: BUDGET_HINT,
|
|
2180
|
+
fields
|
|
2135
2181
|
});
|
|
2136
2182
|
case "moved":
|
|
2137
|
-
return movedExit();
|
|
2183
|
+
return movedExit(fields);
|
|
2138
2184
|
default:
|
|
2139
2185
|
return new AskrExit(EXIT.REFUSED, "probe_failed", { fields });
|
|
2140
2186
|
}
|
|
2141
2187
|
}
|
|
2188
|
+
function skippedProbe(view) {
|
|
2189
|
+
return view.status === "pending" ? {
|
|
2190
|
+
result: "skipped",
|
|
2191
|
+
reason: "the store is pending: the chat is not served until its plan is active"
|
|
2192
|
+
} : { result: "skipped", reason: "the store lists no origin" };
|
|
2193
|
+
}
|
|
2142
2194
|
async function runStatus(session, options) {
|
|
2143
2195
|
const key = await readOwnerKey(session.deps.home, session.profile);
|
|
2144
2196
|
if (key === void 0) {
|
|
@@ -2200,18 +2252,24 @@ async function runStatus(session, options) {
|
|
|
2200
2252
|
if (view.status !== "active") {
|
|
2201
2253
|
output.hint = planHintOf(view);
|
|
2202
2254
|
}
|
|
2255
|
+
if (options.probe !== true) {
|
|
2256
|
+
return { exitCode: EXIT.OK, output };
|
|
2257
|
+
}
|
|
2203
2258
|
const origin = config?.origins[0];
|
|
2204
|
-
if (
|
|
2259
|
+
if (view.status === "pending" || origin === void 0) {
|
|
2260
|
+
output.probe = skippedProbe(view);
|
|
2205
2261
|
return { exitCode: EXIT.OK, output };
|
|
2206
2262
|
}
|
|
2207
2263
|
const probed = await probe(session, view, origin);
|
|
2208
2264
|
output.probe = probed;
|
|
2209
|
-
const
|
|
2265
|
+
const status = Object.fromEntries(Object.entries(output).filter(([name]) => name !== "ok"));
|
|
2266
|
+
const failed = probeExit(session, view, probed, status);
|
|
2210
2267
|
if (failed !== void 0) {
|
|
2211
2268
|
throw failed;
|
|
2212
2269
|
}
|
|
2213
2270
|
return { exitCode: EXIT.OK, output };
|
|
2214
2271
|
}
|
|
2272
|
+
var BUDGET_HINT;
|
|
2215
2273
|
var init_status = __esm({
|
|
2216
2274
|
"src/commands/askr/status.ts"() {
|
|
2217
2275
|
init_connector_run();
|
|
@@ -2220,6 +2278,114 @@ var init_status = __esm({
|
|
|
2220
2278
|
init_owner_key();
|
|
2221
2279
|
init_read();
|
|
2222
2280
|
init_store();
|
|
2281
|
+
BUDGET_HINT = "the store reached its plan's monthly limit, so the chat does not answer until the plan is upgraded or the next month starts: to upgrade, message us with your Store ID (upgrade.contact)";
|
|
2282
|
+
}
|
|
2283
|
+
});
|
|
2284
|
+
function storeLlmsTxtUrl(npub) {
|
|
2285
|
+
return `${STORE_FILES_BASE}/${npub}/llms.txt`;
|
|
2286
|
+
}
|
|
2287
|
+
function storeCatalogJsonUrl(npub) {
|
|
2288
|
+
return `${STORE_FILES_BASE}/${npub}/catalog.json`;
|
|
2289
|
+
}
|
|
2290
|
+
function headingName(name) {
|
|
2291
|
+
const line = name.replace(/\s+/gu, " ").replace(/^[#\s]+/u, "").trim();
|
|
2292
|
+
return line === "" ? "This store" : line;
|
|
2293
|
+
}
|
|
2294
|
+
function siteLlmsTxtSection(npub) {
|
|
2295
|
+
return [
|
|
2296
|
+
LLMS_SECTION_HEADING,
|
|
2297
|
+
"",
|
|
2298
|
+
`- [Products and policies for AI agents](${storeLlmsTxtUrl(npub)}): every product with its price and page, and the store's policies, read-only`,
|
|
2299
|
+
`- [Catalog as JSON](${storeCatalogJsonUrl(npub)}): the same, machine-readable`,
|
|
2300
|
+
`- [Askr](${ASKR_SITE_URL}): the shopping assistant this store uses. Purchases happen on this site's product pages.`,
|
|
2301
|
+
""
|
|
2302
|
+
].join("\n");
|
|
2303
|
+
}
|
|
2304
|
+
function siteLlmsTxt(npub, storeName) {
|
|
2305
|
+
const name = headingName(storeName);
|
|
2306
|
+
return [
|
|
2307
|
+
`# ${name}`,
|
|
2308
|
+
"",
|
|
2309
|
+
`> ${name} has a shopping assistant, Askr: the chat on every page of this site answers questions about products, prices and policies.`,
|
|
2310
|
+
"",
|
|
2311
|
+
siteLlmsTxtSection(npub)
|
|
2312
|
+
].join("\n");
|
|
2313
|
+
}
|
|
2314
|
+
function notWritable(hint) {
|
|
2315
|
+
return new AskrExit(EXIT.BAD_INPUT, "file_not_writable", { hint: `--llms-txt: ${hint}` });
|
|
2316
|
+
}
|
|
2317
|
+
function codeOf(error) {
|
|
2318
|
+
return typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
2319
|
+
}
|
|
2320
|
+
async function create(path, text) {
|
|
2321
|
+
try {
|
|
2322
|
+
await writeFile(path, text, { encoding: "utf-8", flag: "wx" });
|
|
2323
|
+
return "created";
|
|
2324
|
+
} catch (error) {
|
|
2325
|
+
throw notWritable(
|
|
2326
|
+
codeOf(error) === "EEXIST" ? "something else is at that path" : "cannot write there"
|
|
2327
|
+
);
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
async function appendTo(handle, npub) {
|
|
2331
|
+
const info = await handle.stat();
|
|
2332
|
+
if (!info.isFile()) {
|
|
2333
|
+
throw notWritable("not a regular file");
|
|
2334
|
+
}
|
|
2335
|
+
if (info.size > MAX_EXISTING_LLMS_BYTES) {
|
|
2336
|
+
throw notWritable("the file there is over 1 MiB: not an llms.txt");
|
|
2337
|
+
}
|
|
2338
|
+
const existing = await handle.readFile({ encoding: "utf-8" });
|
|
2339
|
+
if (existing.includes("\0")) {
|
|
2340
|
+
throw notWritable("the file there is not text");
|
|
2341
|
+
}
|
|
2342
|
+
if (existing.includes(storeLlmsTxtUrl(npub))) {
|
|
2343
|
+
return "unchanged";
|
|
2344
|
+
}
|
|
2345
|
+
let separator = "\n\n";
|
|
2346
|
+
if (existing === "" || existing.endsWith("\n\n") || existing.endsWith("\r\n\r\n")) {
|
|
2347
|
+
separator = "";
|
|
2348
|
+
} else if (existing.endsWith("\r\n")) {
|
|
2349
|
+
separator = "\r\n";
|
|
2350
|
+
} else if (existing.endsWith("\n")) {
|
|
2351
|
+
separator = "\n";
|
|
2352
|
+
}
|
|
2353
|
+
await handle.appendFile(`${separator}${siteLlmsTxtSection(npub)}`, { encoding: "utf-8" });
|
|
2354
|
+
return "appended";
|
|
2355
|
+
}
|
|
2356
|
+
async function writeSiteLlmsTxt(path, npub, storeName) {
|
|
2357
|
+
if (basename(path) !== LLMS_FILE_NAME) {
|
|
2358
|
+
throw notWritable("name a file called llms.txt (at your site root)");
|
|
2359
|
+
}
|
|
2360
|
+
let handle;
|
|
2361
|
+
try {
|
|
2362
|
+
handle = await open(path, constants.O_RDWR | constants.O_APPEND | NO_FOLLOW);
|
|
2363
|
+
} catch (error) {
|
|
2364
|
+
const code = codeOf(error);
|
|
2365
|
+
if (code === "ENOENT") {
|
|
2366
|
+
return create(path, siteLlmsTxt(npub, storeName));
|
|
2367
|
+
}
|
|
2368
|
+
throw notWritable(
|
|
2369
|
+
code === "ELOOP" ? "a link, not a regular file" : "cannot open the file there"
|
|
2370
|
+
);
|
|
2371
|
+
}
|
|
2372
|
+
try {
|
|
2373
|
+
return await appendTo(handle, npub);
|
|
2374
|
+
} catch (error) {
|
|
2375
|
+
throw error instanceof AskrExit ? error : notWritable("cannot write there");
|
|
2376
|
+
} finally {
|
|
2377
|
+
await handle.close();
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
var LLMS_SECTION_HEADING, LLMS_FILE_NAME, MAX_EXISTING_LLMS_BYTES, NO_FOLLOW;
|
|
2381
|
+
var init_llms_txt = __esm({
|
|
2382
|
+
"src/commands/askr/llms-txt.ts"() {
|
|
2383
|
+
init_constants();
|
|
2384
|
+
init_errors();
|
|
2385
|
+
LLMS_SECTION_HEADING = "## Shopping assistant";
|
|
2386
|
+
LLMS_FILE_NAME = "llms.txt";
|
|
2387
|
+
MAX_EXISTING_LLMS_BYTES = 1024 * 1024;
|
|
2388
|
+
NO_FOLLOW = constants.O_NOFOLLOW ?? 0;
|
|
2223
2389
|
}
|
|
2224
2390
|
});
|
|
2225
2391
|
|
|
@@ -2249,13 +2415,14 @@ function cspSources(askr) {
|
|
|
2249
2415
|
{ directive: "img-src", sources: ["https:"] }
|
|
2250
2416
|
];
|
|
2251
2417
|
}
|
|
2252
|
-
async function runEmbed(session) {
|
|
2418
|
+
async function runEmbed(session, options = {}) {
|
|
2253
2419
|
const key = await useOwnerKey(session);
|
|
2254
2420
|
await readView(session);
|
|
2255
2421
|
const { config } = await readSigned(session, key.owner, key.secretKey);
|
|
2256
2422
|
if (config === void 0) {
|
|
2257
2423
|
throw new AskrExit(EXIT.BAD_INPUT, "no_settings", { hint: "run askr init first" });
|
|
2258
2424
|
}
|
|
2425
|
+
const written = options.llmsTxt === void 0 ? void 0 : await writeSiteLlmsTxt(options.llmsTxt, key.storeId, config.name);
|
|
2259
2426
|
return {
|
|
2260
2427
|
exitCode: EXIT.OK,
|
|
2261
2428
|
output: {
|
|
@@ -2266,7 +2433,10 @@ async function runEmbed(session) {
|
|
|
2266
2433
|
verificationMeta: verificationMeta(key.storeId),
|
|
2267
2434
|
csp: cspSources(session.askr),
|
|
2268
2435
|
platformHints: PLATFORM_HINTS,
|
|
2269
|
-
...config.source.kind === "admin" ? { addToCart: ADD_TO_CART } : {}
|
|
2436
|
+
...config.source.kind === "admin" ? { addToCart: ADD_TO_CART } : {},
|
|
2437
|
+
llmsTxt: siteLlmsTxt(key.storeId, config.name),
|
|
2438
|
+
llmsTxtUrl: storeLlmsTxtUrl(key.storeId),
|
|
2439
|
+
...written === void 0 ? {} : { llmsTxtFile: { path: options.llmsTxt, result: written } }
|
|
2270
2440
|
}
|
|
2271
2441
|
};
|
|
2272
2442
|
}
|
|
@@ -2275,6 +2445,7 @@ var init_embed = __esm({
|
|
|
2275
2445
|
"src/commands/askr/embed.ts"() {
|
|
2276
2446
|
init_constants();
|
|
2277
2447
|
init_errors();
|
|
2448
|
+
init_llms_txt();
|
|
2278
2449
|
init_read();
|
|
2279
2450
|
init_store();
|
|
2280
2451
|
ADD_TO_CART = `<script>
|
|
@@ -3964,7 +4135,20 @@ function registerAskr(program2, run, args, jsonErrors) {
|
|
|
3964
4135
|
askr.command("status").description("Show the store: plan, products, policies, connector, usage").option("--probe", "also check that the chat is served on the first site").option(PROFILE_FLAG, PROFILE_HELP).action(
|
|
3965
4136
|
(options) => run({ command: "status", options }, context(options))
|
|
3966
4137
|
);
|
|
3967
|
-
askr.command("embed").description(
|
|
4138
|
+
askr.command("embed").description(
|
|
4139
|
+
"Print the widget snippet, the verification meta tag, the CSP sources and the site's llms.txt"
|
|
4140
|
+
).option(
|
|
4141
|
+
"--llms-txt <path>",
|
|
4142
|
+
"write the site's llms.txt there (appends the Askr part to an existing one)"
|
|
4143
|
+
).option(PROFILE_FLAG, PROFILE_HELP).action(
|
|
4144
|
+
(options) => run(
|
|
4145
|
+
{
|
|
4146
|
+
command: "embed",
|
|
4147
|
+
options: options.llmsTxt === void 0 ? {} : { llmsTxt: options.llmsTxt }
|
|
4148
|
+
},
|
|
4149
|
+
context(options)
|
|
4150
|
+
)
|
|
4151
|
+
);
|
|
3968
4152
|
askr.command("export-key").description(
|
|
3969
4153
|
"Write the owner key as a key file for your password manager (run it yourself, never by an agent)"
|
|
3970
4154
|
).requiredOption("--out <path>", "a new file to write (never overwritten)").option(PROFILE_FLAG, PROFILE_HELP).action(
|
|
@@ -4275,7 +4459,7 @@ async function dispatch(session, invocation) {
|
|
|
4275
4459
|
}
|
|
4276
4460
|
case "embed": {
|
|
4277
4461
|
const { runEmbed: runEmbed2 } = await Promise.resolve().then(() => (init_embed(), embed_exports));
|
|
4278
|
-
return runEmbed2(session);
|
|
4462
|
+
return runEmbed2(session, invocation.options);
|
|
4279
4463
|
}
|
|
4280
4464
|
case "export-key": {
|
|
4281
4465
|
const { runExportKey: runExportKey2 } = await Promise.resolve().then(() => (init_export_key(), export_key_exports));
|