@shobyde/boaz 0.0.0-stage → 0.8.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/LICENSE +21 -0
- package/README.md +422 -2
- package/dist/build/codes.d.ts +16 -0
- package/dist/build/codes.d.ts.map +1 -0
- package/dist/build/codes.js +72 -0
- package/dist/build/codes.js.map +1 -0
- package/dist/build/extract.d.ts +45 -0
- package/dist/build/extract.d.ts.map +1 -0
- package/dist/build/extract.js +484 -0
- package/dist/build/extract.js.map +1 -0
- package/dist/build/glob.d.ts +11 -0
- package/dist/build/glob.d.ts.map +1 -0
- package/dist/build/glob.js +88 -0
- package/dist/build/glob.js.map +1 -0
- package/dist/build/index.d.ts +7 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +4 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/probes.d.ts +41 -0
- package/dist/build/probes.d.ts.map +1 -0
- package/dist/build/probes.js +134 -0
- package/dist/build/probes.js.map +1 -0
- package/dist/build/report.d.ts +11 -0
- package/dist/build/report.d.ts.map +1 -0
- package/dist/build/report.js +39 -0
- package/dist/build/report.js.map +1 -0
- package/dist/cli/audit.d.ts +15 -0
- package/dist/cli/audit.d.ts.map +1 -0
- package/dist/cli/audit.js +68 -0
- package/dist/cli/audit.js.map +1 -0
- package/dist/cli/bench.d.ts +7 -0
- package/dist/cli/bench.d.ts.map +1 -0
- package/dist/cli/bench.js +147 -0
- package/dist/cli/bench.js.map +1 -0
- package/dist/cli/harness.d.ts +45 -0
- package/dist/cli/harness.d.ts.map +1 -0
- package/dist/cli/harness.js +90 -0
- package/dist/cli/harness.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +404 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/probes.d.ts +20 -0
- package/dist/cli/probes.d.ts.map +1 -0
- package/dist/cli/probes.js +27 -0
- package/dist/cli/probes.js.map +1 -0
- package/dist/cli/skill-template.d.ts +2 -0
- package/dist/cli/skill-template.d.ts.map +1 -0
- package/dist/cli/skill-template.js +254 -0
- package/dist/cli/skill-template.js.map +1 -0
- package/dist/core/actions.d.ts +67 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +357 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/define.d.ts +25 -0
- package/dist/core/define.d.ts.map +1 -0
- package/dist/core/define.js +76 -0
- package/dist/core/define.js.map +1 -0
- package/dist/core/execute.d.ts +75 -0
- package/dist/core/execute.d.ts.map +1 -0
- package/dist/core/execute.js +145 -0
- package/dist/core/execute.js.map +1 -0
- package/dist/core/index.d.ts +35 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +20 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/lemmas.d.ts +32 -0
- package/dist/core/lemmas.d.ts.map +1 -0
- package/dist/core/lemmas.js +80 -0
- package/dist/core/lemmas.js.map +1 -0
- package/dist/core/lexical-engine.d.ts +18 -0
- package/dist/core/lexical-engine.d.ts.map +1 -0
- package/dist/core/lexical-engine.js +296 -0
- package/dist/core/lexical-engine.js.map +1 -0
- package/dist/core/loop.d.ts +51 -0
- package/dist/core/loop.d.ts.map +1 -0
- package/dist/core/loop.js +432 -0
- package/dist/core/loop.js.map +1 -0
- package/dist/core/mcp.d.ts +119 -0
- package/dist/core/mcp.d.ts.map +1 -0
- package/dist/core/mcp.js +253 -0
- package/dist/core/mcp.js.map +1 -0
- package/dist/core/memory.d.ts +106 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +185 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/plan.d.ts +83 -0
- package/dist/core/plan.d.ts.map +1 -0
- package/dist/core/plan.js +258 -0
- package/dist/core/plan.js.map +1 -0
- package/dist/core/preferences.d.ts +54 -0
- package/dist/core/preferences.d.ts.map +1 -0
- package/dist/core/preferences.js +83 -0
- package/dist/core/preferences.js.map +1 -0
- package/dist/core/prompt.d.ts +23 -0
- package/dist/core/prompt.d.ts.map +1 -0
- package/dist/core/prompt.js +76 -0
- package/dist/core/prompt.js.map +1 -0
- package/dist/core/question.d.ts +96 -0
- package/dist/core/question.d.ts.map +1 -0
- package/dist/core/question.js +501 -0
- package/dist/core/question.js.map +1 -0
- package/dist/core/registry.d.ts +33 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +72 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/retriever.d.ts +48 -0
- package/dist/core/retriever.d.ts.map +1 -0
- package/dist/core/retriever.js +123 -0
- package/dist/core/retriever.js.map +1 -0
- package/dist/core/schema.d.ts +27 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +231 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/skill.d.ts +105 -0
- package/dist/core/skill.d.ts.map +1 -0
- package/dist/core/skill.js +205 -0
- package/dist/core/skill.js.map +1 -0
- package/dist/core/summarise.d.ts +52 -0
- package/dist/core/summarise.d.ts.map +1 -0
- package/dist/core/summarise.js +146 -0
- package/dist/core/summarise.js.map +1 -0
- package/dist/core/tools.d.ts +21 -0
- package/dist/core/tools.d.ts.map +1 -0
- package/dist/core/tools.js +120 -0
- package/dist/core/tools.js.map +1 -0
- package/dist/core/types.d.ts +199 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/dom/index.d.ts +22 -0
- package/dist/dom/index.d.ts.map +1 -0
- package/dist/dom/index.js +94 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/extract/index.d.ts +36 -0
- package/dist/extract/index.d.ts.map +1 -0
- package/dist/extract/index.js +86 -0
- package/dist/extract/index.js.map +1 -0
- package/dist/react/index.d.ts +52 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +131 -0
- package/dist/react/index.js.map +1 -0
- package/dist/rules/engine.d.ts +152 -0
- package/dist/rules/engine.d.ts.map +1 -0
- package/dist/rules/engine.js +364 -0
- package/dist/rules/engine.js.map +1 -0
- package/dist/rules/facts.d.ts +63 -0
- package/dist/rules/facts.d.ts.map +1 -0
- package/dist/rules/facts.js +115 -0
- package/dist/rules/facts.js.map +1 -0
- package/dist/rules/index.d.ts +10 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +5 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/knowledge.d.ts +78 -0
- package/dist/rules/knowledge.d.ts.map +1 -0
- package/dist/rules/knowledge.js +254 -0
- package/dist/rules/knowledge.js.map +1 -0
- package/dist/vite/index.d.ts +26 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +112 -0
- package/dist/vite/index.js.map +1 -0
- package/package.json +108 -4
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const ID_KEYS = ['tool', 'name', 'action', 'capability', 'capabilityId'];
|
|
2
|
+
const ARG_KEYS = ['arguments', 'args', 'parameters', 'input', 'params'];
|
|
3
|
+
function asRecord(value) {
|
|
4
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
5
|
+
? value
|
|
6
|
+
: undefined;
|
|
7
|
+
}
|
|
8
|
+
function normalize(value) {
|
|
9
|
+
const record = asRecord(value);
|
|
10
|
+
if (!record)
|
|
11
|
+
return undefined;
|
|
12
|
+
const idKey = ID_KEYS.find((key) => typeof record[key] === 'string');
|
|
13
|
+
if (!idKey)
|
|
14
|
+
return undefined;
|
|
15
|
+
const capabilityId = String(record[idKey]).trim();
|
|
16
|
+
const argKey = ARG_KEYS.find((key) => key in record);
|
|
17
|
+
let args = {};
|
|
18
|
+
if (argKey) {
|
|
19
|
+
const rawArgs = record[argKey];
|
|
20
|
+
if (typeof rawArgs === 'string') {
|
|
21
|
+
try {
|
|
22
|
+
args = asRecord(JSON.parse(rawArgs)) ?? {};
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return { kind: 'malformed', error: 'arguments were a string but not valid JSON', raw: rawArgs };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if (rawArgs === null || rawArgs === undefined) {
|
|
29
|
+
args = {};
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const parsed = asRecord(rawArgs);
|
|
33
|
+
if (!parsed) {
|
|
34
|
+
return { kind: 'malformed', error: 'arguments must be a JSON object', raw: JSON.stringify(rawArgs) };
|
|
35
|
+
}
|
|
36
|
+
args = parsed;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (capabilityId === 'route' && typeof record.route === 'string') {
|
|
40
|
+
return { kind: 'tool', capabilityId: 'navigate', args: { route: record.route } };
|
|
41
|
+
}
|
|
42
|
+
return { kind: 'tool', capabilityId, args };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Extracts one tool call from whatever a small local model actually emitted:
|
|
46
|
+
* a bare JSON object, a fenced block, a fenced block wrapped in prose, or a
|
|
47
|
+
* JSON string nested inside `arguments`.
|
|
48
|
+
*/
|
|
49
|
+
export function parseModelOutput(text) {
|
|
50
|
+
const trimmed = text.trim();
|
|
51
|
+
if (!trimmed)
|
|
52
|
+
return { kind: 'text', text: '' };
|
|
53
|
+
const fences = [...trimmed.matchAll(/```(?:json|JSON)?\s*\n?([\s\S]*?)```/g)];
|
|
54
|
+
if (fences.length > 0) {
|
|
55
|
+
for (const fence of fences) {
|
|
56
|
+
const body = (fence[1] ?? '').trim();
|
|
57
|
+
if (!body.startsWith('{') && !body.startsWith('['))
|
|
58
|
+
continue;
|
|
59
|
+
let parsed;
|
|
60
|
+
try {
|
|
61
|
+
parsed = JSON.parse(body);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return {
|
|
65
|
+
kind: 'malformed',
|
|
66
|
+
error: `the JSON block did not parse: ${error.message}`,
|
|
67
|
+
raw: body,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const normalized = normalize(parsed);
|
|
71
|
+
if (normalized)
|
|
72
|
+
return normalized;
|
|
73
|
+
return { kind: 'malformed', error: 'the JSON block had no "tool" field', raw: body };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
77
|
+
let parsed;
|
|
78
|
+
try {
|
|
79
|
+
parsed = JSON.parse(trimmed);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return {
|
|
83
|
+
kind: 'malformed',
|
|
84
|
+
error: `a JSON object was returned but did not parse: ${error.message}`,
|
|
85
|
+
raw: trimmed,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const normalized = normalize(parsed);
|
|
89
|
+
if (normalized)
|
|
90
|
+
return normalized;
|
|
91
|
+
return { kind: 'malformed', error: 'the JSON object had no "tool" field', raw: trimmed };
|
|
92
|
+
}
|
|
93
|
+
return { kind: 'text', text: trimmed };
|
|
94
|
+
}
|
|
95
|
+
/** Parses the `model_output` of a native function-calling response body. */
|
|
96
|
+
export function parseNativeToolCall(payload) {
|
|
97
|
+
const record = asRecord(payload);
|
|
98
|
+
if (!record)
|
|
99
|
+
return { kind: 'malformed', error: 'payload was not an object', raw: String(payload) };
|
|
100
|
+
const call = asRecord(record.function) ?? asRecord(record.tool_call) ?? record;
|
|
101
|
+
const name = call.name ?? record.name;
|
|
102
|
+
if (typeof name !== 'string') {
|
|
103
|
+
return { kind: 'malformed', error: 'native tool call had no name', raw: JSON.stringify(payload) };
|
|
104
|
+
}
|
|
105
|
+
const rawArgs = call.arguments ?? record.arguments ?? {};
|
|
106
|
+
let args = {};
|
|
107
|
+
if (typeof rawArgs === 'string') {
|
|
108
|
+
try {
|
|
109
|
+
args = asRecord(JSON.parse(rawArgs)) ?? {};
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return { kind: 'malformed', error: 'native tool arguments were not valid JSON', raw: rawArgs };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
args = asRecord(rawArgs) ?? {};
|
|
117
|
+
}
|
|
118
|
+
return { kind: 'tool', capabilityId: name, args };
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/core/tools.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;AACzE,MAAM,QAAQ,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAExE,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,CAAC,CAAC;IACrE,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC;IACrD,IAAI,IAAI,GAA4B,EAAE,CAAC;IACvC,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,OAAO,GAAG,MAAM,CA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,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;QAC7C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,2CAA2C,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;QACjG,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for the capability registry, the manifest, and the tool loop.
|
|
3
|
+
*/
|
|
4
|
+
import type { RegistryLookup } from './registry.js';
|
|
5
|
+
export type CapabilityKind = 'route' | 'action' | 'query' | 'knowledge';
|
|
6
|
+
/** JSON Schema draft-07 subset accepted by the runtime validator. */
|
|
7
|
+
export type JSONSchemaObject = {
|
|
8
|
+
type?: string | string[];
|
|
9
|
+
properties?: Record<string, JSONSchemaObject>;
|
|
10
|
+
required?: string[];
|
|
11
|
+
additionalProperties?: boolean | JSONSchemaObject;
|
|
12
|
+
items?: JSONSchemaObject | JSONSchemaObject[];
|
|
13
|
+
enum?: unknown[];
|
|
14
|
+
const?: unknown;
|
|
15
|
+
anyOf?: JSONSchemaObject[];
|
|
16
|
+
oneOf?: JSONSchemaObject[];
|
|
17
|
+
minimum?: number;
|
|
18
|
+
maximum?: number;
|
|
19
|
+
exclusiveMinimum?: number;
|
|
20
|
+
exclusiveMaximum?: number;
|
|
21
|
+
minLength?: number;
|
|
22
|
+
maxLength?: number;
|
|
23
|
+
pattern?: string;
|
|
24
|
+
minItems?: number;
|
|
25
|
+
maxItems?: number;
|
|
26
|
+
description?: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
default?: unknown;
|
|
29
|
+
[keyword: string]: unknown;
|
|
30
|
+
};
|
|
31
|
+
export interface ExecutionContext {
|
|
32
|
+
currentRoute: string;
|
|
33
|
+
navigate(to: string): void | Promise<void>;
|
|
34
|
+
dispatch(event: string, payload?: unknown): void;
|
|
35
|
+
read<T = unknown>(key: string): T | undefined;
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}
|
|
38
|
+
export interface CapabilityDeclaration<TParams = Record<string, unknown>, TResult = unknown> {
|
|
39
|
+
/** Stable unique identifier, e.g. "billing.open_invoices". */
|
|
40
|
+
id: string;
|
|
41
|
+
kind: CapabilityKind;
|
|
42
|
+
/** Short label a human reads on a suggestion card. */
|
|
43
|
+
title: string;
|
|
44
|
+
/** Intent-focused guidance for the model: what the user gets, not how it is built. */
|
|
45
|
+
description: string;
|
|
46
|
+
/** Extra retrieval synonyms. */
|
|
47
|
+
keywords?: string[];
|
|
48
|
+
/** Target path or pattern for route navigation. */
|
|
49
|
+
route?: string;
|
|
50
|
+
paramsSchema?: JSONSchemaObject;
|
|
51
|
+
requiresConfirmation?: boolean;
|
|
52
|
+
/** Declarative facts the assistant can quote to answer questions without driving the browser. */
|
|
53
|
+
knowledge?: string;
|
|
54
|
+
handler?: (params: TParams, ctx: ExecutionContext) => Promise<TResult> | TResult;
|
|
55
|
+
}
|
|
56
|
+
/** A capability with no runtime handler: what the build plugin emits. */
|
|
57
|
+
export type ManifestCapability = Omit<CapabilityDeclaration, 'handler'>;
|
|
58
|
+
export interface AgentManifest {
|
|
59
|
+
version: 1;
|
|
60
|
+
capabilities: ManifestCapability[];
|
|
61
|
+
}
|
|
62
|
+
export interface RuntimeSnapshot {
|
|
63
|
+
currentRoute: string;
|
|
64
|
+
/** Free-form small state the app wants the model to see (cart count, filters). */
|
|
65
|
+
state?: Record<string, unknown>;
|
|
66
|
+
}
|
|
67
|
+
export interface ChatMessage {
|
|
68
|
+
role: 'system' | 'user' | 'assistant';
|
|
69
|
+
content: string;
|
|
70
|
+
}
|
|
71
|
+
export interface ToolSpec {
|
|
72
|
+
name: string;
|
|
73
|
+
description: string;
|
|
74
|
+
parameters: JSONSchemaObject;
|
|
75
|
+
}
|
|
76
|
+
export interface EngineRequest {
|
|
77
|
+
messages: ChatMessage[];
|
|
78
|
+
tools: ToolSpec[];
|
|
79
|
+
/**
|
|
80
|
+
* Results of capabilities that ran during this turn, keyed by id. Passed
|
|
81
|
+
* structurally because the transcript version is clipped for prompt budgets;
|
|
82
|
+
* an engine that reasons over tool data needs the whole value.
|
|
83
|
+
*/
|
|
84
|
+
observations?: Record<string, unknown>;
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
}
|
|
87
|
+
export interface EngineCompletion {
|
|
88
|
+
text: string;
|
|
89
|
+
/**
|
|
90
|
+
* Steps the engine already took (a rule it applied, a fact set it read).
|
|
91
|
+
* The runtime emits them before the text so a host can show provenance.
|
|
92
|
+
*/
|
|
93
|
+
steps?: TurnStep[];
|
|
94
|
+
}
|
|
95
|
+
/** Anything that can turn messages into text: the rules engine, keyword search, a fake in tests. */
|
|
96
|
+
export interface AgentEngine {
|
|
97
|
+
readonly id: string;
|
|
98
|
+
complete(request: EngineRequest): Promise<EngineCompletion>;
|
|
99
|
+
}
|
|
100
|
+
export interface ConfirmationRequest {
|
|
101
|
+
capabilityId: string;
|
|
102
|
+
title: string;
|
|
103
|
+
description: string;
|
|
104
|
+
args: Record<string, unknown>;
|
|
105
|
+
}
|
|
106
|
+
export type TurnStep = {
|
|
107
|
+
type: 'text';
|
|
108
|
+
text: string;
|
|
109
|
+
} | {
|
|
110
|
+
type: 'inference';
|
|
111
|
+
capabilityId: string;
|
|
112
|
+
goal: string;
|
|
113
|
+
terms: string[];
|
|
114
|
+
solutions: Record<string, string>[];
|
|
115
|
+
rule?: string;
|
|
116
|
+
/** Plain-language line the app wrote for this step, if it declared one. */
|
|
117
|
+
label?: string;
|
|
118
|
+
} | {
|
|
119
|
+
type: 'navigate';
|
|
120
|
+
capabilityId: string;
|
|
121
|
+
route: string;
|
|
122
|
+
} | {
|
|
123
|
+
type: 'action';
|
|
124
|
+
capabilityId: string;
|
|
125
|
+
args: Record<string, unknown>;
|
|
126
|
+
result: unknown;
|
|
127
|
+
} | {
|
|
128
|
+
type: 'query';
|
|
129
|
+
capabilityId: string;
|
|
130
|
+
args: Record<string, unknown>;
|
|
131
|
+
result: unknown;
|
|
132
|
+
} | {
|
|
133
|
+
type: 'surface';
|
|
134
|
+
capabilityId: string;
|
|
135
|
+
messages: unknown[];
|
|
136
|
+
} | {
|
|
137
|
+
type: 'confirmation';
|
|
138
|
+
capabilityId: string;
|
|
139
|
+
approved: boolean;
|
|
140
|
+
} | {
|
|
141
|
+
type: 'validation-error';
|
|
142
|
+
capabilityId: string;
|
|
143
|
+
errors: string[];
|
|
144
|
+
retried: boolean;
|
|
145
|
+
} | {
|
|
146
|
+
type: 'error';
|
|
147
|
+
message: string;
|
|
148
|
+
capabilityId?: string;
|
|
149
|
+
};
|
|
150
|
+
export interface TurnResult {
|
|
151
|
+
/** Final assistant prose, always present (may be a fallback sentence). */
|
|
152
|
+
text: string;
|
|
153
|
+
steps: TurnStep[];
|
|
154
|
+
stoppedBy: 'final' | 'max-tool-calls' | 'aborted';
|
|
155
|
+
}
|
|
156
|
+
export interface AgentEvent {
|
|
157
|
+
type: string;
|
|
158
|
+
[key: string]: unknown;
|
|
159
|
+
}
|
|
160
|
+
export interface AgentRuntimeOptions {
|
|
161
|
+
engine: AgentEngine;
|
|
162
|
+
/** Static capabilities from the build-time manifest (or declared in code). */
|
|
163
|
+
capabilities: ManifestCapability[];
|
|
164
|
+
/** Live handlers, keyed by capability id. */
|
|
165
|
+
registry: RegistryLookup;
|
|
166
|
+
getSnapshot: () => RuntimeSnapshot;
|
|
167
|
+
navigate?: (route: string) => void | Promise<void>;
|
|
168
|
+
dispatch?: (event: string, payload?: unknown) => void;
|
|
169
|
+
confirm?: (request: ConfirmationRequest) => Promise<boolean>;
|
|
170
|
+
/** Sequential tool calls allowed per user message. Default 3. */
|
|
171
|
+
maxToolCalls?: number;
|
|
172
|
+
/** Capabilities injected into the prompt per turn. Default 8. */
|
|
173
|
+
topK?: number;
|
|
174
|
+
/** Approximate prompt budget for the capability list, in tokens. Default 1500. */
|
|
175
|
+
promptBudgetTokens?: number;
|
|
176
|
+
/** Extra system instructions appended after the generated policy. */
|
|
177
|
+
instructions?: string;
|
|
178
|
+
/**
|
|
179
|
+
* Returns extra grounding text for one turn: page content, retrieved docs, a
|
|
180
|
+
* transcript. Called with the visitor's message so the host can pick what is
|
|
181
|
+
* relevant; failures are ignored rather than breaking the turn.
|
|
182
|
+
*/
|
|
183
|
+
readContext?: (query: string) => string | Promise<string>;
|
|
184
|
+
/** Token budget for that grounding text. Default 700. */
|
|
185
|
+
contextBudgetTokens?: number;
|
|
186
|
+
/**
|
|
187
|
+
* Reveal the reply as `delta` events instead of one block. Pacing is
|
|
188
|
+
* presentation only: the text is already known when the first delta fires.
|
|
189
|
+
* Off by default.
|
|
190
|
+
*/
|
|
191
|
+
streaming?: false | {
|
|
192
|
+
chunkChars?: number;
|
|
193
|
+
paceMs?: number;
|
|
194
|
+
/** Pause before the first delta, so a host can show the trace first. */
|
|
195
|
+
leadInMs?: number;
|
|
196
|
+
};
|
|
197
|
+
onEvent?: (event: AgentEvent) => void;
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,WAAW,CAAC;AAExE,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,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C;IACnD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACtD,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7D,iEAAiE;IACjE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kFAAkF;IAClF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1D,yDAAyD;IACzD,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,SAAS,CAAC,EACN,KAAK,GACL;QACE,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,wEAAwE;QACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACN,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface DomSection {
|
|
2
|
+
/** CSS selector for the section, e.g. "#experience". */
|
|
3
|
+
selector: string;
|
|
4
|
+
/** Human label used as a heading in the prompt. */
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
export interface DomContextOptions {
|
|
8
|
+
sections: DomSection[];
|
|
9
|
+
/** Total characters kept. Default 2800, roughly 700 tokens. */
|
|
10
|
+
maxChars?: number;
|
|
11
|
+
/** Characters per section before truncation. Default 700. */
|
|
12
|
+
perSectionChars?: number;
|
|
13
|
+
/** Element to read inside. Defaults to `document`. */
|
|
14
|
+
root?: ParentNode;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns a function for `AgentRuntimeOptions.readContext`. Sections are ranked
|
|
18
|
+
* by the visitor's words, so a question about experience keeps the experience
|
|
19
|
+
* text and drops the blog when the budget is tight.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createDomContextReader(options: DomContextOptions): (query?: string) => string;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dom/index.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,UAAU;IACzB,wDAAwD;IACxD,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,sDAAsD;IACtD,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AA+CD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,iBAAiB,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,MAAM,CAmC7F"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-only helper: turns visible sections of a page into grounding text for
|
|
3
|
+
* one assistant turn. Kept in its own subpath so `@shobyde/boaz/core` stays
|
|
4
|
+
* usable in a worker or on the server, where there is no DOM.
|
|
5
|
+
*/
|
|
6
|
+
import { tokenize } from '../core/retriever.js';
|
|
7
|
+
const BLOCK = /^(ADDRESS|ARTICLE|ASIDE|BLOCKQUOTE|DD|DIV|DL|DT|FIGCAPTION|FIGURE|FOOTER|FORM|H[1-6]|HEADER|HR|LI|MAIN|NAV|OL|P|PRE|SECTION|TABLE|TD|TH|TR|UL)$/;
|
|
8
|
+
function normalize(text) {
|
|
9
|
+
return text
|
|
10
|
+
.replace(/[ \t]+/g, ' ')
|
|
11
|
+
.replace(/ *\n */g, '\n')
|
|
12
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
13
|
+
.trim();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Reads the section as text with block boundaries preserved. `innerText` is the
|
|
17
|
+
* honest source in a browser, but it does not exist in every DOM
|
|
18
|
+
* implementation, so fall back to walking the tree instead of gluing headings
|
|
19
|
+
* onto the paragraph below them.
|
|
20
|
+
*/
|
|
21
|
+
function readText(element) {
|
|
22
|
+
const inner = element.innerText;
|
|
23
|
+
if (typeof inner === 'string' && inner.trim())
|
|
24
|
+
return normalize(inner);
|
|
25
|
+
const parts = [];
|
|
26
|
+
const walk = (node) => {
|
|
27
|
+
if (node.nodeType === 3) {
|
|
28
|
+
parts.push(node.nodeValue ?? '');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (node.nodeType !== 1)
|
|
32
|
+
return;
|
|
33
|
+
const child = node;
|
|
34
|
+
const block = BLOCK.test(child.tagName);
|
|
35
|
+
if (block)
|
|
36
|
+
parts.push('\n');
|
|
37
|
+
if (child.tagName === 'BR')
|
|
38
|
+
parts.push('\n');
|
|
39
|
+
child.childNodes.forEach(walk);
|
|
40
|
+
if (block)
|
|
41
|
+
parts.push('\n');
|
|
42
|
+
};
|
|
43
|
+
element.childNodes.forEach(walk);
|
|
44
|
+
return normalize(parts.join(''));
|
|
45
|
+
}
|
|
46
|
+
function clip(text, limit) {
|
|
47
|
+
if (text.length <= limit)
|
|
48
|
+
return text;
|
|
49
|
+
const cut = text.slice(0, limit);
|
|
50
|
+
const boundary = Math.max(cut.lastIndexOf('. '), cut.lastIndexOf('\n'));
|
|
51
|
+
return `${(boundary > limit * 0.6 ? cut.slice(0, boundary + 1) : cut).trimEnd()}…`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns a function for `AgentRuntimeOptions.readContext`. Sections are ranked
|
|
55
|
+
* by the visitor's words, so a question about experience keeps the experience
|
|
56
|
+
* text and drops the blog when the budget is tight.
|
|
57
|
+
*/
|
|
58
|
+
export function createDomContextReader(options) {
|
|
59
|
+
const maxChars = options.maxChars ?? 2800;
|
|
60
|
+
const perSection = options.perSectionChars ?? 700;
|
|
61
|
+
return (query = '') => {
|
|
62
|
+
const scope = options.root ?? (typeof document === 'undefined' ? undefined : document);
|
|
63
|
+
if (!scope)
|
|
64
|
+
return '';
|
|
65
|
+
const terms = new Set(tokenize(query));
|
|
66
|
+
const found = options.sections.map((section, index) => {
|
|
67
|
+
const element = scope.querySelector(section.selector);
|
|
68
|
+
const text = element ? readText(element) : '';
|
|
69
|
+
let score = 0;
|
|
70
|
+
if (terms.size > 0 && text) {
|
|
71
|
+
const words = new Set(tokenize(`${section.label} ${text}`));
|
|
72
|
+
for (const term of terms)
|
|
73
|
+
if (words.has(term))
|
|
74
|
+
score += 1;
|
|
75
|
+
}
|
|
76
|
+
return { section, text, score, index };
|
|
77
|
+
}).filter((entry) => entry.text.length > 0);
|
|
78
|
+
if (found.length === 0)
|
|
79
|
+
return '';
|
|
80
|
+
found.sort((a, b) => b.score - a.score || a.index - b.index);
|
|
81
|
+
const blocks = [];
|
|
82
|
+
let used = 0;
|
|
83
|
+
for (const entry of found) {
|
|
84
|
+
const body = clip(entry.text, perSection);
|
|
85
|
+
const block = `### ${entry.section.label}\n${body}`;
|
|
86
|
+
if (used + block.length > maxChars && blocks.length > 0)
|
|
87
|
+
break;
|
|
88
|
+
blocks.push(block);
|
|
89
|
+
used += block.length + 2;
|
|
90
|
+
}
|
|
91
|
+
return blocks.join('\n\n');
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
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AG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YAC1C,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YACpD,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,QAAQ,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;gBAAE,MAAM;YAC/D,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field extraction: the "read the page" half of grounding.
|
|
3
|
+
*
|
|
4
|
+
* A deterministic assistant can answer from declared facts, but only for the
|
|
5
|
+
* facts someone declared. This scans text the host already has (the visible
|
|
6
|
+
* page, a README, a retrieved document) for well-known field kinds, so an
|
|
7
|
+
* undeclared value like an email address can still be answered, and cited.
|
|
8
|
+
*/
|
|
9
|
+
export type FieldKind = 'email' | 'linkedin' | 'url' | 'phone';
|
|
10
|
+
export interface ScanHit {
|
|
11
|
+
kind: FieldKind;
|
|
12
|
+
value: string;
|
|
13
|
+
/** Where it was found, for the sentence the host writes. */
|
|
14
|
+
evidence: string;
|
|
15
|
+
}
|
|
16
|
+
export interface FieldScannerOptions {
|
|
17
|
+
/** Override or extend the built-in patterns, keyed by kind. */
|
|
18
|
+
patterns?: Partial<Record<FieldKind, RegExp>>;
|
|
19
|
+
/** Kinds to look for by default. */
|
|
20
|
+
kinds?: FieldKind[];
|
|
21
|
+
}
|
|
22
|
+
/** Ordered worst-to-best: the first match wins per kind, so keep them tight. */
|
|
23
|
+
export declare const DEFAULT_PATTERNS: Record<FieldKind, RegExp>;
|
|
24
|
+
export interface FieldScanner {
|
|
25
|
+
scan(text: string, kinds?: FieldKind[]): ScanHit[];
|
|
26
|
+
kinds: FieldKind[];
|
|
27
|
+
}
|
|
28
|
+
export declare function createFieldScanner(options?: FieldScannerOptions): FieldScanner;
|
|
29
|
+
/**
|
|
30
|
+
* Which field kinds a question names. Kept deliberately small and literal:
|
|
31
|
+
* this decides whether the engine reads the page, so a false positive costs a
|
|
32
|
+
* scan and a wrong answer costs trust.
|
|
33
|
+
*/
|
|
34
|
+
export declare const FIELD_SYNONYMS: Record<FieldKind, string[]>;
|
|
35
|
+
export declare function requestedFields(query: string): FieldKind[];
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extract/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,KAAK,GAAG,OAAO,CAAC;AAE/D,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9C,oCAAoC;IACpC,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;CACrB;AAED,gFAAgF;AAChF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAMtD,CAAC;AAsBF,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAAC;IACnD,KAAK,EAAE,SAAS,EAAE,CAAC;CACpB;AAED,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,YAAY,CAuBlF;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,CAKtD,CAAC;AAEF,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAY1D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field extraction: the "read the page" half of grounding.
|
|
3
|
+
*
|
|
4
|
+
* A deterministic assistant can answer from declared facts, but only for the
|
|
5
|
+
* facts someone declared. This scans text the host already has (the visible
|
|
6
|
+
* page, a README, a retrieved document) for well-known field kinds, so an
|
|
7
|
+
* undeclared value like an email address can still be answered, and cited.
|
|
8
|
+
*/
|
|
9
|
+
/** Ordered worst-to-best: the first match wins per kind, so keep them tight. */
|
|
10
|
+
export const DEFAULT_PATTERNS = {
|
|
11
|
+
email: /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/i,
|
|
12
|
+
linkedin: /(?:https?:\/\/)?(?:[a-z]{2,3}\.)?linkedin\.com\/in\/[a-z0-9_-]+/i,
|
|
13
|
+
phone: /(?:\+?1[\s.-]?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}\b/,
|
|
14
|
+
// Last: it would otherwise swallow the email's domain or a mailto wrapper.
|
|
15
|
+
url: /https?:\/\/[^\s<>"')]+/i,
|
|
16
|
+
};
|
|
17
|
+
const CLEAN_TRAILING = /[.,;:!?)]+$/;
|
|
18
|
+
/** Trims punctuation and a `mailto:` wrapper, without touching the address. */
|
|
19
|
+
function tidy(kind, raw) {
|
|
20
|
+
let value = raw.trim().replace(CLEAN_TRAILING, '');
|
|
21
|
+
if (kind === 'email')
|
|
22
|
+
value = value.replace(/^mailto:/i, '');
|
|
23
|
+
if (kind === 'linkedin')
|
|
24
|
+
value = value.replace(/^https?:\/\//i, '').replace(/\/$/, '');
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
/** The sentence around a hit, trimmed, so a host can say where it came from. */
|
|
28
|
+
function evidenceFor(text, index, length) {
|
|
29
|
+
const before = text.lastIndexOf('.', index);
|
|
30
|
+
const start = before === -1 ? Math.max(0, index - 60) : before + 1;
|
|
31
|
+
const after = text.indexOf('.', index + length);
|
|
32
|
+
const end = after === -1 ? Math.min(text.length, index + length + 60) : after;
|
|
33
|
+
const sentence = text.slice(start, end).replace(/\s+/g, ' ').trim();
|
|
34
|
+
return sentence.length > 140 ? `${sentence.slice(0, 137)}...` : sentence;
|
|
35
|
+
}
|
|
36
|
+
export function createFieldScanner(options = {}) {
|
|
37
|
+
const patterns = { ...DEFAULT_PATTERNS, ...(options.patterns ?? {}) };
|
|
38
|
+
const kinds = options.kinds ?? Object.keys(patterns);
|
|
39
|
+
return {
|
|
40
|
+
kinds,
|
|
41
|
+
scan(text, wanted = kinds) {
|
|
42
|
+
if (!text)
|
|
43
|
+
return [];
|
|
44
|
+
const hits = [];
|
|
45
|
+
for (const kind of wanted) {
|
|
46
|
+
const pattern = patterns[kind];
|
|
47
|
+
if (!pattern)
|
|
48
|
+
continue;
|
|
49
|
+
// A fresh RegExp per call: a shared /g pattern carries lastIndex between
|
|
50
|
+
// visitors and silently skips every other match.
|
|
51
|
+
const match = new RegExp(pattern.source, pattern.flags.replace('g', '')).exec(text);
|
|
52
|
+
if (!match)
|
|
53
|
+
continue;
|
|
54
|
+
const value = tidy(kind, match[0]);
|
|
55
|
+
if (!value)
|
|
56
|
+
continue;
|
|
57
|
+
hits.push({ kind, value, evidence: evidenceFor(text, match.index, match[0].length) });
|
|
58
|
+
}
|
|
59
|
+
return hits;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Which field kinds a question names. Kept deliberately small and literal:
|
|
65
|
+
* this decides whether the engine reads the page, so a false positive costs a
|
|
66
|
+
* scan and a wrong answer costs trust.
|
|
67
|
+
*/
|
|
68
|
+
export const FIELD_SYNONYMS = {
|
|
69
|
+
email: ['email', 'e-mail', 'mail', 'mailto', 'address'],
|
|
70
|
+
linkedin: ['linkedin', 'profile', 'social'],
|
|
71
|
+
phone: ['phone', 'telephone', 'number', 'call'],
|
|
72
|
+
url: ['website', 'site', 'url', 'link'],
|
|
73
|
+
};
|
|
74
|
+
export function requestedFields(query) {
|
|
75
|
+
const words = new Set(query
|
|
76
|
+
.toLowerCase()
|
|
77
|
+
.split(/[^a-z0-9+@.-]+/)
|
|
78
|
+
.filter(Boolean));
|
|
79
|
+
const wanted = [];
|
|
80
|
+
for (const [kind, synonyms] of Object.entries(FIELD_SYNONYMS)) {
|
|
81
|
+
if (synonyms.some((word) => words.has(word)))
|
|
82
|
+
wanted.push(kind);
|
|
83
|
+
}
|
|
84
|
+
return wanted;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extract/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAkBH,gFAAgF;AAChF,MAAM,CAAC,MAAM,gBAAgB,GAA8B;IACzD,KAAK,EAAE,wCAAwC;IAC/C,QAAQ,EAAE,kEAAkE;IAC5E,KAAK,EAAE,uDAAuD;IAC9D,2EAA2E;IAC3E,GAAG,EAAE,yBAAyB;CAC/B,CAAC;AAEF,MAAM,cAAc,GAAG,aAAa,CAAC;AAErC,+EAA+E;AAC/E,SAAS,IAAI,CAAC,IAAe,EAAE,GAAW;IACxC,IAAI,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;IACnD,IAAI,IAAI,KAAK,OAAO;QAAE,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC7D,IAAI,IAAI,KAAK,UAAU;QAAE,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EA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