@relvehq/agent-ready 0.0.0-stage → 0.3.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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +364 -3
  3. package/SETUP.md +354 -0
  4. package/dist/bin/agent-ready.d.ts +23 -0
  5. package/dist/bin/agent-ready.js +444 -0
  6. package/dist/cli/init.d.ts +70 -0
  7. package/dist/cli/init.js +366 -0
  8. package/dist/core/accept.d.ts +8 -0
  9. package/dist/core/accept.js +76 -0
  10. package/dist/core/config.d.ts +145 -0
  11. package/dist/core/config.js +103 -0
  12. package/dist/core/convert.d.ts +22 -0
  13. package/dist/core/convert.js +334 -0
  14. package/dist/core/detect.d.ts +30 -0
  15. package/dist/core/detect.js +82 -0
  16. package/dist/core/easy.d.ts +19 -0
  17. package/dist/core/easy.js +117 -0
  18. package/dist/core/enrich.d.ts +30 -0
  19. package/dist/core/enrich.js +155 -0
  20. package/dist/core/llms.d.ts +11 -0
  21. package/dist/core/llms.js +71 -0
  22. package/dist/core/report.d.ts +15 -0
  23. package/dist/core/report.js +46 -0
  24. package/dist/core/resolve.d.ts +43 -0
  25. package/dist/core/resolve.js +204 -0
  26. package/dist/core/respond.d.ts +18 -0
  27. package/dist/core/respond.js +59 -0
  28. package/dist/core/sitemap.d.ts +31 -0
  29. package/dist/core/sitemap.js +140 -0
  30. package/dist/index.d.ts +14 -0
  31. package/dist/index.js +76 -0
  32. package/dist/next/dashboard.d.ts +14 -0
  33. package/dist/next/dashboard.js +56 -0
  34. package/dist/next/index.d.ts +42 -0
  35. package/dist/next/index.js +100 -0
  36. package/dist/next/route.d.ts +26 -0
  37. package/dist/next/route.js +167 -0
  38. package/dist/node/index.d.ts +8 -0
  39. package/dist/node/index.js +191 -0
  40. package/dist/proof/audit.d.ts +47 -0
  41. package/dist/proof/audit.js +253 -0
  42. package/dist/proof/bots.d.ts +24 -0
  43. package/dist/proof/bots.js +60 -0
  44. package/dist/proof/dashboard.d.ts +8 -0
  45. package/dist/proof/dashboard.js +77 -0
  46. package/dist/proof/hits.d.ts +18 -0
  47. package/dist/proof/hits.js +51 -0
  48. package/dist/proof/jsonl.d.ts +5 -0
  49. package/dist/proof/jsonl.js +80 -0
  50. package/dist/proof/stats.d.ts +39 -0
  51. package/dist/proof/stats.js +127 -0
  52. package/dist/refine/check.d.ts +17 -0
  53. package/dist/refine/check.js +134 -0
  54. package/dist/refine/extract.d.ts +7 -0
  55. package/dist/refine/extract.js +120 -0
  56. package/dist/refine/file-store.d.ts +6 -0
  57. package/dist/refine/file-store.js +87 -0
  58. package/dist/refine/model.d.ts +30 -0
  59. package/dist/refine/model.js +105 -0
  60. package/dist/refine/prompts.d.ts +49 -0
  61. package/dist/refine/prompts.js +178 -0
  62. package/dist/refine/refine.d.ts +38 -0
  63. package/dist/refine/refine.js +75 -0
  64. package/dist/refine/remote.d.ts +57 -0
  65. package/dist/refine/remote.js +238 -0
  66. package/dist/refine/run.d.ts +52 -0
  67. package/dist/refine/run.js +66 -0
  68. package/dist/refine/types.d.ts +17 -0
  69. package/dist/refine/types.js +8 -0
  70. package/dist/wp/relve-agent-ready/includes/class-relve-ar-admin.php +550 -0
  71. package/dist/wp/relve-agent-ready/includes/class-relve-ar-converter.php +762 -0
  72. package/dist/wp/relve-agent-ready/includes/class-relve-ar-llms.php +192 -0
  73. package/dist/wp/relve-agent-ready/includes/class-relve-ar-markdown-builder.php +455 -0
  74. package/dist/wp/relve-agent-ready/includes/class-relve-ar-negotiation.php +334 -0
  75. package/dist/wp/relve-agent-ready/includes/class-relve-ar-refiner.php +894 -0
  76. package/dist/wp/relve-agent-ready/includes/class-relve-ar-response.php +226 -0
  77. package/dist/wp/relve-agent-ready/includes/class-relve-ar-router.php +421 -0
  78. package/dist/wp/relve-agent-ready/includes/class-relve-ar-settings.php +201 -0
  79. package/dist/wp/relve-agent-ready/includes/class-relve-ar-store.php +583 -0
  80. package/dist/wp/relve-agent-ready/includes/index.php +2 -0
  81. package/dist/wp/relve-agent-ready/index.php +2 -0
  82. package/dist/wp/relve-agent-ready/readme.txt +108 -0
  83. package/dist/wp/relve-agent-ready/relve-agent-ready.php +81 -0
  84. package/dist/wp/relve-agent-ready/uninstall.php +35 -0
  85. package/package.json +64 -6
@@ -0,0 +1,52 @@
1
+ import { type RefineResult } from "./refine";
2
+ import { type PageTypeRules, type RefinePrompt } from "./prompts";
3
+ import type { CheckOptions } from "./check";
4
+ import type { ModelClient } from "./model";
5
+ export interface StoredDoc {
6
+ path: string;
7
+ url: string;
8
+ markdown: string;
9
+ sourceHash: string;
10
+ promptId: string;
11
+ generatedAt: string;
12
+ tokens: number;
13
+ }
14
+ export interface RefineStore {
15
+ /** The fingerprint the stored doc was written from, or null. */
16
+ lastHash(path: string): Promise<string | null>;
17
+ save(doc: StoredDoc): Promise<void>;
18
+ }
19
+ export interface RunOptions extends CheckOptions {
20
+ /** Public origin, e.g. "https://relvehq.com". */
21
+ site: string;
22
+ paths: string[];
23
+ /** Prompts by page type (promptsByType). */
24
+ prompts: Record<string, RefinePrompt>;
25
+ pageTypes?: PageTypeRules;
26
+ model: ModelClient;
27
+ store: RefineStore;
28
+ /** Refine even when the fingerprint is unchanged. */
29
+ force?: boolean;
30
+ /** Pages at a time. Default 2. */
31
+ concurrency?: number;
32
+ retries?: number;
33
+ fetch?: typeof fetch;
34
+ now?: () => Date;
35
+ siteName?: string;
36
+ onResult?: (r: RunItem) => void;
37
+ }
38
+ export interface RunItem extends Partial<Omit<RefineResult, "status">> {
39
+ path: string;
40
+ status: RefineResult["status"] | "no-prompt";
41
+ promptId: string | null;
42
+ saved: boolean;
43
+ }
44
+ export interface RunReport {
45
+ items: RunItem[];
46
+ counts: Record<RunItem["status"], number>;
47
+ usage: {
48
+ inputTokens: number;
49
+ outputTokens: number;
50
+ };
51
+ }
52
+ export declare function runRefine(opts: RunOptions): Promise<RunReport>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ // Refine, step 5: the runner. Refines a list of pages, skips pages whose
3
+ // fingerprint hasn't changed ("stay fresh"), saves what passes the check.
4
+ //
5
+ // await runRefine({ site, paths, prompts, model, store })
6
+ //
7
+ // The store is anything with lastHash() and save(): the file store
8
+ // (refine/file-store.ts), a database, a test double.
9
+ // NODE ONLY (through refinePage).
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.runRefine = runRefine;
12
+ const refine_1 = require("./refine");
13
+ const prompts_1 = require("./prompts");
14
+ async function runRefine(opts) {
15
+ const site = opts.site.replace(/\/+$/, "");
16
+ const items = new Array(opts.paths.length);
17
+ let next = 0;
18
+ const one = async (path) => {
19
+ const prompt = (0, prompts_1.promptFor)(path, opts.prompts, opts.pageTypes);
20
+ if (!prompt)
21
+ return { path, status: "no-prompt", promptId: null, saved: false };
22
+ const previousHash = opts.force ? null : await opts.store.lastHash(path);
23
+ const r = await (0, refine_1.refinePage)({
24
+ url: site + path,
25
+ prompt,
26
+ model: opts.model,
27
+ previousHash,
28
+ retries: opts.retries,
29
+ fetch: opts.fetch,
30
+ now: opts.now,
31
+ siteName: opts.siteName,
32
+ countTokens: opts.countTokens,
33
+ });
34
+ let saved = false;
35
+ if (r.status === "ok" && r.doc && r.input && r.generatedAt) {
36
+ await opts.store.save({
37
+ path,
38
+ url: r.url,
39
+ markdown: r.doc,
40
+ sourceHash: r.input.sourceHash,
41
+ promptId: prompt.id,
42
+ generatedAt: r.generatedAt,
43
+ tokens: r.tokens ?? 0,
44
+ });
45
+ saved = true;
46
+ }
47
+ return { ...r, path, promptId: prompt.id, saved };
48
+ };
49
+ const worker = async () => {
50
+ while (next < opts.paths.length) {
51
+ const i = next++;
52
+ const item = await one(opts.paths[i]);
53
+ items[i] = item;
54
+ opts.onResult?.(item);
55
+ }
56
+ };
57
+ await Promise.all(Array.from({ length: Math.max(1, Math.min(opts.concurrency ?? 2, opts.paths.length)) }, worker));
58
+ const counts = { ok: 0, unchanged: 0, rejected: 0, error: 0, "no-prompt": 0 };
59
+ const usage = { inputTokens: 0, outputTokens: 0 };
60
+ for (const it of items) {
61
+ counts[it.status]++;
62
+ usage.inputTokens += it.usage?.inputTokens ?? 0;
63
+ usage.outputTokens += it.usage?.outputTokens ?? 0;
64
+ }
65
+ return { items, counts, usage };
66
+ }
@@ -0,0 +1,17 @@
1
+ export interface PageLink {
2
+ url: string;
3
+ text: string;
4
+ }
5
+ /** The model's input for one page (see refine/extract.ts). */
6
+ export interface PageInput {
7
+ /** Absolute page URL. */
8
+ url: string;
9
+ text: string;
10
+ links: PageLink[];
11
+ jsonLd: unknown[];
12
+ /** SHA-256 hex of `text + "\n" + JSON.stringify(jsonLd)`. */
13
+ sourceHash: string;
14
+ mainSource: "main" | "article" | "body";
15
+ }
16
+ /** Links as the prompt's {{PAGE_LINKS}} block: "url | text" per line. */
17
+ export declare function formatLinks(links: PageLink[]): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ // Shared shapes for refine. EDGE-SAFE (no imports).
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.formatLinks = formatLinks;
5
+ /** Links as the prompt's {{PAGE_LINKS}} block: "url | text" per line. */
6
+ function formatLinks(links) {
7
+ return links.map((l) => (l.text ? `${l.url} | ${l.text}` : l.url)).join("\n");
8
+ }