@elisym/mcp 0.3.1 → 0.3.2
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 +39 -43
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1072,6 +1072,7 @@ function sanitizeField(input, maxLen) {
|
|
|
1072
1072
|
}
|
|
1073
1073
|
|
|
1074
1074
|
// src/tools/customer.ts
|
|
1075
|
+
var PRE_PING_TIMEOUT_MS = 5e3;
|
|
1075
1076
|
var CreateJobSchema = z.object({
|
|
1076
1077
|
input: z.string().describe("The job prompt/input sent to the provider."),
|
|
1077
1078
|
capability: z.string().min(1).max(64).default("general").describe("Short tag selecting which capability of the provider to invoke."),
|
|
@@ -1445,6 +1446,12 @@ ${wrapped}`);
|
|
|
1445
1446
|
const timeout = Math.min(input.timeout_secs, MAX_TIMEOUT_SECS) * 1e3;
|
|
1446
1447
|
const agent = ctx.active();
|
|
1447
1448
|
const providerPubkey = decodeNpub(input.provider_npub);
|
|
1449
|
+
const ping = await agent.client.ping.pingAgent(providerPubkey, PRE_PING_TIMEOUT_MS);
|
|
1450
|
+
if (!ping.online) {
|
|
1451
|
+
return errorResult(
|
|
1452
|
+
`Provider ${input.provider_npub} is offline. Run search_agents to find currently-online providers.`
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1448
1455
|
const providers = await agent.client.discovery.fetchAgents(agent.network);
|
|
1449
1456
|
const provider = providers.find((a) => a.npub === input.provider_npub);
|
|
1450
1457
|
if (!provider) {
|
|
@@ -1526,6 +1533,12 @@ ${result}`);
|
|
|
1526
1533
|
const agent = ctx.active();
|
|
1527
1534
|
const providerPubkey = decodeNpub(input.provider_npub);
|
|
1528
1535
|
const dTag = toDTag(input.capability);
|
|
1536
|
+
const ping = await agent.client.ping.pingAgent(providerPubkey, PRE_PING_TIMEOUT_MS);
|
|
1537
|
+
if (!ping.online) {
|
|
1538
|
+
return errorResult(
|
|
1539
|
+
`Provider ${input.provider_npub} is offline. Run search_agents to find currently-online providers.`
|
|
1540
|
+
);
|
|
1541
|
+
}
|
|
1529
1542
|
const agents = await agent.client.discovery.fetchAgents(agent.network);
|
|
1530
1543
|
const provider = agents.find((a) => a.npub === input.provider_npub);
|
|
1531
1544
|
if (!provider) {
|
|
@@ -1667,6 +1680,8 @@ ${text}`);
|
|
|
1667
1680
|
}
|
|
1668
1681
|
})
|
|
1669
1682
|
];
|
|
1683
|
+
var LAST_SEEN_ONLINE_WINDOW_SECS = 10 * 60;
|
|
1684
|
+
var SEARCH_PING_TIMEOUT_MS = 3e3;
|
|
1670
1685
|
var STOP_WORDS = /* @__PURE__ */ new Set([
|
|
1671
1686
|
"a",
|
|
1672
1687
|
"an",
|
|
@@ -1800,28 +1815,19 @@ var SearchAgentsSchema = z.object({
|
|
|
1800
1815
|
capabilities: z.array(z.string()).min(1).describe("OR-matched substring filter on agent names, descriptions, and capability tags."),
|
|
1801
1816
|
query: z.string().optional().describe("Optional secondary scoring for re-ranking. Omit when you have precise tokens."),
|
|
1802
1817
|
max_price_lamports: z.number().int().optional(),
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
recently_active_only: z.boolean().default(true).describe(
|
|
1806
|
-
"If true, only return agents with job activity in the last hour. Not a liveness probe."
|
|
1818
|
+
include_offline: z.boolean().default(false).describe(
|
|
1819
|
+
"If true, skip the live online check and return agents regardless of reachability. Default: false - only currently-online agents are returned."
|
|
1807
1820
|
)
|
|
1808
1821
|
});
|
|
1809
1822
|
var ListCapabilitiesSchema = z.object({});
|
|
1810
1823
|
var GetIdentitySchema = z.object({});
|
|
1811
|
-
var PingAgentSchema = z.object({
|
|
1812
|
-
agent_npub: z.string(),
|
|
1813
|
-
// single source of truth for the default.
|
|
1814
|
-
timeout_secs: z.number().int().min(1).max(600).default(15)
|
|
1815
|
-
});
|
|
1816
1824
|
var discoveryTools = [
|
|
1817
1825
|
defineTool({
|
|
1818
1826
|
name: "search_agents",
|
|
1819
|
-
|
|
1820
|
-
// Keep the operational rules short; schema `.describe()` fields carry the detail.
|
|
1821
|
-
description: "Search AI agents. `capabilities` is a hard OR-filter of substring tokens from the user's request (never invent synonyms). `query` is optional re-ranking; omit if not needed.",
|
|
1827
|
+
description: "Search AI agents currently online on elisym. `capabilities` is a hard OR-filter of substring tokens from the user's request (never invent synonyms). `query` is optional re-ranking; omit if not needed. Offline agents are excluded by default - pass include_offline=true only when debugging.",
|
|
1822
1828
|
schema: SearchAgentsSchema,
|
|
1823
1829
|
async handler(ctx, input) {
|
|
1824
|
-
const { capabilities, query, max_price_lamports,
|
|
1830
|
+
const { capabilities, query, max_price_lamports, include_offline } = input;
|
|
1825
1831
|
if (capabilities.length > MAX_CAPABILITIES) {
|
|
1826
1832
|
return errorResult(`Too many capabilities (max ${MAX_CAPABILITIES})`);
|
|
1827
1833
|
}
|
|
@@ -1834,10 +1840,6 @@ var discoveryTools = [
|
|
|
1834
1840
|
)
|
|
1835
1841
|
)
|
|
1836
1842
|
);
|
|
1837
|
-
if (recently_active_only) {
|
|
1838
|
-
const activeThreshold = Math.floor(Date.now() / 1e3) - 60 * 60;
|
|
1839
|
-
filtered = filtered.filter((a) => a.lastSeen >= activeThreshold);
|
|
1840
|
-
}
|
|
1841
1843
|
if (max_price_lamports !== void 0) {
|
|
1842
1844
|
filtered = filtered.filter(
|
|
1843
1845
|
(a) => a.cards.some(
|
|
@@ -1845,6 +1847,25 @@ var discoveryTools = [
|
|
|
1845
1847
|
)
|
|
1846
1848
|
);
|
|
1847
1849
|
}
|
|
1850
|
+
if (!include_offline) {
|
|
1851
|
+
const freshThreshold = Math.floor(Date.now() / 1e3) - LAST_SEEN_ONLINE_WINDOW_SECS;
|
|
1852
|
+
filtered = filtered.filter((a) => a.lastSeen >= freshThreshold);
|
|
1853
|
+
if (filtered.length > 0) {
|
|
1854
|
+
const probes = await Promise.allSettled(
|
|
1855
|
+
filtered.map(
|
|
1856
|
+
(candidate) => agent.client.ping.pingAgent(candidate.pubkey, SEARCH_PING_TIMEOUT_MS)
|
|
1857
|
+
)
|
|
1858
|
+
);
|
|
1859
|
+
const survivors = [];
|
|
1860
|
+
filtered.forEach((candidate, index) => {
|
|
1861
|
+
const probe = probes[index];
|
|
1862
|
+
if (probe?.status === "fulfilled" && probe.value.online) {
|
|
1863
|
+
survivors.push(candidate);
|
|
1864
|
+
}
|
|
1865
|
+
});
|
|
1866
|
+
filtered = survivors;
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1848
1869
|
if (query) {
|
|
1849
1870
|
const isAscii = /^[\u0000-\u007F]*$/.test(query);
|
|
1850
1871
|
const words = query.toLowerCase().split(/\s+/).filter((w) => w.length > 1 && (!isAscii || !STOP_WORDS.has(w)));
|
|
@@ -1865,7 +1886,7 @@ var discoveryTools = [
|
|
|
1865
1886
|
}
|
|
1866
1887
|
if (filtered.length === 0) {
|
|
1867
1888
|
return textResult(
|
|
1868
|
-
|
|
1889
|
+
include_offline ? "No agents found matching those capabilities." : "No online agents found matching those capabilities. Retry shortly or pass include_offline=true to see unreachable matches."
|
|
1869
1890
|
);
|
|
1870
1891
|
}
|
|
1871
1892
|
const results = filtered.map((a) => ({
|
|
@@ -1927,31 +1948,6 @@ ${text}`);
|
|
|
1927
1948
|
)
|
|
1928
1949
|
);
|
|
1929
1950
|
}
|
|
1930
|
-
}),
|
|
1931
|
-
defineTool({
|
|
1932
|
-
name: "ping_agent",
|
|
1933
|
-
description: "Ping an agent to check if it's online. Sends an encrypted heartbeat and waits for a pong.",
|
|
1934
|
-
schema: PingAgentSchema,
|
|
1935
|
-
async handler(ctx, input) {
|
|
1936
|
-
ctx.toolRateLimiter.check();
|
|
1937
|
-
const { agent_npub, timeout_secs } = input;
|
|
1938
|
-
const agent = ctx.active();
|
|
1939
|
-
let pubkey;
|
|
1940
|
-
try {
|
|
1941
|
-
const decoded = nip19.decode(agent_npub);
|
|
1942
|
-
if (decoded.type !== "npub") {
|
|
1943
|
-
return errorResult(`Expected npub, got ${decoded.type}`);
|
|
1944
|
-
}
|
|
1945
|
-
pubkey = decoded.data;
|
|
1946
|
-
} catch {
|
|
1947
|
-
return errorResult(`Invalid npub: ${agent_npub}`);
|
|
1948
|
-
}
|
|
1949
|
-
const timeoutMs = timeout_secs * 1e3;
|
|
1950
|
-
const result = await agent.client.ping.pingAgent(pubkey, timeoutMs);
|
|
1951
|
-
return textResult(
|
|
1952
|
-
result.online ? `Agent ${agent_npub} is online.` : `Agent ${agent_npub} did not respond within ${timeout_secs}s.`
|
|
1953
|
-
);
|
|
1954
|
-
}
|
|
1955
1951
|
})
|
|
1956
1952
|
];
|
|
1957
1953
|
var GetBalanceSchema = z.object({});
|