@absolutejs/search 0.1.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/CHANGELOG.md +13 -0
- package/LICENSE +90 -0
- package/README.md +13 -0
- package/changelog.json +16 -0
- package/dist/brave.d.ts +11 -0
- package/dist/brave.js +232 -0
- package/dist/cache.d.ts +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +126 -0
- package/dist/manifest.d.ts +9 -0
- package/dist/manifest.js +296 -0
- package/dist/manifest.json +16 -0
- package/dist/types.d.ts +70 -0
- package/package.json +58 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@absolutejs/search`.
|
|
4
|
+
|
|
5
|
+
This file is generated by `absolute-changelog` from the entries in
|
|
6
|
+
`changelog/`. Edit an entry, not this file — and add new ones under
|
|
7
|
+
`changelog/unreleased/`.
|
|
8
|
+
|
|
9
|
+
## 0.1.0 — 2026-09-24
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Provider-neutral search evidence, Brave Web and LLM Context adapters, explicit attempt outcomes and scoped caching**
|
package/LICENSE
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
**Licensor:** Alex Kahn
|
|
4
|
+
|
|
5
|
+
**Licensed Work:** @absolutejs/search (https://github.com/absolutejs/search)
|
|
6
|
+
|
|
7
|
+
**Change Date:** September 24, 2030
|
|
8
|
+
|
|
9
|
+
**Change License:** Apache License, Version 2.0
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Terms
|
|
14
|
+
|
|
15
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
16
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
17
|
+
Licensor may make an Additional Use Grant, permitting limited production use.
|
|
18
|
+
|
|
19
|
+
### Additional Use Grant
|
|
20
|
+
|
|
21
|
+
You may use the Licensed Work in production, provided your use does not include
|
|
22
|
+
any of the following:
|
|
23
|
+
|
|
24
|
+
1. **Offering a Competing Service.** You may not offer the Licensed Work, or
|
|
25
|
+
any derivative or substantial portion of it, to third parties as a hosted or
|
|
26
|
+
managed B2B contact-discovery, lead-generation, prospecting, or sales-
|
|
27
|
+
intelligence service (including, but not limited to, services like Apollo,
|
|
28
|
+
ZoomInfo, Clay, Clearbit, Lusha, RocketReach, or Seamless.ai). This includes
|
|
29
|
+
any product whose primary value to its users is the functionality the
|
|
30
|
+
Licensed Work provides.
|
|
31
|
+
|
|
32
|
+
2. **Resale or Redistribution as a Standalone Product.** You may not sell,
|
|
33
|
+
license, or distribute the Licensed Work, or any derivative or fork of it,
|
|
34
|
+
as a standalone commercial product.
|
|
35
|
+
|
|
36
|
+
3. **Removal of Attribution.** Any derivative work, fork, or redistribution of
|
|
37
|
+
the Licensed Work must prominently credit AbsoluteJS and include a link to
|
|
38
|
+
the original project repository (https://github.com/absolutejs/discover).
|
|
39
|
+
|
|
40
|
+
For clarity, the following uses are expressly permitted:
|
|
41
|
+
|
|
42
|
+
- Using the Licensed Work to build and operate your own applications, websites,
|
|
43
|
+
internal tools, or SaaS products (whether commercial or non-commercial), so
|
|
44
|
+
long as the Licensed Work itself is not the primary product you are selling.
|
|
45
|
+
- Using the Licensed Work as a dependency in commercial software you build and
|
|
46
|
+
sell, as long as the software is not itself a competing managed service of
|
|
47
|
+
the kind described in clause 1.
|
|
48
|
+
- Providing consulting, development, or professional services to clients using
|
|
49
|
+
the Licensed Work.
|
|
50
|
+
- Forking and modifying the Licensed Work for your own internal use, provided
|
|
51
|
+
attribution is maintained.
|
|
52
|
+
|
|
53
|
+
### Change Date and Change License
|
|
54
|
+
|
|
55
|
+
On the Change Date specified above, or on such other date as the Licensor may
|
|
56
|
+
specify by written notice, the Licensed Work will be made available under the
|
|
57
|
+
Change License (Apache License, Version 2.0). Until the Change Date, the terms
|
|
58
|
+
of this Business Source License 1.1 apply.
|
|
59
|
+
|
|
60
|
+
### Trademark
|
|
61
|
+
|
|
62
|
+
This license does not grant you any rights to use the "AbsoluteJS" or
|
|
63
|
+
"@absolutejs" name, logo, or any related trademarks. Forks and derivative works
|
|
64
|
+
must not be named or branded in a manner that suggests endorsement by or
|
|
65
|
+
affiliation with AbsoluteJS or the Licensor.
|
|
66
|
+
|
|
67
|
+
### Notices
|
|
68
|
+
|
|
69
|
+
You must not remove or obscure any licensing, copyright, or other notices
|
|
70
|
+
included in the Licensed Work.
|
|
71
|
+
|
|
72
|
+
### No Warranty
|
|
73
|
+
|
|
74
|
+
THE LICENSED WORK IS PROVIDED "AS IS". THE LICENSOR HEREBY DISCLAIMS ALL
|
|
75
|
+
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
|
|
76
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO
|
|
77
|
+
EVENT SHALL THE LICENSOR BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY,
|
|
78
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR
|
|
79
|
+
IN CONNECTION WITH THE LICENSED WORK OR THE USE OR OTHER DEALINGS IN THE
|
|
80
|
+
LICENSED WORK.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Contact
|
|
85
|
+
|
|
86
|
+
For commercial licensing inquiries or additional permissions, contact:
|
|
87
|
+
|
|
88
|
+
- **Alex Kahn**
|
|
89
|
+
- alexkahndev@gmail.com
|
|
90
|
+
- alexkahndev.github.io
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @absolutejs/search
|
|
2
|
+
|
|
3
|
+
Provider-neutral web evidence with a Brave Web Search / LLM Context adapter.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createBraveSearch } from '@absolutejs/search/brave';
|
|
7
|
+
const search = createBraveSearch({ apiKey, observe: recordAttempt });
|
|
8
|
+
const result = await search.search({ query: 'company partnership program', mode: 'context', maxTokens: 4096 });
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Successful empty results, partial evidence, provider outages, quota failures and cancellation remain distinct. Every network attempt carries billing disposition; unknown cost remains null. A 200 response remains fulfilled if its body cannot be parsed. The host owns retry/admission, prices, credentials and accounting. No hidden model calls or fallback providers.
|
|
12
|
+
|
|
13
|
+
Source excerpts are untrusted evidence. Publication and retrieval timestamps do not establish an event date. `sourceSupportsQuote` checks quotation presence, not entailment. `withSearchCache` requires an explicit scope, isolates provider/options/version, uses shorter empty-result retention, never caches failures, and optionally persists through a host store. Requests with caller-owned cancellation are not coalesced.
|
package/changelog.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"contract": 1,
|
|
3
|
+
"name": "@absolutejs/search",
|
|
4
|
+
"releases": [
|
|
5
|
+
{
|
|
6
|
+
"changes": [
|
|
7
|
+
{
|
|
8
|
+
"kind": "added",
|
|
9
|
+
"summary": "Provider-neutral search evidence, Brave Web and LLM Context adapters, explicit attempt outcomes and scoped caching"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"date": "2026-09-24",
|
|
13
|
+
"version": "0.1.0"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
package/dist/brave.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SearchAttempt, SearchProvider } from "./types";
|
|
2
|
+
export type BraveOptions = {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
fetch?: typeof fetch;
|
|
5
|
+
now?: () => number;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
apiVersion?: string;
|
|
8
|
+
/** Awaited before returning, including rejected and malformed responses. Does not expose credentials. */
|
|
9
|
+
observe?: (attempt: SearchAttempt) => Promise<void> | void;
|
|
10
|
+
};
|
|
11
|
+
export declare const createBraveSearch: (options: BraveOptions) => SearchProvider;
|
package/dist/brave.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/types.ts
|
|
3
|
+
var searchCompleted = (result) => result.status === "ok" || result.status === "empty";
|
|
4
|
+
var searchUsable = (result) => result.sources.length > 0 && (result.status === "ok" || result.status === "partial");
|
|
5
|
+
var unavailableSearch = (provider, query, reason) => ({
|
|
6
|
+
provider,
|
|
7
|
+
query,
|
|
8
|
+
version: "1",
|
|
9
|
+
status: "unavailable",
|
|
10
|
+
sources: [],
|
|
11
|
+
attempts: [],
|
|
12
|
+
limitations: [reason]
|
|
13
|
+
});
|
|
14
|
+
var evidenceText = (sources) => sources.map((source) => JSON.stringify({
|
|
15
|
+
sourceId: source.id,
|
|
16
|
+
url: source.url,
|
|
17
|
+
title: source.title,
|
|
18
|
+
retrievedAt: source.retrievedAt,
|
|
19
|
+
publishedAt: source.publishedAt,
|
|
20
|
+
excerpts: source.excerpts
|
|
21
|
+
})).join(`
|
|
22
|
+
`);
|
|
23
|
+
var sourceSupportsQuote = (source, quote) => {
|
|
24
|
+
const normalize = (text) => text.normalize("NFKC").replace(/\s+/gu, " ").trim();
|
|
25
|
+
const normalized = normalize(quote);
|
|
26
|
+
return normalized.length >= 12 && source.excerpts.some((text) => normalize(text).includes(normalized));
|
|
27
|
+
};
|
|
28
|
+
var boundedQueries = (text, maxChars = 600, maxWords = 75) => {
|
|
29
|
+
if (!Number.isInteger(maxChars) || maxChars < 1 || !Number.isInteger(maxWords) || maxWords < 1)
|
|
30
|
+
throw new Error("Invalid query limits");
|
|
31
|
+
const chunks = [];
|
|
32
|
+
let words = [];
|
|
33
|
+
for (const word of text.trim().split(/\s+/u).filter(Boolean)) {
|
|
34
|
+
if (word.length > maxChars)
|
|
35
|
+
throw new Error("A search term exceeds the provider query limit");
|
|
36
|
+
if (words.length >= maxWords || [...words, word].join(" ").length > maxChars) {
|
|
37
|
+
chunks.push(words.join(" "));
|
|
38
|
+
words = [];
|
|
39
|
+
}
|
|
40
|
+
words.push(word);
|
|
41
|
+
}
|
|
42
|
+
if (words.length)
|
|
43
|
+
chunks.push(words.join(" "));
|
|
44
|
+
return chunks;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/brave.ts
|
|
48
|
+
var record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
49
|
+
var text = (value) => typeof value === "string" ? value : undefined;
|
|
50
|
+
var strings = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
51
|
+
var publicUrl = (value) => {
|
|
52
|
+
try {
|
|
53
|
+
const url = new URL(String(value));
|
|
54
|
+
return /^https?:$/u.test(url.protocol) && !url.username && !url.password ? url.href : null;
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var numberIn = (value, fallback, min, max) => {
|
|
60
|
+
const n = value ?? fallback;
|
|
61
|
+
if (!Number.isInteger(n) || n < min || n > max)
|
|
62
|
+
throw new Error(`Search option must be an integer from ${min} through ${max}`);
|
|
63
|
+
return n;
|
|
64
|
+
};
|
|
65
|
+
var createBraveSearch = (options) => {
|
|
66
|
+
const now = options.now ?? Date.now;
|
|
67
|
+
const version = options.apiVersion ?? "2026-07-31";
|
|
68
|
+
return {
|
|
69
|
+
name: "brave",
|
|
70
|
+
version,
|
|
71
|
+
search: async (request) => {
|
|
72
|
+
const started = now();
|
|
73
|
+
const mode = request.mode ?? "context";
|
|
74
|
+
const endpoint = mode === "web" ? "/res/v1/web/search" : "/res/v1/llm/context";
|
|
75
|
+
const attempt = {
|
|
76
|
+
id: crypto.randomUUID(),
|
|
77
|
+
provider: "brave",
|
|
78
|
+
endpoint,
|
|
79
|
+
startedAt: new Date(started).toISOString(),
|
|
80
|
+
durationMs: 0,
|
|
81
|
+
status: "error",
|
|
82
|
+
billing: "not_sent",
|
|
83
|
+
costUsd: null
|
|
84
|
+
};
|
|
85
|
+
const result = {
|
|
86
|
+
provider: "brave",
|
|
87
|
+
version,
|
|
88
|
+
query: request.query,
|
|
89
|
+
status: "error",
|
|
90
|
+
sources: [],
|
|
91
|
+
attempts: [attempt],
|
|
92
|
+
limitations: []
|
|
93
|
+
};
|
|
94
|
+
if (!options.apiKey)
|
|
95
|
+
return unavailableSearch("brave", request.query, "Search credentials are unavailable");
|
|
96
|
+
let response;
|
|
97
|
+
try {
|
|
98
|
+
request.signal?.throwIfAborted();
|
|
99
|
+
const queries = boundedQueries(request.query);
|
|
100
|
+
if (queries.length !== 1)
|
|
101
|
+
throw new Error("Search requires one nonempty query within 600 characters and 75 words");
|
|
102
|
+
const params = {
|
|
103
|
+
q: request.query.trim(),
|
|
104
|
+
count: numberIn(request.count, 10, 1, mode === "web" ? 20 : 50)
|
|
105
|
+
};
|
|
106
|
+
if (request.freshness)
|
|
107
|
+
params.freshness = request.freshness;
|
|
108
|
+
if (request.country)
|
|
109
|
+
params.country = request.country;
|
|
110
|
+
if (request.language)
|
|
111
|
+
params.search_lang = request.language;
|
|
112
|
+
if (request.goggles)
|
|
113
|
+
params.goggles = request.goggles;
|
|
114
|
+
if (mode === "context")
|
|
115
|
+
Object.assign(params, {
|
|
116
|
+
maximum_number_of_tokens: numberIn(request.maxTokens, 4096, 1024, 32768),
|
|
117
|
+
maximum_number_of_urls: numberIn(request.maxUrls, 8, 1, 50),
|
|
118
|
+
maximum_number_of_tokens_per_url: numberIn(request.maxTokensPerUrl, 1024, 512, 8192),
|
|
119
|
+
enable_source_metadata: true,
|
|
120
|
+
enable_local: false,
|
|
121
|
+
...request.threshold ? { context_threshold_mode: request.threshold } : {}
|
|
122
|
+
});
|
|
123
|
+
const headers = {
|
|
124
|
+
accept: "application/json",
|
|
125
|
+
"X-Subscription-Token": options.apiKey,
|
|
126
|
+
"Api-Version": version,
|
|
127
|
+
"Content-Type": "application/json"
|
|
128
|
+
};
|
|
129
|
+
const url = new URL(`https://api.search.brave.com${endpoint}`);
|
|
130
|
+
if (mode === "web")
|
|
131
|
+
for (const [key, value] of Object.entries(params)) {
|
|
132
|
+
for (const entry of Array.isArray(value) ? value : [value])
|
|
133
|
+
url.searchParams.append(key, String(entry));
|
|
134
|
+
}
|
|
135
|
+
const signal = AbortSignal.any([
|
|
136
|
+
...request.signal ? [request.signal] : [],
|
|
137
|
+
AbortSignal.timeout(options.timeoutMs ?? 30000)
|
|
138
|
+
]);
|
|
139
|
+
attempt.billing = "unknown";
|
|
140
|
+
response = await (options.fetch ?? fetch)(url, {
|
|
141
|
+
headers,
|
|
142
|
+
signal,
|
|
143
|
+
redirect: "error",
|
|
144
|
+
method: mode === "web" ? "GET" : "POST",
|
|
145
|
+
...mode === "context" ? { body: JSON.stringify(params) } : {}
|
|
146
|
+
});
|
|
147
|
+
attempt.httpStatus = response.status;
|
|
148
|
+
attempt.providerRequestId = response.headers.get("x-request-id") ?? undefined;
|
|
149
|
+
attempt.quota = {
|
|
150
|
+
limit: response.headers.get("x-ratelimit-limit"),
|
|
151
|
+
remaining: response.headers.get("x-ratelimit-remaining"),
|
|
152
|
+
reset: response.headers.get("x-ratelimit-reset")
|
|
153
|
+
};
|
|
154
|
+
const retry = response.headers.get("retry-after");
|
|
155
|
+
if (retry) {
|
|
156
|
+
const milliseconds = /^\d+(?:\.\d+)?$/u.test(retry) ? Number(retry) * 1000 : Date.parse(retry) - now();
|
|
157
|
+
if (Number.isFinite(milliseconds))
|
|
158
|
+
attempt.retryAfterMs = Math.max(0, milliseconds);
|
|
159
|
+
}
|
|
160
|
+
attempt.billing = response.ok ? "fulfilled" : "rejected";
|
|
161
|
+
if (!response.ok) {
|
|
162
|
+
result.status = response.status === 429 ? "rate_limited" : response.status === 401 || response.status === 403 ? "unavailable" : "error";
|
|
163
|
+
const error = await response.json().catch(() => null);
|
|
164
|
+
if (record(error) && record(error.error) && error.error.code === "QUOTA_LIMITED")
|
|
165
|
+
result.status = "quota_exceeded";
|
|
166
|
+
result.limitations.push(`Brave request failed with HTTP ${response.status}`);
|
|
167
|
+
} else {
|
|
168
|
+
const body = await response.json();
|
|
169
|
+
if (!record(body))
|
|
170
|
+
throw new Error("Invalid Brave response");
|
|
171
|
+
const container = mode === "context" ? body.grounding : body.web;
|
|
172
|
+
if (!record(container) || !Array.isArray(container[mode === "context" ? "generic" : "results"]))
|
|
173
|
+
throw new Error("Brave response is missing its result array");
|
|
174
|
+
const rows = container[mode === "context" ? "generic" : "results"];
|
|
175
|
+
let invalid = 0;
|
|
176
|
+
const byUrl = new Map;
|
|
177
|
+
for (const row of rows) {
|
|
178
|
+
if (!record(row)) {
|
|
179
|
+
invalid++;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const url2 = publicUrl(row.url);
|
|
183
|
+
const excerpts = mode === "context" ? strings(row.snippets) : [
|
|
184
|
+
text(row.description),
|
|
185
|
+
...strings(row.extra_snippets)
|
|
186
|
+
].filter((item) => Boolean(item));
|
|
187
|
+
if (!url2 || !text(row.title) || mode === "context" && !excerpts.length) {
|
|
188
|
+
invalid++;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const metadata = record(body.sources) && record(body.sources[String(row.url)]) ? body.sources[String(row.url)] : {};
|
|
192
|
+
const age = Array.isArray(metadata.age) ? text(metadata.age[3]) : undefined;
|
|
193
|
+
const publishedAt = text(row.page_age) ?? age;
|
|
194
|
+
const previous = byUrl.get(url2);
|
|
195
|
+
if (previous)
|
|
196
|
+
previous.excerpts = [
|
|
197
|
+
...new Set([...previous.excerpts, ...excerpts])
|
|
198
|
+
];
|
|
199
|
+
else
|
|
200
|
+
byUrl.set(url2, {
|
|
201
|
+
id: url2,
|
|
202
|
+
url: url2,
|
|
203
|
+
title: String(row.title),
|
|
204
|
+
excerpts,
|
|
205
|
+
retrievedAt: new Date(now()).toISOString(),
|
|
206
|
+
...publishedAt && Number.isFinite(Date.parse(publishedAt)) ? { publishedAt } : {},
|
|
207
|
+
...text(metadata.fetched_content_timestamp) ? {
|
|
208
|
+
contentFetchedAt: String(metadata.fetched_content_timestamp)
|
|
209
|
+
} : {},
|
|
210
|
+
metadata
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
result.sources = [...byUrl.values()];
|
|
214
|
+
result.status = invalid ? result.sources.length ? "partial" : "error" : result.sources.length ? "ok" : "empty";
|
|
215
|
+
if (invalid)
|
|
216
|
+
result.limitations.push(`${invalid} malformed result(s) were excluded`);
|
|
217
|
+
}
|
|
218
|
+
} catch (error) {
|
|
219
|
+
result.status = request.signal?.aborted ? "cancelled" : "error";
|
|
220
|
+
result.limitations.push(error instanceof Error ? error.message : "Search failed");
|
|
221
|
+
} finally {
|
|
222
|
+
attempt.status = result.status;
|
|
223
|
+
attempt.durationMs = Math.max(0, now() - started);
|
|
224
|
+
await options.observe?.({ ...attempt });
|
|
225
|
+
}
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
export {
|
|
231
|
+
createBraveSearch
|
|
232
|
+
};
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type SearchProvider, type SearchRequest, type SearchResult } from "./types";
|
|
2
|
+
export type SearchCacheEntry = {
|
|
3
|
+
expiresAt: number;
|
|
4
|
+
result: SearchResult;
|
|
5
|
+
};
|
|
6
|
+
export type SearchCacheStore = {
|
|
7
|
+
get: (key: string) => Promise<SearchCacheEntry | undefined>;
|
|
8
|
+
set: (key: string, entry: SearchCacheEntry) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export declare const searchCacheKey: (provider: SearchProvider, request: SearchRequest, scope: string) => string;
|
|
11
|
+
export declare const withSearchCache: (provider: SearchProvider, options: {
|
|
12
|
+
scope: string;
|
|
13
|
+
ttlMs?: number;
|
|
14
|
+
emptyTtlMs?: number;
|
|
15
|
+
capacity?: number;
|
|
16
|
+
now?: () => number;
|
|
17
|
+
store?: SearchCacheStore;
|
|
18
|
+
}) => SearchProvider;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/types.ts
|
|
3
|
+
var searchCompleted = (result) => result.status === "ok" || result.status === "empty";
|
|
4
|
+
var searchUsable = (result) => result.sources.length > 0 && (result.status === "ok" || result.status === "partial");
|
|
5
|
+
var unavailableSearch = (provider, query, reason) => ({
|
|
6
|
+
provider,
|
|
7
|
+
query,
|
|
8
|
+
version: "1",
|
|
9
|
+
status: "unavailable",
|
|
10
|
+
sources: [],
|
|
11
|
+
attempts: [],
|
|
12
|
+
limitations: [reason]
|
|
13
|
+
});
|
|
14
|
+
var evidenceText = (sources) => sources.map((source) => JSON.stringify({
|
|
15
|
+
sourceId: source.id,
|
|
16
|
+
url: source.url,
|
|
17
|
+
title: source.title,
|
|
18
|
+
retrievedAt: source.retrievedAt,
|
|
19
|
+
publishedAt: source.publishedAt,
|
|
20
|
+
excerpts: source.excerpts
|
|
21
|
+
})).join(`
|
|
22
|
+
`);
|
|
23
|
+
var sourceSupportsQuote = (source, quote) => {
|
|
24
|
+
const normalize = (text) => text.normalize("NFKC").replace(/\s+/gu, " ").trim();
|
|
25
|
+
const normalized = normalize(quote);
|
|
26
|
+
return normalized.length >= 12 && source.excerpts.some((text) => normalize(text).includes(normalized));
|
|
27
|
+
};
|
|
28
|
+
var boundedQueries = (text, maxChars = 600, maxWords = 75) => {
|
|
29
|
+
if (!Number.isInteger(maxChars) || maxChars < 1 || !Number.isInteger(maxWords) || maxWords < 1)
|
|
30
|
+
throw new Error("Invalid query limits");
|
|
31
|
+
const chunks = [];
|
|
32
|
+
let words = [];
|
|
33
|
+
for (const word of text.trim().split(/\s+/u).filter(Boolean)) {
|
|
34
|
+
if (word.length > maxChars)
|
|
35
|
+
throw new Error("A search term exceeds the provider query limit");
|
|
36
|
+
if (words.length >= maxWords || [...words, word].join(" ").length > maxChars) {
|
|
37
|
+
chunks.push(words.join(" "));
|
|
38
|
+
words = [];
|
|
39
|
+
}
|
|
40
|
+
words.push(word);
|
|
41
|
+
}
|
|
42
|
+
if (words.length)
|
|
43
|
+
chunks.push(words.join(" "));
|
|
44
|
+
return chunks;
|
|
45
|
+
};
|
|
46
|
+
// src/cache.ts
|
|
47
|
+
var stable = (value) => {
|
|
48
|
+
if (Array.isArray(value))
|
|
49
|
+
return `[${value.map(stable).join(",")}]`;
|
|
50
|
+
if (value && typeof value === "object")
|
|
51
|
+
return `{${Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, v]) => `${JSON.stringify(key)}:${stable(v)}`).join(",")}}`;
|
|
52
|
+
return JSON.stringify(value) ?? "null";
|
|
53
|
+
};
|
|
54
|
+
var searchCacheKey = (provider, request, scope) => {
|
|
55
|
+
const { signal: _signal, ...params } = request;
|
|
56
|
+
return stable({
|
|
57
|
+
scope,
|
|
58
|
+
provider: provider.name,
|
|
59
|
+
version: provider.version,
|
|
60
|
+
params
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
var withSearchCache = (provider, options) => {
|
|
64
|
+
if (!options.scope.trim())
|
|
65
|
+
throw new Error("Explicit public or tenant cache scope required");
|
|
66
|
+
const cache = new Map;
|
|
67
|
+
const pending = new Map;
|
|
68
|
+
const now = options.now ?? Date.now;
|
|
69
|
+
const capacity = options.capacity ?? 500;
|
|
70
|
+
if (!Number.isInteger(capacity) || capacity < 1)
|
|
71
|
+
throw new Error("Cache capacity must be positive");
|
|
72
|
+
const deliver = (result) => ({
|
|
73
|
+
...structuredClone(result),
|
|
74
|
+
attempts: [],
|
|
75
|
+
cache: { hit: true, originalAttemptIds: result.attempts.map((a) => a.id) }
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
...provider,
|
|
79
|
+
search: async (request) => {
|
|
80
|
+
request.signal?.throwIfAborted();
|
|
81
|
+
const key = searchCacheKey(provider, request, options.scope);
|
|
82
|
+
const entry = cache.get(key) ?? await options.store?.get(key);
|
|
83
|
+
if (entry && now() < entry.expiresAt)
|
|
84
|
+
return deliver(entry.result);
|
|
85
|
+
cache.delete(key);
|
|
86
|
+
const existing = !request.signal ? pending.get(key) : undefined;
|
|
87
|
+
if (existing)
|
|
88
|
+
return deliver(await existing);
|
|
89
|
+
const work = (async () => {
|
|
90
|
+
const result = await provider.search(request);
|
|
91
|
+
if (searchCompleted(result)) {
|
|
92
|
+
const ttl = result.status === "empty" ? options.emptyTtlMs ?? 60000 : options.ttlMs ?? 300000;
|
|
93
|
+
if (ttl > 0) {
|
|
94
|
+
const entry2 = {
|
|
95
|
+
result: structuredClone(result),
|
|
96
|
+
expiresAt: now() + ttl
|
|
97
|
+
};
|
|
98
|
+
while (cache.size >= capacity)
|
|
99
|
+
cache.delete(cache.keys().next().value);
|
|
100
|
+
cache.set(key, entry2);
|
|
101
|
+
await options.store?.set(key, entry2);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
})();
|
|
106
|
+
if (!request.signal)
|
|
107
|
+
pending.set(key, work);
|
|
108
|
+
try {
|
|
109
|
+
return await work;
|
|
110
|
+
} finally {
|
|
111
|
+
if (pending.get(key) === work)
|
|
112
|
+
pending.delete(key);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
export {
|
|
118
|
+
boundedQueries,
|
|
119
|
+
evidenceText,
|
|
120
|
+
searchCacheKey,
|
|
121
|
+
searchCompleted,
|
|
122
|
+
searchUsable,
|
|
123
|
+
sourceSupportsQuote,
|
|
124
|
+
unavailableSearch,
|
|
125
|
+
withSearchCache
|
|
126
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const manifest: Omit<import("@absolutejs/manifest").PackageManifest<Record<string, never>, never>, "contract" | "settings" | "tools"> & (({
|
|
2
|
+
contract: 1;
|
|
3
|
+
tools?: Record<string, import("@absolutejs/manifest").LegacyManifestTool<never>> | undefined;
|
|
4
|
+
} | {
|
|
5
|
+
contract: 2;
|
|
6
|
+
tools?: Record<string, import("@absolutejs/manifest").AuthorizedManifestTool<never>> | undefined;
|
|
7
|
+
}) & {
|
|
8
|
+
settings: import("@sinclair/typebox").TObject<{}>;
|
|
9
|
+
});
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// node_modules/@absolutejs/manifest/dist/index.js
|
|
3
|
+
import { Value } from "@sinclair/typebox/value";
|
|
4
|
+
import { Type } from "@sinclair/typebox";
|
|
5
|
+
import { Value as Value2 } from "@sinclair/typebox/value";
|
|
6
|
+
var defineManifest = () => (manifest) => manifest;
|
|
7
|
+
var literal = (value) => value;
|
|
8
|
+
var RUNTIME_KIND = literal("runtime");
|
|
9
|
+
var WORKSPACE_KIND = literal("workspace");
|
|
10
|
+
var TOOL_NAME_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
|
|
11
|
+
var envRequirement = Type.Object({
|
|
12
|
+
description: Type.String(),
|
|
13
|
+
docsUrl: Type.Optional(Type.String()),
|
|
14
|
+
example: Type.Optional(Type.String()),
|
|
15
|
+
key: Type.String({ pattern: "^[A-Z][A-Z0-9_]*$" }),
|
|
16
|
+
optional: Type.Optional(Type.Boolean()),
|
|
17
|
+
secret: Type.Optional(Type.Boolean()),
|
|
18
|
+
when: Type.Optional(Type.String())
|
|
19
|
+
});
|
|
20
|
+
var wiringImport = Type.Object({
|
|
21
|
+
from: Type.String(),
|
|
22
|
+
names: Type.Array(Type.String()),
|
|
23
|
+
typeOnly: Type.Optional(Type.Boolean())
|
|
24
|
+
});
|
|
25
|
+
var wiringSnippet = Type.Object({
|
|
26
|
+
code: Type.String(),
|
|
27
|
+
imports: Type.Array(wiringImport),
|
|
28
|
+
placement: Type.Optional(Type.Union([
|
|
29
|
+
Type.Literal("client-entry"),
|
|
30
|
+
Type.Literal("module-scope"),
|
|
31
|
+
Type.Literal("server-boundary"),
|
|
32
|
+
Type.Literal("server-factory"),
|
|
33
|
+
Type.Literal("server-plugin")
|
|
34
|
+
]))
|
|
35
|
+
});
|
|
36
|
+
var clientFrameworks = [
|
|
37
|
+
"angular",
|
|
38
|
+
"client",
|
|
39
|
+
"react",
|
|
40
|
+
"svelte",
|
|
41
|
+
"vue"
|
|
42
|
+
];
|
|
43
|
+
var wiringRecipe = Type.Object({
|
|
44
|
+
client: Type.Optional(Type.Partial(Type.Object(Object.fromEntries(clientFrameworks.map((framework) => [framework, wiringSnippet]))))),
|
|
45
|
+
description: Type.Optional(Type.String()),
|
|
46
|
+
id: Type.String({ minLength: 1 }),
|
|
47
|
+
server: Type.Optional(wiringSnippet),
|
|
48
|
+
title: Type.String()
|
|
49
|
+
});
|
|
50
|
+
var adapterSlot = Type.Object({
|
|
51
|
+
configPath: Type.String({ minLength: 1 }),
|
|
52
|
+
contract: Type.String({ pattern: "^[a-z0-9-]+/[a-z0-9-]+$" }),
|
|
53
|
+
description: Type.String(),
|
|
54
|
+
known: Type.Optional(Type.Array(Type.String())),
|
|
55
|
+
required: Type.Optional(Type.Boolean())
|
|
56
|
+
});
|
|
57
|
+
var jsonSchemaObject = Type.Record(Type.String(), Type.Unknown());
|
|
58
|
+
var peerRequirement = Type.Object({
|
|
59
|
+
name: Type.String(),
|
|
60
|
+
range: Type.String(),
|
|
61
|
+
reason: Type.Optional(Type.String())
|
|
62
|
+
});
|
|
63
|
+
var serviceRequirement = Type.Object({
|
|
64
|
+
description: Type.String(),
|
|
65
|
+
id: Type.String(),
|
|
66
|
+
optional: Type.Optional(Type.Boolean())
|
|
67
|
+
});
|
|
68
|
+
var manifestRequirements = Type.Object({
|
|
69
|
+
env: Type.Optional(Type.Array(envRequirement)),
|
|
70
|
+
peers: Type.Optional(Type.Array(peerRequirement)),
|
|
71
|
+
services: Type.Optional(Type.Array(serviceRequirement))
|
|
72
|
+
});
|
|
73
|
+
var adapterImplementation = Type.Object({
|
|
74
|
+
contract: Type.String({ pattern: "^[a-z0-9-]+/[a-z0-9-]+$" }),
|
|
75
|
+
factory: Type.String({ minLength: 1 }),
|
|
76
|
+
from: Type.String({ minLength: 1 }),
|
|
77
|
+
requires: Type.Optional(manifestRequirements),
|
|
78
|
+
settings: Type.Optional(jsonSchemaObject),
|
|
79
|
+
title: Type.String(),
|
|
80
|
+
wiring: wiringSnippet
|
|
81
|
+
});
|
|
82
|
+
var lifecycleStep = Type.Object({
|
|
83
|
+
command: Type.Optional(Type.String()),
|
|
84
|
+
docsUrl: Type.Optional(Type.String()),
|
|
85
|
+
id: Type.String({ minLength: 1 }),
|
|
86
|
+
idempotent: Type.Optional(Type.Boolean()),
|
|
87
|
+
kind: Type.Union([
|
|
88
|
+
Type.Literal("migration"),
|
|
89
|
+
Type.Literal("post-install"),
|
|
90
|
+
Type.Literal("verify")
|
|
91
|
+
]),
|
|
92
|
+
title: Type.String(),
|
|
93
|
+
when: Type.Union([
|
|
94
|
+
Type.Literal("after-install"),
|
|
95
|
+
Type.Literal("after-upgrade"),
|
|
96
|
+
Type.Literal("before-first-run"),
|
|
97
|
+
Type.Literal("manual")
|
|
98
|
+
])
|
|
99
|
+
});
|
|
100
|
+
var toolAnnotations = Type.Object({
|
|
101
|
+
destructiveHint: Type.Optional(Type.Boolean()),
|
|
102
|
+
idempotentHint: Type.Optional(Type.Boolean()),
|
|
103
|
+
openWorldHint: Type.Optional(Type.Boolean()),
|
|
104
|
+
readOnlyHint: Type.Optional(Type.Boolean()),
|
|
105
|
+
title: Type.Optional(Type.String())
|
|
106
|
+
});
|
|
107
|
+
var toolAuthorization = Type.Object({
|
|
108
|
+
approval: Type.Union([
|
|
109
|
+
Type.Literal("always"),
|
|
110
|
+
Type.Literal("never"),
|
|
111
|
+
Type.Literal("policy")
|
|
112
|
+
]),
|
|
113
|
+
audience: Type.Union([
|
|
114
|
+
Type.Literal("admin"),
|
|
115
|
+
Type.Literal("authenticated"),
|
|
116
|
+
Type.Literal("owner"),
|
|
117
|
+
Type.Literal("public")
|
|
118
|
+
]),
|
|
119
|
+
compensatingTool: Type.Optional(Type.String({ pattern: TOOL_NAME_PATTERN.source })),
|
|
120
|
+
destinationFields: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1 })),
|
|
121
|
+
destinations: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1 })),
|
|
122
|
+
effects: Type.Array(Type.String({ minLength: 1 }), { minItems: 1 }),
|
|
123
|
+
idempotency: Type.Optional(Type.Union([
|
|
124
|
+
Type.Object({
|
|
125
|
+
field: Type.String({ minLength: 1 }),
|
|
126
|
+
mode: Type.Literal("field")
|
|
127
|
+
}),
|
|
128
|
+
Type.Object({ mode: Type.Literal("host") }),
|
|
129
|
+
Type.Object({ mode: Type.Literal("resource") })
|
|
130
|
+
])),
|
|
131
|
+
requiredScopes: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1 })),
|
|
132
|
+
resource: Type.Optional(Type.Object({
|
|
133
|
+
idField: Type.Optional(Type.String({ minLength: 1 })),
|
|
134
|
+
ownerIdField: Type.Optional(Type.String({ minLength: 1 })),
|
|
135
|
+
tenantIdField: Type.Optional(Type.String({ minLength: 1 })),
|
|
136
|
+
type: Type.String({ minLength: 1 })
|
|
137
|
+
})),
|
|
138
|
+
reversible: Type.Optional(Type.Boolean()),
|
|
139
|
+
spend: Type.Optional(Type.Object({
|
|
140
|
+
amountMinorField: Type.String({ minLength: 1 }),
|
|
141
|
+
currencyField: Type.String({ minLength: 1 }),
|
|
142
|
+
maximumAmountMinor: Type.Optional(Type.Integer({ minimum: 0 }))
|
|
143
|
+
}))
|
|
144
|
+
});
|
|
145
|
+
var serializedTool = Type.Object({
|
|
146
|
+
annotations: Type.Optional(toolAnnotations),
|
|
147
|
+
authorization: Type.Optional(toolAuthorization),
|
|
148
|
+
capabilities: Type.Optional(Type.Array(Type.Union([
|
|
149
|
+
Type.Literal("exec"),
|
|
150
|
+
Type.Literal("glob"),
|
|
151
|
+
Type.Literal("read"),
|
|
152
|
+
Type.Literal("write")
|
|
153
|
+
]))),
|
|
154
|
+
description: Type.String(),
|
|
155
|
+
input: jsonSchemaObject,
|
|
156
|
+
kind: Type.Union([Type.Literal("runtime"), Type.Literal("workspace")])
|
|
157
|
+
});
|
|
158
|
+
var productId = Type.String({ pattern: "^[a-z][a-z0-9_-]{0,63}$" });
|
|
159
|
+
var productCopy = {
|
|
160
|
+
description: Type.String({ minLength: 1 }),
|
|
161
|
+
id: productId,
|
|
162
|
+
title: Type.String({ minLength: 1 })
|
|
163
|
+
};
|
|
164
|
+
var productOperation = Type.Union([
|
|
165
|
+
Type.Literal("aggregate"),
|
|
166
|
+
Type.Literal("create"),
|
|
167
|
+
Type.Literal("delete"),
|
|
168
|
+
Type.Literal("detail"),
|
|
169
|
+
Type.Literal("list"),
|
|
170
|
+
Type.Literal("update")
|
|
171
|
+
]);
|
|
172
|
+
var productProjection = Type.Object({
|
|
173
|
+
blocks: Type.Optional(Type.Array(Type.Object({
|
|
174
|
+
...productCopy,
|
|
175
|
+
category: Type.String({ minLength: 1 }),
|
|
176
|
+
componentExport: Type.String({ minLength: 1 }),
|
|
177
|
+
frameworks: Type.Optional(Type.Array(Type.Union(clientFrameworks.map((framework) => Type.Literal(framework))))),
|
|
178
|
+
props: jsonSchemaObject
|
|
179
|
+
}))),
|
|
180
|
+
connections: Type.Optional(Type.Array(Type.Object({
|
|
181
|
+
...productCopy,
|
|
182
|
+
envKeys: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
|
|
183
|
+
kind: Type.Union([
|
|
184
|
+
Type.Literal("none"),
|
|
185
|
+
Type.Literal("oauth"),
|
|
186
|
+
Type.Literal("secret")
|
|
187
|
+
]),
|
|
188
|
+
setupTool: Type.Optional(Type.String({ pattern: TOOL_NAME_PATTERN.source })),
|
|
189
|
+
testTool: Type.Optional(Type.String({ pattern: TOOL_NAME_PATTERN.source }))
|
|
190
|
+
}))),
|
|
191
|
+
dataSources: Type.Optional(Type.Array(Type.Object({
|
|
192
|
+
...productCopy,
|
|
193
|
+
operations: Type.Array(productOperation, { minItems: 1 }),
|
|
194
|
+
schema: jsonSchemaObject,
|
|
195
|
+
tools: Type.Optional(Type.Partial(Type.Object({
|
|
196
|
+
aggregate: Type.String({ pattern: TOOL_NAME_PATTERN.source }),
|
|
197
|
+
create: Type.String({ pattern: TOOL_NAME_PATTERN.source }),
|
|
198
|
+
delete: Type.String({ pattern: TOOL_NAME_PATTERN.source }),
|
|
199
|
+
detail: Type.String({ pattern: TOOL_NAME_PATTERN.source }),
|
|
200
|
+
list: Type.String({ pattern: TOOL_NAME_PATTERN.source }),
|
|
201
|
+
update: Type.String({ pattern: TOOL_NAME_PATTERN.source })
|
|
202
|
+
})))
|
|
203
|
+
}))),
|
|
204
|
+
events: Type.Optional(Type.Array(Type.Object({
|
|
205
|
+
...productCopy,
|
|
206
|
+
schema: jsonSchemaObject,
|
|
207
|
+
source: Type.Union([
|
|
208
|
+
Type.Literal("data"),
|
|
209
|
+
Type.Literal("package"),
|
|
210
|
+
Type.Literal("ui"),
|
|
211
|
+
Type.Literal("webhook")
|
|
212
|
+
])
|
|
213
|
+
}))),
|
|
214
|
+
healthChecks: Type.Optional(Type.Array(Type.Object({
|
|
215
|
+
...productCopy,
|
|
216
|
+
tool: Type.String({ pattern: TOOL_NAME_PATTERN.source })
|
|
217
|
+
}))),
|
|
218
|
+
releaseChecks: Type.Optional(Type.Array(Type.Object({
|
|
219
|
+
...productCopy,
|
|
220
|
+
healthCheckIds: Type.Optional(Type.Array(productId)),
|
|
221
|
+
severity: Type.Union([
|
|
222
|
+
Type.Literal("blocking"),
|
|
223
|
+
Type.Literal("warning")
|
|
224
|
+
])
|
|
225
|
+
}))),
|
|
226
|
+
workflowActions: Type.Optional(Type.Array(Type.Object({
|
|
227
|
+
...productCopy,
|
|
228
|
+
tool: Type.String({ pattern: TOOL_NAME_PATTERN.source })
|
|
229
|
+
})))
|
|
230
|
+
});
|
|
231
|
+
var manifestSchema = Type.Object({
|
|
232
|
+
contract: Type.Union([Type.Literal(1), Type.Literal(2)]),
|
|
233
|
+
discovery: Type.Optional(Type.Object({
|
|
234
|
+
audiences: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
|
|
235
|
+
certificationUrl: Type.Optional(Type.String()),
|
|
236
|
+
intents: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
|
|
237
|
+
keywords: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
|
|
238
|
+
protocols: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
|
|
239
|
+
url: Type.Optional(Type.String())
|
|
240
|
+
})),
|
|
241
|
+
identity: Type.Object({
|
|
242
|
+
accent: Type.Optional(Type.String({ pattern: "^#[0-9a-fA-F]{3,8}$" })),
|
|
243
|
+
category: Type.String({ minLength: 1 }),
|
|
244
|
+
description: Type.Optional(Type.String()),
|
|
245
|
+
docsUrl: Type.Optional(Type.String()),
|
|
246
|
+
logo: Type.Optional(Type.Object({
|
|
247
|
+
svg: Type.Optional(Type.String()),
|
|
248
|
+
url: Type.Optional(Type.String())
|
|
249
|
+
})),
|
|
250
|
+
name: Type.String({
|
|
251
|
+
pattern: "^(@[a-z0-9-~][a-z0-9-._~]*/)?[a-z0-9-~][a-z0-9-._~]*$"
|
|
252
|
+
}),
|
|
253
|
+
tagline: Type.String({ minLength: 1 })
|
|
254
|
+
}),
|
|
255
|
+
implements: Type.Optional(Type.Array(adapterImplementation)),
|
|
256
|
+
integration: Type.Optional(Type.Object({
|
|
257
|
+
description: Type.Optional(Type.String({ minLength: 1 })),
|
|
258
|
+
mode: Type.Union([
|
|
259
|
+
Type.Literal("adapter"),
|
|
260
|
+
Type.Literal("code-first"),
|
|
261
|
+
Type.Literal("recipe")
|
|
262
|
+
])
|
|
263
|
+
})),
|
|
264
|
+
lifecycle: Type.Optional(Type.Array(lifecycleStep)),
|
|
265
|
+
presets: Type.Optional(Type.Array(Type.Object({
|
|
266
|
+
description: Type.Optional(Type.String()),
|
|
267
|
+
id: Type.String({ minLength: 1 }),
|
|
268
|
+
title: Type.String(),
|
|
269
|
+
values: Type.Record(Type.String(), Type.Unknown())
|
|
270
|
+
}))),
|
|
271
|
+
product: Type.Optional(productProjection),
|
|
272
|
+
requires: Type.Optional(manifestRequirements),
|
|
273
|
+
settings: jsonSchemaObject,
|
|
274
|
+
slots: Type.Optional(Type.Record(Type.String(), adapterSlot)),
|
|
275
|
+
tools: Type.Optional(Type.Record(Type.String({ pattern: TOOL_NAME_PATTERN.source }), serializedTool)),
|
|
276
|
+
wiring: Type.Array(wiringRecipe)
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// src/manifest.ts
|
|
280
|
+
import { Type as Type2 } from "@sinclair/typebox";
|
|
281
|
+
var manifest = defineManifest()({
|
|
282
|
+
contract: 2,
|
|
283
|
+
identity: {
|
|
284
|
+
name: "@absolutejs/search",
|
|
285
|
+
accent: "#3b82f6",
|
|
286
|
+
category: "data",
|
|
287
|
+
docsUrl: "https://github.com/absolutejs/search",
|
|
288
|
+
tagline: "Replaceable search providers with explicit evidence and outcomes.",
|
|
289
|
+
description: "Provider-neutral web and context search contracts, Brave adapter, bounded queries, source excerpts, per-attempt accounting hooks, cancellation and scoped caching. Credentials and spending policy belong to the host."
|
|
290
|
+
},
|
|
291
|
+
settings: Type2.Object({}),
|
|
292
|
+
wiring: []
|
|
293
|
+
});
|
|
294
|
+
export {
|
|
295
|
+
manifest
|
|
296
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"contract": 2,
|
|
3
|
+
"identity": {
|
|
4
|
+
"name": "@absolutejs/search",
|
|
5
|
+
"accent": "#3b82f6",
|
|
6
|
+
"category": "data",
|
|
7
|
+
"docsUrl": "https://github.com/absolutejs/search",
|
|
8
|
+
"tagline": "Replaceable search providers with explicit evidence and outcomes.",
|
|
9
|
+
"description": "Provider-neutral web and context search contracts, Brave adapter, bounded queries, source excerpts, per-attempt accounting hooks, cancellation and scoped caching. Credentials and spending policy belong to the host."
|
|
10
|
+
},
|
|
11
|
+
"settings": {
|
|
12
|
+
"type": "object",
|
|
13
|
+
"properties": {}
|
|
14
|
+
},
|
|
15
|
+
"wiring": []
|
|
16
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type SearchStatus = "ok" | "empty" | "partial" | "unavailable" | "rate_limited" | "quota_exceeded" | "cancelled" | "error";
|
|
2
|
+
export type SearchSource = {
|
|
3
|
+
id: string;
|
|
4
|
+
url: string;
|
|
5
|
+
title: string;
|
|
6
|
+
excerpts: string[];
|
|
7
|
+
retrievedAt: string;
|
|
8
|
+
/** Date reported by the page/provider; never an event date inferred from a crawl. */
|
|
9
|
+
publishedAt?: string;
|
|
10
|
+
contentFetchedAt?: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
export type SearchRequest = {
|
|
14
|
+
query: string;
|
|
15
|
+
mode?: "web" | "context";
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
count?: number;
|
|
18
|
+
maxTokens?: number;
|
|
19
|
+
maxUrls?: number;
|
|
20
|
+
maxTokensPerUrl?: number;
|
|
21
|
+
freshness?: string;
|
|
22
|
+
country?: string;
|
|
23
|
+
language?: string;
|
|
24
|
+
threshold?: "strict" | "balanced" | "lenient" | "disabled";
|
|
25
|
+
goggles?: string[];
|
|
26
|
+
};
|
|
27
|
+
export type SearchAttempt = {
|
|
28
|
+
id: string;
|
|
29
|
+
provider: string;
|
|
30
|
+
endpoint: string;
|
|
31
|
+
startedAt: string;
|
|
32
|
+
durationMs: number;
|
|
33
|
+
status: SearchStatus;
|
|
34
|
+
httpStatus?: number;
|
|
35
|
+
retryAfterMs?: number;
|
|
36
|
+
/** A successful HTTP response is billable even if parsing fails. */
|
|
37
|
+
billing: "fulfilled" | "rejected" | "unknown" | "not_sent";
|
|
38
|
+
costUsd: number | null;
|
|
39
|
+
providerRequestId?: string;
|
|
40
|
+
quota?: {
|
|
41
|
+
limit: string | null;
|
|
42
|
+
remaining: string | null;
|
|
43
|
+
reset: string | null;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export type SearchResult = {
|
|
47
|
+
provider: string;
|
|
48
|
+
version: string;
|
|
49
|
+
query: string;
|
|
50
|
+
status: SearchStatus;
|
|
51
|
+
sources: SearchSource[];
|
|
52
|
+
attempts: SearchAttempt[];
|
|
53
|
+
limitations: string[];
|
|
54
|
+
cache?: {
|
|
55
|
+
hit: boolean;
|
|
56
|
+
originalAttemptIds: string[];
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export type SearchProvider = {
|
|
60
|
+
name: string;
|
|
61
|
+
version: string;
|
|
62
|
+
search: (request: SearchRequest) => Promise<SearchResult>;
|
|
63
|
+
};
|
|
64
|
+
export declare const searchCompleted: (result: SearchResult) => boolean;
|
|
65
|
+
export declare const searchUsable: (result: SearchResult) => boolean;
|
|
66
|
+
export declare const unavailableSearch: (provider: string, query: string, reason: string) => SearchResult;
|
|
67
|
+
export declare const evidenceText: (sources: SearchSource[]) => string;
|
|
68
|
+
export declare const sourceSupportsQuote: (source: SearchSource, quote: string) => boolean;
|
|
69
|
+
/** No truncation: split oversized questions into bounded chunks and retain every word. */
|
|
70
|
+
export declare const boundedQueries: (text: string, maxChars?: number, maxWords?: number) => string[];
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@absolutejs/search",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Provider-neutral web search, grounded evidence, and replaceable search adapters",
|
|
6
|
+
"license": "BSL-1.1",
|
|
7
|
+
"author": "Alex Kahn",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/absolutejs/search.git"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"CHANGELOG.md",
|
|
20
|
+
"changelog.json"
|
|
21
|
+
],
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./brave": {
|
|
30
|
+
"types": "./dist/brave.d.ts",
|
|
31
|
+
"default": "./dist/brave.js"
|
|
32
|
+
},
|
|
33
|
+
"./manifest": {
|
|
34
|
+
"types": "./dist/manifest.d.ts",
|
|
35
|
+
"default": "./dist/manifest.js"
|
|
36
|
+
},
|
|
37
|
+
"./manifest.json": "./dist/manifest.json"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "bun build src/index.ts src/brave.ts src/manifest.ts --outdir dist --target bun --external @sinclair/typebox && tsc --emitDeclarationOnly && absolute-manifest emit",
|
|
41
|
+
"test": "bun test",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"check:package": "absolute-changelog check",
|
|
44
|
+
"prepublishOnly": "bun run check:package"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/bun": "^1.3.11",
|
|
48
|
+
"typescript": "5.9.3",
|
|
49
|
+
"@absolutejs/changelog": "^0.6.0"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@absolutejs/manifest": "^0.9.0",
|
|
53
|
+
"@sinclair/typebox": "^0.34.0"
|
|
54
|
+
},
|
|
55
|
+
"absolutejs": {
|
|
56
|
+
"manifestContract": 2
|
|
57
|
+
}
|
|
58
|
+
}
|