@unieai/rabi-web 0.0.0-stage → 0.2.1-rc.3
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 +7 -2
- package/lib/index.js +147 -0
- package/lib/types/index.d.ts +101 -0
- package/lib/types/types.d.ts +126 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +6 -0
- package/package.json +32 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @unieai/rabi-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Abstract web access capability seam (ctx.web) for the Rabi Harness — search/fetch provider registry, registration-order-independent selection, request/result vocabulary, and the WebError taxonomy
|
|
4
|
+
|
|
5
|
+
Part of Rabi, the agent harness UnieAI Code runs on. Installed as a dependency of `@unieai/rabi`;
|
|
6
|
+
not meant to be used on its own.
|
|
7
|
+
|
|
8
|
+
See LICENSE for the license and copyright of this package.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Service } from "@unieai/cordis";
|
|
2
|
+
import z from "@unieai/schemastery";
|
|
3
|
+
import { HarnessError } from "@unieai/rabi-llm";
|
|
4
|
+
//#region lib/types/types.js
|
|
5
|
+
/**
|
|
6
|
+
* Vocabulary for the web capability seam (`ctx.web`). Search and fetch deliberately share one
|
|
7
|
+
* seam so provider selection, cancellation, errors, and product configuration have one owner,
|
|
8
|
+
* while retaining separate request and result types.
|
|
9
|
+
* @module @unieai/rabi-web/types
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Typed web error with a machine-routable, open-string `code` and chained `cause`.
|
|
13
|
+
* Consumers must tolerate provider-specific codes. Shared codes cover unavailable,
|
|
14
|
+
* missing, unusable, ambiguous, or duplicate providers, cancellation, and provider failure;
|
|
15
|
+
* the local fetch provider additionally distinguishes invalid or blocked URLs, redirects,
|
|
16
|
+
* size and timeout limits, and unsupported content types. Tool execution exposes the code in
|
|
17
|
+
* structured error metadata.
|
|
18
|
+
*/
|
|
19
|
+
var WebError = class extends HarnessError {};
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region lib/types/index.js
|
|
22
|
+
/**
|
|
23
|
+
* Service Definition for the web access capability seam (`ctx.web`): registries and provider-selecting execution for search and
|
|
24
|
+
* fetch. Duplicate ids are rejected. At execution time, a configured provider must exist and
|
|
25
|
+
* be usable; without one, exactly one usable provider is required, so selection never depends
|
|
26
|
+
* on registration order.
|
|
27
|
+
* @module @unieai/rabi-web
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* The web access service. Registered as `ctx.web` (one instance per context).
|
|
31
|
+
*
|
|
32
|
+
* Selection semantics (resolved at execution time, never order-dependent):
|
|
33
|
+
* - A configured id that is registered and `available()` → that provider.
|
|
34
|
+
* - A configured id not registered → `WEB_PROVIDER_CONFIGURED_MISSING`.
|
|
35
|
+
* - A configured id registered but unavailable →
|
|
36
|
+
* `WEB_PROVIDER_CONFIGURED_UNAVAILABLE`.
|
|
37
|
+
* - No id configured, exactly one registered usable provider → that provider.
|
|
38
|
+
* - No id configured, multiple usable providers → `WEB_PROVIDER_AMBIGUOUS`.
|
|
39
|
+
* - No id configured, no usable provider → `WEB_PROVIDER_UNAVAILABLE`.
|
|
40
|
+
*/
|
|
41
|
+
var WebRuntime = class extends Service {
|
|
42
|
+
config;
|
|
43
|
+
/**
|
|
44
|
+
* Provider selection config. Operational env overrides feed the SAME fields:
|
|
45
|
+
* `$RABI_WEB_SEARCH_PROVIDER` / `$RABI_WEB_FETCH_PROVIDER` are equivalent to
|
|
46
|
+
* `searchProvider` / `fetchProvider` and are NOT a hidden priority chain.
|
|
47
|
+
*/
|
|
48
|
+
static Config = z.object({
|
|
49
|
+
searchProvider: z.string().volatile(),
|
|
50
|
+
fetchProvider: z.string().volatile()
|
|
51
|
+
});
|
|
52
|
+
searchProviders = /* @__PURE__ */ new Map();
|
|
53
|
+
fetchProviders = /* @__PURE__ */ new Map();
|
|
54
|
+
searchProviderEnv;
|
|
55
|
+
fetchProviderEnv;
|
|
56
|
+
constructor(ctx, config) {
|
|
57
|
+
super(ctx, "web");
|
|
58
|
+
this.config = config;
|
|
59
|
+
this.searchProviderEnv = process.env.RABI_WEB_SEARCH_PROVIDER;
|
|
60
|
+
this.fetchProviderEnv = process.env.RABI_WEB_FETCH_PROVIDER;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Register a search provider. Throws {@link WebError} `WEB_DUPLICATE_PROVIDER`
|
|
64
|
+
* if its id is already registered for search. Returns a disposer; disposed
|
|
65
|
+
* with the calling fiber.
|
|
66
|
+
* @param provider - the provider; its `id` is the registry key.
|
|
67
|
+
* @returns the disposer that unregisters the provider.
|
|
68
|
+
*/
|
|
69
|
+
registerSearchProvider(provider) {
|
|
70
|
+
return this.registerProvider(this.searchProviders, provider);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Register a fetch provider. Throws {@link WebError} `WEB_DUPLICATE_PROVIDER`
|
|
74
|
+
* if its id is already registered for fetch. Returns a disposer; disposed
|
|
75
|
+
* with the calling fiber.
|
|
76
|
+
* @param provider - the provider; its `id` is the registry key.
|
|
77
|
+
* @returns the disposer that unregisters the provider.
|
|
78
|
+
*/
|
|
79
|
+
registerFetchProvider(provider) {
|
|
80
|
+
return this.registerProvider(this.fetchProviders, provider);
|
|
81
|
+
}
|
|
82
|
+
registerProvider(store, provider) {
|
|
83
|
+
if (store.has(provider.id)) throw new WebError(`a web provider with id "${provider.id}" is already registered`, "WEB_DUPLICATE_PROVIDER");
|
|
84
|
+
const dispose = this.ctx.effect(function* () {
|
|
85
|
+
store.set(provider.id, provider);
|
|
86
|
+
yield () => store.delete(provider.id);
|
|
87
|
+
}, "web.registerProvider()");
|
|
88
|
+
return () => void dispose();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Run one search through the selected provider. Resolves the provider at call
|
|
92
|
+
* time with the selection rules above; throws {@link WebError} when the
|
|
93
|
+
* capability cannot run. The seam enforces `request.maxResults` on the result:
|
|
94
|
+
* if the provider over-returns, `sources[]` is truncated and `truncated` set.
|
|
95
|
+
* @param request - the query and optional result limit.
|
|
96
|
+
* @param signal - optional cancellation signal forwarded to the provider.
|
|
97
|
+
* @returns the provider's results, capped to `request.maxResults`.
|
|
98
|
+
*/
|
|
99
|
+
async search(request, signal) {
|
|
100
|
+
const configuredId = this.config.searchProvider.get() ?? this.searchProviderEnv;
|
|
101
|
+
return capSources(await resolveProvider({
|
|
102
|
+
providers: this.searchProviders,
|
|
103
|
+
...configuredId !== void 0 ? { configuredId } : {}
|
|
104
|
+
}).search(request, signal), request.maxResults);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Retrieve one URL through the selected provider. Resolves the provider at
|
|
108
|
+
* call time with the selection rules above; throws {@link WebError} when the
|
|
109
|
+
* capability cannot run. A non-2xx response is a result, not a throw.
|
|
110
|
+
* @param request - the URL plus retrieval options.
|
|
111
|
+
* @param signal - optional cancellation signal forwarded to the provider.
|
|
112
|
+
* @returns the retrieval outcome; non-2xx responses resolve descriptively.
|
|
113
|
+
*/
|
|
114
|
+
async fetch(request, signal) {
|
|
115
|
+
const configuredId = this.config.fetchProvider.get() ?? this.fetchProviderEnv;
|
|
116
|
+
return resolveProvider({
|
|
117
|
+
providers: this.fetchProviders,
|
|
118
|
+
...configuredId !== void 0 ? { configuredId } : {}
|
|
119
|
+
}).fetch(request, signal);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
/** Resolve the selected provider or throw the matching {@link WebError}. */
|
|
123
|
+
function resolveProvider(selection) {
|
|
124
|
+
const { configuredId, providers } = selection;
|
|
125
|
+
if (configuredId !== void 0) {
|
|
126
|
+
const provider = providers.get(configuredId);
|
|
127
|
+
if (!provider) throw new WebError(`configured web provider "${configuredId}" is not registered`, "WEB_PROVIDER_CONFIGURED_MISSING");
|
|
128
|
+
if (!provider.available()) throw new WebError(`configured web provider "${configuredId}" is registered but unavailable`, "WEB_PROVIDER_CONFIGURED_UNAVAILABLE");
|
|
129
|
+
return provider;
|
|
130
|
+
}
|
|
131
|
+
const usable = [...providers.values()].filter((provider) => provider.available());
|
|
132
|
+
const [single] = usable;
|
|
133
|
+
if (single === void 0) throw new WebError("no usable web provider is registered", "WEB_PROVIDER_UNAVAILABLE");
|
|
134
|
+
if (usable.length > 1) throw new WebError(`multiple usable web providers are registered (${usable.map((provider) => provider.id).join(", ")}); configure one explicitly`, "WEB_PROVIDER_AMBIGUOUS");
|
|
135
|
+
return single;
|
|
136
|
+
}
|
|
137
|
+
/** Enforce `maxResults` on a search result: truncate `sources[]` and flag it. */
|
|
138
|
+
function capSources(result, maxResults) {
|
|
139
|
+
if (maxResults === void 0 || result.sources.length <= maxResults) return result;
|
|
140
|
+
return {
|
|
141
|
+
...result,
|
|
142
|
+
sources: result.sources.slice(0, maxResults),
|
|
143
|
+
truncated: true
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
export { WebError, WebRuntime, WebRuntime as default };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Definition for the web access capability seam (`ctx.web`): registries and provider-selecting execution for search and
|
|
3
|
+
* fetch. Duplicate ids are rejected. At execution time, a configured provider must exist and
|
|
4
|
+
* be usable; without one, exactly one usable provider is required, so selection never depends
|
|
5
|
+
* on registration order.
|
|
6
|
+
* @module @unieai/rabi-web
|
|
7
|
+
*/
|
|
8
|
+
import { Context, Service, type Volatile } from '@unieai/cordis';
|
|
9
|
+
import z from '@unieai/schemastery';
|
|
10
|
+
import type { WebFetchProvider, WebFetchRequest, WebFetchResult, WebSearchProvider, WebSearchRequest, WebSearchResult } from './types.ts';
|
|
11
|
+
export { WebError, } from './types.ts';
|
|
12
|
+
export type { WebFetchBody, WebFetchProvider, WebFetchRequest, WebFetchResult, WebSearchProvider, WebSearchRequest, WebSearchResult, WebSearchSource, } from './types.ts';
|
|
13
|
+
declare module '@unieai/cordis' {
|
|
14
|
+
interface Context {
|
|
15
|
+
web: WebRuntime;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Config for the web seam. `searchProvider` / `fetchProvider` pin which provider
|
|
20
|
+
* wins for each capability; both are optional (a single registered usable
|
|
21
|
+
* provider auto-selects). Each operation reads the current value, so a settings
|
|
22
|
+
* change applies to the next search or fetch without remounting the service.
|
|
23
|
+
* Operational overrides such as environment variables must feed these same
|
|
24
|
+
* fields rather than introduce a hidden priority chain.
|
|
25
|
+
*/
|
|
26
|
+
export interface WebRuntimeConfig {
|
|
27
|
+
/** Explicit search provider id. Omitted = auto-select when exactly one usable. */
|
|
28
|
+
readonly searchProvider: Volatile<string | undefined>;
|
|
29
|
+
/** Explicit fetch provider id. Omitted = auto-select when exactly one usable. */
|
|
30
|
+
readonly fetchProvider: Volatile<string | undefined>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The web access service. Registered as `ctx.web` (one instance per context).
|
|
34
|
+
*
|
|
35
|
+
* Selection semantics (resolved at execution time, never order-dependent):
|
|
36
|
+
* - A configured id that is registered and `available()` → that provider.
|
|
37
|
+
* - A configured id not registered → `WEB_PROVIDER_CONFIGURED_MISSING`.
|
|
38
|
+
* - A configured id registered but unavailable →
|
|
39
|
+
* `WEB_PROVIDER_CONFIGURED_UNAVAILABLE`.
|
|
40
|
+
* - No id configured, exactly one registered usable provider → that provider.
|
|
41
|
+
* - No id configured, multiple usable providers → `WEB_PROVIDER_AMBIGUOUS`.
|
|
42
|
+
* - No id configured, no usable provider → `WEB_PROVIDER_UNAVAILABLE`.
|
|
43
|
+
*/
|
|
44
|
+
export declare class WebRuntime extends Service {
|
|
45
|
+
private readonly config;
|
|
46
|
+
/**
|
|
47
|
+
* Provider selection config. Operational env overrides feed the SAME fields:
|
|
48
|
+
* `$RABI_WEB_SEARCH_PROVIDER` / `$RABI_WEB_FETCH_PROVIDER` are equivalent to
|
|
49
|
+
* `searchProvider` / `fetchProvider` and are NOT a hidden priority chain.
|
|
50
|
+
*/
|
|
51
|
+
static Config: z<Schemastery.ObjectS<NoInfer<{
|
|
52
|
+
searchProvider: z<string, string, "volatile">;
|
|
53
|
+
fetchProvider: z<string, string, "volatile">;
|
|
54
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
55
|
+
searchProvider: z<string, string, "volatile">;
|
|
56
|
+
fetchProvider: z<string, string, "volatile">;
|
|
57
|
+
}>>, "plain">;
|
|
58
|
+
private searchProviders;
|
|
59
|
+
private fetchProviders;
|
|
60
|
+
private readonly searchProviderEnv;
|
|
61
|
+
private readonly fetchProviderEnv;
|
|
62
|
+
constructor(ctx: Context, config: WebRuntimeConfig);
|
|
63
|
+
/**
|
|
64
|
+
* Register a search provider. Throws {@link WebError} `WEB_DUPLICATE_PROVIDER`
|
|
65
|
+
* if its id is already registered for search. Returns a disposer; disposed
|
|
66
|
+
* with the calling fiber.
|
|
67
|
+
* @param provider - the provider; its `id` is the registry key.
|
|
68
|
+
* @returns the disposer that unregisters the provider.
|
|
69
|
+
*/
|
|
70
|
+
registerSearchProvider(provider: WebSearchProvider): () => void;
|
|
71
|
+
/**
|
|
72
|
+
* Register a fetch provider. Throws {@link WebError} `WEB_DUPLICATE_PROVIDER`
|
|
73
|
+
* if its id is already registered for fetch. Returns a disposer; disposed
|
|
74
|
+
* with the calling fiber.
|
|
75
|
+
* @param provider - the provider; its `id` is the registry key.
|
|
76
|
+
* @returns the disposer that unregisters the provider.
|
|
77
|
+
*/
|
|
78
|
+
registerFetchProvider(provider: WebFetchProvider): () => void;
|
|
79
|
+
private registerProvider;
|
|
80
|
+
/**
|
|
81
|
+
* Run one search through the selected provider. Resolves the provider at call
|
|
82
|
+
* time with the selection rules above; throws {@link WebError} when the
|
|
83
|
+
* capability cannot run. The seam enforces `request.maxResults` on the result:
|
|
84
|
+
* if the provider over-returns, `sources[]` is truncated and `truncated` set.
|
|
85
|
+
* @param request - the query and optional result limit.
|
|
86
|
+
* @param signal - optional cancellation signal forwarded to the provider.
|
|
87
|
+
* @returns the provider's results, capped to `request.maxResults`.
|
|
88
|
+
*/
|
|
89
|
+
search(request: WebSearchRequest, signal?: AbortSignal): Promise<WebSearchResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Retrieve one URL through the selected provider. Resolves the provider at
|
|
92
|
+
* call time with the selection rules above; throws {@link WebError} when the
|
|
93
|
+
* capability cannot run. A non-2xx response is a result, not a throw.
|
|
94
|
+
* @param request - the URL plus retrieval options.
|
|
95
|
+
* @param signal - optional cancellation signal forwarded to the provider.
|
|
96
|
+
* @returns the retrieval outcome; non-2xx responses resolve descriptively.
|
|
97
|
+
*/
|
|
98
|
+
fetch(request: WebFetchRequest, signal?: AbortSignal): Promise<WebFetchResult>;
|
|
99
|
+
}
|
|
100
|
+
export default WebRuntime;
|
|
101
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vocabulary for the web capability seam (`ctx.web`). Search and fetch deliberately share one
|
|
3
|
+
* seam so provider selection, cancellation, errors, and product configuration have one owner,
|
|
4
|
+
* while retaining separate request and result types.
|
|
5
|
+
* @module @unieai/rabi-web/types
|
|
6
|
+
*/
|
|
7
|
+
import { HarnessError } from '@unieai/rabi-llm';
|
|
8
|
+
/**
|
|
9
|
+
* What one search-capable backend is asked to search. Each request carries one
|
|
10
|
+
* query; a consumer may issue several requests. `maxResults` is a
|
|
11
|
+
* `rabi-tool-web`-layer bound passed through unchanged and enforced on the way
|
|
12
|
+
* back by the seam (see {@link WebSearchResult}).
|
|
13
|
+
*/
|
|
14
|
+
export interface WebSearchRequest {
|
|
15
|
+
readonly query: string;
|
|
16
|
+
/**
|
|
17
|
+
* Upper bound on returned sources; the seam truncates to it. Omitted = no
|
|
18
|
+
* bound. `rabi-tool-web` always sets it. A provider whose API supports a
|
|
19
|
+
* result-count control (Exa's `numResults`) should apply it at the request
|
|
20
|
+
* layer as a cost/latency optimization; the seam enforces the bound
|
|
21
|
+
* regardless.
|
|
22
|
+
*/
|
|
23
|
+
readonly maxResults?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Normalized search outcome. `content` is optional provider-generated answer
|
|
27
|
+
* text or summary (Exa and DeepSeek return none; Perplexity returns a
|
|
28
|
+
* generated answer).
|
|
29
|
+
* `sources[]` is the portable citation shape. `truncated` is set by the seam
|
|
30
|
+
* when it cut `sources[]` down to `maxResults`.
|
|
31
|
+
*/
|
|
32
|
+
export interface WebSearchResult {
|
|
33
|
+
/** Optional provider-generated answer text, search context, or summary. */
|
|
34
|
+
readonly content?: string;
|
|
35
|
+
/** Citeable sources, already truncated to the request's `maxResults`. */
|
|
36
|
+
readonly sources: readonly WebSearchSource[];
|
|
37
|
+
/** True when the seam dropped sources to honor `maxResults`. */
|
|
38
|
+
readonly truncated: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* One citeable source. A source always has a URL; `title`, `snippet`, and
|
|
42
|
+
* `publishedAt` are optional because not every provider returns them — forcing
|
|
43
|
+
* adapters to invent them would make the seam lie (Perplexity citations may be
|
|
44
|
+
* URL-only). `rabi-tool-web` renders `title ?? hostname(url)` for display.
|
|
45
|
+
*/
|
|
46
|
+
export interface WebSearchSource {
|
|
47
|
+
readonly url: string;
|
|
48
|
+
readonly title?: string;
|
|
49
|
+
readonly snippet?: string;
|
|
50
|
+
/** Publication/crawl timestamp as a provider-supplied ISO-8601 string. */
|
|
51
|
+
readonly publishedAt?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* What one fetch-capable backend is asked to retrieve. The request deliberately
|
|
55
|
+
* omits timeout, format, prompt, and extraction controls: cancellation is a
|
|
56
|
+
* direct execution argument, while presentation and higher-level LLM concerns
|
|
57
|
+
* belong outside safe retrieval.
|
|
58
|
+
*/
|
|
59
|
+
export interface WebFetchRequest {
|
|
60
|
+
readonly url: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Normalized fetch outcome. A successful network fetch of a non-2xx response is
|
|
64
|
+
* a result, not an error: the status code is part of the fetched resource
|
|
65
|
+
* state. {@link WebError} is reserved for failures to safely retrieve or
|
|
66
|
+
* represent the resource.
|
|
67
|
+
*/
|
|
68
|
+
export interface WebFetchResult {
|
|
69
|
+
/** The final URL after allowed redirects (the request URL is in the request). */
|
|
70
|
+
readonly url: string;
|
|
71
|
+
/** HTTP status code of the fetched response. */
|
|
72
|
+
readonly statusCode: number;
|
|
73
|
+
/** Decoded body, classified by content kind. */
|
|
74
|
+
readonly body: WebFetchBody;
|
|
75
|
+
/** True when the provider capped the decoded body. */
|
|
76
|
+
readonly truncated: boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The decoded body of a fetched resource. A CLOSED discriminated union owned by
|
|
80
|
+
* `rabi-web`: the provider decodes the kind and `rabi-tool-web` renders it, so a
|
|
81
|
+
* new kind is a coordinated change across known packages, not a plugin
|
|
82
|
+
* extension. Consumers `switch` on `kind` ending in `default: assertNever(...)`
|
|
83
|
+
* so adding a kind breaks compilation at every consumer until handled. Each arm
|
|
84
|
+
* stays its own object literal even where fields coincide, so an arm can gain
|
|
85
|
+
* fields the others lack.
|
|
86
|
+
*/
|
|
87
|
+
export type WebFetchBody = {
|
|
88
|
+
readonly kind: 'html';
|
|
89
|
+
readonly content: string;
|
|
90
|
+
} | {
|
|
91
|
+
readonly kind: 'text';
|
|
92
|
+
readonly content: string;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* A search-capable backend. Registered with `ctx.web.registerSearchProvider`.
|
|
96
|
+
* `id` is a stable string, unique within the search capability kind.
|
|
97
|
+
*/
|
|
98
|
+
export interface WebSearchProvider {
|
|
99
|
+
readonly id: string;
|
|
100
|
+
/** Cheap local usability check; must not make network calls. */
|
|
101
|
+
available(): boolean;
|
|
102
|
+
/** Run one search; honor `signal` for cancellation. */
|
|
103
|
+
search(request: WebSearchRequest, signal?: AbortSignal): Promise<WebSearchResult>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A fetch-capable backend. Registered with `ctx.web.registerFetchProvider`.
|
|
107
|
+
* `id` is a stable string, unique within the fetch capability kind.
|
|
108
|
+
*/
|
|
109
|
+
export interface WebFetchProvider {
|
|
110
|
+
readonly id: string;
|
|
111
|
+
/** Cheap local usability check; must not make network calls. */
|
|
112
|
+
available(): boolean;
|
|
113
|
+
/** Retrieve one URL; honor `signal` for cancellation. */
|
|
114
|
+
fetch(request: WebFetchRequest, signal?: AbortSignal): Promise<WebFetchResult>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Typed web error with a machine-routable, open-string `code` and chained `cause`.
|
|
118
|
+
* Consumers must tolerate provider-specific codes. Shared codes cover unavailable,
|
|
119
|
+
* missing, unusable, ambiguous, or duplicate providers, cancellation, and provider failure;
|
|
120
|
+
* the local fetch provider additionally distinguishes invalid or blocked URLs, redirects,
|
|
121
|
+
* size and timeout limits, and unsupported content types. Tool execution exposes the code in
|
|
122
|
+
* structured error metadata.
|
|
123
|
+
*/
|
|
124
|
+
export declare class WebError extends HarnessError {
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=types.d.ts.map
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unieai/rabi-web",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "Abstract web access capability seam (ctx.web) for the Rabi Harness — search/fetch provider registry, registration-order-independent selection, request/result vocabulary, and the WebError taxonomy",
|
|
4
|
+
"version": "0.2.1-rc.3",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"types": "lib/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./src/*": "./src/*",
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
"./locale/*.json": "./locale/*.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"locale/*.json",
|
|
22
|
+
"lib/index.js",
|
|
23
|
+
"lib/types/**/*.d.ts",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@unieai/rabi-llm": "0.2.1-rc.3",
|
|
29
|
+
"@unieai/cordis": "4.0.5"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@unieai/schemastery": "3.18.5"
|
|
33
|
+
}
|
|
34
|
+
}
|