@datalayer/agent-runtimes 1.6.48 → 1.6.50

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.
@@ -514,6 +514,38 @@ def check_model_additionals(
514
514
  raise SystemExit("\n".join(problems))
515
515
 
516
516
 
517
+ def optional_of(spec: Dict[str, Any]) -> Dict[str, Any] | None:
518
+ """What an agent starts without (agentspecs 0.0.188), by id without version.
519
+
520
+ Refuses an entry that is not among the agent's own MCP servers or skills,
521
+ and a group naming what is not optional: the catalogue says it once.
522
+ """
523
+ optional = spec.get("optional")
524
+ if optional is None:
525
+ return None
526
+ base = lambda ref: str(ref).split(":")[0] # noqa: E731
527
+ servers = [base(ref) for ref in optional.get("mcp_servers") or []]
528
+ skills = [base(ref) for ref in optional.get("skills") or []]
529
+ own_servers = {base(ref) for ref in spec.get("mcp_servers") or []}
530
+ own_skills = {base(ref) for ref in spec.get("skills") or []}
531
+ agent = spec.get("id")
532
+ for kind, named, own in (
533
+ ("MCP server", servers, own_servers),
534
+ ("skill", skills, own_skills),
535
+ ):
536
+ for ref in named:
537
+ if ref not in own:
538
+ raise SystemExit(f"{agent}: optional {kind} {ref} is not its own")
539
+ groups = [
540
+ [base(ref) for ref in group] for group in optional.get("at_least_one") or []
541
+ ]
542
+ for group in groups:
543
+ for ref in group:
544
+ if ref not in servers and ref not in skills:
545
+ raise SystemExit(f"{agent}: {ref} in at_least_one is not optional")
546
+ return {"mcp_servers": servers, "skills": skills, "at_least_one": groups}
547
+
548
+
517
549
  def generate_python_code(specs: List[tuple[str, Dict[str, Any]]]) -> str:
518
550
  """Generate Python code from agent specifications."""
519
551
  # Header
@@ -665,6 +697,10 @@ from agent_runtimes.types import (
665
697
  if model_additionals
666
698
  else ""
667
699
  )
700
+ optional = optional_of(spec)
701
+ optional_py_line = (
702
+ f" optional={_fmt_py_literal(optional)},\n" if optional else ""
703
+ )
668
704
  voice = voice_of(spec)
669
705
  voice_py_line = (
670
706
  f" voice={_fmt_py_literal(voice)},\n" if voice is not None else ""
@@ -796,7 +832,8 @@ from agent_runtimes.types import (
796
832
  tags={_fmt_list(spec.get("tags", []))},
797
833
  domain={f'"{domain_value}"' if domain_value else "None"},
798
834
  enabled={spec.get("enabled", True)},
799
- model={model_str},
835
+ listed={spec.get("listed", True)},
836
+ {optional_py_line} model={model_str},
800
837
  {model_additionals_py_line} inference_provider={inference_provider_str},
801
838
  mcp_servers=[{mcp_servers_str}],
802
839
  skills={_fmt_list(skill_refs)},
@@ -1065,6 +1102,9 @@ def generate_typescript_code(
1065
1102
  import type { Agentspec } from '"""
1066
1103
  code += types_import_path
1067
1104
  code += """';
1105
+ import { isAgentspecComponentOptional } from '"""
1106
+ code += types_import_path
1107
+ code += """/agentspecs';
1068
1108
  """
1069
1109
 
1070
1110
  # Only add MCP server imports if needed
@@ -1308,6 +1348,20 @@ const FRONTEND_TOOL_MAP: Record<string, any> = {
1308
1348
  if model_additionals
1309
1349
  else ""
1310
1350
  )
1351
+ optional = optional_of(spec)
1352
+ optional_ts_line = (
1353
+ " optional: "
1354
+ + _fmt_ts_literal(
1355
+ {
1356
+ "mcpServers": optional["mcp_servers"],
1357
+ "skills": optional["skills"],
1358
+ "atLeastOne": optional["at_least_one"],
1359
+ }
1360
+ )
1361
+ + ",\n"
1362
+ if optional
1363
+ else ""
1364
+ )
1311
1365
  voice = voice_of(spec)
1312
1366
  voice_ts_line = (
1313
1367
  f" voice: {_fmt_ts_literal(voice)},\n" if voice is not None else ""
@@ -1388,7 +1442,8 @@ const FRONTEND_TOOL_MAP: Record<string, any> = {
1388
1442
  tags: {tags_str},
1389
1443
  domain: {domain_ts},
1390
1444
  enabled: {str(spec.get("enabled", True)).lower()},
1391
- model: {model_ts},
1445
+ listed: {str(spec.get("listed", True)).lower()},
1446
+ {optional_ts_line} model: {model_ts},
1392
1447
  {model_additionals_ts_line}{inference_provider_line} mcpServers: [{mcp_servers_str}],
1393
1448
  skills: [{skills_str}].filter(Boolean) as SkillSpec[],
1394
1449
  backendTools: [{tools_str}],
@@ -1485,17 +1540,20 @@ export function listAgentspecs(prefix?: string): Agentspec[] {
1485
1540
  * Collect all required environment variables for an agent spec.
1486
1541
  *
1487
1542
  * Iterates over the spec's MCP servers and skills and returns the
1488
- * deduplicated union of their `requiredEnvVars` arrays.
1543
+ * deduplicated union of their `requiredEnvVars` arrays, without those of
1544
+ * the servers and skills it starts without (`optional`, agentspecs 0.0.188).
1489
1545
  */
1490
1546
  export function getAgentspecRequiredEnvVars(spec: Agentspec): string[] {
1491
1547
  const vars = new Set<string>();
1492
1548
  const baseEnvVar = (v: string): string => v.split(':')[0] ?? v;
1493
1549
  for (const server of spec.mcpServers) {
1550
+ if (isAgentspecComponentOptional(spec, 'mcpServer', server.id)) continue;
1494
1551
  for (const v of server.requiredEnvVars ?? []) {
1495
1552
  vars.add(baseEnvVar(v));
1496
1553
  }
1497
1554
  }
1498
1555
  for (const skill of spec.skills) {
1556
+ if (isAgentspecComponentOptional(spec, 'skill', skill.id)) continue;
1499
1557
  for (const v of skill.requiredEnvVars ?? []) {
1500
1558
  vars.add(baseEnvVar(v));
1501
1559
  }
@@ -1740,6 +1798,7 @@ __all__ = ["AGENTSPECS", "get_agent_spec", "list_agentspecs"]
1740
1798
  */
1741
1799
 
1742
1800
  import type { Agentspec } from '../../types';
1801
+ import { isAgentspecComponentOptional } from '../../types/agentspecs';
1743
1802
 
1744
1803
  """
1745
1804
 
@@ -1797,16 +1856,19 @@ export function listAgentspecs(prefix?: string): Agentspec[] {
1797
1856
  }
1798
1857
 
1799
1858
  /**
1800
- * Collect all required environment variables for an agent spec.
1859
+ * Collect all required environment variables for an agent spec, without
1860
+ * those of the servers and skills it starts without (`optional`).
1801
1861
  */
1802
1862
  export function getAgentspecRequiredEnvVars(spec: Agentspec): string[] {
1803
1863
  const vars = new Set<string>();
1804
1864
  for (const server of spec.mcpServers) {
1865
+ if (isAgentspecComponentOptional(spec, 'mcpServer', server.id)) continue;
1805
1866
  for (const v of server.requiredEnvVars ?? []) {
1806
1867
  vars.add(v);
1807
1868
  }
1808
1869
  }
1809
1870
  for (const skill of spec.skills) {
1871
+ if (isAgentspecComponentOptional(spec, 'skill', skill.id)) continue;
1810
1872
  for (const v of skill.requiredEnvVars ?? []) {
1811
1873
  vars.add(v);
1812
1874
  }