Skip to content

Commit 310802d

Browse files
committed
chore: remove decorator usage
1 parent d7c233b commit 310802d

File tree

2 files changed

+4
-93
lines changed

2 files changed

+4
-93
lines changed

packages/event-handler/src/bedrock-agent/BedrockAgentFunctionResolver.ts

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,6 @@ export class BedrockAgentFunctionResolver {
110110
* app.resolve(event, context);
111111
* ```
112112
*
113-
* The method also works as a class method decorator:
114-
*
115-
* @example
116-
* ```ts
117-
* import {
118-
* BedrockAgentFunctionResolver
119-
* } from '@aws-lambda-powertools/event-handler/bedrock-agent';
120-
*
121-
* const app = new BedrockAgentFunctionResolver();
122-
*
123-
* class Lambda {
124-
* @app.tool({ name: 'greeting', description: 'Greets a person by name' })
125-
* async greeting(params) {
126-
* const { name } = params;
127-
* return `Hello, ${name}!`;
128-
* }
129-
*
130-
* async handler(event, context) {
131-
* return app.resolve(event, context);
132-
* }
133-
* }
134-
*
135-
* const lambda = new Lambda();
136-
* export const handler = lambda.handler.bind(lambda);
137-
* ```
138-
*
139113
* When defining a tool, you can also access the original `event` and `context` objects from the Bedrock Agent function invocation.
140114
* This is useful if you need to access the session attributes or other context-specific information.
141115
*
@@ -172,26 +146,9 @@ export class BedrockAgentFunctionResolver {
172146
public tool<TParams extends Record<string, ParameterValue>>(
173147
fn: ToolFunction<TParams>,
174148
config: Configuration
175-
): undefined;
176-
public tool<TParams extends Record<string, ParameterValue>>(
177-
config: Configuration
178-
): MethodDecorator;
179-
public tool<TParams extends Record<string, ParameterValue>>(
180-
fnOrConfig: ToolFunction<TParams> | Configuration,
181-
config?: Configuration
182-
): MethodDecorator | undefined {
183-
// When used as a method (not a decorator)
184-
if (typeof fnOrConfig === 'function') {
185-
this.#registerTool(fnOrConfig, config as Configuration);
186-
return;
187-
}
188-
189-
// When used as a decorator
190-
return (_target, _propertyKey, descriptor: PropertyDescriptor) => {
191-
const toolFn = descriptor.value as ToolFunction;
192-
this.#registerTool(toolFn, fnOrConfig);
193-
return descriptor;
194-
};
149+
): undefined {
150+
this.#registerTool(fn, config);
151+
return;
195152
}
196153

197154
#registerTool<TParams extends Record<string, ParameterValue>>(
@@ -267,7 +224,7 @@ export class BedrockAgentFunctionResolver {
267224
try {
268225
const response = await tool.handler(toolParams, { event, context });
269226
if (response instanceof BedrockFunctionResponse) {
270-
const res = response.build({
227+
return response.build({
271228
actionGroup,
272229
func: toolName,
273230
});

packages/event-handler/tests/unit/bedrock-agent/BedrockAgentFunctionResolver.test.ts

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -243,52 +243,6 @@ describe('Class: BedrockAgentFunctionResolver', () => {
243243
);
244244
});
245245

246-
it('can be invoked using the decorator pattern', async () => {
247-
// Prepare
248-
const app = new BedrockAgentFunctionResolver();
249-
250-
class Lambda {
251-
@app.tool({ name: 'hello', description: 'Says hello' })
252-
async helloWorld() {
253-
return 'Hello, world!';
254-
}
255-
256-
@app.tool({ name: 'add', description: 'Adds two numbers' })
257-
async add(params: { a: number; b: number }) {
258-
const { a, b } = params;
259-
return a + b;
260-
}
261-
262-
public async handler(event: BedrockAgentFunctionEvent, context: Context) {
263-
return app.resolve(event, context);
264-
}
265-
}
266-
267-
const lambda = new Lambda();
268-
269-
const addEvent = createEvent('add', [
270-
{
271-
name: 'a',
272-
type: 'number',
273-
value: '1',
274-
},
275-
{
276-
name: 'b',
277-
type: 'number',
278-
value: '2',
279-
},
280-
]);
281-
282-
// Act
283-
const actual = await lambda.handler(addEvent, context);
284-
285-
// Assess
286-
expect(actual.response.function).toEqual('add');
287-
expect(actual.response.functionResponse.responseBody.TEXT.body).toEqual(
288-
'3'
289-
);
290-
});
291-
292246
it.each([
293247
{
294248
toolFunction: async () => ({

0 commit comments

Comments
 (0)