marona 0.5.1 → 0.6.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/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- export const packageVersion = "0.5.1";
2
- export const standardInterfaces = ["api", "web", "mobile_app", "desktop", "whatsapp"];
3
- export const interfaceNamePattern = "^[a-z][a-z0-9_-]{0,63}$";
4
- export const standardExecutionModes = ["online", "hybrid", "offline"];
1
+ export const packageVersion = "0.6.0";
2
+ const standardInterfaces = ["api", "web", "mobile_app", "desktop", "whatsapp"];
3
+ const interfaceNamePattern = "^[a-z][a-z0-9_-]{0,63}$";
4
+ const standardExecutionModes = ["online", "hybrid", "offline"];
5
5
  const localExecutionTargetTypes = new Set(["python_package", "wasm", "static_cache", "builtin"]);
6
6
  const remoteExecutionTargetTypes = new Set(["remote_mcp", "marona_hosted"]);
7
7
  const providerDefaultEndpoints = {
@@ -23,7 +23,7 @@ const providerEndpointEnvironment = {
23
23
  ollama: "OLLAMA_API_BASE",
24
24
  litellm: "LITELLM_API_BASE",
25
25
  };
26
- export function normalizeExecutionModes(value) {
26
+ function normalizeExecutionModes(value) {
27
27
  const rawModes = Array.isArray(value) ? value : ["online"];
28
28
  const modes = [];
29
29
  for (const raw of rawModes) {
@@ -39,7 +39,7 @@ export function normalizeExecutionModes(value) {
39
39
  }
40
40
  return [modes[0]];
41
41
  }
42
- export function supportsExecutionMode(value, mode) {
42
+ function supportsExecutionMode(value, mode) {
43
43
  const requested = mode.trim().toLowerCase();
44
44
  const modes = new Set(normalizeExecutionModes(value));
45
45
  if (modes.has("hybrid"))
@@ -48,7 +48,7 @@ export function supportsExecutionMode(value, mode) {
48
48
  return modes.has("online") || modes.has("offline");
49
49
  return modes.has(requested);
50
50
  }
51
- export function executionModeLabel(value) {
51
+ function executionModeLabel(value) {
52
52
  const modes = normalizeExecutionModes(value);
53
53
  if (modes.includes("hybrid"))
54
54
  return "Hybrid";
@@ -85,7 +85,7 @@ export class MaronaModelError extends EdgeRuntimeError {
85
85
  this.name = "MaronaModelError";
86
86
  }
87
87
  }
88
- export class MaronaCache {
88
+ class MaronaCache {
89
89
  syncPayload;
90
90
  privateContext;
91
91
  apps = new Map();
@@ -260,7 +260,7 @@ export class MaronaCache {
260
260
  this.defaultModelName = undefined;
261
261
  }
262
262
  }
263
- export class ModelManager {
263
+ class ModelManager {
264
264
  cache;
265
265
  fetchImpl;
266
266
  executors = new Map();
@@ -305,10 +305,6 @@ export class ModelManager {
305
305
  this.cache.saveModel(detected, { makeDefault: input.makeDefault ?? false });
306
306
  return detected;
307
307
  }
308
- use(name) {
309
- console.warn("models.use() is deprecated; pass model to client() or message().");
310
- return this.cache.useModel(name);
311
- }
312
308
  get(name) {
313
309
  return this.cache.getModel(name);
314
310
  }
@@ -367,11 +363,79 @@ export class ModelManager {
367
363
  };
368
364
  }
369
365
  }
370
- export class HubClient {
366
+ export class MCPConnection {
367
+ payload;
368
+ executor;
369
+ constructor(payload, executor) {
370
+ this.payload = payload;
371
+ this.executor = executor;
372
+ }
373
+ listTools() {
374
+ return normalizeConnectedTools(this.descriptors()).map((descriptor) => {
375
+ const fn = asRecord(descriptor.function) ?? {};
376
+ return {
377
+ name: stringValue(fn.name) ?? "marona_tool",
378
+ description: stringValue(fn.description) ?? stringValue(fn.name) ?? "Marona tool",
379
+ inputSchema: asRecord(fn.parameters) ?? { type: "object", properties: {} },
380
+ annotations: asRecord(descriptor.marona) ?? {},
381
+ };
382
+ });
383
+ }
384
+ async callTool(name, argumentsValue = {}) {
385
+ const descriptor = this.descriptors().find((candidate) => {
386
+ const normalized = normalizeConnectedTools([candidate])[0];
387
+ return stringValue(asRecord(normalized?.function)?.name) === name;
388
+ });
389
+ if (!descriptor)
390
+ throw new EdgeRuntimeError(`Connected MCP tool '${name}' was not found.`);
391
+ if (!this.executor) {
392
+ throw new EdgeRuntimeError("This Hub connection can list tools but cannot execute them. Create it through Marona.hub.");
393
+ }
394
+ return this.executor.execute(descriptor, argumentsValue, {
395
+ interfaceName: "api",
396
+ });
397
+ }
398
+ get serverUrls() {
399
+ const urls = [];
400
+ for (const value of Array.isArray(this.payload.apps) ? this.payload.apps : []) {
401
+ const app = asRecord(value);
402
+ const server = asRecord(app?.mcp_server ?? app?.mcpServer);
403
+ const url = stringValue(server?.server_url ?? server?.serverUrl ?? server?.url);
404
+ if (url)
405
+ urls.push(url);
406
+ }
407
+ for (const descriptor of this.descriptors()) {
408
+ const metadata = asRecord(descriptor.marona ?? descriptor.x_marona) ?? {};
409
+ const url = stringValue(metadata.mcp_server_url ?? metadata.server_url);
410
+ if (url)
411
+ urls.push(url);
412
+ }
413
+ return [...new Set(urls)];
414
+ }
415
+ get serverUrl() {
416
+ return this.serverUrls.length === 1 ? this.serverUrls[0] : undefined;
417
+ }
418
+ get session() {
419
+ return {
420
+ status: this.payload.status,
421
+ execution: this.payload.execution,
422
+ apps: Array.isArray(this.payload.apps) ? this.payload.apps : [],
423
+ skills: Array.isArray(this.payload.skills) ? this.payload.skills : [],
424
+ server_urls: this.serverUrls,
425
+ };
426
+ }
427
+ descriptors() {
428
+ return Array.isArray(this.payload.connections)
429
+ ? this.payload.connections.map(asRecord).filter(Boolean)
430
+ : [];
431
+ }
432
+ }
433
+ class HubClient {
371
434
  baseUrl;
372
435
  defaultHeaders;
373
436
  timeoutMs;
374
437
  fetchImpl;
438
+ toolExecutor;
375
439
  constructor(baseUrl = "https://hub.marona.ai", options = {}) {
376
440
  this.baseUrl = baseUrl.replace(/\/+$/, "");
377
441
  this.timeoutMs = options.timeoutMs ?? 60_000;
@@ -380,21 +444,22 @@ export class HubClient {
380
444
  this.defaultHeaders.Authorization = `Bearer ${options.apiKey}`;
381
445
  }
382
446
  this.fetchImpl = options.fetchImpl ?? globalThis.fetch;
447
+ this.toolExecutor = options.toolExecutor;
383
448
  if (!this.fetchImpl) {
384
449
  throw new EdgeRuntimeError("A fetch implementation is required.");
385
450
  }
386
451
  }
387
- async connect(apps, options = {}) {
388
- const payload = await this.connectResult(apps, options);
389
- const connections = payload.connections;
390
- return Array.isArray(connections) ? connections.map(asRecord).filter(Boolean) : [];
452
+ async connect(options = {}) {
453
+ const payload = await this.connectResult(options);
454
+ return new MCPConnection(payload, this.toolExecutor);
391
455
  }
392
- async connectResult(apps, options = {}) {
456
+ async connectResult(options = {}) {
393
457
  const payload = await this.requestJson("POST", "/hub/connect", {
394
458
  body: {
395
- apps,
459
+ ...(options.apps ? { apps: options.apps } : {}),
396
460
  ...(options.skills?.length ? { skills: options.skills } : {}),
397
- adapter: options.adapter ?? "openai_mcp",
461
+ adapter: "tools",
462
+ interface: "api",
398
463
  },
399
464
  });
400
465
  const record = asRecord(payload);
@@ -439,7 +504,7 @@ export class HubClient {
439
504
  }
440
505
  }
441
506
  }
442
- export class SkillStep {
507
+ class SkillStep {
443
508
  definition;
444
509
  constructor(definition) {
445
510
  this.definition = definition;
@@ -458,7 +523,7 @@ export class SkillStep {
458
523
  return { ...this.definition };
459
524
  }
460
525
  }
461
- export function step(input) {
526
+ function step(input) {
462
527
  const id = input.id.trim();
463
528
  if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(id)) {
464
529
  throw new EdgeRuntimeError("Skill step ids must use lowercase kebab-case.");
@@ -549,7 +614,7 @@ function skillReferences(value) {
549
614
  ...(match[2] ? { path: match[2] } : {}),
550
615
  }));
551
616
  }
552
- export class SkillDefinition {
617
+ class SkillDefinition {
553
618
  definition;
554
619
  constructor(definition) {
555
620
  this.definition = definition;
@@ -624,7 +689,7 @@ export class SkillDefinition {
624
689
  });
625
690
  }
626
691
  }
627
- export class SkillsClient extends HubClient {
692
+ class SkillsClient extends HubClient {
628
693
  async publish(definition, options) {
629
694
  const payload = await this.requestJson('POST', '/hub/skills/publish', {
630
695
  body: { manifest: definition.manifest(options.version) },
@@ -647,9 +712,9 @@ class MaronaHubClient extends HubClient {
647
712
  }
648
713
  mode;
649
714
  cache;
650
- async connectResult(apps, options = {}) {
651
- const adapter = options.adapter ?? "tools";
652
- const cached = connectFromCache(this.cache, apps, options.skills ?? [], adapter, this.mode);
715
+ async connectResult(options = {}) {
716
+ const apps = options.apps ?? [];
717
+ const cached = connectFromCache(this.cache, apps, options.skills ?? [], "tools", this.mode);
653
718
  if (cached.connections.length > 0 && (this.mode === "offline" || this.mode === "hybrid")) {
654
719
  return cached;
655
720
  }
@@ -658,10 +723,10 @@ class MaronaHubClient extends HubClient {
658
723
  payload: { missing_apps: apps },
659
724
  });
660
725
  }
661
- return super.connectResult(apps, { adapter, skills: options.skills });
726
+ return super.connectResult(options);
662
727
  }
663
728
  }
664
- export class RuntimeAttachment {
729
+ class RuntimeAttachment {
665
730
  id;
666
731
  filename;
667
732
  mimeType;
@@ -909,7 +974,7 @@ function utf8Base64(value) {
909
974
  function isObject(value) {
910
975
  return typeof value === "object" && value !== null && !Array.isArray(value);
911
976
  }
912
- export class RuntimeMessageRequest {
977
+ class RuntimeMessageRequest {
913
978
  text;
914
979
  model;
915
980
  interfaceName;
@@ -953,7 +1018,7 @@ export class RuntimeMessageRequest {
953
1018
  });
954
1019
  }
955
1020
  }
956
- export class RealtimeSessionRequest {
1021
+ class RealtimeSessionRequest {
957
1022
  interfaceName;
958
1023
  userId;
959
1024
  identityToken;
@@ -1258,7 +1323,7 @@ class RuntimeTransport {
1258
1323
  return url.toString();
1259
1324
  }
1260
1325
  }
1261
- export class ToolExecutor {
1326
+ class ToolExecutor {
1262
1327
  baseUrl;
1263
1328
  headers;
1264
1329
  fetchImpl;
@@ -1316,12 +1381,29 @@ export class ToolExecutor {
1316
1381
  });
1317
1382
  }
1318
1383
  }
1319
- export class Marona extends RuntimeTransport {
1384
+ class ResponsesClient {
1385
+ runtime;
1386
+ constructor(runtime) {
1387
+ this.runtime = runtime;
1388
+ }
1389
+ async create(options) {
1390
+ const tools = options.tools
1391
+ ? normalizeConnectedTools(options.tools.descriptors())
1392
+ : [];
1393
+ return this.runtime.client({
1394
+ ...options,
1395
+ model: options.model ?? "marona/default",
1396
+ tools,
1397
+ });
1398
+ }
1399
+ }
1400
+ class RuntimeEngine extends RuntimeTransport {
1320
1401
  hub;
1321
1402
  cache;
1322
1403
  models;
1323
1404
  skills;
1324
1405
  tools;
1406
+ responses;
1325
1407
  mode;
1326
1408
  modelFetchImpl;
1327
1409
  developerInstructions;
@@ -1336,12 +1418,13 @@ export class Marona extends RuntimeTransport {
1336
1418
  super(options.baseUrl ?? "https://edge.marona.ai", options);
1337
1419
  this.mode = mode;
1338
1420
  this.cache = options.cache ?? new MaronaCache();
1339
- this.developerInstructions = cleanString(options.developerInstructions ?? options.developer_instructions);
1340
- this.defaultModelRoute = cleanString(options.model);
1421
+ this.developerInstructions = undefined;
1422
+ this.defaultModelRoute = undefined;
1341
1423
  this.providerCredentials = Object.fromEntries(Object.entries(options.providerCredentials ?? {}).map(([key, value]) => [key.toLowerCase(), value]));
1342
1424
  this.providerEndpoints = Object.fromEntries(Object.entries(options.providerEndpoints ?? {}).map(([key, value]) => [key.toLowerCase(), value.replace(/\/+$/, "")]));
1343
1425
  this.modelFetchImpl = options.fetchImpl ?? globalThis.fetch;
1344
1426
  this.models = new ModelManager(this.cache, this.modelFetchImpl);
1427
+ this.tools = new ToolExecutor(this.baseUrl, this.defaultHeaders, this.modelFetchImpl);
1345
1428
  this.hub = new MaronaHubClient(options.hubUrl ?? "https://hub.marona.ai", {
1346
1429
  apiKey: options.apiKey,
1347
1430
  timeoutMs: options.timeoutMs,
@@ -1349,6 +1432,7 @@ export class Marona extends RuntimeTransport {
1349
1432
  fetchImpl: options.hubFetchImpl ?? options.fetchImpl,
1350
1433
  mode,
1351
1434
  cache: this.cache,
1435
+ toolExecutor: this.tools,
1352
1436
  });
1353
1437
  this.skills = new SkillsClient(options.hubUrl ?? 'https://hub.marona.ai', {
1354
1438
  apiKey: options.apiKey,
@@ -1356,7 +1440,7 @@ export class Marona extends RuntimeTransport {
1356
1440
  headers: options.headers,
1357
1441
  fetchImpl: options.hubFetchImpl ?? options.fetchImpl,
1358
1442
  });
1359
- this.tools = new ToolExecutor(this.baseUrl, this.defaultHeaders, this.modelFetchImpl);
1443
+ this.responses = new ResponsesClient(this);
1360
1444
  }
1361
1445
  setMode(mode) {
1362
1446
  if (!['online', 'offline', 'hybrid'].includes(mode)) {
@@ -1429,10 +1513,13 @@ export class Marona extends RuntimeTransport {
1429
1513
  return registered;
1430
1514
  const slash = reference.indexOf("/");
1431
1515
  if (slash <= 0 || slash === reference.length - 1) {
1432
- throw new MaronaModelError(`Unknown model route '${reference}'. Use provider/model or register it first.`);
1516
+ return undefined;
1433
1517
  }
1434
- const provider = reference.slice(0, slash).toLowerCase();
1518
+ const routeProvider = reference.slice(0, slash).toLowerCase();
1519
+ const provider = routeProvider === "google" ? "gemini" : routeProvider;
1435
1520
  const providerModel = reference.slice(slash + 1);
1521
+ if (provider === "marona")
1522
+ return undefined;
1436
1523
  if (provider === "local") {
1437
1524
  throw new MaronaModelError(`Local model '${reference}' must be registered with an executor.`);
1438
1525
  }
@@ -1520,12 +1607,13 @@ export class Marona extends RuntimeTransport {
1520
1607
  }
1521
1608
  messages.push({
1522
1609
  role: 'system',
1523
- content: 'When the current request reads or changes app, personal, or external data, you must call marona__discover_capabilities before answering. Select exact identifiers from its installed catalog. If a record identifier is missing, discover first and use an available list or search capability to resolve it before asking the user. Never tell the user which App, Skill, or tool could be used instead of calling it. Do not ask the user to confirm use of a capability. Ordinary conversation that needs no capability should be answered directly. Memory/profile context is already available in Context data, so do not discover Memory just to answer from saved context.',
1610
+ content: 'When the current request reads or changes app, personal, or external data, select the one matching Marona Skill or App function before answering. Marona reveals only the next required capability schema. If a record identifier is missing, select an available list or search capability to resolve it before asking the user. Never tell the user which App, Skill, or tool could be used instead of calling it. Do not ask the user to confirm use of a capability. Ordinary conversation that needs no capability should be answered directly. Memory/profile context is already available in Context data, so do not select Memory just to answer from saved context.',
1524
1611
  });
1525
1612
  messages.push({ role: "user", content: modelUserContent(text, options.attachments ?? []) });
1613
+ const capabilityCatalog = this.localCapabilityCatalog();
1526
1614
  let availableTools = options.tools?.length
1527
1615
  ? normalizeConnectedTools(options.tools)
1528
- : [capabilityDiscoveryTool(this.localCapabilityCatalog())];
1616
+ : capabilitySelectorTools(capabilityCatalog);
1529
1617
  let payload = {};
1530
1618
  let reply = "";
1531
1619
  const toolResults = [];
@@ -1533,8 +1621,6 @@ export class Marona extends RuntimeTransport {
1533
1621
  const runtimeSteps = [];
1534
1622
  const executedCapabilityCalls = new Map();
1535
1623
  let toolChoice = "auto";
1536
- let emptyDiscoveries = 0;
1537
- let hasExecutedCapability = false;
1538
1624
  let contextTier = model.contextWindow !== undefined && model.contextWindow <= 2048
1539
1625
  ? 2
1540
1626
  : model.contextWindow !== undefined && model.contextWindow <= 4096
@@ -1559,16 +1645,17 @@ export class Marona extends RuntimeTransport {
1559
1645
  break;
1560
1646
  const roundResults = [];
1561
1647
  for (const call of toolCalls) {
1562
- if (toolCallName(call) === 'marona__discover_capabilities') {
1563
- const discovery = this.discoverLocalCapabilities(call);
1564
- availableTools = [capabilityDiscoveryTool(this.localCapabilityCatalog()), ...discovery.tools];
1565
- if (discovery.tools.length) {
1566
- toolChoice = "required";
1567
- }
1568
- else {
1569
- emptyDiscoveries += 1;
1570
- toolChoice = hasExecutedCapability || emptyDiscoveries >= 2 ? "auto" : "required";
1571
- }
1648
+ const selector = selectorForCall(call, availableTools);
1649
+ if (selector) {
1650
+ const selectorType = stringValue(selector.selector_type);
1651
+ const identifier = stringValue(selector.identifier);
1652
+ if (!selectorType || !identifier)
1653
+ continue;
1654
+ const discovery = this.discoverLocalCapabilities(discoveryCallForSelector(call, text, selectorType, identifier));
1655
+ availableTools = discovery.tools.length
1656
+ ? discovery.tools
1657
+ : capabilityChoiceTools(discovery.result);
1658
+ toolChoice = availableTools.length ? "required" : "auto";
1572
1659
  runtimeSteps.push(discovery.result);
1573
1660
  roundResults.push(discovery.result);
1574
1661
  continue;
@@ -1603,10 +1690,8 @@ export class Marona extends RuntimeTransport {
1603
1690
  executedCapabilityCalls.set(callKey, result);
1604
1691
  toolResults.push(result);
1605
1692
  runtimeSteps.push(result);
1606
- availableTools = [capabilityDiscoveryTool(this.localCapabilityCatalog())];
1693
+ availableTools = capabilitySelectorTools(capabilityCatalog);
1607
1694
  toolChoice = "auto";
1608
- emptyDiscoveries = 0;
1609
- hasExecutedCapability = true;
1610
1695
  roundResults.push(result);
1611
1696
  }
1612
1697
  messages.push({
@@ -1622,6 +1707,7 @@ export class Marona extends RuntimeTransport {
1622
1707
  status: "completed",
1623
1708
  reply: reply || "Done.",
1624
1709
  text: reply || "Done.",
1710
+ outputText: reply || "Done.",
1625
1711
  interfaceName: options.interfaceName ?? options.interface ?? "api",
1626
1712
  conversationId: options.conversationId ?? options.conversation_id,
1627
1713
  artifacts: [],
@@ -1828,6 +1914,36 @@ export class Marona extends RuntimeTransport {
1828
1914
  });
1829
1915
  }
1830
1916
  }
1917
+ export class Hub {
1918
+ hub;
1919
+ constructor(hub) {
1920
+ this.hub = hub;
1921
+ }
1922
+ connect(options = {}) {
1923
+ return this.hub.connect(options);
1924
+ }
1925
+ }
1926
+ export class Models {
1927
+ models;
1928
+ constructor(models) {
1929
+ this.models = models;
1930
+ }
1931
+ register(input) {
1932
+ return this.models.register({ ...input, makeDefault: false });
1933
+ }
1934
+ }
1935
+ export class Marona {
1936
+ hub;
1937
+ responses;
1938
+ models;
1939
+ runtime;
1940
+ constructor(options = {}) {
1941
+ this.runtime = new RuntimeEngine(options);
1942
+ this.hub = new Hub(this.runtime.hub);
1943
+ this.responses = new ResponsesClient(this.runtime);
1944
+ this.models = new Models(this.runtime.models);
1945
+ }
1946
+ }
1831
1947
  function parseRuntimeMessageResponse(payload) {
1832
1948
  const ui = asRecord(payload.ui);
1833
1949
  const reply = stringValue(payload.reply) || "";
@@ -1835,6 +1951,7 @@ function parseRuntimeMessageResponse(payload) {
1835
1951
  status: stringValue(payload.status) || "unknown",
1836
1952
  reply,
1837
1953
  text: reply,
1954
+ outputText: reply,
1838
1955
  interfaceName: stringValue(payload.interface) || "api",
1839
1956
  conversationId: stringValue(payload.conversation_id),
1840
1957
  ui: ui ? parseRuntimeUI(ui) : undefined,
@@ -2486,43 +2603,90 @@ function compactLocalSkills(value) {
2486
2603
  ];
2487
2604
  });
2488
2605
  }
2489
- function capabilityDiscoveryTool(catalog = { apps: [], skills: [] }) {
2490
- const appIds = catalog.apps.map((app) => stringValue(app.slug)).filter((value) => Boolean(value));
2491
- const skillIds = catalog.skills.map((skill) => stringValue(skill.name)).filter((value) => Boolean(value));
2492
- const catalogText = JSON.stringify(catalog);
2606
+ function capabilitySelectorTools(catalog) {
2607
+ const selectors = [];
2608
+ for (const skill of catalog.skills) {
2609
+ const identifier = stringValue(skill.name);
2610
+ if (!identifier)
2611
+ continue;
2612
+ selectors.push(capabilitySelectorTool('skill', identifier, stringValue(skill.description), selectors.length));
2613
+ }
2614
+ for (const app of catalog.apps) {
2615
+ const identifier = stringValue(app.slug);
2616
+ if (!identifier)
2617
+ continue;
2618
+ selectors.push(capabilitySelectorTool('app', identifier, stringValue(app.description), selectors.length));
2619
+ }
2620
+ return selectors;
2621
+ }
2622
+ function capabilityChoiceTools(result) {
2623
+ const payload = asRecord(result.result) ?? {};
2624
+ const capabilities = Array.isArray(payload.capabilities) ? payload.capabilities : [];
2625
+ const selectors = [];
2626
+ for (const raw of capabilities) {
2627
+ const capability = asRecord(raw);
2628
+ const identifier = stringValue(capability?.name);
2629
+ if (!identifier)
2630
+ continue;
2631
+ selectors.push(capabilitySelectorTool('capability', identifier, stringValue(capability?.description), selectors.length));
2632
+ }
2633
+ return selectors;
2634
+ }
2635
+ function capabilitySelectorTool(selectorType, identifier, description, index) {
2636
+ const readable = identifier.toLowerCase().replace(/[^a-z0-9_]+/g, '_').replace(/_+/g, '_').replace(/^_|_$/g, '');
2637
+ const prefix = selectorType === 'skill'
2638
+ ? 'marona__skill__'
2639
+ : selectorType === 'app'
2640
+ ? 'marona__app__'
2641
+ : 'marona__capability__';
2642
+ const suffix = readable || String(index);
2493
2643
  return {
2494
2644
  type: 'function',
2495
2645
  function: {
2496
- name: 'marona__discover_capabilities',
2497
- description: `Select the installed capabilities needed for the current request and load only their App tools and Skill workflows. Installed catalog: ${catalogText}`,
2646
+ name: prefix + suffix.slice(0, 64 - prefix.length),
2647
+ description: [
2648
+ `Select ${selectorType} "${identifier}" for the current request.`,
2649
+ description,
2650
+ ].filter(Boolean).join(' '),
2498
2651
  parameters: {
2499
2652
  type: 'object',
2500
- properties: {
2501
- query: { type: 'string', description: 'Concise description of the user intent.' },
2502
- app_slugs: {
2503
- type: 'array',
2504
- items: { type: 'string', ...(appIds.length ? { enum: appIds } : {}) },
2505
- maxItems: 5,
2506
- description: 'Exact App identifiers selected from the installed catalog.',
2507
- },
2508
- skill_names: {
2509
- type: 'array',
2510
- items: { type: 'string', ...(skillIds.length ? { enum: skillIds } : {}) },
2511
- maxItems: 3,
2512
- description: 'Exact Skill identifiers selected from the installed catalog.',
2513
- },
2514
- capability_names: {
2515
- type: 'array',
2516
- items: { type: 'string' },
2517
- maxItems: 5,
2518
- description: 'Exact capability identifiers returned by a previous discovery call.',
2519
- },
2520
- },
2521
- required: ['query'],
2653
+ properties: {},
2522
2654
  additionalProperties: false,
2523
2655
  },
2524
2656
  },
2525
- marona: { internal: true },
2657
+ marona: {
2658
+ internal: true,
2659
+ selector_type: selectorType,
2660
+ identifier,
2661
+ },
2662
+ };
2663
+ }
2664
+ function selectorForCall(call, availableTools) {
2665
+ const name = toolCallName(call);
2666
+ for (const tool of availableTools) {
2667
+ if (toolFunctionName(tool) !== name)
2668
+ continue;
2669
+ const metadata = asRecord(tool.marona);
2670
+ if (stringValue(metadata?.selector_type))
2671
+ return metadata;
2672
+ }
2673
+ return undefined;
2674
+ }
2675
+ function discoveryCallForSelector(call, query, selectorType, identifier) {
2676
+ const args = { query };
2677
+ if (selectorType === 'app')
2678
+ args.app_slugs = [identifier];
2679
+ else if (selectorType === 'skill')
2680
+ args.skill_names = [identifier];
2681
+ else
2682
+ args.capability_names = [identifier];
2683
+ return {
2684
+ id: call.id,
2685
+ type: 'function',
2686
+ function: {
2687
+ name: 'marona__discover_capabilities',
2688
+ arguments: JSON.stringify(args),
2689
+ },
2526
2690
  };
2527
2691
  }
2528
2692
  function toolCallName(call) {