Skip to content

Commit 590ad5f

Browse files
fix: corrected the prefix issue
1 parent e32ab51 commit 590ad5f

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

packages/core/src/muppet.ts

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type MuppetOptions = {
5050
export class Muppet<E extends Env = BlankEnv> {
5151
name?: string;
5252
version?: string;
53-
prefix = "";
53+
#prefix = "";
5454

5555
#id!: string;
5656
routes: RouterRoute = [];
@@ -67,7 +67,7 @@ export class Muppet<E extends Env = BlankEnv> {
6767
this.version = options.version;
6868

6969
if (options.prefix) {
70-
this.prefix = options.prefix;
70+
this.#prefix = options.prefix;
7171
}
7272
}
7373
}
@@ -100,19 +100,8 @@ export class Muppet<E extends Env = BlankEnv> {
100100
return this;
101101
};
102102

103-
merge(app: Muppet, prefix?: string) {
104-
const _prefix = prefix ?? app.name;
105-
106-
let _routes = app.routes;
107-
108-
if (_prefix && _prefix.length > 0) {
109-
_routes = _routes.map((route) => ({
110-
...route,
111-
name: `${_prefix}${route.name}`,
112-
}));
113-
}
114-
115-
this.routes.push(..._routes);
103+
merge(app: Muppet) {
104+
this.routes.push(...app.routes);
116105
return this;
117106
}
118107

@@ -127,11 +116,11 @@ export class Muppet<E extends Env = BlankEnv> {
127116
...args: (ToolHandler<E, I, O> | ToolMiddlewareHandler<E, I, O>)[]
128117
) {
129118
if (typeof args1 === "object" && !Array.isArray(args1)) {
130-
this.#id = args1.name;
119+
this.#id = `${this.#prefix}${args1.name}`;
131120
this.routes.push({
132121
type: "tool",
133122
...args1,
134-
name: `${this.prefix}${args1.name}`,
123+
name: this.#id,
135124
});
136125
} else {
137126
this.routes.push({
@@ -167,13 +156,13 @@ export class Muppet<E extends Env = BlankEnv> {
167156
...args: (PromptHandler<E, I> | PromptMiddlewareHandler<E, I>)[]
168157
) {
169158
if (typeof args1 === "object" && !Array.isArray(args1)) {
170-
this.#id = args1.name;
159+
this.#id = `${this.#prefix}${args1.name}`;
171160
this.routes.push(
172161
// @ts-expect-error
173162
{
174163
type: "prompt",
175164
...args1,
176-
name: `${this.prefix}${args1.name}`,
165+
name: this.#id,
177166
},
178167
);
179168
} else {
@@ -205,20 +194,20 @@ export class Muppet<E extends Env = BlankEnv> {
205194
>(
206195
args1:
207196
| ResourceOptions<E, I>
208-
| ResourceHandler<E>
209-
| ResourceMiddlewareHandler<E>,
210-
...args: (ResourceHandler<E> | ResourceMiddlewareHandler<E>)[]
197+
| ResourceHandler<E, I>
198+
| ResourceMiddlewareHandler<E, I>,
199+
...args: (ResourceHandler<E, I> | ResourceMiddlewareHandler<E, I>)[]
211200
) {
212201
if (typeof args1 === "object" && !Array.isArray(args1)) {
213-
this.#id = args1.name;
202+
this.#id = `${this.#prefix}${args1.name}`;
214203
const type = "uriTemplate" in args1 ? "resource-template" : "resource";
215204

216205
this.routes.push(
217206
// @ts-expect-error
218207
{
219208
...args1,
220209
type,
221-
name: `${this.prefix}${args1.name}`
210+
name: this.#id,
222211
},
223212
);
224213
} else {
@@ -234,6 +223,7 @@ export class Muppet<E extends Env = BlankEnv> {
234223
this.routes.push({
235224
type: "middleware",
236225
name: this.#id,
226+
// @ts-expect-error
237227
handler,
238228
});
239229
}

0 commit comments

Comments
 (0)