openrich 0.0.0-stage → 0.1.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.
Files changed (65) hide show
  1. package/.env.example +23 -0
  2. package/LICENSE +21 -0
  3. package/README.md +410 -2
  4. package/assets/logo.svg +41 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +144 -0
  7. package/dist/env.d.ts +5 -0
  8. package/dist/env.js +24 -0
  9. package/dist/eval.d.ts +30 -0
  10. package/dist/eval.js +78 -0
  11. package/dist/mcp/client.d.ts +31 -0
  12. package/dist/mcp/client.js +94 -0
  13. package/dist/mcp/oauth.d.ts +13 -0
  14. package/dist/mcp/oauth.js +93 -0
  15. package/dist/mcp/server.d.ts +87 -0
  16. package/dist/mcp/server.js +125 -0
  17. package/dist/merge.d.ts +7 -0
  18. package/dist/merge.js +39 -0
  19. package/dist/providers/devplatforms.d.ts +34 -0
  20. package/dist/providers/devplatforms.js +612 -0
  21. package/dist/providers/finders.d.ts +38 -0
  22. package/dist/providers/finders.js +708 -0
  23. package/dist/providers/freetier.d.ts +9 -0
  24. package/dist/providers/freetier.js +254 -0
  25. package/dist/providers/github.d.ts +8 -0
  26. package/dist/providers/github.js +109 -0
  27. package/dist/providers/identity.d.ts +5 -0
  28. package/dist/providers/identity.js +62 -0
  29. package/dist/providers/index.d.ts +10 -0
  30. package/dist/providers/index.js +68 -0
  31. package/dist/providers/knowledge.d.ts +52 -0
  32. package/dist/providers/knowledge.js +302 -0
  33. package/dist/providers/pattern.d.ts +6 -0
  34. package/dist/providers/pattern.js +99 -0
  35. package/dist/providers/registries.d.ts +36 -0
  36. package/dist/providers/registries.js +396 -0
  37. package/dist/providers/research.d.ts +30 -0
  38. package/dist/providers/research.js +471 -0
  39. package/dist/providers/signals.d.ts +15 -0
  40. package/dist/providers/signals.js +116 -0
  41. package/dist/providers/smtp.d.ts +25 -0
  42. package/dist/providers/smtp.js +97 -0
  43. package/dist/providers/social.d.ts +37 -0
  44. package/dist/providers/social.js +657 -0
  45. package/dist/providers/verifiers.d.ts +47 -0
  46. package/dist/providers/verifiers.js +455 -0
  47. package/dist/providers/websearch.d.ts +32 -0
  48. package/dist/providers/websearch.js +346 -0
  49. package/dist/router.d.ts +31 -0
  50. package/dist/router.js +214 -0
  51. package/dist/server.d.ts +2 -0
  52. package/dist/server.js +52 -0
  53. package/dist/store.d.ts +32 -0
  54. package/dist/store.js +95 -0
  55. package/dist/types.d.ts +82 -0
  56. package/dist/types.js +1 -0
  57. package/dist/util/http.d.ts +19 -0
  58. package/dist/util/http.js +34 -0
  59. package/dist/util/match.d.ts +23 -0
  60. package/dist/util/match.js +72 -0
  61. package/dist/util/names.d.ts +11 -0
  62. package/dist/util/names.js +56 -0
  63. package/dist/util/patterns.d.ts +14 -0
  64. package/dist/util/patterns.js +61 -0
  65. package/package.json +55 -4
@@ -0,0 +1,125 @@
1
+ import { createInterface } from 'node:readline';
2
+ import { enrich, isEnabled } from "../router.js";
3
+ import { DEFAULT_PROVIDERS } from "../providers/index.js";
4
+ import { Store } from "../store.js";
5
+ /**
6
+ * openrich as an MCP server, so any agent can look people up. One JSON-RPC handler, two transports:
7
+ * stdio (`openrich mcp`, for Claude Code / Cursor / Claude Desktop) and Streamable HTTP (POST /mcp on `openrich serve`).
8
+ * Tools: enrich_person, list_sources.
9
+ */
10
+ const PROTOCOLS = ['2025-06-18', '2025-03-26', '2024-11-05'];
11
+ export const TOOLS = [
12
+ {
13
+ name: 'enrich_person',
14
+ title: 'Enrich a person',
15
+ description: 'Find a person\'s work email, title, company, LinkedIn, GitHub, X and other public profiles. ' +
16
+ 'Give a name plus a company domain or company name, or an email, or a GitHub login. ' +
17
+ 'Free sources run first; the user\'s free-tier API keys are used only for fields still missing. ' +
18
+ 'Every field comes with a confidence (0-1) and the sources that agree. Below 0.8 means unconfirmed.',
19
+ inputSchema: {
20
+ type: 'object',
21
+ properties: {
22
+ name: { type: 'string', description: 'Full name, e.g. "Jane Doe"' },
23
+ domain: { type: 'string', description: 'Company domain, e.g. "acme.com"' },
24
+ company: { type: 'string', description: 'Company name, if no domain' },
25
+ email: { type: 'string', description: 'A known email address' },
26
+ github: { type: 'string', description: 'GitHub login' },
27
+ free_only: { type: 'boolean', description: 'Use free sources only (no free-tier API credits). Default false.' },
28
+ },
29
+ anyOf: [{ required: ['name'] }, { required: ['email'] }, { required: ['github'] }],
30
+ },
31
+ annotations: { readOnlyHint: true, openWorldHint: true },
32
+ },
33
+ {
34
+ name: 'list_sources',
35
+ title: 'List sources',
36
+ description: 'List the sources openrich can use, whether each is on, and the free quota left for keyed ones.',
37
+ inputSchema: { type: 'object', properties: {} },
38
+ annotations: { readOnlyHint: true },
39
+ },
40
+ ];
41
+ /** The compact answer an agent needs: per field, the best value, its confidence and sources. */
42
+ export function summarize(r) {
43
+ const fields = {};
44
+ for (const [f, v] of Object.entries(r.best)) {
45
+ fields[f] = { value: v.value, confidence: Math.round(v.confidence * 100) / 100, sources: v.sources };
46
+ }
47
+ const used = r.trace.filter((t) => t.status === 'hit' || t.status === 'miss').length;
48
+ return { query: r.query, fields, sourcesCalled: used, cached: r.trace.some((t) => t.status === 'cached') };
49
+ }
50
+ export function createHandler(opts = {}) {
51
+ const store = opts.store ?? new Store();
52
+ const env = opts.env ?? process.env;
53
+ async function callTool(name, args) {
54
+ if (name === 'enrich_person') {
55
+ const { name: n, domain, company, email, github, free_only } = args ?? {};
56
+ if (!n && !email && !github)
57
+ return toolError('Give a name (with a domain or company), an email, or a GitHub login.');
58
+ const r = await enrich({ name: n, domain, company, email, github }, { store, env, freeTier: free_only !== true });
59
+ const s = summarize(r);
60
+ return { content: [{ type: 'text', text: JSON.stringify(s, null, 2) }], structuredContent: s };
61
+ }
62
+ if (name === 'list_sources') {
63
+ const sources = DEFAULT_PROVIDERS.map((p) => ({
64
+ id: p.id, kind: p.kind, on: isEnabled(p, env), provides: p.provides,
65
+ quotaLeft: p.quota ? `${store.quotaLeft(p.id, p.quota)}/${p.quota.limit} per ${p.quota.period}` : null,
66
+ }));
67
+ return { content: [{ type: 'text', text: JSON.stringify(sources, null, 2) }], structuredContent: { sources } };
68
+ }
69
+ return toolError(`Unknown tool: ${name}`);
70
+ }
71
+ /** One JSON-RPC message in; the reply, or null for notifications. */
72
+ return async function handle(msg) {
73
+ const reply = (result) => ({ jsonrpc: '2.0', id: msg.id ?? null, result });
74
+ const fail = (code, message) => ({ jsonrpc: '2.0', id: msg.id ?? null, error: { code, message } });
75
+ if (msg.id === undefined || msg.id === null)
76
+ return null; // notification (e.g. notifications/initialized)
77
+ try {
78
+ switch (msg.method) {
79
+ case 'initialize': {
80
+ const asked = msg.params?.protocolVersion;
81
+ return reply({
82
+ protocolVersion: PROTOCOLS.includes(asked) ? asked : PROTOCOLS[0],
83
+ capabilities: { tools: {} },
84
+ serverInfo: { name: 'openrich', version: '0.1.0' },
85
+ instructions: 'Use enrich_person to look up a person. Treat fields below 0.8 confidence as unconfirmed.',
86
+ });
87
+ }
88
+ case 'ping': return reply({});
89
+ case 'tools/list': return reply({ tools: TOOLS });
90
+ case 'tools/call': return reply(await callTool(msg.params?.name, msg.params?.arguments));
91
+ default: return fail(-32601, `Method not found: ${msg.method}`);
92
+ }
93
+ }
94
+ catch (e) {
95
+ // Tool failures are results the agent can read, not protocol errors.
96
+ if (msg.method === 'tools/call')
97
+ return reply(toolError(e.message));
98
+ return fail(-32603, e.message);
99
+ }
100
+ };
101
+ }
102
+ function toolError(text) {
103
+ return { content: [{ type: 'text', text }], isError: true };
104
+ }
105
+ /** stdio transport: one JSON-RPC message per line on stdin, replies on stdout. Logs go to stderr only. */
106
+ export function serveStdio() {
107
+ const handle = createHandler();
108
+ const rl = createInterface({ input: process.stdin });
109
+ rl.on('line', async (line) => {
110
+ if (!line.trim())
111
+ return;
112
+ let msg;
113
+ try {
114
+ msg = JSON.parse(line);
115
+ }
116
+ catch {
117
+ process.stdout.write(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } }) + '\n');
118
+ return;
119
+ }
120
+ const out = await handle(msg);
121
+ if (out)
122
+ process.stdout.write(JSON.stringify(out) + '\n');
123
+ });
124
+ rl.on('close', () => process.exit(0));
125
+ }
@@ -0,0 +1,7 @@
1
+ import type { EnrichResult, Field, Finding } from './types.ts';
2
+ export declare function normValue(field: Field, v: string): string;
3
+ /**
4
+ * Group findings by field and value. Independent sources agreeing raise confidence:
5
+ * combined = 1 - Π(1 - c_source), using each source's highest confidence for that value.
6
+ */
7
+ export declare function merge(findings: Finding[]): Pick<EnrichResult, 'best' | 'alternatives'>;
package/dist/merge.js ADDED
@@ -0,0 +1,39 @@
1
+ export function normValue(field, v) {
2
+ let x = v.trim();
3
+ if (field === 'email')
4
+ return x.toLowerCase();
5
+ if (['linkedin', 'github', 'twitter', 'website', 'photo', 'orcid', 'profile'].includes(field)) {
6
+ x = x.toLowerCase().replace(/^https?:\/\//, '').replace(/^www\./, '').replace(/\/+$/, '').replace(/^twitter\.com/, 'x.com');
7
+ return x;
8
+ }
9
+ return x.toLowerCase().replace(/\s+/g, ' ');
10
+ }
11
+ /**
12
+ * Group findings by field and value. Independent sources agreeing raise confidence:
13
+ * combined = 1 - Π(1 - c_source), using each source's highest confidence for that value.
14
+ */
15
+ export function merge(findings) {
16
+ const groups = new Map();
17
+ for (const f of findings) {
18
+ const key = `${f.field}\u0000${normValue(f.field, f.value)}`;
19
+ let g = groups.get(key);
20
+ if (!g)
21
+ groups.set(key, (g = { field: f.field, value: f.value, bySource: new Map() }));
22
+ g.bySource.set(f.source, Math.max(g.bySource.get(f.source) ?? 0, f.confidence));
23
+ }
24
+ const perField = new Map();
25
+ for (const g of groups.values()) {
26
+ const miss = [...g.bySource.values()].reduce((acc, c) => acc * (1 - Math.min(c, 0.99)), 1);
27
+ const r = { value: g.value, confidence: Math.round((1 - miss) * 1000) / 1000, sources: [...g.bySource.keys()] };
28
+ perField.set(g.field, [...(perField.get(g.field) ?? []), r]);
29
+ }
30
+ const best = {};
31
+ const alternatives = {};
32
+ for (const [field, rs] of perField) {
33
+ rs.sort((a, b) => b.confidence - a.confidence || b.sources.length - a.sources.length);
34
+ best[field] = rs[0];
35
+ if (rs.length > 1)
36
+ alternatives[field] = rs.slice(1);
37
+ }
38
+ return { best, alternatives };
39
+ }
@@ -0,0 +1,34 @@
1
+ import type { PersonQuery, Provider } from '../types.ts';
2
+ /** Candidate handles, GitHub login first, de-duplicated case-insensitively, at most 3 (be polite). */
3
+ export declare function handles(q: PersonQuery): string[];
4
+ /** Does some text link to the query's GitHub account (github.com/<login> or <login>.github.io)? */
5
+ export declare function linksGithub(text: string | null | undefined, q: PersonQuery): boolean;
6
+ /**
7
+ * The confidence rule shared by every handle-based source.
8
+ * 0.9 links back to q.github; 0.75 name matches and company mentioned; 0.6 name matches; 0 otherwise.
9
+ */
10
+ export declare function judge(q: PersonQuery, name: string | null | undefined, texts: (string | null | undefined)[]): number;
11
+ /** GitLab: username lookup works without a key (name only); GITLAB_TOKEN unlocks name search and full profiles. */
12
+ export declare const gitlabProvider: Provider;
13
+ export declare const stackexchangeProvider: Provider;
14
+ export declare const hackernewsProvider: Provider;
15
+ export declare const devtoProvider: Provider;
16
+ /** Keybase: proofs are signed statements published on each service, so linked accounts are verified. */
17
+ export declare const keybaseProvider: Provider;
18
+ /**
19
+ * npm: packages maintained by <username>; maintainer entries carry the npm account email.
20
+ * The npm user is accepted when its packages live under github.com/<q.github>/, or its email names the person.
21
+ */
22
+ export declare const npmProvider: Provider;
23
+ /** crates.io accounts are GitHub OAuth logins, so the GitHub login maps to exactly one crates.io user. */
24
+ export declare const cratesProvider: Provider;
25
+ /** RubyGems: profile shows the email only if public; accepted via gems hosted under github.com/<q.github>/ or a name-bearing email. */
26
+ export declare const rubygemsProvider: Provider;
27
+ /** MetaCPAN (CPAN authors): name search; profiles list GitHub/X/LinkedIn, plus emails and websites. */
28
+ export declare const metacpanProvider: Provider;
29
+ /** Launchpad: confirms an email belongs to a registered person (getByEmail), or finds a person by name. */
30
+ export declare const launchpadProvider: Provider;
31
+ export declare const huggingfaceProvider: Provider;
32
+ export declare const codebergProvider: Provider;
33
+ export declare const dockerhubProvider: Provider;
34
+ export declare const DEV_PROVIDERS: Provider[];