@appinternalleads/ui 0.3.0 → 0.4.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/cjs/agent/base.js +25 -0
- package/dist/cjs/agent/base.js.map +1 -0
- package/dist/cjs/agent/catalog.js +0 -32
- package/dist/cjs/agent/catalog.js.map +1 -1
- package/dist/cjs/agent/core.js +22 -20
- package/dist/cjs/agent/core.js.map +1 -1
- package/dist/cjs/agent/index.js +6 -5
- package/dist/cjs/agent/index.js.map +1 -1
- package/dist/cjs/agent/search/document.js +50 -0
- package/dist/cjs/agent/search/document.js.map +1 -0
- package/dist/cjs/agent/search/embedding.js +107 -0
- package/dist/cjs/agent/search/embedding.js.map +1 -0
- package/dist/cjs/agent/search/index.js +25 -0
- package/dist/cjs/agent/search/index.js.map +1 -0
- package/dist/cjs/agent/search/lexical.js +28 -0
- package/dist/cjs/agent/search/lexical.js.map +1 -0
- package/dist/cjs/agent/search/normalize.js +15 -0
- package/dist/cjs/agent/search/normalize.js.map +1 -0
- package/dist/cjs/agent/search/search.js +123 -0
- package/dist/cjs/agent/search/search.js.map +1 -0
- package/dist/cjs/agent/search/searchIndex.js +120 -0
- package/dist/cjs/agent/search/searchIndex.js.map +1 -0
- package/dist/cjs/agent/search/types.js +8 -0
- package/dist/cjs/agent/search/types.js.map +1 -0
- package/dist/cjs/agent/search/weights.js +34 -0
- package/dist/cjs/agent/search/weights.js.map +1 -0
- package/dist/cjs/agent/search/wordvectors.json +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/agent/base.d.ts +11 -0
- package/dist/esm/agent/base.d.ts.map +1 -0
- package/dist/esm/agent/base.js +11 -0
- package/dist/esm/agent/base.js.map +1 -0
- package/dist/esm/agent/catalog.d.ts +0 -8
- package/dist/esm/agent/catalog.d.ts.map +1 -1
- package/dist/esm/agent/catalog.js +0 -31
- package/dist/esm/agent/catalog.js.map +1 -1
- package/dist/esm/agent/core.d.ts +6 -7
- package/dist/esm/agent/core.d.ts.map +1 -1
- package/dist/esm/agent/core.js +6 -7
- package/dist/esm/agent/core.js.map +1 -1
- package/dist/esm/agent/index.d.ts +6 -5
- package/dist/esm/agent/index.d.ts.map +1 -1
- package/dist/esm/agent/index.js +6 -5
- package/dist/esm/agent/index.js.map +1 -1
- package/dist/esm/agent/search/document.d.ts +6 -0
- package/dist/esm/agent/search/document.d.ts.map +1 -0
- package/dist/esm/agent/search/document.js +46 -0
- package/dist/esm/agent/search/document.js.map +1 -0
- package/dist/esm/agent/search/embedding.d.ts +31 -0
- package/dist/esm/agent/search/embedding.d.ts.map +1 -0
- package/dist/esm/agent/search/embedding.js +103 -0
- package/dist/esm/agent/search/embedding.js.map +1 -0
- package/dist/esm/agent/search/index.d.ts +10 -0
- package/dist/esm/agent/search/index.d.ts.map +1 -0
- package/dist/esm/agent/search/index.js +17 -0
- package/dist/esm/agent/search/index.js.map +1 -0
- package/dist/esm/agent/search/lexical.d.ts +3 -0
- package/dist/esm/agent/search/lexical.d.ts.map +1 -0
- package/dist/esm/agent/search/lexical.js +25 -0
- package/dist/esm/agent/search/lexical.js.map +1 -0
- package/dist/esm/agent/search/normalize.d.ts +13 -0
- package/dist/esm/agent/search/normalize.d.ts.map +1 -0
- package/dist/esm/agent/search/normalize.js +12 -0
- package/dist/esm/agent/search/normalize.js.map +1 -0
- package/dist/esm/agent/search/search.d.ts +42 -0
- package/dist/esm/agent/search/search.d.ts.map +1 -0
- package/dist/esm/agent/search/search.js +119 -0
- package/dist/esm/agent/search/search.js.map +1 -0
- package/dist/esm/agent/search/searchIndex.d.ts +42 -0
- package/dist/esm/agent/search/searchIndex.d.ts.map +1 -0
- package/dist/esm/agent/search/searchIndex.js +114 -0
- package/dist/esm/agent/search/searchIndex.js.map +1 -0
- package/dist/esm/agent/search/types.d.ts +67 -0
- package/dist/esm/agent/search/types.d.ts.map +1 -0
- package/dist/esm/agent/search/types.js +7 -0
- package/dist/esm/agent/search/types.js.map +1 -0
- package/dist/esm/agent/search/weights.d.ts +22 -0
- package/dist/esm/agent/search/weights.d.ts.map +1 -0
- package/dist/esm/agent/search/weights.js +31 -0
- package/dist/esm/agent/search/weights.js.map +1 -0
- package/dist/esm/agent/search/wordvectors.json +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -1
- package/src/agent/base.ts +17 -0
- package/src/agent/catalog.ts +0 -32
- package/src/agent/core.ts +6 -14
- package/src/agent/index.ts +6 -5
- package/src/agent/search/document.ts +46 -0
- package/src/agent/search/embedding.ts +95 -0
- package/src/agent/search/index.ts +20 -0
- package/src/agent/search/lexical.ts +25 -0
- package/src/agent/search/normalize.ts +17 -0
- package/src/agent/search/search.ts +148 -0
- package/src/agent/search/searchIndex.ts +107 -0
- package/src/agent/search/types.ts +68 -0
- package/src/agent/search/weights.ts +32 -0
- package/src/index.ts +1 -1
- package/tools/ask/dist/components.mjs +348 -12
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **Component search — its internal types.** None of this is part of the agent contract: the agent
|
|
3
|
+
* calls `searchComponents(query)` and gets cards. How candidates are found — lexical, semantic,
|
|
4
|
+
* in memory or not — can change without it knowing.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Turns text into vectors. Swap it for a hosted model without touching the search. */
|
|
8
|
+
export interface EmbeddingProvider {
|
|
9
|
+
/** Changes whenever the vectors would: part of the index version. */
|
|
10
|
+
readonly id: string;
|
|
11
|
+
embed(texts: readonly string[]): Float32Array[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The same, for a provider that has to wait (a hosted embedding API). */
|
|
15
|
+
export interface AsyncEmbeddingProvider {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
embed(texts: readonly string[]): Promise<Float32Array[]>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** What each piece of a component's search document says about it. */
|
|
21
|
+
export type FieldType = 'name' | 'purpose' | 'signal' | 'useWhen' | 'scenario' | 'action' | 'state' | 'event' | 'data';
|
|
22
|
+
|
|
23
|
+
/** A component, as search sees it: what problem it solves (positive) and what it is not for (negative). Built from its capability — nothing is written for search alone. */
|
|
24
|
+
export type SearchDocument = {
|
|
25
|
+
component: string;
|
|
26
|
+
/** Catalogue order: the stable tie-break. */
|
|
27
|
+
order: number;
|
|
28
|
+
positive: { type: FieldType; text: string }[];
|
|
29
|
+
negative: { text: string }[];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type SearchWeights = {
|
|
33
|
+
/** How much each kind of field counts when it is the closest to the query (0 leaves it out). */
|
|
34
|
+
fields: Record<FieldType, number>;
|
|
35
|
+
/** The semantic score is the mean of the best `topK` field similarities. */
|
|
36
|
+
topK: number;
|
|
37
|
+
/** How hard a query nearer to what a component is *not* for pushes it down. */
|
|
38
|
+
negative: number;
|
|
39
|
+
/** Before comparing: subtract the catalogue's mean vector (`mean`), and also its first principal component (`pc`) — what every document shares. */
|
|
40
|
+
centre: 'none' | 'mean' | 'pc';
|
|
41
|
+
semantic: number;
|
|
42
|
+
lexical: number;
|
|
43
|
+
/** The lexical score saturates: `s / (s + lexicalHalf)`. */
|
|
44
|
+
lexicalHalf: number;
|
|
45
|
+
/** Below this final score a component is not a candidate. */
|
|
46
|
+
minScore: number;
|
|
47
|
+
/** …nor if it scores below this share of the best one. */
|
|
48
|
+
relative: number;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type ScoreBreakdown = {
|
|
52
|
+
component: string;
|
|
53
|
+
semantic: number | null;
|
|
54
|
+
negative: number | null;
|
|
55
|
+
lexical: number;
|
|
56
|
+
/** 1 when the component passes the request's filters (kinds), else 0. */
|
|
57
|
+
metadata: number;
|
|
58
|
+
/** 1 when the host may use it, else 0. */
|
|
59
|
+
availability: number;
|
|
60
|
+
final: number;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type SearchOptions = {
|
|
64
|
+
/** Host policy: only these components may be offered. Absent → every approved component. */
|
|
65
|
+
available?: readonly string[];
|
|
66
|
+
/** Only components of these kinds. */
|
|
67
|
+
kinds?: readonly string[];
|
|
68
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { SearchWeights } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* **The ranking weights — measured, not guessed.** Chosen on the dev half of the evaluation set
|
|
5
|
+
* (`tests/agent/search-eval.ts`) with `tools/search/tune.ts` and a threshold sweep; the test half is
|
|
6
|
+
* reported, never tuned on. The record of why is in docs/DECISIONS.md §19.
|
|
7
|
+
*
|
|
8
|
+
* - Every document field counts; the ones about what a person does with the component (actions,
|
|
9
|
+
* states, events, data) a little less than what it is for.
|
|
10
|
+
* - The semantic score is the mean of the three closest fields, after removing the catalogue mean.
|
|
11
|
+
* - A query closer to a component's `avoidWhen` than to anything it is for is pushed down by half
|
|
12
|
+
* the difference.
|
|
13
|
+
* - Lexical matching adds up to 0.3 — a confident phrase or name match keeps its place; a shared
|
|
14
|
+
* word alone cannot outvote meaning.
|
|
15
|
+
* - A candidate needs 0.3, and 60% of the best — so an ambiguous request keeps its alternatives and
|
|
16
|
+
* a clear one does not trail five weak ones. (Off-topic and on-topic scores overlap; 0.3 rejects
|
|
17
|
+
* about half the off-topic requests without losing on-topic ones.)
|
|
18
|
+
*
|
|
19
|
+
* Measured and not adopted: word-level alignment, reciprocal rank fusion, hubness (CSLS) correction
|
|
20
|
+
* and principal-component removal — none beat this on the development data.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_WEIGHTS: SearchWeights = {
|
|
23
|
+
fields: { name: 1, purpose: 1, signal: 1, useWhen: 1, scenario: 1, action: 0.8, state: 0.8, event: 0.8, data: 0.8 },
|
|
24
|
+
topK: 3,
|
|
25
|
+
negative: 0.5,
|
|
26
|
+
centre: 'mean',
|
|
27
|
+
semantic: 1,
|
|
28
|
+
lexical: 0.3,
|
|
29
|
+
lexicalHalf: 6,
|
|
30
|
+
minScore: 0.3,
|
|
31
|
+
relative: 0.6,
|
|
32
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -16,5 +16,5 @@ export * from './widgets';
|
|
|
16
16
|
nothing is implemented. See docs/architecture/COMPONENT-FAMILIES.md. */
|
|
17
17
|
export * from './components';
|
|
18
18
|
export * from './sheets';
|
|
19
|
-
/* The agent component contract:
|
|
19
|
+
/* The agent component contract for the renderer: AgentComponent, describe, render/1 validation, result/1. Search is in `@appinternalleads/ui/agent`. */
|
|
20
20
|
export * from './agent';
|