@browserstack/mcp-server 2.2.0-beta.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -432
- package/capability/loadtesting.capability-index.json +3001 -0
- package/capability/tm.capability-index.json +1 -2
- package/dist/tools/ask-browserstack/central-oauth.d.ts +46 -25
- package/dist/tools/ask-browserstack/central-oauth.js +177 -55
- package/dist/tools/capability-registry/bind.js +7 -43
- package/dist/tools/capability-registry/discovery.js +1 -3
- package/dist/tools/capability-registry/egress.d.ts +5 -12
- package/dist/tools/capability-registry/egress.js +1 -24
- package/dist/tools/capability-registry/register.js +41 -289
- package/dist/tools/capability-registry/resolve.d.ts +1 -1
- package/dist/tools/capability-registry/resolve.js +3 -24
- package/dist/tools/capability-registry/search.d.ts +1 -28
- package/dist/tools/capability-registry/search.js +4 -202
- package/dist/tools/capability-registry/types.d.ts +3 -42
- package/dist/tools/testmanagement.js +5 -5
- package/dist/tools/tool-handoff.d.ts +12 -15
- package/dist/tools/tool-handoff.js +18 -21
- package/package.json +3 -4
- package/capability/tra.capability-index.json +0 -52096
- package/dist/lib/central-oauth.d.ts +0 -133
- package/dist/lib/central-oauth.js +0 -246
- package/dist/tools/capability-registry/oauth.d.ts +0 -63
- package/dist/tools/capability-registry/oauth.js +0 -176
- package/dist/tools/capability-registry/routing-token.d.ts +0 -25
- package/dist/tools/capability-registry/routing-token.js +0 -87
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* enforced HERE rather than on a client-side hint — which is the one thing a separate
|
|
14
14
|
* read/write tool pair was buying.
|
|
15
15
|
*/
|
|
16
|
-
import { signRouting, readRouting } from "./routing-token.js";
|
|
17
16
|
import { z } from "zod";
|
|
18
17
|
import logger from "../../logger.js";
|
|
19
18
|
import { trackMCP } from "../../lib/instrumentation.js";
|
|
@@ -22,7 +21,7 @@ import { redact } from "./redact.js";
|
|
|
22
21
|
import { fetchTransport } from "./egress.js";
|
|
23
22
|
import { CapabilityRegistry, InvocationError, resolveResponses, } from "./index-loader.js";
|
|
24
23
|
import { invoke } from "./resolve.js";
|
|
25
|
-
import { ambiguousProducts,
|
|
24
|
+
import { ambiguousProducts, isBrowseQuery, searchCapabilities, singular, terms, vocabularyOf, } from "./search.js";
|
|
26
25
|
export const PERMISSION_VALUES = ["not_asked", "granted", "denied"];
|
|
27
26
|
/**
|
|
28
27
|
* The search-side twin of `user_permission`: did a human choose the product, or did you?
|
|
@@ -156,10 +155,6 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
156
155
|
// likeliest refusal of all, and it was landing in the generic bucket.
|
|
157
156
|
if (message.startsWith("capability_disabled:"))
|
|
158
157
|
return "capability_disabled";
|
|
159
|
-
// Auth failed before the product was ever called, so it is not the product's 401 and
|
|
160
|
-
// must not be counted as one. oauth.ts prefixes every one of these.
|
|
161
|
-
if (message.startsWith("token_mint_failed:"))
|
|
162
|
-
return "token_mint_failed";
|
|
163
158
|
if (message.startsWith("missing required parameter"))
|
|
164
159
|
return "missing_parameter";
|
|
165
160
|
if (/is not a usable path value/.test(message))
|
|
@@ -192,122 +187,15 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
192
187
|
tools.listProducts = server.tool("listProducts", "List the BrowserStack products this surface can reach: what each one does, the " +
|
|
193
188
|
"entities it models, and a line saying what each entity is. START HERE — " +
|
|
194
189
|
"searchCapability needs a product, and this is what tells you which one. If two " +
|
|
195
|
-
"products could both fit the task, ask the user rather than choosing for them.
|
|
196
|
-
"ALWAYS pass the user's request, in their own words, as `query`: the answer then " +
|
|
197
|
-
"says outright whether the products clash over the words in it. WHEN IT REPORTS A " +
|
|
198
|
-
"CLASH — two products claiming the same word for different things — ASK THE USER " +
|
|
199
|
-
"WHICH PRODUCT THEY MEAN AND WAIT FOR THEIR ANSWER BEFORE SEARCHING OR INVOKING " +
|
|
200
|
-
"ANYTHING. The response carries the question to put to them and what the shared " +
|
|
201
|
-
"word means in each product. Choosing for them, or searching each product in turn " +
|
|
202
|
-
"and merging the results, is the failure this call exists to prevent.", {
|
|
203
|
-
query: z
|
|
204
|
-
.string()
|
|
205
|
-
.optional()
|
|
206
|
-
.describe("The user's request, in their own words. With it the response carries a " +
|
|
207
|
-
"`routing` block saying whether the products share the vocabulary this " +
|
|
208
|
-
"request uses — and, when they do, the question to put to the user before " +
|
|
209
|
-
"searching either product."),
|
|
210
|
-
}, {
|
|
190
|
+
"products could both fit the task, ask the user rather than choosing for them.", {}, {
|
|
211
191
|
title: "List Capability Products",
|
|
212
192
|
readOnlyHint: true,
|
|
213
193
|
destructiveHint: false,
|
|
214
194
|
idempotentHint: true,
|
|
215
195
|
openWorldHint: false,
|
|
216
|
-
}, async (
|
|
196
|
+
}, async () => {
|
|
217
197
|
track("listProducts");
|
|
218
|
-
// THE CLASH, STATED RATHER THAN LEFT TO BE NOTICED. The entity lists below carry
|
|
219
|
-
// the evidence — `report` under two products — but reading two lists and spotting
|
|
220
|
-
// the overlap is work an agent skips when it already has a product in mind. So the
|
|
221
|
-
// overlap is computed here and put at the top, with the question already written:
|
|
222
|
-
// the cheap failure is picking one silently, and this is the call that precedes it.
|
|
223
|
-
const ambiguity = query
|
|
224
|
-
? ambiguousProducts(registry.index.products, query)
|
|
225
|
-
: { products: [], terms: [] };
|
|
226
|
-
// A CLASH ANNOUNCED HERE BINDS THE NEXT SEARCH. Reporting it and then letting the
|
|
227
|
-
// very next call through was the gap the measured runs walked through: the agent
|
|
228
|
-
// read the clash, searched one product and then the other, and asked only
|
|
229
|
-
// afterwards. The gate downstream judges the caller's paraphrase when no user words
|
|
230
|
-
// are quoted, and a paraphrase carries none of the shared words that caused this —
|
|
231
|
-
// so the refusal never fired. Opening a token here makes the question outlive the
|
|
232
|
-
// call that raised it, and `user_words` is what closes it.
|
|
233
|
-
// THE VERDICT TRAVELS WITH THE CALLER. Signed here, read back by the search — which
|
|
234
|
-
// is how the search can know what this call concluded about the whole request
|
|
235
|
-
// without the server keeping a note between the two.
|
|
236
|
-
const listingToken = query
|
|
237
|
-
? signRouting(ambiguity.products.length > 1
|
|
238
|
-
? { verdict: "clash", terms: ambiguity.terms }
|
|
239
|
-
: ambiguity.unknown
|
|
240
|
-
? { verdict: "blank" }
|
|
241
|
-
: { verdict: "settled", product: ambiguity.settled })
|
|
242
|
-
: undefined;
|
|
243
|
-
const routing = ambiguity.products.length > 1
|
|
244
|
-
? {
|
|
245
|
-
verdict: "products_clash",
|
|
246
|
-
note: `These products clash over ${ambiguity.terms.map((t) => `'${t}'`).join(", ")} — ` +
|
|
247
|
-
`the same word means something different in ${ambiguity.products.join(" and ")}. ` +
|
|
248
|
-
"ASK THE USER which they mean before searching or invoking anything; do not " +
|
|
249
|
-
"search each product in turn and merge the results. Searching before you " +
|
|
250
|
-
"ask will be refused: send the user's answer in `user_words` with this " +
|
|
251
|
-
"`routing_token`.",
|
|
252
|
-
routing_token: listingToken,
|
|
253
|
-
shared_terms: ambiguity.terms,
|
|
254
|
-
products: ambiguity.products,
|
|
255
|
-
question: `Which product do you mean — ${ambiguity.products.join(" or ")}?`,
|
|
256
|
-
senses: ambiguity.products.map((name) => ({
|
|
257
|
-
product: name,
|
|
258
|
-
means: ambiguity.terms
|
|
259
|
-
.map((term) => {
|
|
260
|
-
const entities = registry.index.products[name]?.entities ?? {};
|
|
261
|
-
const key = Object.keys(entities).find((candidate) => [
|
|
262
|
-
candidate,
|
|
263
|
-
...(entities[candidate].aliases ?? []),
|
|
264
|
-
].some((word) => terms(word).map(singular).join(" ") === term));
|
|
265
|
-
return key
|
|
266
|
-
? {
|
|
267
|
-
term,
|
|
268
|
-
entity: key,
|
|
269
|
-
description: entities[key].description,
|
|
270
|
-
}
|
|
271
|
-
: undefined;
|
|
272
|
-
})
|
|
273
|
-
.filter(Boolean),
|
|
274
|
-
})),
|
|
275
|
-
}
|
|
276
|
-
: query && ambiguity.unknown
|
|
277
|
-
? {
|
|
278
|
-
verdict: "no_vocabulary",
|
|
279
|
-
note: "Nothing in this request names a product, or any word that belongs to " +
|
|
280
|
-
"one — so there is no evidence here about which product is meant. This " +
|
|
281
|
-
"is the LEAST settled a request can be, not the most. ASK THE USER " +
|
|
282
|
-
"which product they mean before searching or invoking anything. " +
|
|
283
|
-
"Searching before you ask will be refused: send their answer in " +
|
|
284
|
-
"`user_words` with this `routing_token`.",
|
|
285
|
-
routing_token: listingToken,
|
|
286
|
-
question: `Which product do you mean — ${registry
|
|
287
|
-
.productNames()
|
|
288
|
-
.join(" or ")}?`,
|
|
289
|
-
}
|
|
290
|
-
: query
|
|
291
|
-
? {
|
|
292
|
-
verdict: "no_clash",
|
|
293
|
-
note: ambiguity.settled
|
|
294
|
-
? `This request names words only ${ambiguity.settled} claims` +
|
|
295
|
-
(ambiguity.because?.length
|
|
296
|
-
? ` (${ambiguity.because.map((t) => `'${t}'`).join(", ")})`
|
|
297
|
-
: "") +
|
|
298
|
-
`, so it settles on ${ambiguity.settled} without asking. SEARCH ` +
|
|
299
|
-
`${ambiguity.settled}; the other products do not answer this request.`
|
|
300
|
-
: "No word in this request is claimed by more than one product, so the " +
|
|
301
|
-
"entity lists below settle it without asking.",
|
|
302
|
-
routing_token: listingToken,
|
|
303
|
-
...(ambiguity.settled ? { product: ambiguity.settled } : {}),
|
|
304
|
-
...(ambiguity.because?.length
|
|
305
|
-
? { deciding_terms: ambiguity.because }
|
|
306
|
-
: {}),
|
|
307
|
-
}
|
|
308
|
-
: undefined;
|
|
309
198
|
return ok({
|
|
310
|
-
...(routing ? { routing } : {}),
|
|
311
199
|
products: registry.productNames().map((name) => ({
|
|
312
200
|
name,
|
|
313
201
|
summary: registry.index.products[name].summary,
|
|
@@ -372,11 +260,10 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
372
260
|
return ok({ product, entity, ...doc });
|
|
373
261
|
});
|
|
374
262
|
tools.searchCapability = server.tool("searchCapability", "Find endpoints this surface can call, by plain language, within ONE product. " +
|
|
375
|
-
|
|
376
|
-
"
|
|
377
|
-
"
|
|
378
|
-
"
|
|
379
|
-
"different things, ask the USER and wait for an answer rather than picking. " +
|
|
263
|
+
`You must say which: ${productList}. If the task does not name it unambiguously, ` +
|
|
264
|
+
"call listProducts first — it returns what each product does, the entities each " +
|
|
265
|
+
"models, and what every entity means, which is what settles the choice. Where two " +
|
|
266
|
+
"products use the same word for different things, ask the user rather than picking. " +
|
|
380
267
|
"Search matches the product's OWN words, not synonyms. When your words are not the " +
|
|
381
268
|
"product's, the response says so: `weak_match: true` with a `suggested_vocabulary` " +
|
|
382
269
|
"map of the product's entities and their aliases. Results are still returned, but " +
|
|
@@ -419,44 +306,19 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
419
306
|
// not (run, project, report, result, folder, workspace, execution, history), where
|
|
420
307
|
// the old behaviour was to silently pick whichever product ranked higher. A wasted
|
|
421
308
|
// round trip against a silent wrong-product answer is not a close trade.
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
//
|
|
425
|
-
//
|
|
426
|
-
//
|
|
427
|
-
//
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
"
|
|
435
|
-
"whether the products clash over it, in which case ask the user first."),
|
|
436
|
-
// `product_choice` USED TO LIVE HERE, AND WAS ITS OWN DEFEAT.
|
|
437
|
-
//
|
|
438
|
-
// A required enum of 'user_confirmed' | 'not_asked' publishes, in the schema every
|
|
439
|
-
// client shows the model before it calls anything, the exact string that opens the
|
|
440
|
-
// gate. Measured on the prompts that still routed silently: the caller wrote
|
|
441
|
-
// `user_confirmed` on every single one, with no user input behind any of them. A
|
|
442
|
-
// flag the caller fills in about itself can always be filled in; there is no wording
|
|
443
|
-
// of it that makes it true. What replaced it is a token this server mints and the
|
|
444
|
-
// caller cannot guess, plus `user_words`, which is a claim the index can test.
|
|
445
|
-
routing_token: z
|
|
446
|
-
.string()
|
|
447
|
-
.optional()
|
|
448
|
-
.describe("The `routing_token` from the last listProducts call or product_ambiguous " +
|
|
449
|
-
"refusal — it carries what that step concluded about the user's request, " +
|
|
450
|
-
"signed. Always pass the most recent one. When it reports a clash, send the " +
|
|
451
|
-
"user's answer in `user_words` alongside it; neither works alone."),
|
|
452
|
-
user_words: z
|
|
453
|
-
.string()
|
|
454
|
-
.optional()
|
|
455
|
-
.describe("The USER'S OWN words, verbatim, that settle which product this is — either " +
|
|
456
|
-
"the product's name or a term only one product uses ('quality gate', 'test " +
|
|
457
|
-
"plan'). Quote them; do not paraphrase, and do not write words the user did " +
|
|
458
|
-
"not say. When a query could mean either product this is what lifts the " +
|
|
459
|
-
"refusal, because it is checked against the index rather than taken on trust."),
|
|
309
|
+
product: productArg().describe(`Which product to search: ${productList}. Call listProducts if the task does ` +
|
|
310
|
+
`not make it obvious, and ask the user when two products could both fit.`),
|
|
311
|
+
// REQUIRED, and self-reported, exactly like `user_permission` on a write. The
|
|
312
|
+
// server cannot see whether you asked anyone; what it can do is refuse to answer a
|
|
313
|
+
// question only the user can settle, and make claiming otherwise an explicit act
|
|
314
|
+
// rather than an omission.
|
|
315
|
+
product_choice: z
|
|
316
|
+
.enum(PRODUCT_CHOICE_VALUES)
|
|
317
|
+
.describe("'user_confirmed' only when the user named the product, or the task names it " +
|
|
318
|
+
"unmistakably. 'not_asked' otherwise — then a query that could mean either " +
|
|
319
|
+
"product is refused and told what to ask, instead of being answered for the " +
|
|
320
|
+
"wrong one. Never search each product in turn and merge the results: that is " +
|
|
321
|
+
"the guess this argument exists to prevent."),
|
|
460
322
|
mode: z
|
|
461
323
|
.enum(["read", "write", "destructive"])
|
|
462
324
|
.optional()
|
|
@@ -473,7 +335,7 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
473
335
|
destructiveHint: false,
|
|
474
336
|
idempotentHint: true,
|
|
475
337
|
openWorldHint: false,
|
|
476
|
-
}, async ({ query, entity, product,
|
|
338
|
+
}, async ({ query, entity, product, product_choice, mode, limit, offset }) => {
|
|
477
339
|
// THE GATE. Nothing here can tell whether a human was asked — same as the write
|
|
478
340
|
// gate, which also takes the caller's word. What it can do is refuse to answer a
|
|
479
341
|
// question that is genuinely the user's, so that answering it anyway takes a
|
|
@@ -487,106 +349,18 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
487
349
|
// contains no word to be ambiguous about — `*` names nothing — so there is nothing
|
|
488
350
|
// to ask, and asking anyway would block the one query whose whole purpose is to
|
|
489
351
|
// show what a product contains.
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
// `entity` USED TO BYPASS THIS TOO, and had no business doing so. An entity narrows
|
|
497
|
-
// WITHIN a product; it says nothing about WHICH product, and the four names both
|
|
498
|
-
// products carry — project, report, test_run, comment — are precisely the ones the
|
|
499
|
-
// clash is about. `entity: "report"` alongside a guessed product is the silent pick
|
|
500
|
-
// this gate exists to stop, stated more confidently, so it skipped the check at the
|
|
501
|
-
// exact moment the check mattered.
|
|
502
|
-
// `product` is a free string now, so an unknown name reaches the handler. Refuse it
|
|
503
|
-
// where the caller can act on it: naming listProducts, which is where the real names
|
|
504
|
-
// come from, rather than returning an empty search that reads as "nothing matched".
|
|
505
|
-
if (!registry.index.products[product]) {
|
|
506
|
-
return refuse("searchCapability", "unknown_product", `No product named '${product}'. Call listProducts — passing the user's request ` +
|
|
507
|
-
"as `query` — for the names, and for whether the products clash over it.", {}, { product });
|
|
508
|
-
}
|
|
509
|
-
if (!isBrowseQuery(query)) {
|
|
510
|
-
// JUDGE THE USER'S WORDS, NOT THE AGENT'S REWRITE.
|
|
511
|
-
//
|
|
512
|
-
// `query` is the caller's paraphrase into product vocabulary, so the caller
|
|
513
|
-
// decides, through its own phrasing, whether this check fires: "what did the last
|
|
514
|
-
// report say?" became "list saved reports", and `saved report` is tra-only, so the
|
|
515
|
-
// shared word the user actually said stopped being examined. It is also the escape
|
|
516
|
-
// from a refusal — reword and try again, which is what the measured runs did. The
|
|
517
|
-
// user's text is the one input the caller cannot rewrite without quoting something
|
|
518
|
-
// different, and `productAnchors` checks what it quotes against this index.
|
|
519
|
-
const subject = user_words?.trim() ? user_words : query;
|
|
520
|
-
const ambiguity = ambiguousProducts(registry.index.products, subject);
|
|
521
|
-
// ALWAYS, NOT ONLY UNDER THE FLAG. With the self-reported flag gone, quoting the
|
|
522
|
-
// user is the only way past a clash, so the check that reads the quote has to run
|
|
523
|
-
// on both paths — otherwise the default path refuses with no way out at all. The
|
|
524
|
-
// flag now governs the stricter refusals (a blank request, a clash still open),
|
|
525
|
-
// not whether the user's own words count.
|
|
526
|
-
const anchor = productAnchors(registry.index.products, user_words);
|
|
527
|
-
// WHAT THE ROUTING STEP CONCLUDED, READ BACK OFF THE CALLER. The token is signed
|
|
528
|
-
// here and verified by recomputation, so the server keeps no note between the two
|
|
529
|
-
// calls — and the caller cannot write one, edit the product inside it, or hold one
|
|
530
|
-
// without having made the routing call that issues it.
|
|
531
|
-
const routed = readRouting(routing_token);
|
|
532
|
-
// A clash the routing step already reported is only cleared by the user's own
|
|
533
|
-
// words: the token shows the question was put, `user_words` says what came back.
|
|
534
|
-
// Neither works alone — a token on its own is just proof of having been refused.
|
|
535
|
-
const answered = routed?.verdict !== "settled" &&
|
|
536
|
-
anchor.products.length === 1 &&
|
|
537
|
-
anchor.products[0] === product;
|
|
538
|
-
// One product anchored, and it is the one being searched: the user settled it.
|
|
539
|
-
// A routing step that already settled on this product counts the same way — it
|
|
540
|
-
// read the user's whole request, which is more than the fragment quoted here.
|
|
541
|
-
const settled = (anchor.products.length === 1 && anchor.products[0] === product) ||
|
|
542
|
-
(routed?.verdict === "settled" && routed.product === product);
|
|
543
|
-
// NOTHING TO ASK WHEN THERE IS NOTHING TO CHOOSE BETWEEN. A registry serving one
|
|
544
|
-
// product cannot route a request to the wrong one, so every refusal below is a
|
|
545
|
-
// question with a single possible answer — pure obstruction.
|
|
546
|
-
const routable = registry.productNames().length > 1;
|
|
547
|
-
// A CLASH THE CALLER IS CARRYING IS STILL OPEN UNTIL IT IS ANSWERED, whatever this
|
|
548
|
-
// call's wording looks like. It has to outlive a REWORDING of the request — the
|
|
549
|
-
// escape it exists to close — while leaving a genuinely different request alone:
|
|
550
|
-
// "bulk delete test cases" names a thing only one product has, and blocking it
|
|
551
|
-
// because something earlier was ambiguous is obstruction, not routing.
|
|
552
|
-
const reopened = routable &&
|
|
553
|
-
!settled &&
|
|
554
|
-
!answered &&
|
|
555
|
-
ambiguity.settled !== product &&
|
|
556
|
-
(routed?.verdict === "clash" || routed?.verdict === "blank");
|
|
557
|
-
// THE WORDS POINT SOMEWHERE ELSE, WHICH IS EVIDENCE, NOT NOISE. A request whose
|
|
558
|
-
// own vocabulary settles on one product, sent as a search of the OTHER one, is the
|
|
559
|
-
// silent wrong pick this gate exists to catch — and it used to pass, because the
|
|
560
|
-
// checks above only ask whether the request settles, never whether it settles on
|
|
561
|
-
// what is being asked for. `product` is the caller's conclusion; the words are the
|
|
562
|
-
// evidence, and when they disagree the evidence is the thing to go on. The refusal
|
|
563
|
-
// already had the sentence for it ("the words you quoted point at X, not Y") and
|
|
564
|
-
// nothing could reach it.
|
|
565
|
-
const mismatch = routable && !!ambiguity.settled && ambiguity.settled !== product;
|
|
566
|
-
// NOTHING RECOGNISED IS NOT PERMISSION TO PICK. A request carrying no product's
|
|
567
|
-
// vocabulary is the least settled kind there is, and it used to pass this gate
|
|
568
|
-
// untouched because there was no shared word in it to object to.
|
|
569
|
-
const blank = routable && ambiguity.unknown && !settled;
|
|
570
|
-
if (routable &&
|
|
571
|
-
(ambiguity.products.length > 1 || reopened || blank || mismatch) &&
|
|
572
|
-
!settled &&
|
|
573
|
-
!answered) {
|
|
574
|
-
const token = signRouting(ambiguity.products.length > 1
|
|
575
|
-
? { verdict: "clash", terms: ambiguity.terms }
|
|
576
|
-
: mismatch
|
|
577
|
-
? { verdict: "settled", product: ambiguity.settled }
|
|
578
|
-
: { verdict: "blank" });
|
|
579
|
-
// WHAT TO ASK, NOT JUST THAT ASKING IS NEEDED. Sending the caller back to
|
|
352
|
+
if (product_choice !== "user_confirmed" &&
|
|
353
|
+
!entity &&
|
|
354
|
+
!isBrowseQuery(query)) {
|
|
355
|
+
const ambiguity = ambiguousProducts(registry.index.products, query);
|
|
356
|
+
if (ambiguity.products.length > 1) {
|
|
357
|
+
// EVERYTHING NEEDED TO ASK, IN THE REFUSAL. Telling the agent to go and call
|
|
580
358
|
// listProducts costs a round trip and still leaves it composing a question out
|
|
581
359
|
// of nothing — so it tends to guess instead, which is the behaviour being
|
|
582
|
-
// stopped. What makes the choice answerable is what each product
|
|
583
|
-
// shared word and what it means
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
: mismatch
|
|
587
|
-
? [ambiguity.settled, product]
|
|
588
|
-
: registry.productNames();
|
|
589
|
-
const options = choices.map((name) => {
|
|
360
|
+
// stopped. What makes the choice answerable is what each product calls the
|
|
361
|
+
// shared word and what it means THERE: tm's project owns folders and test
|
|
362
|
+
// cases, Load Testing's does not.
|
|
363
|
+
const options = ambiguity.products.map((name) => {
|
|
590
364
|
const entities = registry.index.products[name]?.entities ?? {};
|
|
591
365
|
const senses = ambiguity.terms
|
|
592
366
|
.map((term) => {
|
|
@@ -606,41 +380,19 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
606
380
|
...(senses.length ? { shared_terms: senses } : {}),
|
|
607
381
|
};
|
|
608
382
|
});
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
(ambiguity.because?.length
|
|
617
|
-
? ` (${ambiguity.because.map((t) => `'${t}'`).join(", ")})`
|
|
618
|
-
: "") +
|
|
619
|
-
`, so the request points at ${ambiguity.settled}, not ${product}. ` +
|
|
620
|
-
"Search the product the words name, or — if the user meant " +
|
|
621
|
-
`${product} — get them to say so and quote them. `
|
|
622
|
-
: `'${subject}' could mean ${ambiguity.products.join(" or ")} — ` +
|
|
623
|
-
`${ambiguity.terms.map((t) => `'${t}'`).join(", ")} ` +
|
|
624
|
-
`${ambiguity.terms.length === 1 ? "belongs" : "belong"} to both. `) +
|
|
625
|
-
(named
|
|
626
|
-
? `The words you quoted (${anchor.terms.map((t) => `'${t}'`).join(", ")}) ` +
|
|
627
|
-
`point at ${anchor.products.join(" and ")}, not ${product}. `
|
|
628
|
-
: user_words
|
|
629
|
-
? "Nothing in the words you quoted names a product or a term only one " +
|
|
630
|
-
"product uses. "
|
|
631
|
-
: "Send `user_words` — the user's OWN words naming the product, or a " +
|
|
632
|
-
"term only one product uses — or ask them. ") +
|
|
633
|
-
"Put the choice to the USER in their own terms, wait for an answer, then " +
|
|
634
|
-
"resend with their words in `user_words` AND `routing_token` set to the " +
|
|
635
|
-
"token below. Rewording this query will not get past here. Do NOT search " +
|
|
636
|
-
"each product in turn and merge the results.", {
|
|
637
|
-
routing_token: token,
|
|
383
|
+
return refuse("searchCapability", "product_ambiguous", `'${query}' could mean ${ambiguity.products.join(" or ")} — ` +
|
|
384
|
+
`${ambiguity.terms.map((t) => `'${t}'`).join(", ")} ` +
|
|
385
|
+
`${ambiguity.terms.length === 1 ? "belongs" : "belong"} to both. ` +
|
|
386
|
+
"Put the choice in `clarify` to the USER in their own terms, wait for an " +
|
|
387
|
+
"answer, then resend with product_choice='user_confirmed'. Do NOT search " +
|
|
388
|
+
"each product in turn and merge the results — that answers the question " +
|
|
389
|
+
"instead of asking it.", {
|
|
638
390
|
clarify: {
|
|
639
|
-
question: `Which product do you mean — ${
|
|
391
|
+
question: `Which product do you mean — ${ambiguity.products.join(" or ")}?`,
|
|
640
392
|
shared: ambiguity.terms,
|
|
641
393
|
options,
|
|
642
394
|
},
|
|
643
|
-
}, { product: ambiguity.products.join("+")
|
|
395
|
+
}, { product: ambiguity.products.join("+") });
|
|
644
396
|
}
|
|
645
397
|
}
|
|
646
398
|
const { hits, weak, top_matched, ...rest } = searchCapabilities(registry.index.products, query, {
|
|
@@ -932,7 +684,7 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
932
684
|
return refuse("invokeCapability", "change_summary_missing", "change_summary is required: state what will change", undefined, identity);
|
|
933
685
|
}
|
|
934
686
|
}
|
|
935
|
-
const result = await invoke(capability, args, await deps.baseUrlFor(product), deps.credentialsFor(), transport, registry.index.products[product]?.auth
|
|
687
|
+
const result = await invoke(capability, args, await deps.baseUrlFor(product), deps.credentialsFor(), transport, registry.index.products[product]?.auth);
|
|
936
688
|
// The one row for a completed invoke. invoke() returns a 4xx/5xx rather than
|
|
937
689
|
// throwing, so `success` keeps its tool-level meaning and these two fields carry
|
|
938
690
|
// whether the product call worked. Status 0 means it could not be reached.
|
|
@@ -35,4 +35,4 @@ export interface InvokeResult {
|
|
|
35
35
|
error?: string;
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
export declare function invoke(capability: Capability, args: GroupedArguments, baseUrl: string, credentials: Credentials, transport: Transport, auth?: AuthScheme
|
|
38
|
+
export declare function invoke(capability: Capability, args: GroupedArguments, baseUrl: string, credentials: Credentials, transport: Transport, auth?: AuthScheme): Promise<InvokeResult>;
|
|
@@ -12,10 +12,8 @@
|
|
|
12
12
|
* page-size parameter are published for paginated endpoints (see `project.py::_is_public`).
|
|
13
13
|
* Hiding them made sense only while this module walked the pages itself.
|
|
14
14
|
*/
|
|
15
|
-
import { invalidateToken } from "../../lib/central-oauth.js";
|
|
16
15
|
import { bind } from "./bind.js";
|
|
17
16
|
import { authHeaders } from "./egress.js";
|
|
18
|
-
import { resolveScope, resolveTokenUrl } from "./oauth.js";
|
|
19
17
|
import { InvocationError } from "./index-loader.js";
|
|
20
18
|
function hasNextPage(body) {
|
|
21
19
|
if (typeof body !== "object" || body === null || Array.isArray(body))
|
|
@@ -63,32 +61,13 @@ function assertTransportSafe(baseUrl) {
|
|
|
63
61
|
`carries your BrowserStack access key, so the base URL must be https (or a local ` +
|
|
64
62
|
`host for development). Check CAPABILITY_REGISTRY_BASE_URL_* for a typo.`);
|
|
65
63
|
}
|
|
66
|
-
export async function invoke(capability, args, baseUrl, credentials, transport, auth
|
|
64
|
+
export async function invoke(capability, args, baseUrl, credentials, transport, auth) {
|
|
67
65
|
if (!baseUrl)
|
|
68
66
|
throw new InvocationError("no base URL is configured for that product");
|
|
69
67
|
assertTransportSafe(baseUrl);
|
|
70
68
|
const bound = bind(capability, args);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const url = `${baseUrl.replace(/\/$/, "")}${bound.path}`;
|
|
74
|
-
const send = async () => transport(capability.method, url, await authHeaders(credentials, auth, product), bound.query, bound.body);
|
|
75
|
-
let response = await send();
|
|
76
|
-
/**
|
|
77
|
-
* One replay, for a minted token the product rejected.
|
|
78
|
-
*
|
|
79
|
-
* The expiry skirt covers clock skew; it does not cover a token revoked mid-life, and a
|
|
80
|
-
* cached one can outlive its welcome by up to its whole lifetime. Discarding it and
|
|
81
|
-
* retrying once turns that from a failed call into a slow one.
|
|
82
|
-
*
|
|
83
|
-
* SAFE TO REPLAY EVEN FOR A WRITE: a 401 means the request was never authorised, so
|
|
84
|
-
* nothing was changed. Once only — with genuinely bad credentials the second attempt
|
|
85
|
-
* fails identically, and a loop here would hammer the token endpoint on every wrong
|
|
86
|
-
* password.
|
|
87
|
-
*/
|
|
88
|
-
if (response.status === 401 && auth?.type === "oauth2") {
|
|
89
|
-
invalidateToken(resolveTokenUrl(product ?? "this product", auth), resolveScope(auth), credentials);
|
|
90
|
-
response = await send();
|
|
91
|
-
}
|
|
69
|
+
const headers = authHeaders(credentials, auth);
|
|
70
|
+
const response = await transport(capability.method, `${baseUrl.replace(/\/$/, "")}${bound.path}`, headers, bound.query, bound.body);
|
|
92
71
|
const ok = response.status >= 200 && response.status < 300;
|
|
93
72
|
return {
|
|
94
73
|
ok,
|
|
@@ -105,17 +105,12 @@ export interface SearchResult {
|
|
|
105
105
|
coverage: number;
|
|
106
106
|
weak: boolean;
|
|
107
107
|
}
|
|
108
|
+
/** Which products a query could plausibly be about, when more than one could. */
|
|
108
109
|
export interface ProductAmbiguity {
|
|
109
110
|
/** The products that claim the query's words. Empty when the query settles itself. */
|
|
110
111
|
products: string[];
|
|
111
112
|
/** The shared vocabulary that caused it — what to put in front of the user. */
|
|
112
113
|
terms: string[];
|
|
113
|
-
/** The one product the query's own words point at, when they point at exactly one. */
|
|
114
|
-
settled?: string;
|
|
115
|
-
/** The words that pointed there — the evidence for `settled`. */
|
|
116
|
-
because?: string[];
|
|
117
|
-
/** No word in the request belongs to ANY product: there is nothing to route on. */
|
|
118
|
-
unknown?: boolean;
|
|
119
114
|
}
|
|
120
115
|
/**
|
|
121
116
|
* Products whose OWN vocabulary the query hits, when no word in the query settles it.
|
|
@@ -173,25 +168,3 @@ export declare function searchCapabilities(products: Record<string, ProductIndex
|
|
|
173
168
|
limit?: number;
|
|
174
169
|
offset?: number;
|
|
175
170
|
}): SearchResult;
|
|
176
|
-
export interface ProductAnchor {
|
|
177
|
-
/** Products the quoted words point at, through a word only that product claims. */
|
|
178
|
-
products: string[];
|
|
179
|
-
/** The words that did the anchoring, so a refusal can quote them back. */
|
|
180
|
-
terms: string[];
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Which products the USER'S OWN WORDS name, directly or through vocabulary only one
|
|
184
|
-
* product claims.
|
|
185
|
-
*
|
|
186
|
-
* This is the other half of `ambiguousProducts`. That one asks "is the query a word both
|
|
187
|
-
* products use?"; this asks "did the user say anything that settles it?" — and it reads
|
|
188
|
-
* the user's text, not a flag the caller sets about itself. A boolean saying the user
|
|
189
|
-
* confirmed is answered by whoever wants to proceed; a quote has to come from the
|
|
190
|
-
* conversation, and the words in it are checked against the index here.
|
|
191
|
-
*
|
|
192
|
-
* Anchors are of two kinds and both are needed. A product NAME ("test management",
|
|
193
|
-
* "observability") is the explicit case. A word only one product's vocabulary claims
|
|
194
|
-
* ("quality gate", "test plan") is the implicit one, and it is the common one: users say
|
|
195
|
-
* what they want, not which product owns it.
|
|
196
|
-
*/
|
|
197
|
-
export declare function productAnchors(products: Record<string, ProductIndex>, text: string | undefined): ProductAnchor;
|