agentface 0.5.0 → 0.5.1
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 +18 -13
- package/package.json +1 -1
package/dist/agentface.mjs
CHANGED
|
@@ -34,10 +34,10 @@ function registrableOrigin(input) {
|
|
|
34
34
|
// worker/tag.js
|
|
35
35
|
var toolListUrl = (serviceOrigin, id) => `${serviceOrigin}/s/${id}.md`;
|
|
36
36
|
function siteTag(serviceOrigin, id) {
|
|
37
|
-
return `<script
|
|
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>`;
|
|
38
38
|
}
|
|
39
39
|
function siteNotice(serviceOrigin, id) {
|
|
40
|
-
return `<noscript>This site has
|
|
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
43
|
// cli/heads.mjs
|
|
@@ -246,9 +246,10 @@ ${notice ? ` ${notice}
|
|
|
246
246
|
`;
|
|
247
247
|
var GATSBY_SSR = (tag, notice) => {
|
|
248
248
|
const src = tag.match(/\bsrc="([^"]+)"/)[1];
|
|
249
|
-
const about = tag.match(/\
|
|
249
|
+
const [, attribute, about] = tag.match(/\b(data-[a-z-]+)="([^"]+)"/) ?? [];
|
|
250
250
|
const text = notice?.match(/>([^<]*)</)[1];
|
|
251
|
-
const
|
|
251
|
+
const load = tag.match(/^<script (async|defer)\b/)?.[1] ?? "defer";
|
|
252
|
+
const props = `key: 'agentface', ${load}: true, src: '${src}'${about ? `, '${attribute}': '${about}'` : ""}`;
|
|
252
253
|
return `// ${OURS}: puts the Agentface tag in every page's <head>.
|
|
253
254
|
const React = require('react');
|
|
254
255
|
|
|
@@ -282,16 +283,20 @@ async function findTags(dir) {
|
|
|
282
283
|
return tagged;
|
|
283
284
|
}
|
|
284
285
|
function madeByInit(source) {
|
|
285
|
-
const
|
|
286
|
-
const
|
|
287
|
-
|
|
286
|
+
const gatsby = (pattern) => source.match(pattern)?.[1];
|
|
287
|
+
const load = gatsby(/key: 'agentface', (async|defer): true/);
|
|
288
|
+
const src = gatsby(/\bsrc: '([^']+)'/);
|
|
289
|
+
const [, attribute, about] = source.match(/'(data-[a-z-]+)': '([^']+)'/) ?? [];
|
|
290
|
+
const text = gatsby(/createElement\('noscript', \{ key: 'agentface' \}, '([^']*)'\)/);
|
|
288
291
|
const made = [
|
|
289
|
-
[
|
|
290
|
-
[
|
|
292
|
+
[NEXT_DOCUMENT, source.match(TAG)?.[0], source.match(NOTICE)?.[0]],
|
|
293
|
+
[
|
|
294
|
+
GATSBY_SSR,
|
|
295
|
+
load && src && `<script ${load} src="${src}"${about ? ` ${attribute}="${about}"` : ""}></script>`,
|
|
296
|
+
text && `<noscript>${text}</noscript>`
|
|
297
|
+
]
|
|
291
298
|
];
|
|
292
|
-
return made.some(
|
|
293
|
-
([tag, notice]) => [NEXT_DOCUMENT, GATSBY_SSR].some((write) => source === write(tag, notice))
|
|
294
|
-
);
|
|
299
|
+
return made.some(([write, tag, notice]) => tag && source === write(tag, notice ?? null));
|
|
295
300
|
}
|
|
296
301
|
function removeTag(source) {
|
|
297
302
|
if (source.includes(OURS) && madeByInit(source)) return null;
|
|
@@ -541,7 +546,7 @@ function prBody(site, files2, service = DEFAULT_SERVICE) {
|
|
|
541
546
|
const notice = site.notice ? ` A \`<noscript>\` line first in the body links agents that read pages without running them, and so never get the tools, to a list of them. Browsers that run scripts don't show it.` : "";
|
|
542
547
|
return `Adds the Agentface tag to ${site.origin}, so AI agents that use the site in a browser get tools made for them.
|
|
543
548
|
|
|
544
|
-
**What it does.** It changes ${files2.map((file) => `\`${file}\``).join(", ")}. One \`<script
|
|
549
|
+
**What it does.** It changes ${files2.map((file) => `\`${file}\``).join(", ")}. One \`<script defer>\` line in the head loads ${src} on every page. It gives browser agents tools for this site (read a page as Markdown, search the site, fill in forms, close pop-ups) and reports how agents use them: which tools, how long they took and their error codes, never what anyone typed or read.${notice} People visiting the site see no change, and it sets no cookies.
|
|
545
550
|
|
|
546
551
|
**Check it.** ${nextSteps(site, service)}
|
|
547
552
|
|