@agentproto/runtime 5.7.0 → 5.9.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.
@@ -27,6 +27,10 @@ var providers_store_exports = {};
27
27
  __reExport(providers_store_exports, providers_store_star);
28
28
 
29
29
  // src/spawn-defaults.ts
30
+ function modelIdPrefixProvider(modelId) {
31
+ const slash = modelId.indexOf("/");
32
+ return slash > 0 ? modelId.slice(0, slash) : void 0;
33
+ }
30
34
  function subscriptionSurfaceFor(sub, endpoint) {
31
35
  if (sub === void 0) return void 0;
32
36
  if (!Array.isArray(sub)) {
@@ -34,6 +38,31 @@ function subscriptionSurfaceFor(sub, endpoint) {
34
38
  }
35
39
  return sub.find((s) => s.provider !== void 0 && s.provider === endpoint) ?? sub.find((s) => s.provider === void 0);
36
40
  }
41
+ function directAuthMethods(descriptor, endpoint) {
42
+ const methods = [];
43
+ if (subscriptionSurfaceFor(descriptor?.authSubscription, endpoint) !== void 0) {
44
+ methods.push("oauth-bearer");
45
+ }
46
+ if (descriptor?.provider || descriptor?.modelDerivedApiKey) methods.push("api-key");
47
+ return methods;
48
+ }
49
+ function spawnEligibilityManifest(adapter, descriptor, route, model) {
50
+ const directEndpoint = descriptor?.provider ?? (model ? descriptor?.modelProviders?.[model] : void 0) ?? (model && descriptor?.modelDerivedApiKey ? modelIdPrefixProvider(model) : void 0) ?? (model ? getModelProvider(model) : void 0);
51
+ const routeId = route?.gateway ?? directEndpoint;
52
+ if (!routeId) return void 0;
53
+ const direct = directEndpoint !== void 0 && routeId === directEndpoint;
54
+ return {
55
+ manifest: {
56
+ id: adapter,
57
+ endpointByRoute: { [routeId]: direct ? directEndpoint : routeId },
58
+ methodsByRoute: {
59
+ [routeId]: direct ? directAuthMethods(descriptor, directEndpoint) : ["api-key"]
60
+ }
61
+ },
62
+ routeId,
63
+ direct
64
+ };
65
+ }
37
66
 
38
67
  // src/catalog-models.ts
39
68
  var WIDENING_ROUTES = [
@@ -270,6 +299,7 @@ function buildCatalogModels(input) {
270
299
  ];
271
300
  const merged = mergeContributions(contributions);
272
301
  const query = input.query ?? {};
302
+ const queryAdapter = query.adapter ? input.adapters.find((a) => a.slug === query.adapter) : void 0;
273
303
  const servableByRoute = /* @__PURE__ */ new Map();
274
304
  for (const row of merged) {
275
305
  const set = servableByRoute.get(row.route) ?? /* @__PURE__ */ new Set();
@@ -284,12 +314,18 @@ function buildCatalogModels(input) {
284
314
  if (query.adapter && !row.adapters.includes(query.adapter)) continue;
285
315
  const isDirectVendorRoute = row.route === row.vendor && row.adapterModes.length === 0;
286
316
  const walletEligible = !isDirectVendorRoute || checkModelWalletEligibility(`${row.vendor}/${row.product}`, row.route).ok;
287
- const manifest = {
317
+ const projected = queryAdapter === void 0 ? void 0 : queryAdapter.authDescriptor ? spawnEligibilityManifest(
318
+ queryAdapter.slug,
319
+ queryAdapter.authDescriptor,
320
+ { gateway: row.route },
321
+ row.ref
322
+ ) : null;
323
+ const manifest = projected?.manifest ?? {
288
324
  id: `${row.vendor}/${row.product}@${row.route}`,
289
325
  endpointByRoute: { [row.route]: billedVendor(row.vendor, row.route) },
290
326
  methodsByRoute: { [row.route]: row.methods }
291
327
  };
292
- const eligible = walletEligible ? eligibleProfiles(input.profiles, manifest, row.route).filter(
328
+ const eligible = walletEligible && projected !== null ? eligibleProfiles(input.profiles, manifest, projected?.routeId ?? row.route).filter(
293
329
  (p) => profileAllowsModel(p, row.ref, `${row.vendor}/${row.product}`)
294
330
  ) : [];
295
331
  const runnable = eligible.length > 0;