agentface 0.5.1 → 0.5.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.
- package/dist/agentface.mjs +46 -13
- package/package.json +6 -1
package/dist/agentface.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// cli/agentface.
|
|
3
|
+
// cli/agentface.mts
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
|
|
6
|
-
// cli/init.
|
|
6
|
+
// cli/init.mts
|
|
7
7
|
import { execFile as execFile2 } from "node:child_process";
|
|
8
8
|
import { mkdir, readFile as readFile2, rm, writeFile } from "node:fs/promises";
|
|
9
9
|
import path2 from "node:path";
|
|
10
10
|
|
|
11
|
-
// worker/origin.
|
|
11
|
+
// worker/origin.ts
|
|
12
12
|
var PRIVATE_NAMES = /(?:^|\.)(?:localhost|local|internal|lan|intranet|corp|home|arpa)$/;
|
|
13
13
|
function registrableOrigin(input) {
|
|
14
14
|
const text = String(input ?? "").trim();
|
|
@@ -31,7 +31,7 @@ function registrableOrigin(input) {
|
|
|
31
31
|
return origin;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// worker/tag.
|
|
34
|
+
// worker/tag.ts
|
|
35
35
|
var toolListUrl = (serviceOrigin, id) => `${serviceOrigin}/s/${id}.md`;
|
|
36
36
|
function siteTag(serviceOrigin, id) {
|
|
37
37
|
return `<script defer src="${serviceOrigin}/s/${id}.js" data-api="This site has an API in its pages. What each function returns: ${toolListUrl(serviceOrigin, id)}"></script>`;
|
|
@@ -40,10 +40,24 @@ function siteNotice(serviceOrigin, id) {
|
|
|
40
40
|
return `<noscript>This site has an API that runs in its pages, in a browser. What each function returns: ${toolListUrl(serviceOrigin, id)}</noscript>`;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
// cli/heads.
|
|
43
|
+
// cli/heads.mts
|
|
44
44
|
import { execFile } from "node:child_process";
|
|
45
45
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
46
46
|
import path from "node:path";
|
|
47
|
+
|
|
48
|
+
// worker/head.ts
|
|
49
|
+
var ATTRIBUTES = String.raw`(?:\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}|"[^"]*"|'[^']*'|[^>"'{/]|\/(?!>))*`;
|
|
50
|
+
var HEAD_END = new RegExp(
|
|
51
|
+
String.raw`<!--[\s\S]*?(?:-->|$)|<(script|style|template|textarea|title|noscript)\b${ATTRIBUTES}(?:\/>|>[\s\S]*?(?:<\/\1\s*>|$))|<\/head\s*>|<body[\s/>]`,
|
|
52
|
+
"gi"
|
|
53
|
+
);
|
|
54
|
+
function headEnd(html) {
|
|
55
|
+
HEAD_END.lastIndex = 0;
|
|
56
|
+
for (let m; m = HEAD_END.exec(html); ) if (!m[1] && !m[0].startsWith("<!--")) return m.index;
|
|
57
|
+
return -1;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// cli/heads.mts
|
|
47
61
|
var EXTENSIONS = [
|
|
48
62
|
"html",
|
|
49
63
|
"htm",
|
|
@@ -122,7 +136,11 @@ var exists = (file) => stat(file).then(
|
|
|
122
136
|
() => false
|
|
123
137
|
);
|
|
124
138
|
var KEY = /\/s\/(site-[a-z0-9-]+)\.js(?=[?#"'`\s]|$)/;
|
|
125
|
-
var
|
|
139
|
+
var ATTRIBUTES2 = String.raw`(?:\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}|[^>])*?`;
|
|
140
|
+
var TAG = new RegExp(
|
|
141
|
+
`<script\\b${ATTRIBUTES2}${KEY.source}${ATTRIBUTES2}(?:\\/>|>\\s*<\\/script\\s*>)`,
|
|
142
|
+
"gi"
|
|
143
|
+
);
|
|
126
144
|
var NOTICE = /<noscript\b[^>]*>[^<]*\/s\/(site-[a-z0-9-]+)\.md[^<]*<\/noscript\s*>/i;
|
|
127
145
|
var BODY = /<body(?=[\s>/])(?:<\?[\s\S]*?\?>|<%[\s\S]*?%>|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}|"[^"]*"|'[^']*'|[^>])*>/i;
|
|
128
146
|
var onItsLine = (pattern) => new RegExp(`(\\r?\\n[ \\t]*)?${pattern.source}`, "gi");
|
|
@@ -146,7 +164,8 @@ function addTag(source, tag) {
|
|
|
146
164
|
});
|
|
147
165
|
if (!first) return replaced;
|
|
148
166
|
const eol = source.includes("\r\n") ? "\r\n" : "\n";
|
|
149
|
-
const
|
|
167
|
+
const at = headEnd(source);
|
|
168
|
+
const close = at !== -1 && /^<\/head\s*>/i.test(source.slice(at)) ? at : -1;
|
|
150
169
|
if (close !== -1) {
|
|
151
170
|
const lineStart = source.lastIndexOf("\n", close - 1) + 1;
|
|
152
171
|
const before = source.slice(lineStart, close);
|
|
@@ -386,7 +405,7 @@ async function findHeads(dir) {
|
|
|
386
405
|
return { framework, heads, bodies, creates, key: sources.map(tagKey).find(Boolean) ?? null };
|
|
387
406
|
}
|
|
388
407
|
|
|
389
|
-
// cli/init.
|
|
408
|
+
// cli/init.mts
|
|
390
409
|
var DEFAULT_SERVICE = "https://cdn.agentfacehq.com";
|
|
391
410
|
var BRANCH = "agentface";
|
|
392
411
|
var readJson = async (file) => JSON.parse(await readFile2(file, "utf8").catch(() => "null"));
|
|
@@ -468,14 +487,26 @@ function run(command, args, { cwd }) {
|
|
|
468
487
|
return new Promise((resolve, reject) => {
|
|
469
488
|
execFile2(command, args, { cwd }, (error, stdout, stderr) => {
|
|
470
489
|
if (error)
|
|
471
|
-
reject(
|
|
490
|
+
reject(
|
|
491
|
+
new Error(`${command} ${args.join(" ")} failed: ${(stderr || error.message).trim()}`)
|
|
492
|
+
);
|
|
472
493
|
else resolve(stdout.trim());
|
|
473
494
|
});
|
|
474
495
|
});
|
|
475
496
|
}
|
|
476
497
|
var bare = (origin) => origin.replace(/^https:\/\/www\./, "https://");
|
|
477
498
|
var sameSite = (a, b) => bare(a) === bare(b);
|
|
478
|
-
async function siteFor({
|
|
499
|
+
async function siteFor({
|
|
500
|
+
id,
|
|
501
|
+
url,
|
|
502
|
+
dir,
|
|
503
|
+
found,
|
|
504
|
+
service,
|
|
505
|
+
fetcher,
|
|
506
|
+
exec,
|
|
507
|
+
dryRun,
|
|
508
|
+
log
|
|
509
|
+
}) {
|
|
479
510
|
let origin;
|
|
480
511
|
if (url) {
|
|
481
512
|
try {
|
|
@@ -539,7 +570,7 @@ var serviceFlag = (service) => service === DEFAULT_SERVICE ? "" : ` --service ${
|
|
|
539
570
|
var list = (files2) => files2.length <= 3 ? files2.join(", ") : `${files2.slice(0, 3).join(", ")} and ${files2.length - 3} more`;
|
|
540
571
|
function nextSteps(site, service) {
|
|
541
572
|
const check2 = `npx agentface check${serviceFlag(service)}`;
|
|
542
|
-
return site.expiresAt ? `Deploy it as usual, then run \`${check2}\` here: once ${site.origin}'s homepage has the tag, that confirms the site is yours. Agentface also confirms it by itself when the site's first events arrive, but a quiet site may send none in time: until it's confirmed, Agentface deletes ${site.id} at ${when(site.expiresAt)}. If that happens first, run \`npx agentface init\` again.` : `Deploy it as usual. \`${check2}\` shows whether ${site.origin}'s homepage has the tag.`;
|
|
573
|
+
return site.expiresAt ? `Deploy it as usual, then run \`${check2}\` here: once ${site.origin}'s homepage has the tag, in its HTML or in the Google Tag Manager container it loads, that confirms the site is yours. Agentface also confirms it by itself when the site's first events arrive, but a quiet site may send none in time: until it's confirmed, Agentface deletes ${site.id} at ${when(site.expiresAt)}. If that happens first, run \`npx agentface init\` again.` : `Deploy it as usual. \`${check2}\` shows whether ${site.origin}'s homepage has the tag.`;
|
|
543
574
|
}
|
|
544
575
|
function prBody(site, files2, service = DEFAULT_SERVICE) {
|
|
545
576
|
const src = site.tag.match(/\bsrc="([^"]+)"/)?.[1];
|
|
@@ -553,6 +584,7 @@ function prBody(site, files2, service = DEFAULT_SERVICE) {
|
|
|
553
584
|
**Uninstall.** Revert this pull request, or delete ${site.notice ? "the two lines" : "the line"}.
|
|
554
585
|
`;
|
|
555
586
|
}
|
|
587
|
+
var GTM_HOW = "Can't change the site's code? Add the same line in Google Tag Manager instead: Tags > New > Custom HTML, paste it, set the trigger to Initialization - All Pages, then Submit and Publish the container.";
|
|
556
588
|
function noticeByHand(site, noticed, log) {
|
|
557
589
|
if (site.notice && !noticed.includes(site.id))
|
|
558
590
|
log(
|
|
@@ -584,6 +616,7 @@ function byHand2({ manual, tagged, noticed }, site, service, dryRun, log) {
|
|
|
584
616
|
${site.tag}
|
|
585
617
|
`
|
|
586
618
|
);
|
|
619
|
+
if (!old.length) log(GTM_HOW);
|
|
587
620
|
noticeByHand(site, noticed, log);
|
|
588
621
|
log(nextSteps(site, service));
|
|
589
622
|
return { site, files: [], written: false };
|
|
@@ -766,7 +799,7 @@ async function uninstall({
|
|
|
766
799
|
return { files: files2, deleted, byHand: byHand3 };
|
|
767
800
|
}
|
|
768
801
|
|
|
769
|
-
// cli/agentface.
|
|
802
|
+
// cli/agentface.mts
|
|
770
803
|
var HELP = `Usage:
|
|
771
804
|
agentface init [<site-key>] Add the Agentface tag to the pages of the site in this
|
|
772
805
|
folder. Without a site key, registers the site first.
|
|
@@ -823,7 +856,7 @@ async function main(argv, { log = console.log, dir = process.cwd(), fetch: fetch
|
|
|
823
856
|
${HELP}`);
|
|
824
857
|
}
|
|
825
858
|
|
|
826
|
-
// cli/bin.
|
|
859
|
+
// cli/bin.mts
|
|
827
860
|
main(process.argv.slice(2)).then(
|
|
828
861
|
(code) => {
|
|
829
862
|
process.exitCode = code;
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentface",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Add the Agentface tag to a website's pages, so AI agents get tools made for it.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/agentfacehq/agentface-app.git",
|
|
8
|
+
"directory": "adapter/cli"
|
|
9
|
+
},
|
|
5
10
|
"bin": {
|
|
6
11
|
"agentface": "dist/agentface.mjs"
|
|
7
12
|
},
|