Files
paseo/packages/protocol/src/tool-name-normalization.ts
Mohamed Boudra 53c14d9855 Extract client SDK package (#1052)
* Extract client SDK package

* Polish SDK client identity defaults

* Build client before dependent CI jobs

* Restore daemon client server export

* Extract protocol and client SDK packages

* Fix provider override schema validation

* Fix app test daemon client imports

* Simplify workspace build targets

* Fix CLI test server build bootstrap

* Run SDK package tests in CI

* Fix rebase package split drift

* Restore lockfile registry metadata

* Update SDK config test for prompt default

* Move terminal stream router test to client package

* Fix rebase drift for protocol imports

* Fix SDK agent capability fixture

* Restore legacy server client exports

* Fix server export compatibility test

* Advertise custom mode icon client capability

* Remove server daemon-client exports

* Format rebased mode control import

* Fix rebase drift for protocol imports

Files added by upstream PRs (#893, #1147, #1154) referenced the pre-split
shared/ paths that this branch moves into @getpaseo/protocol. Redirect
those imports to the protocol package so typecheck stays green after the
rebase.
2026-05-28 01:58:18 +08:00

95 lines
2.7 KiB
TypeScript

const TOOL_TOKEN_REGEX = /[a-z0-9]+/g;
const STANDARD_NAMESPACE_SEPARATOR_REGEX = /[.:/]/;
export function normalizeToolName(name: string): string {
return name.trim().toLowerCase();
}
export function tokenizeToolName(name: string): string[] {
const normalized = normalizeToolName(name);
return normalized.match(TOOL_TOKEN_REGEX) ?? [];
}
export function getToolLeafName(name: string): string | null {
const tokens = tokenizeToolName(name);
return tokens.length > 0 ? tokens[tokens.length - 1] : null;
}
export function isSpeakToolName(name: string): boolean {
return getToolLeafName(name) === "speak";
}
export function isLikelyNamespacedToolName(name: string): boolean {
const normalized = normalizeToolName(name);
if (STANDARD_NAMESPACE_SEPARATOR_REGEX.test(normalized)) {
return true;
}
if (!normalized.includes("__")) {
return false;
}
// Keep `__` handling strict to avoid false positives on arbitrary custom names.
const segments = normalized.split("__").filter((segment) => segment.length > 0);
if (segments.length >= 3) {
return true;
}
if (segments.length === 2 && segments[1].includes("_")) {
return true;
}
return false;
}
export function isPaseoToolName(name: string): boolean {
const normalized = normalizeToolName(name);
if (isSpeakToolName(normalized)) {
return false;
}
if (normalized.includes("__")) {
const segments = normalized.split("__").filter((s) => s.length > 0);
return (
segments.length >= 3 &&
segments[0] === "mcp" &&
(segments[1] === "paseo" || segments[1].startsWith("paseo_"))
);
}
if (normalized.includes(".")) {
const firstSegment = normalized.split(".")[0];
return firstSegment === "paseo" || firstSegment.startsWith("paseo_");
}
return false;
}
export function getPaseoToolLeafName(name: string): string | null {
const normalized = normalizeToolName(name);
if (normalized.includes("__")) {
const segments = normalized.split("__").filter((s) => s.length > 0);
if (
segments.length >= 3 &&
segments[0] === "mcp" &&
(segments[1] === "paseo" || segments[1].startsWith("paseo_"))
) {
return segments.slice(2).join("__");
}
return null;
}
if (normalized.includes(".")) {
const firstSegment = normalized.split(".")[0];
if (firstSegment === "paseo" || firstSegment.startsWith("paseo_")) {
return normalized.split(".").slice(1).join(".");
}
return null;
}
return null;
}
export function isLikelyExternalToolName(name: string): boolean {
const normalized = normalizeToolName(name);
if (!normalized) {
return false;
}
if (isSpeakToolName(normalized)) {
return true;
}
return isLikelyNamespacedToolName(normalized);
}