@contractspec/lib.ai-agent 2.4.0 → 2.5.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.
Files changed (100) hide show
  1. package/dist/agent/agent-factory.js +97 -67
  2. package/dist/agent/contract-spec-agent.js +97 -67
  3. package/dist/agent/index.js +140 -100
  4. package/dist/agent/json-runner.js +103 -71
  5. package/dist/agent/unified-agent.d.ts +4 -0
  6. package/dist/agent/unified-agent.js +134 -96
  7. package/dist/approval/index.js +86 -62
  8. package/dist/approval/workflow.d.ts +2 -0
  9. package/dist/approval/workflow.js +86 -62
  10. package/dist/exporters/claude-agent-exporter.js +90 -66
  11. package/dist/exporters/index.js +100 -76
  12. package/dist/exporters/opencode-exporter.js +96 -72
  13. package/dist/exporters/types.d.ts +2 -0
  14. package/dist/i18n/catalogs/en.js +20 -0
  15. package/dist/i18n/catalogs/es.js +20 -0
  16. package/dist/i18n/catalogs/fr.js +20 -0
  17. package/dist/i18n/catalogs/index.js +60 -0
  18. package/dist/i18n/index.js +85 -61
  19. package/dist/i18n/keys.d.ts +16 -0
  20. package/dist/i18n/keys.js +5 -1
  21. package/dist/i18n/locale.d.ts +3 -28
  22. package/dist/i18n/locale.js +7 -18
  23. package/dist/i18n/messages.d.ts +9 -60
  24. package/dist/i18n/messages.js +71 -60
  25. package/dist/index.js +88 -64
  26. package/dist/interop/index.js +117 -79
  27. package/dist/interop/spec-consumer.d.ts +1 -0
  28. package/dist/interop/spec-consumer.js +92 -66
  29. package/dist/interop/tool-consumer.d.ts +1 -0
  30. package/dist/interop/tool-consumer.js +110 -74
  31. package/dist/interop/types.d.ts +10 -0
  32. package/dist/knowledge/index.js +85 -61
  33. package/dist/knowledge/injector.js +85 -61
  34. package/dist/node/agent/agent-factory.js +97 -67
  35. package/dist/node/agent/contract-spec-agent.js +97 -67
  36. package/dist/node/agent/index.js +140 -100
  37. package/dist/node/agent/json-runner.js +103 -71
  38. package/dist/node/agent/unified-agent.js +134 -96
  39. package/dist/node/approval/index.js +86 -62
  40. package/dist/node/approval/workflow.js +86 -62
  41. package/dist/node/exporters/claude-agent-exporter.js +90 -66
  42. package/dist/node/exporters/index.js +100 -76
  43. package/dist/node/exporters/opencode-exporter.js +96 -72
  44. package/dist/node/i18n/catalogs/en.js +20 -0
  45. package/dist/node/i18n/catalogs/es.js +20 -0
  46. package/dist/node/i18n/catalogs/fr.js +20 -0
  47. package/dist/node/i18n/catalogs/index.js +60 -0
  48. package/dist/node/i18n/index.js +85 -61
  49. package/dist/node/i18n/keys.js +5 -1
  50. package/dist/node/i18n/locale.js +7 -18
  51. package/dist/node/i18n/messages.js +71 -60
  52. package/dist/node/index.js +88 -64
  53. package/dist/node/interop/index.js +117 -79
  54. package/dist/node/interop/spec-consumer.js +92 -66
  55. package/dist/node/interop/tool-consumer.js +110 -74
  56. package/dist/node/knowledge/index.js +85 -61
  57. package/dist/node/knowledge/injector.js +85 -61
  58. package/dist/node/providers/claude-agent-sdk/adapter.js +103 -74
  59. package/dist/node/providers/claude-agent-sdk/index.js +103 -74
  60. package/dist/node/providers/claude-agent-sdk/tool-bridge.js +88 -64
  61. package/dist/node/providers/index.js +116 -86
  62. package/dist/node/providers/opencode-sdk/adapter.js +102 -73
  63. package/dist/node/providers/opencode-sdk/agent-bridge.js +89 -65
  64. package/dist/node/providers/opencode-sdk/index.js +102 -73
  65. package/dist/node/providers/opencode-sdk/tool-bridge.js +88 -64
  66. package/dist/node/providers/registry.js +96 -66
  67. package/dist/node/providers/types.js +2122 -2
  68. package/dist/node/spec/index.js +88 -64
  69. package/dist/node/spec/registry.js +87 -63
  70. package/dist/node/spec/spec.js +86 -62
  71. package/dist/node/telemetry/index.js +2122 -3
  72. package/dist/node/telemetry/posthog.js +2123 -3
  73. package/dist/node/tools/index.js +90 -63
  74. package/dist/node/tools/knowledge-tool.js +85 -61
  75. package/dist/node/tools/mcp-server.js +86 -62
  76. package/dist/node/tools/tool-adapter.js +89 -62
  77. package/dist/providers/claude-agent-sdk/adapter.js +103 -74
  78. package/dist/providers/claude-agent-sdk/index.js +103 -74
  79. package/dist/providers/claude-agent-sdk/tool-bridge.js +88 -64
  80. package/dist/providers/index.js +116 -86
  81. package/dist/providers/opencode-sdk/adapter.js +102 -73
  82. package/dist/providers/opencode-sdk/agent-bridge.js +89 -65
  83. package/dist/providers/opencode-sdk/index.js +102 -73
  84. package/dist/providers/opencode-sdk/tool-bridge.js +88 -64
  85. package/dist/providers/registry.d.ts +2 -2
  86. package/dist/providers/registry.js +96 -66
  87. package/dist/providers/types.d.ts +5 -1
  88. package/dist/providers/types.js +2122 -2
  89. package/dist/spec/index.js +88 -64
  90. package/dist/spec/registry.d.ts +1 -1
  91. package/dist/spec/registry.js +87 -63
  92. package/dist/spec/spec.js +86 -62
  93. package/dist/telemetry/index.js +2122 -3
  94. package/dist/telemetry/posthog.js +2123 -3
  95. package/dist/tools/index.js +90 -63
  96. package/dist/tools/knowledge-tool.js +85 -61
  97. package/dist/tools/mcp-server.js +86 -62
  98. package/dist/tools/tool-adapter.js +89 -62
  99. package/dist/types.d.ts +2 -0
  100. package/package.json +6 -6
@@ -603,6 +603,26 @@ var init_en = __esm(() => {
603
603
  value: "[MCPToolServer] Stopped {name}",
604
604
  description: "Log message when MCP tool server stops",
605
605
  placeholders: [{ name: "name", type: "string" }]
606
+ },
607
+ "error.telemetry.posthogAiRequired": {
608
+ value: "PostHog LLM Analytics requires @posthog/ai to be installed. Run: npm install @posthog/ai posthog-node",
609
+ description: "Error when PostHog AI dependency is missing"
610
+ },
611
+ "error.telemetry.posthogClientOrKeyRequired": {
612
+ value: "PostHog LLM Analytics requires either a client instance or an apiKey.",
613
+ description: "Error when PostHog client or API key is not configured"
614
+ },
615
+ "error.telemetry.posthogNodeRequired": {
616
+ value: "PostHog LLM Analytics requires posthog-node to be installed. Run: npm install posthog-node",
617
+ description: "Error when posthog-node dependency is missing"
618
+ },
619
+ "error.provider.notAvailable": {
620
+ value: "Provider '{provider}' is not available{reason}",
621
+ description: "Error when a provider is unavailable",
622
+ placeholders: [
623
+ { name: "provider", type: "string" },
624
+ { name: "reason", type: "string" }
625
+ ]
606
626
  }
607
627
  }
608
628
  });
@@ -1214,6 +1234,26 @@ var init_fr = __esm(() => {
1214
1234
  value: "[MCPToolServer] {name} arrêté",
1215
1235
  description: "Log message when MCP tool server stops",
1216
1236
  placeholders: [{ name: "name", type: "string" }]
1237
+ },
1238
+ "error.telemetry.posthogAiRequired": {
1239
+ value: "PostHog LLM Analytics nécessite l'installation de @posthog/ai. Exécutez : npm install @posthog/ai posthog-node",
1240
+ description: "Error when PostHog AI dependency is missing"
1241
+ },
1242
+ "error.telemetry.posthogClientOrKeyRequired": {
1243
+ value: "PostHog LLM Analytics nécessite soit une instance client, soit une apiKey.",
1244
+ description: "Error when PostHog client or API key is not configured"
1245
+ },
1246
+ "error.telemetry.posthogNodeRequired": {
1247
+ value: "PostHog LLM Analytics nécessite l'installation de posthog-node. Exécutez : npm install posthog-node",
1248
+ description: "Error when posthog-node dependency is missing"
1249
+ },
1250
+ "error.provider.notAvailable": {
1251
+ value: "Le fournisseur « {provider} » n'est pas disponible{reason}",
1252
+ description: "Error when a provider is unavailable",
1253
+ placeholders: [
1254
+ { name: "provider", type: "string" },
1255
+ { name: "reason", type: "string" }
1256
+ ]
1217
1257
  }
1218
1258
  }
1219
1259
  });
@@ -1859,78 +1899,58 @@ var init_es = __esm(() => {
1859
1899
  value: "[MCPToolServer] Detenido {name}",
1860
1900
  description: "Mensaje de registro cuando el servidor de herramientas MCP se detiene",
1861
1901
  placeholders: [{ name: "name", type: "string" }]
1902
+ },
1903
+ "error.telemetry.posthogAiRequired": {
1904
+ value: "PostHog LLM Analytics requiere que @posthog/ai esté instalado. Ejecute: npm install @posthog/ai posthog-node",
1905
+ description: "Error when PostHog AI dependency is missing"
1906
+ },
1907
+ "error.telemetry.posthogClientOrKeyRequired": {
1908
+ value: "PostHog LLM Analytics requiere una instancia de cliente o una apiKey.",
1909
+ description: "Error when PostHog client or API key is not configured"
1910
+ },
1911
+ "error.telemetry.posthogNodeRequired": {
1912
+ value: "PostHog LLM Analytics requiere que posthog-node esté instalado. Ejecute: npm install posthog-node",
1913
+ description: "Error when posthog-node dependency is missing"
1914
+ },
1915
+ "error.provider.notAvailable": {
1916
+ value: "El proveedor '{provider}' no está disponible{reason}",
1917
+ description: "Error when a provider is unavailable",
1918
+ placeholders: [
1919
+ { name: "provider", type: "string" },
1920
+ { name: "reason", type: "string" }
1921
+ ]
1862
1922
  }
1863
1923
  }
1864
1924
  });
1865
1925
  });
1866
1926
 
1867
- // src/i18n/locale.ts
1868
- function resolveLocale(specLocale, runtimeLocale) {
1869
- const raw = runtimeLocale ?? specLocale ?? DEFAULT_LOCALE;
1870
- if (isSupportedLocale(raw)) {
1871
- return raw;
1872
- }
1873
- const base = raw.split("-")[0];
1874
- if (base && isSupportedLocale(base)) {
1875
- return base;
1876
- }
1877
- return DEFAULT_LOCALE;
1878
- }
1879
- function isSupportedLocale(locale) {
1880
- return SUPPORTED_LOCALES.includes(locale);
1881
- }
1882
- var DEFAULT_LOCALE = "en", SUPPORTED_LOCALES;
1883
- var init_locale = __esm(() => {
1884
- SUPPORTED_LOCALES = ["en", "fr", "es"];
1885
- });
1886
-
1887
1927
  // src/i18n/messages.ts
1888
- import { TranslationRegistry } from "@contractspec/lib.contracts-spec/translations";
1889
- function getRegistry() {
1890
- if (!sharedRegistry) {
1891
- sharedRegistry = new TranslationRegistry([
1892
- enMessages,
1893
- frMessages,
1894
- esMessages
1895
- ]);
1896
- }
1897
- return sharedRegistry;
1898
- }
1899
- function interpolate(template, params) {
1900
- if (!params)
1901
- return template;
1902
- return template.replace(/\{(\w+)\}/g, (match, key) => {
1903
- if (key in params) {
1904
- return String(params[key]);
1905
- }
1906
- return match;
1907
- });
1908
- }
1909
- function createAgentI18n(specLocale, runtimeLocale) {
1910
- const locale = resolveLocale(specLocale, runtimeLocale);
1911
- const registry = getRegistry();
1912
- return {
1913
- locale,
1914
- t(key, params) {
1915
- const raw = registry.getValue(SPEC_KEY, key, locale, key);
1916
- return interpolate(raw, params);
1917
- }
1918
- };
1919
- }
1920
- function getDefaultI18n() {
1921
- return createAgentI18n(DEFAULT_LOCALE);
1922
- }
1923
- function resetI18nRegistry() {
1924
- sharedRegistry = null;
1925
- }
1926
- var SPEC_KEY = "ai-agent.messages", sharedRegistry = null;
1928
+ import {
1929
+ createI18nFactory
1930
+ } from "@contractspec/lib.contracts-spec/translations";
1931
+ var factory, createAgentI18n, getDefaultI18n, resetI18nRegistry;
1927
1932
  var init_messages = __esm(() => {
1928
1933
  init_en();
1929
1934
  init_fr();
1930
1935
  init_es();
1931
- init_locale();
1936
+ factory = createI18nFactory({
1937
+ specKey: "ai-agent.messages",
1938
+ catalogs: [enMessages, frMessages, esMessages]
1939
+ });
1940
+ createAgentI18n = factory.create;
1941
+ getDefaultI18n = factory.getDefault;
1942
+ resetI18nRegistry = factory.resetRegistry;
1932
1943
  });
1933
1944
 
1945
+ // src/i18n/locale.ts
1946
+ import {
1947
+ DEFAULT_LOCALE,
1948
+ SUPPORTED_LOCALES,
1949
+ resolveLocale,
1950
+ isSupportedLocale
1951
+ } from "@contractspec/lib.contracts-spec/translations";
1952
+ var init_locale = () => {};
1953
+
1934
1954
  // src/i18n/keys.ts
1935
1955
  var AGENT_KEYS, KNOWLEDGE_KEYS, TOOL_KEYS, INTEROP_KEYS, ERROR_KEYS, EXPORT_KEYS, APPROVAL_KEYS, LOG_KEYS, I18N_KEYS;
1936
1956
  var init_keys = __esm(() => {
@@ -2025,7 +2045,11 @@ var init_keys = __esm(() => {
2025
2045
  "error.provider.sdkNotInstalled": "error.provider.sdkNotInstalled",
2026
2046
  "error.provider.contextCreation": "error.provider.contextCreation",
2027
2047
  "error.provider.executionFailed": "error.provider.executionFailed",
2028
- "error.provider.streamFailed": "error.provider.streamFailed"
2048
+ "error.provider.streamFailed": "error.provider.streamFailed",
2049
+ "error.provider.notAvailable": "error.provider.notAvailable",
2050
+ "error.telemetry.posthogAiRequired": "error.telemetry.posthogAiRequired",
2051
+ "error.telemetry.posthogClientOrKeyRequired": "error.telemetry.posthogClientOrKeyRequired",
2052
+ "error.telemetry.posthogNodeRequired": "error.telemetry.posthogNodeRequired"
2029
2053
  };
2030
2054
  EXPORT_KEYS = {
2031
2055
  "export.agentConfiguration": "export.agentConfiguration",
@@ -2105,7 +2129,7 @@ var init_i18n = __esm(() => {
2105
2129
 
2106
2130
  // src/spec/spec.ts
2107
2131
  function defineAgent(spec) {
2108
- const i18n = getDefaultI18n();
2132
+ const i18n = createAgentI18n(spec.locale);
2109
2133
  if (!spec.meta?.key) {
2110
2134
  throw new Error(i18n.t("error.agentKeyRequired"));
2111
2135
  }
@@ -2141,7 +2165,7 @@ var init_spec = __esm(() => {
2141
2165
  function specToolToOpenCodeTool(tool) {
2142
2166
  return {
2143
2167
  name: tool.name,
2144
- description: tool.description ?? getDefaultI18n().t("tool.fallbackDescription", { name: tool.name }),
2168
+ description: tool.description ?? createAgentI18n().t("tool.fallbackDescription", { name: tool.name }),
2145
2169
  parameters: normalizeToOpenCodeParameters(tool.schema),
2146
2170
  permission: getPermissionLevel(tool)
2147
2171
  };
@@ -2173,7 +2197,7 @@ function openCodeToolsToSpecTools(openCodeTools) {
2173
2197
  function specToolToExternalToolForOpenCode(tool, handler, context) {
2174
2198
  return {
2175
2199
  name: tool.name,
2176
- description: tool.description ?? getDefaultI18n().t("tool.fallbackDescription", { name: tool.name }),
2200
+ description: tool.description ?? createAgentI18n().t("tool.fallbackDescription", { name: tool.name }),
2177
2201
  inputSchema: tool.schema ?? { type: "object" },
2178
2202
  requiresApproval: tool.requiresApproval ?? !tool.automationSafe,
2179
2203
  execute: handler ? async (input) => {
@@ -2237,7 +2261,7 @@ async function executeToolCall(toolCall, handlers) {
2237
2261
  if (!handler) {
2238
2262
  return {
2239
2263
  tool_call_id: toolCall.id,
2240
- output: getDefaultI18n().t("error.toolNotFoundOrNoHandler", {
2264
+ output: createAgentI18n().t("error.toolNotFoundOrNoHandler", {
2241
2265
  name: toolCall.name
2242
2266
  }),
2243
2267
  is_error: true
@@ -2334,7 +2358,7 @@ function specToOpenCodeMarkdown(spec, options) {
2334
2358
  };
2335
2359
  }
2336
2360
  function buildMarkdownBody(spec) {
2337
- const i18n = getDefaultI18n();
2361
+ const i18n = createAgentI18n(spec.locale);
2338
2362
  const lines = [];
2339
2363
  lines.push(`# ${spec.meta.key}`);
2340
2364
  lines.push("");
@@ -2445,7 +2469,7 @@ class ClaudeAgentExporter {
2445
2469
  return specs.map((spec) => this.export(spec, options));
2446
2470
  }
2447
2471
  validate(spec) {
2448
- const i18n = getDefaultI18n();
2472
+ const i18n = createAgentI18n(spec.locale);
2449
2473
  const errors = [];
2450
2474
  if (!spec.meta?.key) {
2451
2475
  errors.push(i18n.t("export.validation.requiresKey"));
@@ -2485,7 +2509,7 @@ class ClaudeAgentExporter {
2485
2509
  return config;
2486
2510
  }
2487
2511
  buildSystemPrompt(spec, options) {
2488
- const i18n = getDefaultI18n();
2512
+ const i18n = createAgentI18n(options.locale ?? spec.locale);
2489
2513
  const parts = [];
2490
2514
  parts.push(spec.instructions);
2491
2515
  if (spec.knowledge && spec.knowledge.length > 0) {
@@ -2518,7 +2542,7 @@ class ClaudeAgentExporter {
2518
2542
  `);
2519
2543
  }
2520
2544
  exportTools(spec) {
2521
- const i18n = getDefaultI18n();
2545
+ const i18n = createAgentI18n(spec.locale);
2522
2546
  return spec.tools.map((tool) => ({
2523
2547
  name: tool.name,
2524
2548
  description: tool.description ?? i18n.t("tool.fallbackDescription", { name: tool.name }),
@@ -2544,7 +2568,7 @@ class ClaudeAgentExporter {
2544
2568
  };
2545
2569
  }
2546
2570
  generateClaudeMd(spec, options) {
2547
- const i18n = getDefaultI18n();
2571
+ const i18n = createAgentI18n(options.locale ?? spec.locale);
2548
2572
  const lines = [];
2549
2573
  lines.push(i18n.t("export.agentConfiguration"));
2550
2574
  lines.push("");
@@ -2673,7 +2697,7 @@ class OpenCodeExporter {
2673
2697
  return specs.map((spec) => this.export(spec, options));
2674
2698
  }
2675
2699
  validate(spec) {
2676
- const i18n = getDefaultI18n();
2700
+ const i18n = createAgentI18n(spec.locale);
2677
2701
  const errors = [];
2678
2702
  if (!spec.meta?.key) {
2679
2703
  errors.push(i18n.t("export.validation.requiresKey"));
@@ -2708,7 +2732,7 @@ class OpenCodeExporter {
2708
2732
  };
2709
2733
  }
2710
2734
  exportTools(spec) {
2711
- const i18n = getDefaultI18n();
2735
+ const i18n = createAgentI18n(spec.locale);
2712
2736
  return spec.tools.map((tool) => ({
2713
2737
  name: tool.name,
2714
2738
  description: tool.description ?? i18n.t("tool.fallbackDescription", { name: tool.name }),
@@ -2717,7 +2741,7 @@ class OpenCodeExporter {
2717
2741
  }));
2718
2742
  }
2719
2743
  generateMarkdown(spec, jsonConfig, options) {
2720
- const i18n = getDefaultI18n();
2744
+ const i18n = createAgentI18n(options.locale ?? spec.locale);
2721
2745
  const lines = [];
2722
2746
  lines.push("---");
2723
2747
  lines.push(`name: ${jsonConfig.name}`);
@@ -2751,7 +2775,7 @@ class OpenCodeExporter {
2751
2775
  }
2752
2776
  lines.push(i18n.t("export.agentType", { type: jsonConfig.type }));
2753
2777
  lines.push("");
2754
- lines.push(this.getAgentTypeDescription(jsonConfig.type));
2778
+ lines.push(this.getAgentTypeDescription(jsonConfig.type, options.locale ?? spec.locale));
2755
2779
  lines.push("");
2756
2780
  lines.push(i18n.t("export.instructions"));
2757
2781
  lines.push("");
@@ -2815,8 +2839,8 @@ class OpenCodeExporter {
2815
2839
  return lines.join(`
2816
2840
  `);
2817
2841
  }
2818
- getAgentTypeDescription(type) {
2819
- const i18n = getDefaultI18n();
2842
+ getAgentTypeDescription(type, locale) {
2843
+ const i18n = createAgentI18n(locale);
2820
2844
  switch (type) {
2821
2845
  case "build":
2822
2846
  return i18n.t("export.agentType.build");
@@ -603,6 +603,26 @@ var init_en = __esm(() => {
603
603
  value: "[MCPToolServer] Stopped {name}",
604
604
  description: "Log message when MCP tool server stops",
605
605
  placeholders: [{ name: "name", type: "string" }]
606
+ },
607
+ "error.telemetry.posthogAiRequired": {
608
+ value: "PostHog LLM Analytics requires @posthog/ai to be installed. Run: npm install @posthog/ai posthog-node",
609
+ description: "Error when PostHog AI dependency is missing"
610
+ },
611
+ "error.telemetry.posthogClientOrKeyRequired": {
612
+ value: "PostHog LLM Analytics requires either a client instance or an apiKey.",
613
+ description: "Error when PostHog client or API key is not configured"
614
+ },
615
+ "error.telemetry.posthogNodeRequired": {
616
+ value: "PostHog LLM Analytics requires posthog-node to be installed. Run: npm install posthog-node",
617
+ description: "Error when posthog-node dependency is missing"
618
+ },
619
+ "error.provider.notAvailable": {
620
+ value: "Provider '{provider}' is not available{reason}",
621
+ description: "Error when a provider is unavailable",
622
+ placeholders: [
623
+ { name: "provider", type: "string" },
624
+ { name: "reason", type: "string" }
625
+ ]
606
626
  }
607
627
  }
608
628
  });
@@ -1214,6 +1234,26 @@ var init_fr = __esm(() => {
1214
1234
  value: "[MCPToolServer] {name} arrêté",
1215
1235
  description: "Log message when MCP tool server stops",
1216
1236
  placeholders: [{ name: "name", type: "string" }]
1237
+ },
1238
+ "error.telemetry.posthogAiRequired": {
1239
+ value: "PostHog LLM Analytics nécessite l'installation de @posthog/ai. Exécutez : npm install @posthog/ai posthog-node",
1240
+ description: "Error when PostHog AI dependency is missing"
1241
+ },
1242
+ "error.telemetry.posthogClientOrKeyRequired": {
1243
+ value: "PostHog LLM Analytics nécessite soit une instance client, soit une apiKey.",
1244
+ description: "Error when PostHog client or API key is not configured"
1245
+ },
1246
+ "error.telemetry.posthogNodeRequired": {
1247
+ value: "PostHog LLM Analytics nécessite l'installation de posthog-node. Exécutez : npm install posthog-node",
1248
+ description: "Error when posthog-node dependency is missing"
1249
+ },
1250
+ "error.provider.notAvailable": {
1251
+ value: "Le fournisseur « {provider} » n'est pas disponible{reason}",
1252
+ description: "Error when a provider is unavailable",
1253
+ placeholders: [
1254
+ { name: "provider", type: "string" },
1255
+ { name: "reason", type: "string" }
1256
+ ]
1217
1257
  }
1218
1258
  }
1219
1259
  });
@@ -1859,78 +1899,58 @@ var init_es = __esm(() => {
1859
1899
  value: "[MCPToolServer] Detenido {name}",
1860
1900
  description: "Mensaje de registro cuando el servidor de herramientas MCP se detiene",
1861
1901
  placeholders: [{ name: "name", type: "string" }]
1902
+ },
1903
+ "error.telemetry.posthogAiRequired": {
1904
+ value: "PostHog LLM Analytics requiere que @posthog/ai esté instalado. Ejecute: npm install @posthog/ai posthog-node",
1905
+ description: "Error when PostHog AI dependency is missing"
1906
+ },
1907
+ "error.telemetry.posthogClientOrKeyRequired": {
1908
+ value: "PostHog LLM Analytics requiere una instancia de cliente o una apiKey.",
1909
+ description: "Error when PostHog client or API key is not configured"
1910
+ },
1911
+ "error.telemetry.posthogNodeRequired": {
1912
+ value: "PostHog LLM Analytics requiere que posthog-node esté instalado. Ejecute: npm install posthog-node",
1913
+ description: "Error when posthog-node dependency is missing"
1914
+ },
1915
+ "error.provider.notAvailable": {
1916
+ value: "El proveedor '{provider}' no está disponible{reason}",
1917
+ description: "Error when a provider is unavailable",
1918
+ placeholders: [
1919
+ { name: "provider", type: "string" },
1920
+ { name: "reason", type: "string" }
1921
+ ]
1862
1922
  }
1863
1923
  }
1864
1924
  });
1865
1925
  });
1866
1926
 
1867
- // src/i18n/locale.ts
1868
- function resolveLocale(specLocale, runtimeLocale) {
1869
- const raw = runtimeLocale ?? specLocale ?? DEFAULT_LOCALE;
1870
- if (isSupportedLocale(raw)) {
1871
- return raw;
1872
- }
1873
- const base = raw.split("-")[0];
1874
- if (base && isSupportedLocale(base)) {
1875
- return base;
1876
- }
1877
- return DEFAULT_LOCALE;
1878
- }
1879
- function isSupportedLocale(locale) {
1880
- return SUPPORTED_LOCALES.includes(locale);
1881
- }
1882
- var DEFAULT_LOCALE = "en", SUPPORTED_LOCALES;
1883
- var init_locale = __esm(() => {
1884
- SUPPORTED_LOCALES = ["en", "fr", "es"];
1885
- });
1886
-
1887
1927
  // src/i18n/messages.ts
1888
- import { TranslationRegistry } from "@contractspec/lib.contracts-spec/translations";
1889
- function getRegistry() {
1890
- if (!sharedRegistry) {
1891
- sharedRegistry = new TranslationRegistry([
1892
- enMessages,
1893
- frMessages,
1894
- esMessages
1895
- ]);
1896
- }
1897
- return sharedRegistry;
1898
- }
1899
- function interpolate(template, params) {
1900
- if (!params)
1901
- return template;
1902
- return template.replace(/\{(\w+)\}/g, (match, key) => {
1903
- if (key in params) {
1904
- return String(params[key]);
1905
- }
1906
- return match;
1907
- });
1908
- }
1909
- function createAgentI18n(specLocale, runtimeLocale) {
1910
- const locale = resolveLocale(specLocale, runtimeLocale);
1911
- const registry = getRegistry();
1912
- return {
1913
- locale,
1914
- t(key, params) {
1915
- const raw = registry.getValue(SPEC_KEY, key, locale, key);
1916
- return interpolate(raw, params);
1917
- }
1918
- };
1919
- }
1920
- function getDefaultI18n() {
1921
- return createAgentI18n(DEFAULT_LOCALE);
1922
- }
1923
- function resetI18nRegistry() {
1924
- sharedRegistry = null;
1925
- }
1926
- var SPEC_KEY = "ai-agent.messages", sharedRegistry = null;
1928
+ import {
1929
+ createI18nFactory
1930
+ } from "@contractspec/lib.contracts-spec/translations";
1931
+ var factory, createAgentI18n, getDefaultI18n, resetI18nRegistry;
1927
1932
  var init_messages = __esm(() => {
1928
1933
  init_en();
1929
1934
  init_fr();
1930
1935
  init_es();
1931
- init_locale();
1936
+ factory = createI18nFactory({
1937
+ specKey: "ai-agent.messages",
1938
+ catalogs: [enMessages, frMessages, esMessages]
1939
+ });
1940
+ createAgentI18n = factory.create;
1941
+ getDefaultI18n = factory.getDefault;
1942
+ resetI18nRegistry = factory.resetRegistry;
1932
1943
  });
1933
1944
 
1945
+ // src/i18n/locale.ts
1946
+ import {
1947
+ DEFAULT_LOCALE,
1948
+ SUPPORTED_LOCALES,
1949
+ resolveLocale,
1950
+ isSupportedLocale
1951
+ } from "@contractspec/lib.contracts-spec/translations";
1952
+ var init_locale = () => {};
1953
+
1934
1954
  // src/i18n/keys.ts
1935
1955
  var AGENT_KEYS, KNOWLEDGE_KEYS, TOOL_KEYS, INTEROP_KEYS, ERROR_KEYS, EXPORT_KEYS, APPROVAL_KEYS, LOG_KEYS, I18N_KEYS;
1936
1956
  var init_keys = __esm(() => {
@@ -2025,7 +2045,11 @@ var init_keys = __esm(() => {
2025
2045
  "error.provider.sdkNotInstalled": "error.provider.sdkNotInstalled",
2026
2046
  "error.provider.contextCreation": "error.provider.contextCreation",
2027
2047
  "error.provider.executionFailed": "error.provider.executionFailed",
2028
- "error.provider.streamFailed": "error.provider.streamFailed"
2048
+ "error.provider.streamFailed": "error.provider.streamFailed",
2049
+ "error.provider.notAvailable": "error.provider.notAvailable",
2050
+ "error.telemetry.posthogAiRequired": "error.telemetry.posthogAiRequired",
2051
+ "error.telemetry.posthogClientOrKeyRequired": "error.telemetry.posthogClientOrKeyRequired",
2052
+ "error.telemetry.posthogNodeRequired": "error.telemetry.posthogNodeRequired"
2029
2053
  };
2030
2054
  EXPORT_KEYS = {
2031
2055
  "export.agentConfiguration": "export.agentConfiguration",
@@ -2105,7 +2129,7 @@ var init_i18n = __esm(() => {
2105
2129
 
2106
2130
  // src/spec/spec.ts
2107
2131
  function defineAgent(spec) {
2108
- const i18n = getDefaultI18n();
2132
+ const i18n = createAgentI18n(spec.locale);
2109
2133
  if (!spec.meta?.key) {
2110
2134
  throw new Error(i18n.t("error.agentKeyRequired"));
2111
2135
  }
@@ -2141,7 +2165,7 @@ var init_spec = __esm(() => {
2141
2165
  function specToolToOpenCodeTool(tool) {
2142
2166
  return {
2143
2167
  name: tool.name,
2144
- description: tool.description ?? getDefaultI18n().t("tool.fallbackDescription", { name: tool.name }),
2168
+ description: tool.description ?? createAgentI18n().t("tool.fallbackDescription", { name: tool.name }),
2145
2169
  parameters: normalizeToOpenCodeParameters(tool.schema),
2146
2170
  permission: getPermissionLevel(tool)
2147
2171
  };
@@ -2173,7 +2197,7 @@ function openCodeToolsToSpecTools(openCodeTools) {
2173
2197
  function specToolToExternalToolForOpenCode(tool, handler, context) {
2174
2198
  return {
2175
2199
  name: tool.name,
2176
- description: tool.description ?? getDefaultI18n().t("tool.fallbackDescription", { name: tool.name }),
2200
+ description: tool.description ?? createAgentI18n().t("tool.fallbackDescription", { name: tool.name }),
2177
2201
  inputSchema: tool.schema ?? { type: "object" },
2178
2202
  requiresApproval: tool.requiresApproval ?? !tool.automationSafe,
2179
2203
  execute: handler ? async (input) => {
@@ -2237,7 +2261,7 @@ async function executeToolCall(toolCall, handlers) {
2237
2261
  if (!handler) {
2238
2262
  return {
2239
2263
  tool_call_id: toolCall.id,
2240
- output: getDefaultI18n().t("error.toolNotFoundOrNoHandler", {
2264
+ output: createAgentI18n().t("error.toolNotFoundOrNoHandler", {
2241
2265
  name: toolCall.name
2242
2266
  }),
2243
2267
  is_error: true
@@ -2334,7 +2358,7 @@ function specToOpenCodeMarkdown(spec, options) {
2334
2358
  };
2335
2359
  }
2336
2360
  function buildMarkdownBody(spec) {
2337
- const i18n = getDefaultI18n();
2361
+ const i18n = createAgentI18n(spec.locale);
2338
2362
  const lines = [];
2339
2363
  lines.push(`# ${spec.meta.key}`);
2340
2364
  lines.push("");
@@ -2444,7 +2468,7 @@ class OpenCodeExporter {
2444
2468
  return specs.map((spec) => this.export(spec, options));
2445
2469
  }
2446
2470
  validate(spec) {
2447
- const i18n = getDefaultI18n();
2471
+ const i18n = createAgentI18n(spec.locale);
2448
2472
  const errors = [];
2449
2473
  if (!spec.meta?.key) {
2450
2474
  errors.push(i18n.t("export.validation.requiresKey"));
@@ -2479,7 +2503,7 @@ class OpenCodeExporter {
2479
2503
  };
2480
2504
  }
2481
2505
  exportTools(spec) {
2482
- const i18n = getDefaultI18n();
2506
+ const i18n = createAgentI18n(spec.locale);
2483
2507
  return spec.tools.map((tool) => ({
2484
2508
  name: tool.name,
2485
2509
  description: tool.description ?? i18n.t("tool.fallbackDescription", { name: tool.name }),
@@ -2488,7 +2512,7 @@ class OpenCodeExporter {
2488
2512
  }));
2489
2513
  }
2490
2514
  generateMarkdown(spec, jsonConfig, options) {
2491
- const i18n = getDefaultI18n();
2515
+ const i18n = createAgentI18n(options.locale ?? spec.locale);
2492
2516
  const lines = [];
2493
2517
  lines.push("---");
2494
2518
  lines.push(`name: ${jsonConfig.name}`);
@@ -2522,7 +2546,7 @@ class OpenCodeExporter {
2522
2546
  }
2523
2547
  lines.push(i18n.t("export.agentType", { type: jsonConfig.type }));
2524
2548
  lines.push("");
2525
- lines.push(this.getAgentTypeDescription(jsonConfig.type));
2549
+ lines.push(this.getAgentTypeDescription(jsonConfig.type, options.locale ?? spec.locale));
2526
2550
  lines.push("");
2527
2551
  lines.push(i18n.t("export.instructions"));
2528
2552
  lines.push("");
@@ -2586,8 +2610,8 @@ class OpenCodeExporter {
2586
2610
  return lines.join(`
2587
2611
  `);
2588
2612
  }
2589
- getAgentTypeDescription(type) {
2590
- const i18n = getDefaultI18n();
2613
+ getAgentTypeDescription(type, locale) {
2614
+ const i18n = createAgentI18n(locale);
2591
2615
  switch (type) {
2592
2616
  case "build":
2593
2617
  return i18n.t("export.agentType.build");
@@ -603,6 +603,26 @@ var init_en = __esm(() => {
603
603
  value: "[MCPToolServer] Stopped {name}",
604
604
  description: "Log message when MCP tool server stops",
605
605
  placeholders: [{ name: "name", type: "string" }]
606
+ },
607
+ "error.telemetry.posthogAiRequired": {
608
+ value: "PostHog LLM Analytics requires @posthog/ai to be installed. Run: npm install @posthog/ai posthog-node",
609
+ description: "Error when PostHog AI dependency is missing"
610
+ },
611
+ "error.telemetry.posthogClientOrKeyRequired": {
612
+ value: "PostHog LLM Analytics requires either a client instance or an apiKey.",
613
+ description: "Error when PostHog client or API key is not configured"
614
+ },
615
+ "error.telemetry.posthogNodeRequired": {
616
+ value: "PostHog LLM Analytics requires posthog-node to be installed. Run: npm install posthog-node",
617
+ description: "Error when posthog-node dependency is missing"
618
+ },
619
+ "error.provider.notAvailable": {
620
+ value: "Provider '{provider}' is not available{reason}",
621
+ description: "Error when a provider is unavailable",
622
+ placeholders: [
623
+ { name: "provider", type: "string" },
624
+ { name: "reason", type: "string" }
625
+ ]
606
626
  }
607
627
  }
608
628
  });
@@ -652,6 +652,26 @@ var init_es = __esm(() => {
652
652
  value: "[MCPToolServer] Detenido {name}",
653
653
  description: "Mensaje de registro cuando el servidor de herramientas MCP se detiene",
654
654
  placeholders: [{ name: "name", type: "string" }]
655
+ },
656
+ "error.telemetry.posthogAiRequired": {
657
+ value: "PostHog LLM Analytics requiere que @posthog/ai esté instalado. Ejecute: npm install @posthog/ai posthog-node",
658
+ description: "Error when PostHog AI dependency is missing"
659
+ },
660
+ "error.telemetry.posthogClientOrKeyRequired": {
661
+ value: "PostHog LLM Analytics requiere una instancia de cliente o una apiKey.",
662
+ description: "Error when PostHog client or API key is not configured"
663
+ },
664
+ "error.telemetry.posthogNodeRequired": {
665
+ value: "PostHog LLM Analytics requiere que posthog-node esté instalado. Ejecute: npm install posthog-node",
666
+ description: "Error when posthog-node dependency is missing"
667
+ },
668
+ "error.provider.notAvailable": {
669
+ value: "El proveedor '{provider}' no está disponible{reason}",
670
+ description: "Error when a provider is unavailable",
671
+ placeholders: [
672
+ { name: "provider", type: "string" },
673
+ { name: "reason", type: "string" }
674
+ ]
655
675
  }
656
676
  }
657
677
  });
@@ -618,6 +618,26 @@ var init_fr = __esm(() => {
618
618
  value: "[MCPToolServer] {name} arrêté",
619
619
  description: "Log message when MCP tool server stops",
620
620
  placeholders: [{ name: "name", type: "string" }]
621
+ },
622
+ "error.telemetry.posthogAiRequired": {
623
+ value: "PostHog LLM Analytics nécessite l'installation de @posthog/ai. Exécutez : npm install @posthog/ai posthog-node",
624
+ description: "Error when PostHog AI dependency is missing"
625
+ },
626
+ "error.telemetry.posthogClientOrKeyRequired": {
627
+ value: "PostHog LLM Analytics nécessite soit une instance client, soit une apiKey.",
628
+ description: "Error when PostHog client or API key is not configured"
629
+ },
630
+ "error.telemetry.posthogNodeRequired": {
631
+ value: "PostHog LLM Analytics nécessite l'installation de posthog-node. Exécutez : npm install posthog-node",
632
+ description: "Error when posthog-node dependency is missing"
633
+ },
634
+ "error.provider.notAvailable": {
635
+ value: "Le fournisseur « {provider} » n'est pas disponible{reason}",
636
+ description: "Error when a provider is unavailable",
637
+ placeholders: [
638
+ { name: "provider", type: "string" },
639
+ { name: "reason", type: "string" }
640
+ ]
621
641
  }
622
642
  }
623
643
  });