dsh-web-search-enhanced 0.2.1 → 0.2.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/README.md +17 -3
- package/lib/client.cjs +136 -73
- package/lib/client.cjs.map +1 -1
- package/lib/index.js +492 -100
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -150,10 +150,23 @@ function decodeJsonEscapes(value) {
|
|
|
150
150
|
}
|
|
151
151
|
//#endregion
|
|
152
152
|
//#region ../core/src/host/adapter.ts
|
|
153
|
+
/** The default: generic wording with the generic explanation, as today. */
|
|
154
|
+
const statusVerdict = (response) => ({
|
|
155
|
+
kind: "status",
|
|
156
|
+
detail: response.explanation
|
|
157
|
+
});
|
|
153
158
|
function mapWire(wire, map) {
|
|
159
|
+
const parseFailure = wire.parseFailure === void 0 ? void 0 : wire.parseFailure.bind(wire);
|
|
154
160
|
const mapped = {
|
|
155
161
|
request: (input, endpoint, auth) => wire.request(input, endpoint, auth),
|
|
156
|
-
parse: (payload, input) => map(wire.parse(payload, input))
|
|
162
|
+
parse: (payload, input) => map(wire.parse(payload, input)),
|
|
163
|
+
...parseFailure === void 0 ? {} : { parseFailure(response, input) {
|
|
164
|
+
const verdict = parseFailure(response, input);
|
|
165
|
+
return verdict.kind === "status" ? verdict : {
|
|
166
|
+
kind: "outcome",
|
|
167
|
+
outcome: map(verdict.outcome)
|
|
168
|
+
};
|
|
169
|
+
} }
|
|
157
170
|
};
|
|
158
171
|
const route = wire.keyless;
|
|
159
172
|
if (route === void 0) return mapped;
|
|
@@ -216,8 +229,7 @@ function runAdapter(io, wire, target, input, signal) {
|
|
|
216
229
|
}, deadline, upstream);
|
|
217
230
|
return route.parse(result, input);
|
|
218
231
|
}
|
|
219
|
-
|
|
220
|
-
return wire.parse(await io.transport.requestJson(request, deadline, upstream), input);
|
|
232
|
+
return await runRest(io, wire, wire.request(input, target.endpoint, { kind: "keyless" }), input, deadline, upstream);
|
|
221
233
|
}
|
|
222
234
|
const stored = storedApiKey(await adapterCredential(io, target.credentialRef, deadline));
|
|
223
235
|
if (stored.kind === "missing") throw io.errors.error("WEB_PROVIDER_CREDENTIAL_MISSING", io.credentialMissing(target.credentialRef));
|
|
@@ -229,17 +241,23 @@ function runAdapter(io, wire, target, input, signal) {
|
|
|
229
241
|
onDiagnostic: io.onDiagnostic,
|
|
230
242
|
matcher
|
|
231
243
|
};
|
|
232
|
-
|
|
244
|
+
return await runRest(io, wire, wire.request(input, target.endpoint, {
|
|
233
245
|
kind: "api-key",
|
|
234
246
|
key: stored.key
|
|
235
|
-
});
|
|
236
|
-
return redactJson(wire.parse(await io.transport.requestJson(request, deadline, upstream), input), matcher);
|
|
247
|
+
}), input, deadline, upstream);
|
|
237
248
|
} catch (error) {
|
|
238
249
|
if (error instanceof WebError) throw error;
|
|
239
250
|
throw redactDiagnostic(error, matcher === void 0 ? secretMatcher([]) : matcher);
|
|
240
251
|
}
|
|
241
252
|
});
|
|
242
253
|
}
|
|
254
|
+
async function runRest(io, wire, request, input, signal, upstream) {
|
|
255
|
+
const exchange = await io.transport.exchangeJson(request, signal, upstream);
|
|
256
|
+
if (exchange.kind === "ok") return redactJson(wire.parse(exchange.payload, input), upstream.matcher);
|
|
257
|
+
const verdict = wire.parseFailure === void 0 ? statusVerdict(exchange.response) : wire.parseFailure(exchange.response, input);
|
|
258
|
+
if (verdict.kind === "status") throw io.transport.statusFailure(exchange.response.status, upstream, verdict.detail);
|
|
259
|
+
return verdict.outcome;
|
|
260
|
+
}
|
|
243
261
|
async function adapterCredential(io, ref, signal) {
|
|
244
262
|
try {
|
|
245
263
|
return await io.errors.abortable(io.credential(ref), signal);
|
|
@@ -304,9 +322,8 @@ function createTransport(errors, { timeoutMs, maxResponseBytes, messages }) {
|
|
|
304
322
|
clearTimeout(timer);
|
|
305
323
|
}
|
|
306
324
|
}
|
|
307
|
-
async function
|
|
325
|
+
async function exchangeResponse(request, signal, upstream, matcher) {
|
|
308
326
|
throwIfAborted(signal);
|
|
309
|
-
const matcher = upstream.matcher === void 0 ? secretMatcher([]) : upstream.matcher;
|
|
310
327
|
let response;
|
|
311
328
|
try {
|
|
312
329
|
response = await fetch(request.url, {
|
|
@@ -321,14 +338,25 @@ function createTransport(errors, { timeoutMs, maxResponseBytes, messages }) {
|
|
|
321
338
|
throwIfAborted(signal);
|
|
322
339
|
throw capabilityError("WEB_PROVIDER_ERROR", messages.unreachable(upstream.label));
|
|
323
340
|
}
|
|
324
|
-
if (
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
341
|
+
if (response.ok) return {
|
|
342
|
+
kind: "ok",
|
|
343
|
+
response
|
|
344
|
+
};
|
|
345
|
+
const body = await readFailureText(response, signal, upstream, matcher);
|
|
346
|
+
return {
|
|
347
|
+
kind: "failure",
|
|
348
|
+
response: failureResponse(response.status, body.text, matcher, body.truncated)
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
async function send(request, signal, upstream) {
|
|
352
|
+
const exchange = await exchangeResponse(request, signal, upstream, upstream.matcher === void 0 ? secretMatcher([]) : upstream.matcher);
|
|
353
|
+
if (exchange.kind === "failure") throw statusFailure(exchange.response.status, upstream, exchange.response.explanation);
|
|
354
|
+
return exchange.response;
|
|
355
|
+
}
|
|
356
|
+
function statusFailure(status, upstream, detail) {
|
|
357
|
+
const failure = statusError(status, upstream);
|
|
358
|
+
if (detail === void 0) return failure;
|
|
359
|
+
return new WebError(failure.message + upstreamSuffix(upstream.label, detail), failure.code);
|
|
332
360
|
}
|
|
333
361
|
function statusError(status, { label, access }) {
|
|
334
362
|
if (status === 401 || status === 403) {
|
|
@@ -448,12 +476,19 @@ function createTransport(errors, { timeoutMs, maxResponseBytes, messages }) {
|
|
|
448
476
|
}
|
|
449
477
|
return payload;
|
|
450
478
|
}
|
|
451
|
-
async function
|
|
479
|
+
async function exchangeJson(request, signal, upstream) {
|
|
452
480
|
const matcher = upstream.matcher === void 0 ? secretMatcher([]) : upstream.matcher;
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
481
|
+
const exchange = await exchangeResponse(request, signal, upstream, matcher);
|
|
482
|
+
if (exchange.kind === "failure") return exchange;
|
|
483
|
+
return {
|
|
484
|
+
kind: "ok",
|
|
485
|
+
payload: redactJson(await readJson(exchange.response, signal, upstream.onDiagnostic, matcher), matcher)
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
async function requestJson(request, signal, upstream) {
|
|
489
|
+
const exchange = await exchangeJson(request, signal, upstream);
|
|
490
|
+
if (exchange.kind === "failure") throw statusFailure(exchange.response.status, upstream, exchange.response.explanation);
|
|
491
|
+
return exchange.payload;
|
|
457
492
|
}
|
|
458
493
|
function invalidResponse(detail) {
|
|
459
494
|
return capabilityError("WEB_PROVIDER_ERROR", messages.invalidResponse(detail));
|
|
@@ -467,6 +502,8 @@ function createTransport(errors, { timeoutMs, maxResponseBytes, messages }) {
|
|
|
467
502
|
readText,
|
|
468
503
|
readJson,
|
|
469
504
|
requestJson,
|
|
505
|
+
exchangeJson,
|
|
506
|
+
statusFailure,
|
|
470
507
|
invalidResponse
|
|
471
508
|
};
|
|
472
509
|
}
|
|
@@ -479,26 +516,55 @@ function upstreamText(value) {
|
|
|
479
516
|
const boundary = last >= 55296 && last <= 56319 ? 1998 : 1999;
|
|
480
517
|
return text.slice(0, boundary) + "…";
|
|
481
518
|
}
|
|
519
|
+
function screenedText(value) {
|
|
520
|
+
return value.trim() === "" ? void 0 : {
|
|
521
|
+
kind: "text",
|
|
522
|
+
text: value
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
/** Text from a successful body, already redacted by transport: uncut, never withheld. */
|
|
526
|
+
function bodyDetail(value) {
|
|
527
|
+
return typeof value === "string" ? screenedText(value) : void 0;
|
|
528
|
+
}
|
|
482
529
|
/** Sensitive raw explanations are withheld, not precisely edited. */
|
|
483
530
|
function upstreamDetail(value, matcher, truncated = false) {
|
|
484
531
|
if (containsSecret(value, matcher)) return { kind: "withheld" };
|
|
485
|
-
|
|
486
|
-
return text === void 0 ? void 0 : {
|
|
487
|
-
kind: "text",
|
|
488
|
-
text
|
|
489
|
-
};
|
|
532
|
+
return screenedText(truncated ? stripPrefix(value, matcher) : value);
|
|
490
533
|
}
|
|
491
534
|
function upstreamSuffix(label, detail) {
|
|
492
535
|
if (detail === void 0) return "";
|
|
493
|
-
if (
|
|
494
|
-
|
|
536
|
+
if ("text" in detail) {
|
|
537
|
+
const text = upstreamText(detail.text);
|
|
538
|
+
return text === void 0 ? "" : "\n\n" + label + " responded (untrusted): " + text;
|
|
539
|
+
}
|
|
540
|
+
return "\n\n" + label + "'s response was withheld because it contained this request's credential.";
|
|
495
541
|
}
|
|
496
542
|
function stripPrefix(text, matcher) {
|
|
497
543
|
for (let length = Math.min(7, text.length); length > 0; length--) if (matcher.prefixes.has(text.slice(-length))) return text.slice(0, -length);
|
|
498
544
|
return text;
|
|
499
545
|
}
|
|
500
|
-
function
|
|
501
|
-
|
|
546
|
+
function failureResponse(status, body, matcher, truncated) {
|
|
547
|
+
const sensitive = containsSecret(body, matcher);
|
|
548
|
+
return {
|
|
549
|
+
status,
|
|
550
|
+
json: truncated ? void 0 : redactJson(failureJson(body), matcher),
|
|
551
|
+
explanation: failureExplanation(body, matcher, truncated, sensitive),
|
|
552
|
+
explain(value) {
|
|
553
|
+
if (sensitive) return { kind: "withheld" };
|
|
554
|
+
return typeof value === "string" ? upstreamDetail(value, matcher) : void 0;
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
function failureJson(body) {
|
|
559
|
+
try {
|
|
560
|
+
return JSON.parse(body);
|
|
561
|
+
} catch (error) {
|
|
562
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
function failureExplanation(body, matcher, truncated, sensitive) {
|
|
567
|
+
if (sensitive) return { kind: "withheld" };
|
|
502
568
|
const text = truncated ? stripPrefix(body, matcher) : body;
|
|
503
569
|
let payload;
|
|
504
570
|
try {
|
|
@@ -14680,7 +14746,8 @@ const SEARCH = {
|
|
|
14680
14746
|
tools: {
|
|
14681
14747
|
action: "web_search_enhanced",
|
|
14682
14748
|
list: "list_web_search_providers"
|
|
14683
|
-
}
|
|
14749
|
+
},
|
|
14750
|
+
command: "setup-search"
|
|
14684
14751
|
};
|
|
14685
14752
|
//#endregion
|
|
14686
14753
|
//#region ../core/src/shared/route.ts
|
|
@@ -14952,8 +15019,6 @@ async function runOnProvider(voice, access, connectionId, request, call, unhinte
|
|
|
14952
15019
|
/** The recipient `sendsTo` names for fetch `local`; the text says `fetches from this machine`. */
|
|
14953
15020
|
const THIS_MACHINE = "this machine";
|
|
14954
15021
|
const SESSION_MODEL = "the service behind the session model";
|
|
14955
|
-
/** Operator data in the listing is one line and bounded; labels and service names share the settings label bound. */
|
|
14956
|
-
const LABEL_MAX = 200;
|
|
14957
15022
|
const HOST_MAX = 253;
|
|
14958
15023
|
/** Why the session model cannot search, in English; the execution layer's error and the listing share it. */
|
|
14959
15024
|
const UNSUPPORTED_REASON_TEXT = {
|
|
@@ -15084,7 +15149,7 @@ function renderSearchListing(voice, value) {
|
|
|
15084
15149
|
}
|
|
15085
15150
|
function renderLines(voice, value, head, parts) {
|
|
15086
15151
|
const entries = value.providers.map((entry) => {
|
|
15087
|
-
const line = [statusText(entry)];
|
|
15152
|
+
const line = [statusText$1(entry)];
|
|
15088
15153
|
if (entry.id === value.sessionProvider) line.push("selected for this session");
|
|
15089
15154
|
if (entry.use !== void 0) line.push(entry.use);
|
|
15090
15155
|
line.push(...parts.marks(entry));
|
|
@@ -15100,7 +15165,7 @@ function renderLines(voice, value, head, parts) {
|
|
|
15100
15165
|
...tail
|
|
15101
15166
|
].join("\n");
|
|
15102
15167
|
}
|
|
15103
|
-
function statusText(entry) {
|
|
15168
|
+
function statusText$1(entry) {
|
|
15104
15169
|
switch (entry.status) {
|
|
15105
15170
|
case "ready": return "ready";
|
|
15106
15171
|
case "needs-key": return "needs an API key (ask the user)";
|
|
@@ -15118,7 +15183,7 @@ function listedBase(entry) {
|
|
|
15118
15183
|
const { use, recipient } = entry.facts;
|
|
15119
15184
|
return {
|
|
15120
15185
|
id: entry.id,
|
|
15121
|
-
name: oneLine(entry.name,
|
|
15186
|
+
name: oneLine(entry.name, 200),
|
|
15122
15187
|
...use === void 0 ? {} : { use },
|
|
15123
15188
|
sendsTo: recipientText(recipient)
|
|
15124
15189
|
};
|
|
@@ -15126,8 +15191,8 @@ function listedBase(entry) {
|
|
|
15126
15191
|
function recipientText(recipient) {
|
|
15127
15192
|
switch (recipient.kind) {
|
|
15128
15193
|
case "this-machine": return THIS_MACHINE;
|
|
15129
|
-
case "session-model": return recipient.provider === void 0 ? SESSION_MODEL : `${SESSION_MODEL} (${oneLine(recipient.provider,
|
|
15130
|
-
case "service": return recipient.host === void 0 ? oneLine(recipient.service,
|
|
15194
|
+
case "session-model": return recipient.provider === void 0 ? SESSION_MODEL : `${SESSION_MODEL} (${oneLine(recipient.provider, 200)})`;
|
|
15195
|
+
case "service": return recipient.host === void 0 ? oneLine(recipient.service, 200) : oneLine(recipient.host, HOST_MAX);
|
|
15131
15196
|
}
|
|
15132
15197
|
}
|
|
15133
15198
|
function readiness(entry) {
|
|
@@ -15214,8 +15279,8 @@ function nativeAuth(ctx, ref, secrets = /* @__PURE__ */ new Set()) {
|
|
|
15214
15279
|
};
|
|
15215
15280
|
}
|
|
15216
15281
|
/** Account readiness uses the next selected model, while request authentication uses its frozen route. */
|
|
15217
|
-
async function credentialReadiness(ctx,
|
|
15218
|
-
const account = options.endpoint !== void 0 &&
|
|
15282
|
+
async function credentialReadiness(ctx, model, options) {
|
|
15283
|
+
const account = options.endpoint !== void 0 && model?.provider === "deepseek-account" ? ctx.get("deepseekAccount") : void 0;
|
|
15219
15284
|
if (account !== void 0 && await account.resolveToken(options.endpoint) !== void 0) return {
|
|
15220
15285
|
access: "account",
|
|
15221
15286
|
status: "ready"
|
|
@@ -15311,10 +15376,32 @@ var Snapshots = class {
|
|
|
15311
15376
|
}
|
|
15312
15377
|
};
|
|
15313
15378
|
//#endregion
|
|
15379
|
+
//#region ../core/src/host/session-origin.ts
|
|
15380
|
+
function sessionOrigin(header) {
|
|
15381
|
+
const { parentSession: parent, isSeeded: seeded, origin } = header;
|
|
15382
|
+
if (origin === "subagent") return {
|
|
15383
|
+
kind: "subagent",
|
|
15384
|
+
parent,
|
|
15385
|
+
seeded
|
|
15386
|
+
};
|
|
15387
|
+
return parent === void 0 ? {
|
|
15388
|
+
kind: "top-level",
|
|
15389
|
+
seeded
|
|
15390
|
+
} : {
|
|
15391
|
+
kind: "fork",
|
|
15392
|
+
parent,
|
|
15393
|
+
seeded
|
|
15394
|
+
};
|
|
15395
|
+
}
|
|
15396
|
+
function parentOf(origin) {
|
|
15397
|
+
return origin.kind === "top-level" ? void 0 : origin.parent;
|
|
15398
|
+
}
|
|
15399
|
+
//#endregion
|
|
15314
15400
|
//#region ../core/src/host/provider-lists.ts
|
|
15315
15401
|
/** Live setup/created events do not make a new conversation a restored one. */
|
|
15316
15402
|
function isNewConversation(session) {
|
|
15317
|
-
|
|
15403
|
+
const origin = sessionOrigin(session.header);
|
|
15404
|
+
return parentOf(origin) === void 0 && !origin.seeded && session.firstLiveSeq === 0 && session.firstLifecycleSeq === 0;
|
|
15318
15405
|
}
|
|
15319
15406
|
/** Immutable conversation authorization, sharing the selection queue and storage lifetime. */
|
|
15320
15407
|
var ProviderLists = class {
|
|
@@ -15333,7 +15420,7 @@ var ProviderLists = class {
|
|
|
15333
15420
|
const table = (await this.storage.domain()).table("provider_lists");
|
|
15334
15421
|
const stored = table.get(agent.session.id);
|
|
15335
15422
|
if (stored !== void 0) return this.nonempty(stored);
|
|
15336
|
-
const parent = agent.session.header
|
|
15423
|
+
const parent = parentOf(sessionOrigin(agent.session.header));
|
|
15337
15424
|
let ids;
|
|
15338
15425
|
if (parent !== void 0) {
|
|
15339
15426
|
await this.storage.settled(parent);
|
|
@@ -15356,6 +15443,14 @@ function isSelectable(connection) {
|
|
|
15356
15443
|
}
|
|
15357
15444
|
//#endregion
|
|
15358
15445
|
//#region ../core/src/host/sessions.ts
|
|
15446
|
+
function liveSession(agent) {
|
|
15447
|
+
return {
|
|
15448
|
+
kind: "live",
|
|
15449
|
+
id: agent.session.id,
|
|
15450
|
+
header: agent.session.header,
|
|
15451
|
+
agent
|
|
15452
|
+
};
|
|
15453
|
+
}
|
|
15359
15454
|
var SelectionConflict = class extends Error {
|
|
15360
15455
|
constructor() {
|
|
15361
15456
|
super("the selection changed since it was read");
|
|
@@ -15376,20 +15471,20 @@ var Sessions = class {
|
|
|
15376
15471
|
this.restriction = restriction;
|
|
15377
15472
|
this.describe = describe;
|
|
15378
15473
|
}
|
|
15379
|
-
current(
|
|
15380
|
-
return this.exclusive(
|
|
15474
|
+
current(target) {
|
|
15475
|
+
return this.exclusive(target.id, async () => this.read(target, await this.table()));
|
|
15381
15476
|
}
|
|
15382
15477
|
/** Resolve visibility without creating records or materializing inherited/default options. */
|
|
15383
|
-
peek(
|
|
15384
|
-
return this.exclusive(
|
|
15478
|
+
peek(target) {
|
|
15479
|
+
return this.exclusive(target.id, async () => this.read(target, await this.table(), false));
|
|
15385
15480
|
}
|
|
15386
|
-
change(
|
|
15387
|
-
return this.exclusive(
|
|
15481
|
+
change(target, change, expectedRevision) {
|
|
15482
|
+
return this.exclusive(target.id, async () => {
|
|
15388
15483
|
const table = await this.table();
|
|
15389
|
-
await this.read(
|
|
15484
|
+
await this.read(target, table);
|
|
15390
15485
|
const { connectionId, ...options } = change;
|
|
15391
15486
|
const record = this.storage.optionsCodec.toRecord(options);
|
|
15392
|
-
const updated = await table.update(
|
|
15487
|
+
const updated = await table.update(target.id, (current) => {
|
|
15393
15488
|
if (current.revision !== expectedRevision) throw new SelectionConflict();
|
|
15394
15489
|
return {
|
|
15395
15490
|
...current,
|
|
@@ -15398,9 +15493,10 @@ var Sessions = class {
|
|
|
15398
15493
|
revision: current.revision + 1
|
|
15399
15494
|
};
|
|
15400
15495
|
});
|
|
15401
|
-
this.
|
|
15402
|
-
if (
|
|
15403
|
-
|
|
15496
|
+
const agent = this.ctx.get("agents")?.get(target.id);
|
|
15497
|
+
if (agent !== void 0) this.restriction.sync(agent, updated.connectionId);
|
|
15498
|
+
if (connectionId !== void 0 && sessionOrigin(target.header).kind !== "subagent") {
|
|
15499
|
+
const model = this.model(target);
|
|
15404
15500
|
if (model !== void 0) {
|
|
15405
15501
|
const memory = await this.pairings.set(model, updated.connectionId).then(() => ({ kind: "stored" }), (error) => ({
|
|
15406
15502
|
kind: "failed",
|
|
@@ -15415,29 +15511,33 @@ var Sessions = class {
|
|
|
15415
15511
|
};
|
|
15416
15512
|
});
|
|
15417
15513
|
}
|
|
15418
|
-
connections(
|
|
15419
|
-
return this.describe(this.settings(),
|
|
15514
|
+
connections(target) {
|
|
15515
|
+
return this.describe(this.settings(), this.model(target));
|
|
15420
15516
|
}
|
|
15421
15517
|
selectable(connectionId) {
|
|
15422
15518
|
return isSelectable(this.settings().connections.get(connectionId));
|
|
15423
15519
|
}
|
|
15520
|
+
model(target) {
|
|
15521
|
+
return target.kind === "live" ? nextModel(this.ctx, target.agent) : void 0;
|
|
15522
|
+
}
|
|
15424
15523
|
async table() {
|
|
15425
15524
|
return (await this.storage.domain()).table("selections");
|
|
15426
15525
|
}
|
|
15427
15526
|
exclusive(id, work) {
|
|
15428
15527
|
return this.storage.exclusive(id, work);
|
|
15429
15528
|
}
|
|
15430
|
-
async read(
|
|
15529
|
+
async read(target, table, persist = true) {
|
|
15431
15530
|
const settings = this.settings();
|
|
15432
15531
|
const codec = this.storage.optionsCodec;
|
|
15433
|
-
const id =
|
|
15532
|
+
const id = target.id;
|
|
15434
15533
|
let stored = table.get(id);
|
|
15435
|
-
const
|
|
15436
|
-
const
|
|
15534
|
+
const origin = sessionOrigin(target.header);
|
|
15535
|
+
const parentSession = parentOf(origin);
|
|
15536
|
+
const seeded = parentSession !== void 0 && origin.seeded;
|
|
15437
15537
|
let inherited = stored !== void 0 && seeded && (stored.inherited ?? table.get(parentSession) !== void 0);
|
|
15438
15538
|
if (stored === void 0 && seeded) {
|
|
15439
15539
|
const parentAgent = this.ctx.get("agents")?.get(parentSession);
|
|
15440
|
-
if (parentAgent !== void 0 && persist) await this.current(parentAgent);
|
|
15540
|
+
if (parentAgent !== void 0 && persist) await this.current(liveSession(parentAgent));
|
|
15441
15541
|
else await this.storage.settled(parentSession);
|
|
15442
15542
|
const parent = table.get(parentSession);
|
|
15443
15543
|
if (parent !== void 0) {
|
|
@@ -15461,7 +15561,7 @@ var Sessions = class {
|
|
|
15461
15561
|
source: next.revision > 0 ? "session" : "inherited"
|
|
15462
15562
|
};
|
|
15463
15563
|
}
|
|
15464
|
-
const fallback = await this.defaultFor(
|
|
15564
|
+
const fallback = await this.defaultFor(target, settings);
|
|
15465
15565
|
const options = stored === void 0 ? codec.initial(settings) : codec.fromRecord(stored, settings);
|
|
15466
15566
|
const next = {
|
|
15467
15567
|
...codec.toRecord(options),
|
|
@@ -15475,8 +15575,8 @@ var Sessions = class {
|
|
|
15475
15575
|
source: fallback.source
|
|
15476
15576
|
};
|
|
15477
15577
|
}
|
|
15478
|
-
async defaultFor(
|
|
15479
|
-
const model =
|
|
15578
|
+
async defaultFor(target, settings) {
|
|
15579
|
+
const model = this.model(target);
|
|
15480
15580
|
const paired = model === void 0 ? void 0 : await this.pairings.get(model);
|
|
15481
15581
|
if (paired === null) return {
|
|
15482
15582
|
connectionId: null,
|
|
@@ -15503,6 +15603,24 @@ function sameRecord(left, right) {
|
|
|
15503
15603
|
return left !== void 0 && JSON.stringify(left) === JSON.stringify(right);
|
|
15504
15604
|
}
|
|
15505
15605
|
//#endregion
|
|
15606
|
+
//#region ../core/src/host/selection-write.ts
|
|
15607
|
+
/** The shared eligibility check and revisioned write for commands and Remote set. */
|
|
15608
|
+
async function writeSelection(sessions, target, change, expectedRevision) {
|
|
15609
|
+
if (typeof change.connectionId === "string" && !sessions.selectable(change.connectionId)) return {
|
|
15610
|
+
kind: "unavailable",
|
|
15611
|
+
connectionId: change.connectionId
|
|
15612
|
+
};
|
|
15613
|
+
try {
|
|
15614
|
+
return {
|
|
15615
|
+
kind: "written",
|
|
15616
|
+
current: await sessions.change(target, change, expectedRevision)
|
|
15617
|
+
};
|
|
15618
|
+
} catch (error) {
|
|
15619
|
+
if (error instanceof SelectionConflict) return { kind: "conflict" };
|
|
15620
|
+
throw error;
|
|
15621
|
+
}
|
|
15622
|
+
}
|
|
15623
|
+
//#endregion
|
|
15506
15624
|
//#region ../core/src/host/remote.ts
|
|
15507
15625
|
var __runInitializers = function(thisArg, initializers, value) {
|
|
15508
15626
|
var useValue = arguments.length > 2;
|
|
@@ -15650,27 +15768,22 @@ function createConnectionsService(ctx, spec) {
|
|
|
15650
15768
|
async get(request) {
|
|
15651
15769
|
return boundary("get", async () => {
|
|
15652
15770
|
const { sessionId } = parse(selectionRequest, request);
|
|
15653
|
-
const
|
|
15654
|
-
return this.view(
|
|
15771
|
+
const target = await this.target(sessionId);
|
|
15772
|
+
return this.view(target, await spec.sessions.current(target));
|
|
15655
15773
|
});
|
|
15656
15774
|
}
|
|
15657
15775
|
async set(request) {
|
|
15658
15776
|
return boundary("set", async () => {
|
|
15659
15777
|
const { sessionId, connectionId, options, expectedRevision } = parse(spec.contract.selectionChange, request);
|
|
15660
|
-
const
|
|
15661
|
-
|
|
15662
|
-
|
|
15663
|
-
|
|
15664
|
-
|
|
15665
|
-
|
|
15666
|
-
|
|
15667
|
-
|
|
15668
|
-
|
|
15669
|
-
} catch (error) {
|
|
15670
|
-
if (error instanceof SelectionConflict) throw new RemoteError(spec.namespace + "/conflict", "the selection changed elsewhere; re-read it and retry", {});
|
|
15671
|
-
throw error;
|
|
15672
|
-
}
|
|
15673
|
-
return this.view(agent, current);
|
|
15778
|
+
const target = await this.target(sessionId);
|
|
15779
|
+
const change = {
|
|
15780
|
+
...options,
|
|
15781
|
+
...connectionId === void 0 ? {} : { connectionId }
|
|
15782
|
+
};
|
|
15783
|
+
const result = await writeSelection(spec.sessions, target, change, expectedRevision);
|
|
15784
|
+
if (result.kind === "unavailable") throw new RemoteError(spec.namespace + "/unavailable", "the connection is missing, disabled or unsupported", { connectionId: result.connectionId });
|
|
15785
|
+
if (result.kind === "conflict") throw new RemoteError(spec.namespace + "/conflict", "the selection changed elsewhere; re-read it and retry", {});
|
|
15786
|
+
return this.view(target, result.current);
|
|
15674
15787
|
});
|
|
15675
15788
|
}
|
|
15676
15789
|
async provider(request) {
|
|
@@ -15692,15 +15805,27 @@ function createConnectionsService(ctx, spec) {
|
|
|
15692
15805
|
return { pairings: await spec.pairings.list() };
|
|
15693
15806
|
});
|
|
15694
15807
|
}
|
|
15695
|
-
async
|
|
15696
|
-
const
|
|
15808
|
+
async target(sessionId) {
|
|
15809
|
+
const id = sessionId;
|
|
15810
|
+
const agent = this.ctx.agents.get(id);
|
|
15811
|
+
if (agent !== void 0) return liveSession(agent);
|
|
15812
|
+
const persistence = this.ctx.get("sessionPersistence");
|
|
15813
|
+
if (persistence !== void 0) {
|
|
15814
|
+
const stored = await persistence.stat(id);
|
|
15815
|
+
if (stored !== void 0 && sessionOrigin(stored.header).kind === "subagent") return {
|
|
15816
|
+
kind: "cold",
|
|
15817
|
+
id,
|
|
15818
|
+
header: stored.header
|
|
15819
|
+
};
|
|
15820
|
+
}
|
|
15821
|
+
const found = await this.ctx.sessionController.resolveAgent(id);
|
|
15697
15822
|
if ("error" in found) throw found.error;
|
|
15698
|
-
return found.agent;
|
|
15823
|
+
return liveSession(found.agent);
|
|
15699
15824
|
}
|
|
15700
|
-
async view(
|
|
15825
|
+
async view(target, current) {
|
|
15701
15826
|
return {
|
|
15702
15827
|
...current,
|
|
15703
|
-
connections: await spec.sessions.connections(
|
|
15828
|
+
connections: await spec.sessions.connections(target)
|
|
15704
15829
|
};
|
|
15705
15830
|
}
|
|
15706
15831
|
};
|
|
@@ -16014,7 +16139,7 @@ function explicitAccess(ctx, capability, runtime, errors, unavailable) {
|
|
|
16014
16139
|
const described = await errors.abortable(capability.describe({
|
|
16015
16140
|
...prepared.settings,
|
|
16016
16141
|
connections
|
|
16017
|
-
}, call.agent), call.signal);
|
|
16142
|
+
}, nextModel(ctx, call.agent)), call.signal);
|
|
16018
16143
|
errors.throwIfAborted(call.signal);
|
|
16019
16144
|
return new Map(described.map((view) => [view.id, view]));
|
|
16020
16145
|
} catch {
|
|
@@ -16211,6 +16336,188 @@ var SessionStorage = class {
|
|
|
16211
16336
|
}
|
|
16212
16337
|
};
|
|
16213
16338
|
//#endregion
|
|
16339
|
+
//#region ../core/src/host/command.ts
|
|
16340
|
+
var SelectionOperationError = class extends Error {};
|
|
16341
|
+
const SOURCES = {
|
|
16342
|
+
session: "chosen in this session",
|
|
16343
|
+
inherited: "copied from the parent session",
|
|
16344
|
+
model: "remembered for this model",
|
|
16345
|
+
default: "the default connection"
|
|
16346
|
+
};
|
|
16347
|
+
function registerCommand(ctx, capability, sessions) {
|
|
16348
|
+
const { command, providerId, rowId } = capability.identity;
|
|
16349
|
+
const noun = capability.tool === "web_search" ? "web search" : "web fetch";
|
|
16350
|
+
const capital = capability.tool === "web_search" ? "Web search" : "Web fetch";
|
|
16351
|
+
const options = capability.commandOptions;
|
|
16352
|
+
const hint = options === void 0 ? "[off | <connection id>]" : "[off | <connection id> | freshness auto|fresh|realtime]";
|
|
16353
|
+
const failure = "The " + noun + " selection could not be read or saved; retry, or check the Host logs.";
|
|
16354
|
+
const error = (text) => ({
|
|
16355
|
+
kind: "error",
|
|
16356
|
+
text
|
|
16357
|
+
});
|
|
16358
|
+
const selectionOperation = async (work) => {
|
|
16359
|
+
try {
|
|
16360
|
+
return await work();
|
|
16361
|
+
} catch (cause) {
|
|
16362
|
+
if (cause instanceof InvalidSettingsError) throw cause;
|
|
16363
|
+
ctx.logger.warn("%s command selection read or write failed: %s", rowId, cause);
|
|
16364
|
+
throw new SelectionOperationError("selection read or write failed");
|
|
16365
|
+
}
|
|
16366
|
+
};
|
|
16367
|
+
const route = () => routeFacts(ctx, capability.field, providerId);
|
|
16368
|
+
const routing = () => routingText(route(), capability.tool, providerId);
|
|
16369
|
+
const unavailable = (id) => error(id + " is missing or turned off in the settings. Run /" + command + " to list the connections.");
|
|
16370
|
+
const success = (text) => ({
|
|
16371
|
+
kind: "success",
|
|
16372
|
+
text: text + (route().kind === "this" ? "" : "\n" + routing())
|
|
16373
|
+
});
|
|
16374
|
+
const run = async (invocation) => {
|
|
16375
|
+
const raw = invocation.rawInput.trim();
|
|
16376
|
+
const args = raw === "" ? [] : raw.split(/\s+/u);
|
|
16377
|
+
const usage = () => error("Unknown argument \"" + oneLine(raw, 64) + "\". Usage: /" + command + " " + hint);
|
|
16378
|
+
const keyword = args.length === 0 ? "" : args[0].toLowerCase();
|
|
16379
|
+
const freshnessValue = args.length === 2 ? args[1].toLowerCase() : "";
|
|
16380
|
+
const freshness = options !== void 0 && args.length === 2 && keyword === "freshness";
|
|
16381
|
+
if (args.length > 0 && !freshness && !(args.length === 1 && (keyword === "off" || isConnectionId(args[0])))) return usage();
|
|
16382
|
+
if (freshness && !FRESHNESS.some((value) => value === freshnessValue)) return error("Unknown freshness \"" + oneLine(args[1], 64) + "\". Use auto, fresh or realtime.");
|
|
16383
|
+
const target = liveSession(invocation.agent);
|
|
16384
|
+
const settings = capability.settings();
|
|
16385
|
+
const current = await selectionOperation(() => sessions.current(target));
|
|
16386
|
+
if (args.length === 0) {
|
|
16387
|
+
const views = await sessions.connections(target);
|
|
16388
|
+
const id = current.selection.connectionId;
|
|
16389
|
+
const selected = id === null ? void 0 : views.find((view) => view.id === id);
|
|
16390
|
+
let summary = id === null ? "Off" : selected === void 0 || !sessions.selectable(id) ? id : oneLine(selected.label, 200) + " (" + id + ")";
|
|
16391
|
+
summary += " · " + SOURCES[current.source];
|
|
16392
|
+
if (id !== null && !sessions.selectable(id)) summary += " · missing or turned off in the settings; " + capability.tool + " fails until another connection is chosen";
|
|
16393
|
+
if (options !== void 0) summary += " · freshness: " + options.freshness(current.selection.options);
|
|
16394
|
+
const entries = [];
|
|
16395
|
+
for (const view of views) {
|
|
16396
|
+
const connection = settings.connections.get(view.id);
|
|
16397
|
+
if (!isSelectable(connection)) continue;
|
|
16398
|
+
const name = oneLine(view.label, 200);
|
|
16399
|
+
const parts = [statusText(view)];
|
|
16400
|
+
if (view.id === id) parts.push("current");
|
|
16401
|
+
if (view.freshness === true) parts.push("applies freshness");
|
|
16402
|
+
const recipient = recipientText(capability.enhanced.listing(connection, {
|
|
16403
|
+
agent: invocation.agent,
|
|
16404
|
+
signal: invocation.signal
|
|
16405
|
+
}).recipient);
|
|
16406
|
+
if (recipient === "this machine") parts.push("fetches from this machine");
|
|
16407
|
+
else if (recipient !== name) parts.push((capability.tool === "web_search" ? "queries" : "URLs") + " go to " + recipient);
|
|
16408
|
+
entries.push("- " + view.id + " — " + name + " · " + parts.join(" · "));
|
|
16409
|
+
}
|
|
16410
|
+
if (entries.length === 0) entries.push("- (none; turn connections on in the row settings)");
|
|
16411
|
+
const tail = "Turn off: /" + command + " off" + (options === void 0 ? "" : " · Freshness: /" + command + " freshness auto|fresh|realtime (connections marked \"applies freshness\")");
|
|
16412
|
+
return {
|
|
16413
|
+
kind: "success",
|
|
16414
|
+
text: [
|
|
16415
|
+
summary,
|
|
16416
|
+
routing(),
|
|
16417
|
+
"Connections (/" + command + " <id> chooses one):",
|
|
16418
|
+
...entries,
|
|
16419
|
+
tail
|
|
16420
|
+
].join("\n")
|
|
16421
|
+
};
|
|
16422
|
+
}
|
|
16423
|
+
let change;
|
|
16424
|
+
let message;
|
|
16425
|
+
if (freshness && options !== void 0) {
|
|
16426
|
+
const selected = (await sessions.connections(target)).find((view) => view.id === current.selection.connectionId);
|
|
16427
|
+
if (selected === void 0 || selected.freshness !== true || !sessions.selectable(selected.id)) return error("The current connection does not apply freshness. Choose one marked \"applies freshness\" first.");
|
|
16428
|
+
const value = FRESHNESS.find((mode) => mode === freshnessValue);
|
|
16429
|
+
change = options.changeFreshness(value);
|
|
16430
|
+
message = "Freshness is " + value + " from the next model request.";
|
|
16431
|
+
} else if (keyword === "off") {
|
|
16432
|
+
change = { connectionId: null };
|
|
16433
|
+
message = capital + " is off for this session from the next model request.";
|
|
16434
|
+
} else {
|
|
16435
|
+
const id = args[0];
|
|
16436
|
+
if (!sessions.selectable(id)) return unavailable(id);
|
|
16437
|
+
const selected = (await sessions.connections(target)).find((view) => view.id === id);
|
|
16438
|
+
change = { connectionId: id };
|
|
16439
|
+
message = "Now using " + oneLine(selected.label, 200) + " (" + id + ") for " + noun + " from the next model request.";
|
|
16440
|
+
}
|
|
16441
|
+
const result = await selectionOperation(() => writeSelection(sessions, target, change, current.selection.revision));
|
|
16442
|
+
if (result.kind === "unavailable") return unavailable(result.connectionId);
|
|
16443
|
+
if (result.kind === "conflict") return error("The selection changed while this command ran. Run /" + command + " to see it, then try again.");
|
|
16444
|
+
return success(message);
|
|
16445
|
+
};
|
|
16446
|
+
ctx.effect(() => ctx.commands.register({
|
|
16447
|
+
name: command,
|
|
16448
|
+
description: "Show or change this session's " + noun + " connection",
|
|
16449
|
+
input: { hint },
|
|
16450
|
+
async handler(invocation) {
|
|
16451
|
+
try {
|
|
16452
|
+
return await run(invocation);
|
|
16453
|
+
} catch (cause) {
|
|
16454
|
+
if (cause instanceof SelectionOperationError) return error(failure);
|
|
16455
|
+
ctx.logger.warn("%s command failed: %s", rowId, cause);
|
|
16456
|
+
if (cause instanceof InvalidSettingsError) return error("The " + noun + " settings are invalid; fix them in the Enhanced " + noun + " row settings.");
|
|
16457
|
+
throw new Error("The " + noun + " command failed; retry, or check the Host logs.");
|
|
16458
|
+
}
|
|
16459
|
+
}
|
|
16460
|
+
}));
|
|
16461
|
+
}
|
|
16462
|
+
function routingText(route, tool, providerId) {
|
|
16463
|
+
switch (route.kind) {
|
|
16464
|
+
case "this": return "Routing: " + tool + " goes to this plugin.";
|
|
16465
|
+
case "other": return "Routing: " + tool + " goes to " + oneLine(route.provider, 200) + ", so this selection has no effect until the web row routes it to " + providerId + ".";
|
|
16466
|
+
case "auto": return "Routing: the web row pins no " + tool + " provider, so this selection has no effect until it routes " + tool + " to " + providerId + ".";
|
|
16467
|
+
case "unknown": return "Routing: the web row could not be read, so this selection may have no effect.";
|
|
16468
|
+
}
|
|
16469
|
+
}
|
|
16470
|
+
function statusText(view) {
|
|
16471
|
+
switch (view.status) {
|
|
16472
|
+
case "ready": return "ready";
|
|
16473
|
+
case "needs-credential": return view.access === "account" ? "needs DeepSeek sign-in" : "needs an API key";
|
|
16474
|
+
case "unsupported": return "unavailable: " + UNSUPPORTED_REASON_TEXT[view.reason];
|
|
16475
|
+
case "disabled": return "missing or turned off in the settings";
|
|
16476
|
+
}
|
|
16477
|
+
}
|
|
16478
|
+
//#endregion
|
|
16479
|
+
//#region ../core/src/host/terminal.ts
|
|
16480
|
+
function registerTerminal(ctx, root, noun, settings, freshness) {
|
|
16481
|
+
ctx.effect(() => ctx.tuiCommandTrees.register({
|
|
16482
|
+
root,
|
|
16483
|
+
children(path) {
|
|
16484
|
+
if (path[0] !== root) return [];
|
|
16485
|
+
if (freshness && path.length === 2 && path[1] === "freshness") return [
|
|
16486
|
+
{
|
|
16487
|
+
name: "auto",
|
|
16488
|
+
description: "Auto"
|
|
16489
|
+
},
|
|
16490
|
+
{
|
|
16491
|
+
name: "fresh",
|
|
16492
|
+
description: "Within 24 hours"
|
|
16493
|
+
},
|
|
16494
|
+
{
|
|
16495
|
+
name: "realtime",
|
|
16496
|
+
description: "Live"
|
|
16497
|
+
}
|
|
16498
|
+
];
|
|
16499
|
+
if (path.length !== 1) return [];
|
|
16500
|
+
const nodes = [{
|
|
16501
|
+
name: "off",
|
|
16502
|
+
description: "Turn " + noun + " off for this session"
|
|
16503
|
+
}];
|
|
16504
|
+
try {
|
|
16505
|
+
for (const connection of settings().connections.values()) if (isSelectable(connection)) nodes.push({
|
|
16506
|
+
name: connection.id,
|
|
16507
|
+
description: oneLine(connection.label, 200)
|
|
16508
|
+
});
|
|
16509
|
+
} catch (error) {
|
|
16510
|
+
if (!(error instanceof InvalidSettingsError)) throw error;
|
|
16511
|
+
}
|
|
16512
|
+
if (freshness) nodes.push({
|
|
16513
|
+
name: "freshness",
|
|
16514
|
+
description: "Content freshness, for connections that apply it"
|
|
16515
|
+
});
|
|
16516
|
+
return nodes;
|
|
16517
|
+
}
|
|
16518
|
+
}));
|
|
16519
|
+
}
|
|
16520
|
+
//#endregion
|
|
16214
16521
|
//#region ../core/src/host/runtime.ts
|
|
16215
16522
|
/** Install the sole Seat, session lifecycle, route-guarded restrictions and Remote service. */
|
|
16216
16523
|
function installCapability(ctx, capability) {
|
|
@@ -16231,7 +16538,7 @@ function installCapability(ctx, capability) {
|
|
|
16231
16538
|
const restriction = new ToolRestriction(ctx, {
|
|
16232
16539
|
tool: capability.tool,
|
|
16233
16540
|
routed: () => routeFacts(ctx, capability.field, capability.identity.providerId).kind === "this",
|
|
16234
|
-
selection: async (agent) => (await sessions.peek(agent)).selection.connectionId,
|
|
16541
|
+
selection: async (agent) => (await sessions.peek(liveSession(agent))).selection.connectionId,
|
|
16235
16542
|
enhanced: {
|
|
16236
16543
|
rowId: capability.identity.rowId,
|
|
16237
16544
|
names: capability.enhanced.names,
|
|
@@ -16247,11 +16554,11 @@ function installCapability(ctx, capability) {
|
|
|
16247
16554
|
providers: (agent) => lists.read(agent)
|
|
16248
16555
|
}
|
|
16249
16556
|
});
|
|
16250
|
-
const sessions = new Sessions(ctx, () => capability.settings(), storage, pairings, restriction, (settings,
|
|
16557
|
+
const sessions = new Sessions(ctx, () => capability.settings(), storage, pairings, restriction, (settings, model) => capability.describe(settings, model));
|
|
16251
16558
|
const capture = async (agent, signal) => {
|
|
16252
16559
|
const operation = restriction.begin(agent);
|
|
16253
16560
|
try {
|
|
16254
|
-
const read = sessions.current(agent);
|
|
16561
|
+
const read = sessions.current(liveSession(agent));
|
|
16255
16562
|
const { selection } = signal === void 0 ? await read : await errors.abortable(read, signal);
|
|
16256
16563
|
if (!restriction.active) return {
|
|
16257
16564
|
kind: "failed",
|
|
@@ -16298,7 +16605,17 @@ function installCapability(ctx, capability) {
|
|
|
16298
16605
|
snapshots.forget(agent);
|
|
16299
16606
|
restriction.forget(agent);
|
|
16300
16607
|
});
|
|
16301
|
-
ctx.inject(["
|
|
16608
|
+
ctx.inject(["commands"], (scope) => {
|
|
16609
|
+
registerCommand(scope, capability, sessions);
|
|
16610
|
+
});
|
|
16611
|
+
ctx.inject(["tuiCommandTrees"], (scope) => {
|
|
16612
|
+
registerTerminal(scope, capability.identity.command, "web " + kind, () => capability.settings(), capability.commandOptions !== void 0);
|
|
16613
|
+
});
|
|
16614
|
+
ctx.inject([
|
|
16615
|
+
"sessionController",
|
|
16616
|
+
"typert",
|
|
16617
|
+
"agents"
|
|
16618
|
+
], (scope) => {
|
|
16302
16619
|
createConnectionsService(scope, {
|
|
16303
16620
|
namespace: capability.remoteNamespace,
|
|
16304
16621
|
contract: capability.contract,
|
|
@@ -16366,7 +16683,7 @@ function envelope(payload) {
|
|
|
16366
16683
|
payload.message
|
|
16367
16684
|
]) {
|
|
16368
16685
|
if (typeof candidate !== "string") continue;
|
|
16369
|
-
detail =
|
|
16686
|
+
detail = bodyDetail(candidate);
|
|
16370
16687
|
if (detail !== void 0) break;
|
|
16371
16688
|
}
|
|
16372
16689
|
return {
|
|
@@ -16684,6 +17001,54 @@ const tinyfishSearch = {
|
|
|
16684
17001
|
}
|
|
16685
17002
|
};
|
|
16686
17003
|
//#endregion
|
|
17004
|
+
//#region ../core/src/host/providers/anysearch.ts
|
|
17005
|
+
/** AnySearch REST search and extract. The catalog offers personal keys only; there is no anonymous route here. */
|
|
17006
|
+
/** 402 means the quota is spent; its body is ignored (for anonymous callers it carries a generated account). */
|
|
17007
|
+
function quotaVerdict(response) {
|
|
17008
|
+
return response.status === 402 ? {
|
|
17009
|
+
kind: "status",
|
|
17010
|
+
detail: void 0
|
|
17011
|
+
} : void 0;
|
|
17012
|
+
}
|
|
17013
|
+
const anysearchSearch = {
|
|
17014
|
+
request(input, endpoint, auth) {
|
|
17015
|
+
return postJson(endpoint, bearer(auth), {
|
|
17016
|
+
...input.options,
|
|
17017
|
+
query: input.query,
|
|
17018
|
+
...count("max_results", input.maxResults, 10)
|
|
17019
|
+
});
|
|
17020
|
+
},
|
|
17021
|
+
parse(payload) {
|
|
17022
|
+
if (!isRecord(payload)) return {
|
|
17023
|
+
kind: "failure",
|
|
17024
|
+
failure: "invalid",
|
|
17025
|
+
reason: "not-object"
|
|
17026
|
+
};
|
|
17027
|
+
if (typeof payload.code !== "number") return {
|
|
17028
|
+
kind: "failure",
|
|
17029
|
+
failure: "invalid",
|
|
17030
|
+
reason: "code-number"
|
|
17031
|
+
};
|
|
17032
|
+
if (payload.code !== 0) return {
|
|
17033
|
+
kind: "failure",
|
|
17034
|
+
failure: "api",
|
|
17035
|
+
detail: bodyDetail(payload.message)
|
|
17036
|
+
};
|
|
17037
|
+
const rows = isRecord(payload.data) ? payload.data.results : void 0;
|
|
17038
|
+
if (!Array.isArray(rows)) return {
|
|
17039
|
+
kind: "failure",
|
|
17040
|
+
failure: "invalid",
|
|
17041
|
+
reason: "data-results-array"
|
|
17042
|
+
};
|
|
17043
|
+
return mapRows(rows, (row) => ({
|
|
17044
|
+
url: row.url,
|
|
17045
|
+
title: row.title,
|
|
17046
|
+
snippet: text$1(row.snippet) ?? row.content
|
|
17047
|
+
}));
|
|
17048
|
+
},
|
|
17049
|
+
parseFailure: (response) => quotaVerdict(response) ?? statusVerdict(response)
|
|
17050
|
+
};
|
|
17051
|
+
//#endregion
|
|
16687
17052
|
//#region ../core/src/host/providers/openalex.ts
|
|
16688
17053
|
/** OpenAlex works search, scholarly field mapping and bounded inverted abstracts. */
|
|
16689
17054
|
/** OpenAlex asks anonymous clients to identify themselves for the polite pool. */
|
|
@@ -17180,7 +17545,7 @@ const { withDeadline, readJson, requestJson, invalidResponse } = transport;
|
|
|
17180
17545
|
const mcp = createMcpClient(transport, searchErrors, {
|
|
17181
17546
|
clientInfo: {
|
|
17182
17547
|
name: SEARCH.packageName,
|
|
17183
|
-
version: "0.2.
|
|
17548
|
+
version: "0.2.3"
|
|
17184
17549
|
},
|
|
17185
17550
|
messages: {
|
|
17186
17551
|
toolFailed: (label, detail) => label + " could not complete the search; retry later or choose another search connection" + upstreamSuffix(label, detail),
|
|
@@ -17529,6 +17894,30 @@ const CATALOG = {
|
|
|
17529
17894
|
}
|
|
17530
17895
|
}
|
|
17531
17896
|
},
|
|
17897
|
+
anysearch: {
|
|
17898
|
+
label: "AnySearch",
|
|
17899
|
+
endpoint: "https://api.anysearch.com/v1/search",
|
|
17900
|
+
access: {
|
|
17901
|
+
keyless: false,
|
|
17902
|
+
apiKey: { credentialRef: "ANYSEARCH_API_KEY" },
|
|
17903
|
+
account: false
|
|
17904
|
+
},
|
|
17905
|
+
kind: "adapter",
|
|
17906
|
+
remote: true,
|
|
17907
|
+
optIn: true,
|
|
17908
|
+
freshness: [],
|
|
17909
|
+
homepage: "https://www.anysearch.com",
|
|
17910
|
+
options: {
|
|
17911
|
+
zone: {
|
|
17912
|
+
kind: "enum",
|
|
17913
|
+
values: ["cn", "intl"]
|
|
17914
|
+
},
|
|
17915
|
+
language: {
|
|
17916
|
+
kind: "text",
|
|
17917
|
+
pattern: /^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8}){0,2}$/u
|
|
17918
|
+
}
|
|
17919
|
+
}
|
|
17920
|
+
},
|
|
17532
17921
|
openalex: {
|
|
17533
17922
|
label: "OpenAlex",
|
|
17534
17923
|
endpoint: "https://api.openalex.org/works",
|
|
@@ -17906,6 +18295,8 @@ contract.options;
|
|
|
17906
18295
|
/** What the search service returned, in the model-facing invalid-response message. */
|
|
17907
18296
|
const INVALID_DETAIL = {
|
|
17908
18297
|
"not-object": "a body that is not a JSON object",
|
|
18298
|
+
"code-number": "no numeric \"code\" field",
|
|
18299
|
+
"data-results-array": "no \"data.results\" array",
|
|
17909
18300
|
"results-array": "no \"results\" array",
|
|
17910
18301
|
"data-array": "no \"data\" array",
|
|
17911
18302
|
"data-web-array": "no \"data.web\" array",
|
|
@@ -17921,11 +18312,7 @@ function searchSources(outcome) {
|
|
|
17921
18312
|
for (const row of outcome.rows) list.add(row);
|
|
17922
18313
|
return list.sources;
|
|
17923
18314
|
}
|
|
17924
|
-
if (outcome.failure === "api")
|
|
17925
|
-
const detail = outcome.detail === void 0 ? void 0 : upstreamText(outcome.detail);
|
|
17926
|
-
const message = "the search service reported an API error; retry later or choose another search connection";
|
|
17927
|
-
throw searchError("WEB_PROVIDER_ERROR", detail === void 0 ? message : message + "\n\nThe search service responded (untrusted): " + detail);
|
|
17928
|
-
}
|
|
18315
|
+
if (outcome.failure === "api") throw searchError("WEB_PROVIDER_ERROR", "the search service reported an API error; retry later or choose another search connection" + upstreamSuffix("The search service", outcome.detail));
|
|
17929
18316
|
throw invalidResponse(INVALID_DETAIL[outcome.reason]);
|
|
17930
18317
|
}
|
|
17931
18318
|
//#endregion
|
|
@@ -17935,6 +18322,7 @@ const ADAPTER_WIRES = {
|
|
|
17935
18322
|
firecrawl: mapWire(firecrawlSearch, searchSources),
|
|
17936
18323
|
tavily: mapWire(tavilySearch, searchSources),
|
|
17937
18324
|
tinyfish: mapWire(tinyfishSearch, searchSources),
|
|
18325
|
+
anysearch: mapWire(anysearchSearch, searchSources),
|
|
17938
18326
|
openalex: mapWire(openalexSearch, searchSources),
|
|
17939
18327
|
semanticscholar: mapWire(semanticscholarSearch, searchSources)
|
|
17940
18328
|
};
|
|
@@ -18258,14 +18646,14 @@ function searchEnhanced(ctx) {
|
|
|
18258
18646
|
}
|
|
18259
18647
|
//#endregion
|
|
18260
18648
|
//#region src/host/connections.ts
|
|
18261
|
-
async function describeConnections(ctx, settings,
|
|
18649
|
+
async function describeConnections(ctx, settings, model) {
|
|
18262
18650
|
return Promise.all([...settings.connections.values()].map(async (connection) => {
|
|
18263
18651
|
const base = baseOf(connection);
|
|
18264
18652
|
if (connection.kind === "model") {
|
|
18265
18653
|
const target = connection.route.kind === "fixed" ? {
|
|
18266
18654
|
kind: "route",
|
|
18267
18655
|
route: fixedRoute(connection.route)
|
|
18268
|
-
} : sessionRoute(ctx,
|
|
18656
|
+
} : sessionRoute(ctx, model);
|
|
18269
18657
|
const access = target.kind === "route" ? target.route.auth.kind : "api-key";
|
|
18270
18658
|
if (connection.disabled) return {
|
|
18271
18659
|
...base,
|
|
@@ -18298,7 +18686,7 @@ async function describeConnections(ctx, settings, agent) {
|
|
|
18298
18686
|
const endpoint = connection.kind === "native" ? typeof connection.options.baseURL === "string" ? connection.options.baseURL : CATALOG[connection.native].endpoint : void 0;
|
|
18299
18687
|
return {
|
|
18300
18688
|
...base,
|
|
18301
|
-
...await credentialReadiness(ctx,
|
|
18689
|
+
...await credentialReadiness(ctx, model, {
|
|
18302
18690
|
endpoint,
|
|
18303
18691
|
credentialRef: connection.credentialRef
|
|
18304
18692
|
})
|
|
@@ -18343,7 +18731,11 @@ function searchCapability(ctx, settings) {
|
|
|
18343
18731
|
contract,
|
|
18344
18732
|
optionsCodec,
|
|
18345
18733
|
settings,
|
|
18346
|
-
|
|
18734
|
+
commandOptions: {
|
|
18735
|
+
freshness: (options) => options.freshness,
|
|
18736
|
+
changeFreshness: (freshness) => ({ freshness })
|
|
18737
|
+
},
|
|
18738
|
+
describe: (current, model) => describeConnections(ctx, current, model),
|
|
18347
18739
|
target: (connection, options, call) => {
|
|
18348
18740
|
switch (connection.kind) {
|
|
18349
18741
|
case "adapter": return {
|