@access-mcp/shared 0.6.0 → 0.7.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/utils.d.ts +40 -0
- package/dist/utils.js +59 -0
- package/package.json +1 -1
package/dist/utils.d.ts
CHANGED
|
@@ -72,3 +72,43 @@ export declare const CommonNextSteps: {
|
|
|
72
72
|
description: string;
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Resource ID Resolution Utilities
|
|
77
|
+
*
|
|
78
|
+
* These utilities help resolve human-readable resource names (e.g., "Anvil", "Delta")
|
|
79
|
+
* to full resource IDs (e.g., "anvil.purdue.access-ci.org").
|
|
80
|
+
*/
|
|
81
|
+
export interface ResourceMatch {
|
|
82
|
+
id: string;
|
|
83
|
+
name: string;
|
|
84
|
+
}
|
|
85
|
+
export type ResolveResult = {
|
|
86
|
+
success: true;
|
|
87
|
+
id: string;
|
|
88
|
+
} | {
|
|
89
|
+
success: false;
|
|
90
|
+
error: string;
|
|
91
|
+
suggestion?: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Resolve a human-readable name to a resource ID.
|
|
95
|
+
*
|
|
96
|
+
* @param input - The input string (name or ID)
|
|
97
|
+
* @param searchFn - A function that searches for resources by name and returns matches
|
|
98
|
+
* @returns ResolveResult with either the resolved ID or an error message
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* const result = await resolveResourceId("Anvil", async (query) => {
|
|
103
|
+
* const resources = await searchResources({ query });
|
|
104
|
+
* return resources.map(r => ({ id: r.id, name: r.name }));
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* if (result.success) {
|
|
108
|
+
* console.log(result.id); // "anvil.purdue.access-ci.org"
|
|
109
|
+
* } else {
|
|
110
|
+
* console.log(result.error); // "Multiple resources match..."
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function resolveResourceId(input: string, searchFn: (query: string) => Promise<ResourceMatch[]>): Promise<ResolveResult>;
|
package/dist/utils.js
CHANGED
|
@@ -82,3 +82,62 @@ export const CommonNextSteps = {
|
|
|
82
82
|
description: `Try these refinements: ${suggestions.join(", ")}`,
|
|
83
83
|
}),
|
|
84
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* Resolve a human-readable name to a resource ID.
|
|
87
|
+
*
|
|
88
|
+
* @param input - The input string (name or ID)
|
|
89
|
+
* @param searchFn - A function that searches for resources by name and returns matches
|
|
90
|
+
* @returns ResolveResult with either the resolved ID or an error message
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const result = await resolveResourceId("Anvil", async (query) => {
|
|
95
|
+
* const resources = await searchResources({ query });
|
|
96
|
+
* return resources.map(r => ({ id: r.id, name: r.name }));
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* if (result.success) {
|
|
100
|
+
* console.log(result.id); // "anvil.purdue.access-ci.org"
|
|
101
|
+
* } else {
|
|
102
|
+
* console.log(result.error); // "Multiple resources match..."
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export async function resolveResourceId(input, searchFn) {
|
|
107
|
+
// If it already looks like a full resource ID (contains dots), return as-is
|
|
108
|
+
if (input.includes(".")) {
|
|
109
|
+
return { success: true, id: input };
|
|
110
|
+
}
|
|
111
|
+
// Search for the resource by name
|
|
112
|
+
const items = await searchFn(input);
|
|
113
|
+
if (items.length === 0) {
|
|
114
|
+
return {
|
|
115
|
+
success: false,
|
|
116
|
+
error: `No resource found matching '${input}'`,
|
|
117
|
+
suggestion: "Use the search tool to find valid resource names.",
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// Find exact name match first (case-insensitive)
|
|
121
|
+
const inputLower = input.toLowerCase();
|
|
122
|
+
const exactMatch = items.find((item) => item.name?.toLowerCase() === inputLower);
|
|
123
|
+
if (exactMatch && exactMatch.id) {
|
|
124
|
+
return { success: true, id: exactMatch.id };
|
|
125
|
+
}
|
|
126
|
+
// Multiple partial matches - ask user to be more specific
|
|
127
|
+
if (items.length > 1) {
|
|
128
|
+
const names = items.map((i) => i.name).join(", ");
|
|
129
|
+
return {
|
|
130
|
+
success: false,
|
|
131
|
+
error: `Multiple resources match '${input}': ${names}`,
|
|
132
|
+
suggestion: "Please specify the exact resource name.",
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// Single partial match - use it
|
|
136
|
+
if (items[0].id) {
|
|
137
|
+
return { success: true, id: items[0].id };
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
success: false,
|
|
141
|
+
error: `Could not resolve resource '${input}'`,
|
|
142
|
+
};
|
|
143
|
+
}
|