@unieai/rabi-web 0.0.0-stage → 0.2.2-rc.5
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 +323 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +178 -0
- package/lib/typert.remote-client.d.ts +25 -0
- package/lib/typert.remote-client.js +45 -0
- package/lib/types/index.d.ts +148 -0
- package/lib/types/index.js +301 -0
- package/lib/types/types.d.ts +201 -0
- package/lib/types/types.js +17 -0
- package/locale/de.json +6 -0
- package/locale/en.json +5 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +55 -4
- package/src/index.ts +337 -0
- package/src/types.ts +208 -0
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,323 @@
|
|
|
1
|
+
import { Remote, TypertRemoteService } from "@unieai/rabi-typert-protocol";
|
|
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, except that a search prefers the
|
|
26
|
+
* usable DeepSeek provider assigned to the route of the model request it serves, so selection never
|
|
27
|
+
* depends on registration order.
|
|
28
|
+
* @module @unieai/rabi-web
|
|
29
|
+
*/
|
|
30
|
+
var __runInitializers = function(thisArg, initializers, value) {
|
|
31
|
+
var useValue = arguments.length > 2;
|
|
32
|
+
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
36
|
+
function accept(f) {
|
|
37
|
+
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
38
|
+
return f;
|
|
39
|
+
}
|
|
40
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
41
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
42
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
43
|
+
var _, done = false;
|
|
44
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
45
|
+
var context = {};
|
|
46
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
47
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
48
|
+
context.addInitializer = function(f) {
|
|
49
|
+
if (done) throw new TypeError("Cannot add initializers after decoration has completed");
|
|
50
|
+
extraInitializers.push(accept(f || null));
|
|
51
|
+
};
|
|
52
|
+
var result = (0, decorators[i])(kind === "accessor" ? {
|
|
53
|
+
get: descriptor.get,
|
|
54
|
+
set: descriptor.set
|
|
55
|
+
} : descriptor[key], context);
|
|
56
|
+
if (kind === "accessor") {
|
|
57
|
+
if (result === void 0) continue;
|
|
58
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
59
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
60
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
61
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
62
|
+
} else if (_ = accept(result)) if (kind === "field") initializers.unshift(_);
|
|
63
|
+
else descriptor[key] = _;
|
|
64
|
+
}
|
|
65
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
66
|
+
done = true;
|
|
67
|
+
};
|
|
68
|
+
/** Provider routes of the DeepSeek API-key and account models. */
|
|
69
|
+
const DEEPSEEK_MODEL_ROUTES = new Set(["deepseek-official", "deepseek-account"]);
|
|
70
|
+
/**
|
|
71
|
+
* Search provider preferred for a model request on a DeepSeek model route while none is configured: DeepSeek
|
|
72
|
+
* Messages search, which DeepSeek serves without a per-search charge.
|
|
73
|
+
*/
|
|
74
|
+
const DEEPSEEK_ROUTE_SEARCH_PROVIDER = "deepseek-official";
|
|
75
|
+
/** Search provider preferred on every other route and outside a model request while none is configured. */
|
|
76
|
+
const OTHER_ROUTE_SEARCH_PROVIDER = "deepseek-search-api";
|
|
77
|
+
/**
|
|
78
|
+
* The web access service. Registered as `ctx.web` (one instance per context)
|
|
79
|
+
* and exposed to Clients as the `web` Remote namespace (`listProviders`).
|
|
80
|
+
*
|
|
81
|
+
* Selection semantics (resolved at execution time, never order-dependent):
|
|
82
|
+
* - A configured id that is registered and `available()` → that provider.
|
|
83
|
+
* - A configured id not registered → `WEB_PROVIDER_CONFIGURED_MISSING`.
|
|
84
|
+
* - A configured id registered but unavailable →
|
|
85
|
+
* `WEB_PROVIDER_CONFIGURED_UNAVAILABLE`.
|
|
86
|
+
* - No search id configured, and the provider assigned to the route of the model request
|
|
87
|
+
* the search serves is usable → that provider: `deepseek-official` (Messages search) on the
|
|
88
|
+
* `deepseek-official` and `deepseek-account` routes, `deepseek-search-api` on every other
|
|
89
|
+
* route and outside a model request.
|
|
90
|
+
* - No id configured, exactly one registered usable provider → that provider.
|
|
91
|
+
* - No id configured, multiple usable providers → `WEB_PROVIDER_AMBIGUOUS`.
|
|
92
|
+
* - No id configured, no usable provider → `WEB_PROVIDER_UNAVAILABLE`.
|
|
93
|
+
*/
|
|
94
|
+
let WebRuntime = (() => {
|
|
95
|
+
let _classSuper = TypertRemoteService;
|
|
96
|
+
let _instanceExtraInitializers = [];
|
|
97
|
+
let _listProviders_decorators;
|
|
98
|
+
return class WebRuntime extends _classSuper {
|
|
99
|
+
static {
|
|
100
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
101
|
+
_listProviders_decorators = [Remote];
|
|
102
|
+
__esDecorate(this, null, _listProviders_decorators, {
|
|
103
|
+
kind: "method",
|
|
104
|
+
name: "listProviders",
|
|
105
|
+
static: false,
|
|
106
|
+
private: false,
|
|
107
|
+
access: {
|
|
108
|
+
has: (obj) => "listProviders" in obj,
|
|
109
|
+
get: (obj) => obj.listProviders
|
|
110
|
+
},
|
|
111
|
+
metadata: _metadata
|
|
112
|
+
}, null, _instanceExtraInitializers);
|
|
113
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: _metadata
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
config = __runInitializers(this, _instanceExtraInitializers);
|
|
121
|
+
/**
|
|
122
|
+
* Provider selection config. Operational env overrides feed the SAME fields:
|
|
123
|
+
* `$RABI_WEB_SEARCH_PROVIDER` / `$RABI_WEB_FETCH_PROVIDER` are equivalent to
|
|
124
|
+
* `searchProvider` / `fetchProvider` and are NOT a hidden priority chain.
|
|
125
|
+
*/
|
|
126
|
+
static Config = z.object({
|
|
127
|
+
searchProvider: z.string().volatile(),
|
|
128
|
+
fetchProvider: z.string().volatile()
|
|
129
|
+
});
|
|
130
|
+
searchProviders = /* @__PURE__ */ new Map();
|
|
131
|
+
fetchProviders = /* @__PURE__ */ new Map();
|
|
132
|
+
searchProviderEnv;
|
|
133
|
+
fetchProviderEnv;
|
|
134
|
+
constructor(ctx, config) {
|
|
135
|
+
super(ctx, "web");
|
|
136
|
+
this.config = config;
|
|
137
|
+
this.searchProviderEnv = process.env.RABI_WEB_SEARCH_PROVIDER;
|
|
138
|
+
this.fetchProviderEnv = process.env.RABI_WEB_FETCH_PROVIDER;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Register a search provider. `listProviders()` lists it until the
|
|
142
|
+
* registration is disposed, which happens with the calling fiber or through
|
|
143
|
+
* the returned disposer; registration and disposal each emit
|
|
144
|
+
* `web/providers-changed`. Throws {@link WebError} `WEB_DUPLICATE_PROVIDER`
|
|
145
|
+
* if its id is already registered for search.
|
|
146
|
+
* @param provider - the provider; its `id` is the registry key.
|
|
147
|
+
* @returns the disposer that unregisters the provider.
|
|
148
|
+
*/
|
|
149
|
+
registerSearchProvider(provider) {
|
|
150
|
+
return this.registerProvider(this.searchProviders, provider);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Register a fetch provider, with the listing, disposal, and event behavior
|
|
154
|
+
* of {@link WebRuntime.registerSearchProvider}. Throws {@link WebError}
|
|
155
|
+
* `WEB_DUPLICATE_PROVIDER` if its id is already registered for fetch.
|
|
156
|
+
* @param provider - the provider; its `id` is the registry key.
|
|
157
|
+
* @returns the disposer that unregisters the provider.
|
|
158
|
+
*/
|
|
159
|
+
registerFetchProvider(provider) {
|
|
160
|
+
return this.registerProvider(this.fetchProviders, provider);
|
|
161
|
+
}
|
|
162
|
+
registerProvider(store, provider) {
|
|
163
|
+
if (store.has(provider.id)) throw new WebError(`a web provider with id "${provider.id}" is already registered`, "WEB_DUPLICATE_PROVIDER");
|
|
164
|
+
const emitChanged = () => {
|
|
165
|
+
this.emitProvidersChanged();
|
|
166
|
+
};
|
|
167
|
+
const dispose = this.ctx.effect(function* () {
|
|
168
|
+
store.set(provider.id, provider);
|
|
169
|
+
emitChanged();
|
|
170
|
+
yield () => {
|
|
171
|
+
store.delete(provider.id);
|
|
172
|
+
emitChanged();
|
|
173
|
+
};
|
|
174
|
+
}, "web.registerProvider()");
|
|
175
|
+
return () => void dispose();
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* List every registered search and fetch provider for provider pickers.
|
|
179
|
+
* Availability does not filter the lists.
|
|
180
|
+
* @returns detached `{ id, title, description }` entries per capability, in registration order.
|
|
181
|
+
*/
|
|
182
|
+
listProviders() {
|
|
183
|
+
return {
|
|
184
|
+
search: [...this.searchProviders.values()].map(providerInfo),
|
|
185
|
+
fetch: [...this.fetchProviders.values()].map(providerInfo)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/** Emit `web/providers-changed`, containing each listener's failure so none vetoes the mutation. */
|
|
189
|
+
emitProvidersChanged() {
|
|
190
|
+
for (const listener of this.ctx.events.dispatch("emit", ["web/providers-changed"])) try {
|
|
191
|
+
const returned = listener();
|
|
192
|
+
Promise.resolve(returned).catch((error) => {
|
|
193
|
+
this.warnListenerFailure(error);
|
|
194
|
+
});
|
|
195
|
+
} catch (error) {
|
|
196
|
+
this.warnListenerFailure(error);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
warnListenerFailure(error) {
|
|
200
|
+
this.ctx.logger.warn("web: a web/providers-changed listener failed");
|
|
201
|
+
this.ctx.logger.warn(error);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Run one search through the selected provider. Resolves the provider at call
|
|
205
|
+
* time with the selection rules above; throws {@link WebError} when the
|
|
206
|
+
* capability cannot run. The seam enforces `request.maxResults` on the result:
|
|
207
|
+
* if the provider over-returns, `sources[]` is truncated and `truncated` set.
|
|
208
|
+
* @param request - the query, the optional result limit, and the route of the model request the search serves.
|
|
209
|
+
* @param signal - optional cancellation signal forwarded to the provider.
|
|
210
|
+
* @returns the provider's results, capped to `request.maxResults`.
|
|
211
|
+
*/
|
|
212
|
+
async search(request, signal) {
|
|
213
|
+
return capSources(await this.selectSearchProvider(request.llmProvider).search(request, signal), request.maxResults);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Whether the provider `search()` would select can authenticate a search made for a
|
|
217
|
+
* model request on the `llmProvider` chat route. Asks only that provider's `ready()`;
|
|
218
|
+
* one without `ready()` counts as ready. Makes no network calls. A selection failure
|
|
219
|
+
* answers true, because `search()` reports that failure as a structured `WebError`.
|
|
220
|
+
* @param llmProvider - the provider route id of the model request, when known.
|
|
221
|
+
* @returns false only when the selected provider reports that it cannot authenticate.
|
|
222
|
+
*/
|
|
223
|
+
async searchReady(llmProvider) {
|
|
224
|
+
return await selectedProviderReady(() => this.selectSearchProvider(llmProvider), llmProvider);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Select the search provider with the rules above, throwing the matching {@link WebError}.
|
|
228
|
+
* @param llmProvider - provider route id of the model request the search serves, when known.
|
|
229
|
+
* @returns the provider the search runs through.
|
|
230
|
+
*/
|
|
231
|
+
selectSearchProvider(llmProvider) {
|
|
232
|
+
const configuredId = this.config.searchProvider.get() ?? this.searchProviderEnv;
|
|
233
|
+
const preferredId = llmProvider !== void 0 && DEEPSEEK_MODEL_ROUTES.has(llmProvider) ? DEEPSEEK_ROUTE_SEARCH_PROVIDER : OTHER_ROUTE_SEARCH_PROVIDER;
|
|
234
|
+
return resolveProvider({
|
|
235
|
+
providers: this.searchProviders,
|
|
236
|
+
preferredId,
|
|
237
|
+
...configuredId !== void 0 ? { configuredId } : {}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Retrieve one URL through the selected provider. Resolves the provider at
|
|
242
|
+
* call time with the selection rules above; throws {@link WebError} when the
|
|
243
|
+
* capability cannot run. A non-2xx response is a result, not a throw.
|
|
244
|
+
* @param request - the URL plus retrieval options.
|
|
245
|
+
* @param signal - optional cancellation signal forwarded to the provider.
|
|
246
|
+
* @returns the retrieval outcome; non-2xx responses resolve descriptively.
|
|
247
|
+
*/
|
|
248
|
+
async fetch(request, signal) {
|
|
249
|
+
return await this.selectFetchProvider().fetch(request, signal);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Whether the provider `fetch()` would select can authenticate a fetch made for a
|
|
253
|
+
* model request on the `llmProvider` chat route. Asks only that provider's `ready()`;
|
|
254
|
+
* one without `ready()` counts as ready. Makes no network calls. A selection failure
|
|
255
|
+
* answers true, because `fetch()` reports that failure as a structured `WebError`.
|
|
256
|
+
* @param llmProvider - the provider route id of the model request, when known.
|
|
257
|
+
* @returns false only when the selected provider reports that it cannot authenticate.
|
|
258
|
+
*/
|
|
259
|
+
async fetchReady(llmProvider) {
|
|
260
|
+
return await selectedProviderReady(() => this.selectFetchProvider(), llmProvider);
|
|
261
|
+
}
|
|
262
|
+
/** Select the fetch provider with the rules above, throwing the matching {@link WebError}. */
|
|
263
|
+
selectFetchProvider() {
|
|
264
|
+
const configuredId = this.config.fetchProvider.get() ?? this.fetchProviderEnv;
|
|
265
|
+
return resolveProvider({
|
|
266
|
+
providers: this.fetchProviders,
|
|
267
|
+
...configuredId !== void 0 ? { configuredId } : {}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
})();
|
|
272
|
+
/** Project one provider to its picker entry, omitting an absent title or description. */
|
|
273
|
+
function providerInfo(provider) {
|
|
274
|
+
return {
|
|
275
|
+
id: provider.id,
|
|
276
|
+
...provider.title === void 0 ? {} : { title: provider.title },
|
|
277
|
+
...provider.description === void 0 ? {} : { description: provider.description }
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Ask the provider an operation selects whether it can authenticate for one chat route.
|
|
282
|
+
* @param select - the operation's selection; throws its {@link WebError} when no provider qualifies.
|
|
283
|
+
* @param llmProvider - the provider route id of the model request, when known.
|
|
284
|
+
* @returns the provider's answer; true when it has no `ready()` or selection fails, because the
|
|
285
|
+
* operation reports that failure itself.
|
|
286
|
+
*/
|
|
287
|
+
async function selectedProviderReady(select, llmProvider) {
|
|
288
|
+
let provider;
|
|
289
|
+
try {
|
|
290
|
+
provider = select();
|
|
291
|
+
} catch (_selectionFailure) {
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
return await provider.ready?.(llmProvider) ?? true;
|
|
295
|
+
}
|
|
296
|
+
/** Resolve the selected provider or throw the matching {@link WebError}. */
|
|
297
|
+
function resolveProvider(selection) {
|
|
298
|
+
const { configuredId, providers } = selection;
|
|
299
|
+
if (configuredId !== void 0) {
|
|
300
|
+
const provider = providers.get(configuredId);
|
|
301
|
+
if (!provider) throw new WebError(`configured web provider "${configuredId}" is not registered`, "WEB_PROVIDER_CONFIGURED_MISSING");
|
|
302
|
+
if (!provider.available()) throw new WebError(`configured web provider "${configuredId}" is registered but unavailable`, "WEB_PROVIDER_CONFIGURED_UNAVAILABLE");
|
|
303
|
+
return provider;
|
|
304
|
+
}
|
|
305
|
+
const usable = [...providers.values()].filter((provider) => provider.available());
|
|
306
|
+
const preferred = usable.find((provider) => provider.id === selection.preferredId);
|
|
307
|
+
if (preferred !== void 0) return preferred;
|
|
308
|
+
const [single] = usable;
|
|
309
|
+
if (single === void 0) throw new WebError("no usable web provider is registered", "WEB_PROVIDER_UNAVAILABLE");
|
|
310
|
+
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");
|
|
311
|
+
return single;
|
|
312
|
+
}
|
|
313
|
+
/** Enforce `maxResults` on a search result: truncate `sources[]` and flag it. */
|
|
314
|
+
function capSources(result, maxResults) {
|
|
315
|
+
if (maxResults === void 0 || result.sources.length <= maxResults) return result;
|
|
316
|
+
return {
|
|
317
|
+
...result,
|
|
318
|
+
sources: result.sources.slice(0, maxResults),
|
|
319
|
+
truncated: true
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
//#endregion
|
|
323
|
+
export { WebError, WebRuntime, WebRuntime as default };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/* Generated by @unieai/rabi-typert-generator from FaceModel — do not edit. */
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { createTypertRemoteInfo } from '@unieai/rabi-typert-protocol/remote-info'
|
|
5
|
+
|
|
6
|
+
let _unieai_rabi_web_web_listProviders_result$schema$value
|
|
7
|
+
const _unieai_rabi_web_web_listProviders_result$schema = () => (_unieai_rabi_web_web_listProviders_result$schema$value ??= z.object({
|
|
8
|
+
'search': z.array(z.object({
|
|
9
|
+
'id': z.string().readonly().describe('The provider\'s registry id, the value `searchProvider` / `fetchProvider` select.'),
|
|
10
|
+
'title': z.string().readonly().optional().describe('The provider\'s display name; absent when the provider declares none.'),
|
|
11
|
+
'description': z.union([z.string(), z.intersection(z.object({
|
|
12
|
+
'en': z.string().readonly(),
|
|
13
|
+
}), z.record(z.string(), z.string()).readonly())]).readonly().optional().describe('The provider\'s picker description; absent when the provider declares none.'),
|
|
14
|
+
})).readonly().describe('Registered search providers.'),
|
|
15
|
+
'fetch': z.array(z.object({
|
|
16
|
+
'id': z.string().readonly().describe('The provider\'s registry id, the value `searchProvider` / `fetchProvider` select.'),
|
|
17
|
+
'title': z.string().readonly().optional().describe('The provider\'s display name; absent when the provider declares none.'),
|
|
18
|
+
'description': z.union([z.string(), z.intersection(z.object({
|
|
19
|
+
'en': z.string().readonly(),
|
|
20
|
+
}), z.record(z.string(), z.string()).readonly())]).readonly().optional().describe('The provider\'s picker description; absent when the provider declares none.'),
|
|
21
|
+
})).readonly().describe('Registered fetch providers.'),
|
|
22
|
+
}))
|
|
23
|
+
|
|
24
|
+
const $remote = createTypertRemoteInfo({
|
|
25
|
+
package: '@unieai/rabi-web',
|
|
26
|
+
methods: {
|
|
27
|
+
'web/listProviders': {
|
|
28
|
+
service: 'web',
|
|
29
|
+
description: 'List every registered search and fetch provider for provider pickers. Availability does not filter the lists.',
|
|
30
|
+
invocation: { kind: 'direct' },
|
|
31
|
+
parameters: [
|
|
32
|
+
],
|
|
33
|
+
result: {
|
|
34
|
+
mode: 'strict',
|
|
35
|
+
typeSymbol: '@unieai/rabi-web/types#WebProviderList',
|
|
36
|
+
create: _unieai_rabi_web_web_listProviders_result$schema,
|
|
37
|
+
description: 'detached `{ id, title, description }` entries per capability, in registration order.',
|
|
38
|
+
jsonSchemaError: 'typert tool schema: selected dictionaries require string keys and unconstrained JSON values',
|
|
39
|
+
},
|
|
40
|
+
sourceLocation: {"file":"packages/web/web/src/index.ts","line":174,"column":3},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
}, z)
|
|
44
|
+
|
|
45
|
+
export const TYPERT = {
|
|
46
|
+
package: '@unieai/rabi-web',
|
|
47
|
+
face: 'host',
|
|
48
|
+
schemas: [
|
|
49
|
+
],
|
|
50
|
+
get invocations() { return $remote.descriptors },
|
|
51
|
+
model: {
|
|
52
|
+
"services": [
|
|
53
|
+
{
|
|
54
|
+
"description": "The web access service. Registered as `ctx.web` (one instance per context) and exposed to Clients as the `web` Remote namespace (`listProviders`). Selection semantics (resolved at execution time, never order-dependent): - A configured id that is registered and `available()` → that provider. - A configured id not registered → `WEB_PROVIDER_CONFIGURED_MISSING`. - A configured id registered but unavailable → `WEB_PROVIDER_CONFIGURED_UNAVAILABLE`. - No search id configured, and the provider assigned to the route of the model request the search serves is usable → that provider: `deepseek-official` (Messages search) on the `deepseek-official` and `deepseek-account` routes, `deepseek-search-api` on every other route and outside a model request. - No id configured, exactly one registered usable provider → that provider. - No id configured, multiple usable providers → `WEB_PROVIDER_AMBIGUOUS`. - No id configured, no usable provider → `WEB_PROVIDER_UNAVAILABLE`.",
|
|
55
|
+
"summary": "The web access service.",
|
|
56
|
+
"tags": [],
|
|
57
|
+
"jsDoc": "/**\n * The web access service. Registered as `ctx.web` (one instance per context)\n * and exposed to Clients as the `web` Remote namespace (`listProviders`).\n *\n * Selection semantics (resolved at execution time, never order-dependent):\n * - A configured id that is registered and `available()` → that provider.\n * - A configured id not registered → `WEB_PROVIDER_CONFIGURED_MISSING`.\n * - A configured id registered but unavailable →\n * `WEB_PROVIDER_CONFIGURED_UNAVAILABLE`.\n * - No search id configured, and the provider assigned to the route of the model request\n * the search serves is usable → that provider: `deepseek-official` (Messages search) on the\n * `deepseek-official` and `deepseek-account` routes, `deepseek-search-api` on every other\n * route and outside a model request.\n * - No id configured, exactly one registered usable provider → that provider.\n * - No id configured, multiple usable providers → `WEB_PROVIDER_AMBIGUOUS`.\n * - No id configured, no usable provider → `WEB_PROVIDER_UNAVAILABLE`.\n */",
|
|
58
|
+
"key": "web",
|
|
59
|
+
"exportName": "WebRuntime",
|
|
60
|
+
"members": [
|
|
61
|
+
{
|
|
62
|
+
"kind": "method",
|
|
63
|
+
"name": "registerSearchProvider",
|
|
64
|
+
"signature": "registerSearchProvider(provider: WebSearchProvider): () => void",
|
|
65
|
+
"summary": "Register a search provider.",
|
|
66
|
+
"jsDoc": "/**\n * Register a search provider. `listProviders()` lists it until the\n * registration is disposed, which happens with the calling fiber or through\n * the returned disposer; registration and disposal each emit\n * `web/providers-changed`. Throws {@link WebError} `WEB_DUPLICATE_PROVIDER`\n * if its id is already registered for search.\n * @param provider - the provider; its `id` is the registry key.\n * @returns the disposer that unregisters the provider.\n */"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"kind": "method",
|
|
70
|
+
"name": "registerFetchProvider",
|
|
71
|
+
"signature": "registerFetchProvider(provider: WebFetchProvider): () => void",
|
|
72
|
+
"summary": "Register a fetch provider, with the listing, disposal, and event behavior of {@link WebRuntime.registerSearchProvider}.",
|
|
73
|
+
"jsDoc": "/**\n * Register a fetch provider, with the listing, disposal, and event behavior\n * of {@link WebRuntime.registerSearchProvider}. Throws {@link WebError}\n * `WEB_DUPLICATE_PROVIDER` if its id is already registered for fetch.\n * @param provider - the provider; its `id` is the registry key.\n * @returns the disposer that unregisters the provider.\n */"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"kind": "method",
|
|
77
|
+
"name": "listProviders",
|
|
78
|
+
"signature": "@Remote listProviders(): WebProviderList",
|
|
79
|
+
"summary": "List every registered search and fetch provider for provider pickers.",
|
|
80
|
+
"jsDoc": "/**\n * List every registered search and fetch provider for provider pickers.\n * Availability does not filter the lists.\n * @returns detached `{ id, title, description }` entries per capability, in registration order.\n */"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"kind": "method",
|
|
84
|
+
"name": "search",
|
|
85
|
+
"signature": "async search(request: WebSearchRequest, signal?: AbortSignal): Promise<WebSearchResult>",
|
|
86
|
+
"summary": "Run one search through the selected provider.",
|
|
87
|
+
"jsDoc": "/**\n * Run one search through the selected provider. Resolves the provider at call\n * time with the selection rules above; throws {@link WebError} when the\n * capability cannot run. The seam enforces `request.maxResults` on the result:\n * if the provider over-returns, `sources[]` is truncated and `truncated` set.\n * @param request - the query, the optional result limit, and the route of the model request the search serves.\n * @param signal - optional cancellation signal forwarded to the provider.\n * @returns the provider's results, capped to `request.maxResults`.\n */"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"kind": "method",
|
|
91
|
+
"name": "searchReady",
|
|
92
|
+
"signature": "async searchReady(llmProvider?: string): Promise<boolean>",
|
|
93
|
+
"summary": "Whether the provider `search()` would select can authenticate a search made for a model request on the `llmProvider` chat route.",
|
|
94
|
+
"jsDoc": "/**\n * Whether the provider `search()` would select can authenticate a search made for a\n * model request on the `llmProvider` chat route. Asks only that provider's `ready()`;\n * one without `ready()` counts as ready. Makes no network calls. A selection failure\n * answers true, because `search()` reports that failure as a structured `WebError`.\n * @param llmProvider - the provider route id of the model request, when known.\n * @returns false only when the selected provider reports that it cannot authenticate.\n */"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"kind": "method",
|
|
98
|
+
"name": "fetch",
|
|
99
|
+
"signature": "async fetch(request: WebFetchRequest, signal?: AbortSignal): Promise<WebFetchResult>",
|
|
100
|
+
"summary": "Retrieve one URL through the selected provider.",
|
|
101
|
+
"jsDoc": "/**\n * Retrieve one URL through the selected provider. Resolves the provider at\n * call time with the selection rules above; throws {@link WebError} when the\n * capability cannot run. A non-2xx response is a result, not a throw.\n * @param request - the URL plus retrieval options.\n * @param signal - optional cancellation signal forwarded to the provider.\n * @returns the retrieval outcome; non-2xx responses resolve descriptively.\n */"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"kind": "method",
|
|
105
|
+
"name": "fetchReady",
|
|
106
|
+
"signature": "async fetchReady(llmProvider?: string): Promise<boolean>",
|
|
107
|
+
"summary": "Whether the provider `fetch()` would select can authenticate a fetch made for a model request on the `llmProvider` chat route.",
|
|
108
|
+
"jsDoc": "/**\n * Whether the provider `fetch()` would select can authenticate a fetch made for a\n * model request on the `llmProvider` chat route. Asks only that provider's `ready()`;\n * one without `ready()` counts as ready. Makes no network calls. A selection failure\n * answers true, because `fetch()` reports that failure as a structured `WebError`.\n * @param llmProvider - the provider route id of the model request, when known.\n * @returns false only when the selected provider reports that it cannot authenticate.\n */"
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
"types": [
|
|
112
|
+
{
|
|
113
|
+
"name": "LocalizedText",
|
|
114
|
+
"declaration": "export type LocalizedText = string | { readonly en: string; readonly [locale: string]: string; };"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"name": "WebFetchBody",
|
|
118
|
+
"declaration": "export type WebFetchBody = { readonly kind: 'html'; readonly content: string; } | { readonly kind: 'text'; readonly content: string; };"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"name": "WebFetchProvider",
|
|
122
|
+
"declaration": "export interface WebFetchProvider {\n readonly id: string;\n readonly title?: string;\n readonly description?: LocalizedText;\n available(): boolean;\n ready?(llmProvider: string | undefined): Promise<boolean>;\n fetch(request: WebFetchRequest, signal?: AbortSignal): Promise<WebFetchResult>;\n}"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"name": "WebFetchRequest",
|
|
126
|
+
"declaration": "export interface WebFetchRequest {\n readonly url: string;\n}"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": "WebFetchResult",
|
|
130
|
+
"declaration": "export interface WebFetchResult {\n readonly url: string;\n readonly statusCode: number;\n readonly body: WebFetchBody;\n readonly truncated: boolean;\n}"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"name": "WebProviderInfo",
|
|
134
|
+
"declaration": "export interface WebProviderInfo {\n readonly id: string;\n readonly title?: string;\n readonly description?: LocalizedText;\n}"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"name": "WebProviderList",
|
|
138
|
+
"declaration": "export interface WebProviderList {\n readonly search: readonly WebProviderInfo[];\n readonly fetch: readonly WebProviderInfo[];\n}"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"name": "WebSearchProvider",
|
|
142
|
+
"declaration": "export interface WebSearchProvider {\n readonly id: string;\n readonly title?: string;\n readonly description?: LocalizedText;\n available(): boolean;\n ready?(llmProvider: string | undefined): Promise<boolean>;\n search(request: WebSearchRequest, signal?: AbortSignal): Promise<WebSearchResult>;\n}"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"name": "WebSearchRequest",
|
|
146
|
+
"declaration": "export interface WebSearchRequest {\n readonly query: string;\n readonly maxResults?: number;\n readonly llmProvider?: string;\n}"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"name": "WebSearchResult",
|
|
150
|
+
"declaration": "export interface WebSearchResult {\n readonly content?: string;\n readonly sources: readonly WebSearchSource[];\n readonly truncated: boolean;\n}"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"name": "WebSearchSource",
|
|
154
|
+
"declaration": "export interface WebSearchSource {\n readonly url: string;\n readonly title?: string;\n readonly snippet?: string;\n readonly summary?: string;\n readonly publishedAt?: string;\n}"
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"events": [
|
|
160
|
+
{
|
|
161
|
+
"description": "The set of registered search or fetch providers changed: one provider registered, or its registration was disposed. Payload-free; consumers re-read `ctx.web.listProviders()` (Remote `web/listProviders`) for the new list. Fires after each committed registry mutation. Observer failures are contained and cannot veto the mutation.",
|
|
162
|
+
"summary": "The set of registered search or fetch providers changed: one provider registered, or its registration was disposed.",
|
|
163
|
+
"tags": [
|
|
164
|
+
{
|
|
165
|
+
"name": "mode",
|
|
166
|
+
"comment": "emit",
|
|
167
|
+
"text": "@mode emit"
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
"jsDoc": "/**\n * The set of registered search or fetch providers changed: one provider\n * registered, or its registration was disposed. Payload-free; consumers\n * re-read `ctx.web.listProviders()` (Remote `web/listProviders`) for the\n * new list. Fires after each committed registry mutation. Observer failures\n * are contained and cannot veto the mutation.\n * @mode emit\n */",
|
|
171
|
+
"name": "web/providers-changed",
|
|
172
|
+
"mode": "emit",
|
|
173
|
+
"signature": "'web/providers-changed'(): void"
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
"objects": []
|
|
177
|
+
},
|
|
178
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* Generated by @unieai/rabi-typert-generator from the Host FaceModel — do not edit. */
|
|
2
|
+
import type {
|
|
3
|
+
RemoteResult,
|
|
4
|
+
TypertRemoteInfo,
|
|
5
|
+
TypertRemoteMethod,
|
|
6
|
+
} from '@unieai/rabi-typert-protocol'
|
|
7
|
+
import type { WebProviderList } from '@unieai/rabi-web/types'
|
|
8
|
+
|
|
9
|
+
declare module '@unieai/rabi-typert-protocol' {
|
|
10
|
+
interface TypertRemoteNamespace$776562 {
|
|
11
|
+
listProviders: () => Promise<RemoteResult<WebProviderList>>
|
|
12
|
+
}
|
|
13
|
+
interface TypertRemoteMap {
|
|
14
|
+
'web/listProviders': () => Promise<RemoteResult<WebProviderList>>
|
|
15
|
+
}
|
|
16
|
+
interface TypertRemoteNamespaceMap {
|
|
17
|
+
'web': TypertRemoteNamespace$776562
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export declare const TYPERT_REMOTE: TypertRemoteInfo<{
|
|
22
|
+
readonly 'web/listProviders': TypertRemoteMethod<{ }, WebProviderList>
|
|
23
|
+
}>
|
|
24
|
+
export default TYPERT_REMOTE
|
|
25
|
+
//# sourceMappingURL=typert.remote-client.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* Generated by @unieai/rabi-typert-generator from the Host FaceModel — do not edit. */
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { createTypertRemoteInfo } from '@unieai/rabi-typert-protocol/remote-info'
|
|
5
|
+
|
|
6
|
+
let _unieai_rabi_web_web_listProviders_result$schema$value
|
|
7
|
+
const _unieai_rabi_web_web_listProviders_result$schema = () => (_unieai_rabi_web_web_listProviders_result$schema$value ??= z.object({
|
|
8
|
+
'search': z.array(z.object({
|
|
9
|
+
'id': z.string().readonly().describe('The provider\'s registry id, the value `searchProvider` / `fetchProvider` select.'),
|
|
10
|
+
'title': z.string().readonly().optional().describe('The provider\'s display name; absent when the provider declares none.'),
|
|
11
|
+
'description': z.union([z.string(), z.intersection(z.object({
|
|
12
|
+
'en': z.string().readonly(),
|
|
13
|
+
}), z.record(z.string(), z.string()).readonly())]).readonly().optional().describe('The provider\'s picker description; absent when the provider declares none.'),
|
|
14
|
+
})).readonly().describe('Registered search providers.'),
|
|
15
|
+
'fetch': z.array(z.object({
|
|
16
|
+
'id': z.string().readonly().describe('The provider\'s registry id, the value `searchProvider` / `fetchProvider` select.'),
|
|
17
|
+
'title': z.string().readonly().optional().describe('The provider\'s display name; absent when the provider declares none.'),
|
|
18
|
+
'description': z.union([z.string(), z.intersection(z.object({
|
|
19
|
+
'en': z.string().readonly(),
|
|
20
|
+
}), z.record(z.string(), z.string()).readonly())]).readonly().optional().describe('The provider\'s picker description; absent when the provider declares none.'),
|
|
21
|
+
})).readonly().describe('Registered fetch providers.'),
|
|
22
|
+
}))
|
|
23
|
+
|
|
24
|
+
export const TYPERT_REMOTE = createTypertRemoteInfo({
|
|
25
|
+
package: '@unieai/rabi-web',
|
|
26
|
+
methods: {
|
|
27
|
+
'web/listProviders': {
|
|
28
|
+
service: 'web',
|
|
29
|
+
description: 'List every registered search and fetch provider for provider pickers. Availability does not filter the lists.',
|
|
30
|
+
invocation: { kind: 'direct' },
|
|
31
|
+
parameters: [
|
|
32
|
+
],
|
|
33
|
+
result: {
|
|
34
|
+
mode: 'strict',
|
|
35
|
+
typeSymbol: '@unieai/rabi-web/types#WebProviderList',
|
|
36
|
+
create: _unieai_rabi_web_web_listProviders_result$schema,
|
|
37
|
+
description: 'detached `{ id, title, description }` entries per capability, in registration order.',
|
|
38
|
+
jsonSchemaError: 'typert tool schema: selected dictionaries require string keys and unconstrained JSON values',
|
|
39
|
+
},
|
|
40
|
+
sourceLocation: {"file":"packages/web/web/src/index.ts","line":174,"column":3},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
}, z)
|
|
44
|
+
|
|
45
|
+
export default TYPERT_REMOTE
|