@contractspec/lib.ai-agent 2.3.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.
- package/dist/agent/agent-factory.js +97 -67
- package/dist/agent/contract-spec-agent.js +97 -67
- package/dist/agent/index.js +140 -100
- package/dist/agent/json-runner.js +103 -71
- package/dist/agent/unified-agent.d.ts +4 -0
- package/dist/agent/unified-agent.js +134 -96
- package/dist/approval/index.js +86 -62
- package/dist/approval/workflow.d.ts +2 -0
- package/dist/approval/workflow.js +86 -62
- package/dist/exporters/claude-agent-exporter.js +90 -66
- package/dist/exporters/index.js +100 -76
- package/dist/exporters/opencode-exporter.js +96 -72
- package/dist/exporters/types.d.ts +2 -0
- package/dist/i18n/catalogs/en.js +20 -0
- package/dist/i18n/catalogs/es.js +20 -0
- package/dist/i18n/catalogs/fr.js +20 -0
- package/dist/i18n/catalogs/index.js +60 -0
- package/dist/i18n/index.js +85 -61
- package/dist/i18n/keys.d.ts +16 -0
- package/dist/i18n/keys.js +5 -1
- package/dist/i18n/locale.d.ts +3 -28
- package/dist/i18n/locale.js +7 -18
- package/dist/i18n/messages.d.ts +9 -60
- package/dist/i18n/messages.js +71 -60
- package/dist/index.js +88 -64
- package/dist/interop/index.js +117 -79
- package/dist/interop/spec-consumer.d.ts +1 -0
- package/dist/interop/spec-consumer.js +92 -66
- package/dist/interop/tool-consumer.d.ts +1 -0
- package/dist/interop/tool-consumer.js +110 -74
- package/dist/interop/types.d.ts +10 -0
- package/dist/knowledge/index.js +85 -61
- package/dist/knowledge/injector.js +85 -61
- package/dist/node/agent/agent-factory.js +97 -67
- package/dist/node/agent/contract-spec-agent.js +97 -67
- package/dist/node/agent/index.js +140 -100
- package/dist/node/agent/json-runner.js +103 -71
- package/dist/node/agent/unified-agent.js +134 -96
- package/dist/node/approval/index.js +86 -62
- package/dist/node/approval/workflow.js +86 -62
- package/dist/node/exporters/claude-agent-exporter.js +90 -66
- package/dist/node/exporters/index.js +100 -76
- package/dist/node/exporters/opencode-exporter.js +96 -72
- package/dist/node/i18n/catalogs/en.js +20 -0
- package/dist/node/i18n/catalogs/es.js +20 -0
- package/dist/node/i18n/catalogs/fr.js +20 -0
- package/dist/node/i18n/catalogs/index.js +60 -0
- package/dist/node/i18n/index.js +85 -61
- package/dist/node/i18n/keys.js +5 -1
- package/dist/node/i18n/locale.js +7 -18
- package/dist/node/i18n/messages.js +71 -60
- package/dist/node/index.js +88 -64
- package/dist/node/interop/index.js +117 -79
- package/dist/node/interop/spec-consumer.js +92 -66
- package/dist/node/interop/tool-consumer.js +110 -74
- package/dist/node/knowledge/index.js +85 -61
- package/dist/node/knowledge/injector.js +85 -61
- package/dist/node/providers/claude-agent-sdk/adapter.js +103 -74
- package/dist/node/providers/claude-agent-sdk/index.js +103 -74
- package/dist/node/providers/claude-agent-sdk/tool-bridge.js +88 -64
- package/dist/node/providers/index.js +116 -86
- package/dist/node/providers/opencode-sdk/adapter.js +102 -73
- package/dist/node/providers/opencode-sdk/agent-bridge.js +89 -65
- package/dist/node/providers/opencode-sdk/index.js +102 -73
- package/dist/node/providers/opencode-sdk/tool-bridge.js +88 -64
- package/dist/node/providers/registry.js +96 -66
- package/dist/node/providers/types.js +2122 -2
- package/dist/node/spec/index.js +88 -64
- package/dist/node/spec/registry.js +87 -63
- package/dist/node/spec/spec.js +86 -62
- package/dist/node/telemetry/index.js +2122 -3
- package/dist/node/telemetry/posthog.js +2123 -3
- package/dist/node/tools/index.js +90 -63
- package/dist/node/tools/knowledge-tool.js +85 -61
- package/dist/node/tools/mcp-server.js +86 -62
- package/dist/node/tools/tool-adapter.js +89 -62
- package/dist/providers/claude-agent-sdk/adapter.js +103 -74
- package/dist/providers/claude-agent-sdk/index.js +103 -74
- package/dist/providers/claude-agent-sdk/tool-bridge.js +88 -64
- package/dist/providers/index.js +116 -86
- package/dist/providers/opencode-sdk/adapter.js +102 -73
- package/dist/providers/opencode-sdk/agent-bridge.js +89 -65
- package/dist/providers/opencode-sdk/index.js +102 -73
- package/dist/providers/opencode-sdk/tool-bridge.js +88 -64
- package/dist/providers/registry.d.ts +2 -2
- package/dist/providers/registry.js +96 -66
- package/dist/providers/types.d.ts +5 -1
- package/dist/providers/types.js +2122 -2
- package/dist/spec/index.js +88 -64
- package/dist/spec/registry.d.ts +1 -1
- package/dist/spec/registry.js +87 -63
- package/dist/spec/spec.js +86 -62
- package/dist/telemetry/index.js +2122 -3
- package/dist/telemetry/posthog.js +2123 -3
- package/dist/tools/index.js +90 -63
- package/dist/tools/knowledge-tool.js +85 -61
- package/dist/tools/mcp-server.js +86 -62
- package/dist/tools/tool-adapter.js +89 -62
- package/dist/types.d.ts +2 -0
- 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\xEAt\xE9",
|
|
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\xE9cessite l'installation de @posthog/ai. Ex\xE9cutez : 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\xE9cessite 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\xE9cessite l'installation de posthog-node. Ex\xE9cutez : npm install posthog-node",
|
|
1248
|
+
description: "Error when posthog-node dependency is missing"
|
|
1249
|
+
},
|
|
1250
|
+
"error.provider.notAvailable": {
|
|
1251
|
+
value: "Le fournisseur \xAB {provider} \xBB 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\xE9 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\xE9 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\xE1 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 {
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
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
|
-
|
|
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 =
|
|
2132
|
+
const i18n = createAgentI18n(spec.locale);
|
|
2109
2133
|
if (!spec.meta?.key) {
|
|
2110
2134
|
throw new Error(i18n.t("error.agentKeyRequired"));
|
|
2111
2135
|
}
|
|
@@ -2145,10 +2169,12 @@ class ContractSpecConsumer {
|
|
|
2145
2169
|
specs;
|
|
2146
2170
|
includeMetadata;
|
|
2147
2171
|
baseUrl;
|
|
2172
|
+
locale;
|
|
2148
2173
|
constructor(config) {
|
|
2149
2174
|
this.specs = new Map;
|
|
2150
2175
|
this.includeMetadata = config.includeMetadata ?? true;
|
|
2151
2176
|
this.baseUrl = config.baseUrl;
|
|
2177
|
+
this.locale = config.locale;
|
|
2152
2178
|
for (const spec of config.specs) {
|
|
2153
2179
|
const key = agentKey(spec.meta);
|
|
2154
2180
|
this.specs.set(key, spec);
|
|
@@ -2157,9 +2183,9 @@ class ContractSpecConsumer {
|
|
|
2157
2183
|
getSpecMarkdown(specKey, options) {
|
|
2158
2184
|
const spec = this.specs.get(specKey);
|
|
2159
2185
|
if (!spec) {
|
|
2160
|
-
throw new Error(
|
|
2186
|
+
throw new Error(createAgentI18n(this.locale).t("error.specNotFound", { specKey }));
|
|
2161
2187
|
}
|
|
2162
|
-
const i18n =
|
|
2188
|
+
const i18n = createAgentI18n(options?.locale ?? this.locale);
|
|
2163
2189
|
const sections = [];
|
|
2164
2190
|
const opts = {
|
|
2165
2191
|
includeToc: options?.includeToc ?? true,
|
|
@@ -2282,9 +2308,9 @@ class ContractSpecConsumer {
|
|
|
2282
2308
|
getSpecPrompt(specKey, options) {
|
|
2283
2309
|
const spec = this.specs.get(specKey);
|
|
2284
2310
|
if (!spec) {
|
|
2285
|
-
throw new Error(
|
|
2311
|
+
throw new Error(createAgentI18n(this.locale).t("error.specNotFound", { specKey }));
|
|
2286
2312
|
}
|
|
2287
|
-
const i18n =
|
|
2313
|
+
const i18n = createAgentI18n(options?.locale ?? this.locale);
|
|
2288
2314
|
const sections = [];
|
|
2289
2315
|
const opts = {
|
|
2290
2316
|
includeTools: options?.includeTools ?? true,
|
|
@@ -14,6 +14,7 @@ import type { ToolConsumer, ToolConsumerConfig, ToolServerConfig, ToolServer, To
|
|
|
14
14
|
*/
|
|
15
15
|
export declare class ContractSpecToolConsumer implements ToolConsumer {
|
|
16
16
|
private readonly tools;
|
|
17
|
+
private readonly locale?;
|
|
17
18
|
constructor(config: ToolConsumerConfig);
|
|
18
19
|
/**
|
|
19
20
|
* Create an MCP server exposing the tools.
|
|
@@ -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\xEAt\xE9",
|
|
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\xE9cessite l'installation de @posthog/ai. Ex\xE9cutez : 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\xE9cessite 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\xE9cessite l'installation de posthog-node. Ex\xE9cutez : npm install posthog-node",
|
|
1248
|
+
description: "Error when posthog-node dependency is missing"
|
|
1249
|
+
},
|
|
1250
|
+
"error.provider.notAvailable": {
|
|
1251
|
+
value: "Le fournisseur \xAB {provider} \xBB 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\xE9 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\xE9 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\xE1 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 {
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
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
|
-
|
|
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",
|
|
@@ -2107,7 +2131,7 @@ var init_i18n = __esm(() => {
|
|
|
2107
2131
|
function specToolToClaudeAgentTool(tool, handler, context) {
|
|
2108
2132
|
return {
|
|
2109
2133
|
name: tool.name,
|
|
2110
|
-
description: tool.description ??
|
|
2134
|
+
description: tool.description ?? createAgentI18n().t("tool.fallbackDescription", { name: tool.name }),
|
|
2111
2135
|
input_schema: normalizeSchema(tool.schema),
|
|
2112
2136
|
requires_confirmation: tool.requiresApproval ?? !tool.automationSafe,
|
|
2113
2137
|
execute: async (input) => {
|
|
@@ -2127,7 +2151,7 @@ function specToolsToClaudeAgentTools(tools, handlers, context) {
|
|
|
2127
2151
|
return tools.filter((tool) => handlers.has(tool.name)).map((tool) => {
|
|
2128
2152
|
const handler = handlers.get(tool.name);
|
|
2129
2153
|
if (!handler) {
|
|
2130
|
-
throw new Error(
|
|
2154
|
+
throw new Error(createAgentI18n().t("error.handlerNotFoundForTool", {
|
|
2131
2155
|
name: tool.name
|
|
2132
2156
|
}));
|
|
2133
2157
|
}
|
|
@@ -2160,7 +2184,7 @@ function claudeAgentToolsToSpecTools(claudeTools) {
|
|
|
2160
2184
|
function specToolToExternalTool(tool, handler, context) {
|
|
2161
2185
|
return {
|
|
2162
2186
|
name: tool.name,
|
|
2163
|
-
description: tool.description ??
|
|
2187
|
+
description: tool.description ?? createAgentI18n().t("tool.fallbackDescription", { name: tool.name }),
|
|
2164
2188
|
inputSchema: tool.schema ?? { type: "object" },
|
|
2165
2189
|
requiresApproval: tool.requiresApproval ?? !tool.automationSafe,
|
|
2166
2190
|
execute: handler ? async (input) => {
|
|
@@ -2209,7 +2233,7 @@ var init_tool_bridge = __esm(() => {
|
|
|
2209
2233
|
function specToolToOpenCodeTool(tool) {
|
|
2210
2234
|
return {
|
|
2211
2235
|
name: tool.name,
|
|
2212
|
-
description: tool.description ??
|
|
2236
|
+
description: tool.description ?? createAgentI18n().t("tool.fallbackDescription", { name: tool.name }),
|
|
2213
2237
|
parameters: normalizeToOpenCodeParameters(tool.schema),
|
|
2214
2238
|
permission: getPermissionLevel(tool)
|
|
2215
2239
|
};
|
|
@@ -2241,7 +2265,7 @@ function openCodeToolsToSpecTools(openCodeTools) {
|
|
|
2241
2265
|
function specToolToExternalToolForOpenCode(tool, handler, context) {
|
|
2242
2266
|
return {
|
|
2243
2267
|
name: tool.name,
|
|
2244
|
-
description: tool.description ??
|
|
2268
|
+
description: tool.description ?? createAgentI18n().t("tool.fallbackDescription", { name: tool.name }),
|
|
2245
2269
|
inputSchema: tool.schema ?? { type: "object" },
|
|
2246
2270
|
requiresApproval: tool.requiresApproval ?? !tool.automationSafe,
|
|
2247
2271
|
execute: handler ? async (input) => {
|
|
@@ -2305,7 +2329,7 @@ async function executeToolCall(toolCall, handlers) {
|
|
|
2305
2329
|
if (!handler) {
|
|
2306
2330
|
return {
|
|
2307
2331
|
tool_call_id: toolCall.id,
|
|
2308
|
-
output:
|
|
2332
|
+
output: createAgentI18n().t("error.toolNotFoundOrNoHandler", {
|
|
2309
2333
|
name: toolCall.name
|
|
2310
2334
|
}),
|
|
2311
2335
|
is_error: true
|
|
@@ -2338,11 +2362,13 @@ class MCPToolServer {
|
|
|
2338
2362
|
tools;
|
|
2339
2363
|
name;
|
|
2340
2364
|
version;
|
|
2365
|
+
locale;
|
|
2341
2366
|
running = false;
|
|
2342
2367
|
constructor(config) {
|
|
2343
2368
|
this.tools = new Map;
|
|
2344
2369
|
this.name = config.name ?? "contractspec-tools";
|
|
2345
2370
|
this.version = config.version ?? "1.0.0";
|
|
2371
|
+
this.locale = config.locale;
|
|
2346
2372
|
for (const tool of config.tools) {
|
|
2347
2373
|
this.tools.set(tool.config.name, tool);
|
|
2348
2374
|
}
|
|
@@ -2352,7 +2378,7 @@ class MCPToolServer {
|
|
|
2352
2378
|
return;
|
|
2353
2379
|
}
|
|
2354
2380
|
this.running = true;
|
|
2355
|
-
console.log(
|
|
2381
|
+
console.log(createAgentI18n(this.locale).t("log.mcpServer.started", {
|
|
2356
2382
|
name: this.name,
|
|
2357
2383
|
version: this.version,
|
|
2358
2384
|
count: this.tools.size
|
|
@@ -2363,7 +2389,9 @@ class MCPToolServer {
|
|
|
2363
2389
|
return;
|
|
2364
2390
|
}
|
|
2365
2391
|
this.running = false;
|
|
2366
|
-
console.log(
|
|
2392
|
+
console.log(createAgentI18n(this.locale).t("log.mcpServer.stopped", {
|
|
2393
|
+
name: this.name
|
|
2394
|
+
}));
|
|
2367
2395
|
}
|
|
2368
2396
|
isRunning() {
|
|
2369
2397
|
return this.running;
|
|
@@ -2372,18 +2400,20 @@ class MCPToolServer {
|
|
|
2372
2400
|
return Array.from(this.tools.values()).map((t) => t.config);
|
|
2373
2401
|
}
|
|
2374
2402
|
async executeTool(toolName, args, context) {
|
|
2403
|
+
const i18n = createAgentI18n(context?.locale ?? this.locale);
|
|
2375
2404
|
const tool = this.tools.get(toolName);
|
|
2376
2405
|
if (!tool) {
|
|
2377
|
-
throw new Error(
|
|
2406
|
+
throw new Error(i18n.t("error.toolNotFound", { name: toolName }));
|
|
2378
2407
|
}
|
|
2379
2408
|
if (!tool.handler) {
|
|
2380
|
-
throw new Error(
|
|
2409
|
+
throw new Error(i18n.t("error.noHandlerForTool", { name: toolName }));
|
|
2381
2410
|
}
|
|
2382
2411
|
const fullContext = {
|
|
2383
2412
|
agentId: context?.agentId ?? "mcp-server",
|
|
2384
2413
|
sessionId: context?.sessionId ?? "mcp-session",
|
|
2385
2414
|
tenantId: context?.tenantId,
|
|
2386
2415
|
actorId: context?.actorId,
|
|
2416
|
+
locale: context?.locale ?? this.locale,
|
|
2387
2417
|
metadata: context?.metadata,
|
|
2388
2418
|
signal: context?.signal
|
|
2389
2419
|
};
|
|
@@ -2412,8 +2442,10 @@ class MCPToolServer {
|
|
|
2412
2442
|
|
|
2413
2443
|
class ContractSpecToolConsumer {
|
|
2414
2444
|
tools;
|
|
2445
|
+
locale;
|
|
2415
2446
|
constructor(config) {
|
|
2416
2447
|
this.tools = new Map;
|
|
2448
|
+
this.locale = config.locale;
|
|
2417
2449
|
for (const tool of config.tools) {
|
|
2418
2450
|
this.tools.set(tool.config.name, tool);
|
|
2419
2451
|
}
|
|
@@ -2454,7 +2486,9 @@ class ContractSpecToolConsumer {
|
|
|
2454
2486
|
}
|
|
2455
2487
|
}));
|
|
2456
2488
|
default:
|
|
2457
|
-
throw new Error(
|
|
2489
|
+
throw new Error(createAgentI18n(this.locale).t("error.unknownExportFormat", {
|
|
2490
|
+
format
|
|
2491
|
+
}));
|
|
2458
2492
|
}
|
|
2459
2493
|
}
|
|
2460
2494
|
createBridgedHandler(toolName, _format) {
|
|
@@ -2481,18 +2515,20 @@ class ContractSpecToolConsumer {
|
|
|
2481
2515
|
return this.tools.has(name);
|
|
2482
2516
|
}
|
|
2483
2517
|
async executeTool(name, args, context) {
|
|
2518
|
+
const i18n = createAgentI18n(context?.locale ?? this.locale);
|
|
2484
2519
|
const tool = this.tools.get(name);
|
|
2485
2520
|
if (!tool) {
|
|
2486
|
-
throw new Error(
|
|
2521
|
+
throw new Error(i18n.t("error.toolNotFound", { name }));
|
|
2487
2522
|
}
|
|
2488
2523
|
if (!tool.handler) {
|
|
2489
|
-
throw new Error(
|
|
2524
|
+
throw new Error(i18n.t("error.noToolHandler", { name }));
|
|
2490
2525
|
}
|
|
2491
2526
|
const fullContext = {
|
|
2492
2527
|
agentId: context?.agentId ?? "consumer",
|
|
2493
2528
|
sessionId: context?.sessionId ?? "consumer-session",
|
|
2494
2529
|
tenantId: context?.tenantId,
|
|
2495
2530
|
actorId: context?.actorId,
|
|
2531
|
+
locale: context?.locale ?? this.locale,
|
|
2496
2532
|
metadata: context?.metadata,
|
|
2497
2533
|
signal: context?.signal
|
|
2498
2534
|
};
|
package/dist/interop/types.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface SpecConsumerConfig {
|
|
|
16
16
|
includeMetadata?: boolean;
|
|
17
17
|
/** Base URL for linking */
|
|
18
18
|
baseUrl?: string;
|
|
19
|
+
/** Locale for i18n (BCP 47). Falls back to 'en'. */
|
|
20
|
+
locale?: string;
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Options for markdown generation.
|
|
@@ -31,6 +33,8 @@ export interface SpecMarkdownOptions {
|
|
|
31
33
|
includeConstraints?: boolean;
|
|
32
34
|
/** Custom header */
|
|
33
35
|
customHeader?: string;
|
|
36
|
+
/** Locale override for this call (BCP 47). */
|
|
37
|
+
locale?: string;
|
|
34
38
|
}
|
|
35
39
|
/**
|
|
36
40
|
* Options for prompt generation.
|
|
@@ -46,6 +50,8 @@ export interface SpecPromptOptions {
|
|
|
46
50
|
format?: 'structured' | 'natural';
|
|
47
51
|
/** Custom context to append */
|
|
48
52
|
customContext?: string;
|
|
53
|
+
/** Locale override for this call (BCP 47). */
|
|
54
|
+
locale?: string;
|
|
49
55
|
}
|
|
50
56
|
/**
|
|
51
57
|
* Result from querying a spec.
|
|
@@ -112,6 +118,8 @@ export interface ToolConsumerConfig {
|
|
|
112
118
|
config: AgentToolConfig;
|
|
113
119
|
handler?: ToolHandler;
|
|
114
120
|
}[];
|
|
121
|
+
/** Locale for i18n (BCP 47). Falls back to 'en'. */
|
|
122
|
+
locale?: string;
|
|
115
123
|
}
|
|
116
124
|
/**
|
|
117
125
|
* Configuration for a tool server.
|
|
@@ -128,6 +136,8 @@ export interface ToolServerConfig {
|
|
|
128
136
|
version?: string;
|
|
129
137
|
/** Port to run on */
|
|
130
138
|
port?: number;
|
|
139
|
+
/** Locale for i18n (BCP 47). Falls back to 'en'. */
|
|
140
|
+
locale?: string;
|
|
131
141
|
}
|
|
132
142
|
/**
|
|
133
143
|
* Interface for tool servers.
|