Skip to content

Commit 77d5d90

Browse files
committed
chore: tests and coverage
1 parent 49b4c74 commit 77d5d90

File tree

4 files changed

+34
-29
lines changed

4 files changed

+34
-29
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import type {
2+
BedrockAgentFunctionEvent,
3+
ResponseState,
4+
} from '../types/bedrock-agent.js';
15
import type { BedrockAgentFunctionResolver } from './BedrockAgentFunctionResolver.js';
2-
36
/**
47
* Class representing a response from a Bedrock agent function.
58
*
@@ -23,35 +26,35 @@ class BedrockFunctionResponse {
2326
* - `FAILURE`: The agent throws a `DependencyFailedException` for the current session.
2427
* - `REPROMPT`: The agent passes a response string to the model to reprompt it.
2528
*/
26-
readonly responseState?: 'FAILURE' | 'REPROMPT';
29+
readonly responseState?: ResponseState;
2730
/**
2831
* Optional field to store session attributes and their values.
2932
* @see {@link https://docs.aws.amazon.com/bedrock/latest/userguide/agents-session-state.html#session-state-attributes | Bedrock Agent Session State Attributes} for more details.
3033
*/
31-
readonly sessionAttributes: Record<string, string>;
34+
readonly sessionAttributes: BedrockAgentFunctionEvent['sessionAttributes'];
3235
/**
3336
* Optional field to instruct the agent to prompt attributes and their values.
3437
* @see {@link https://docs.aws.amazon.com/bedrock/latest/userguide/agents-session-state.html#session-state-attributes | Bedrock Agent Session State Attributes} for more details.
3538
*/
36-
readonly promptSessionAttributes: Record<string, string>;
39+
readonly promptSessionAttributes: BedrockAgentFunctionEvent['promptSessionAttributes'];
3740
/**
3841
* Optional field to configure knowledge bases for the agent.
3942
* @see {@link https://docs.aws.amazon.com/bedrock/latest/userguide/agents-session-state.html#session-state-kb | Bedrock Agent Knowledge Bases} for more details.
4043
*/
41-
readonly knowledgeBasesConfiguration?: Record<string, unknown>;
44+
readonly knowledgeBasesConfiguration?: BedrockAgentFunctionEvent['knowledgeBasesConfiguration'];
4245

4346
constructor({
4447
body,
4548
responseState = undefined,
4649
sessionAttributes = {},
4750
promptSessionAttributes = {},
48-
knowledgeBasesConfiguration = {},
51+
knowledgeBasesConfiguration = undefined,
4952
}: {
5053
body: string;
51-
responseState?: 'FAILURE' | 'REPROMPT';
52-
sessionAttributes?: Record<string, string>;
53-
promptSessionAttributes?: Record<string, string>;
54-
knowledgeBasesConfiguration?: Record<string, unknown>;
54+
responseState?: ResponseState;
55+
sessionAttributes?: BedrockAgentFunctionEvent['sessionAttributes'];
56+
promptSessionAttributes?: BedrockAgentFunctionEvent['promptSessionAttributes'];
57+
knowledgeBasesConfiguration?: BedrockAgentFunctionEvent['knowledgeBasesConfiguration'];
5558
}) {
5659
this.body = body;
5760
this.responseState = responseState;

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ type BedrockAgentFunctionEvent = {
114114
parameters?: Array<Parameter>;
115115
inputText: string;
116116
sessionId: string;
117-
sessionAttributes: Record<string, string>;
118-
promptSessionAttributes: Record<string, string>;
119-
knowledgeBasesConfiguration?: Record<string, unknown>;
117+
sessionAttributes: Record<string, JSONValue>;
118+
promptSessionAttributes: Record<string, JSONValue>;
119+
knowledgeBasesConfiguration?: Record<string, JSONValue>;
120120
};
121121

122122
/**
@@ -143,8 +143,9 @@ type BedrockAgentFunctionResponse = {
143143
};
144144
};
145145
};
146-
sessionAttributes?: Record<string, string>;
147-
promptSessionAttributes?: Record<string, string>;
146+
sessionAttributes?: BedrockAgentFunctionEvent['sessionAttributes'];
147+
promptSessionAttributes?: BedrockAgentFunctionEvent['promptSessionAttributes'];
148+
knowledgeBasesConfiguration?: BedrockAgentFunctionEvent['knowledgeBasesConfiguration'];
148149
};
149150

150151
/**
@@ -169,4 +170,5 @@ export type {
169170
BedrockAgentFunctionEvent,
170171
BedrockAgentFunctionResponse,
171172
ResolverOptions,
173+
ResponseState,
172174
};

packages/event-handler/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type {
1414
BedrockAgentFunctionResponse,
1515
ResolverOptions,
1616
Parameter,
17+
ResponseState,
1718
} from './bedrock-agent.js';
1819

1920
export type {

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import context from '@aws-lambda-powertools/testing-utils/context';
2-
import type { Context } from 'aws-lambda';
32
import { beforeEach, describe, expect, it, vi } from 'vitest';
43
import { BedrockFunctionResponse } from '../../../src/bedrock-agent/BedrockFunctionResponse.js';
54
import { BedrockAgentFunctionResolver } from '../../../src/bedrock-agent/index.js';
65
import type {
7-
BedrockAgentFunctionEvent,
86
Configuration,
97
Parameter,
108
ToolFunction,
@@ -575,14 +573,6 @@ describe('Class: BedrockAgentFunctionResolver', () => {
575573
}
576574
);
577575

578-
const customSessionAttrs = {
579-
sessionAttr: '12345',
580-
};
581-
582-
const customPromptAttrs = {
583-
promptAttr: 'promptAttr',
584-
};
585-
586576
const customEvent = {
587577
...createEvent('greeting', [
588578
{
@@ -592,8 +582,16 @@ describe('Class: BedrockAgentFunctionResolver', () => {
592582
},
593583
]),
594584
actionGroup: 'actionGroup',
595-
sessionAttributes: customSessionAttrs,
596-
promptSessionAttributes: customPromptAttrs,
585+
sessionAttributes: {
586+
sessionAttr: '12345',
587+
},
588+
promptSessionAttributes: {
589+
promptAttr: 'promptAttr',
590+
},
591+
knowledgeBasesConfiguration: {
592+
knowledgeBase1: { enabled: true },
593+
knowledgeBase2: { enabled: false },
594+
},
597595
};
598596

599597
// Act
@@ -613,8 +611,9 @@ describe('Class: BedrockAgentFunctionResolver', () => {
613611
},
614612
},
615613
},
616-
sessionAttributes: customSessionAttrs,
617-
promptSessionAttributes: customPromptAttrs,
614+
sessionAttributes: customEvent.sessionAttributes,
615+
promptSessionAttributes: customEvent.promptSessionAttributes,
616+
knowledgeBasesConfiguration: customEvent.knowledgeBasesConfiguration,
618617
});
619618
});
620619
});

0 commit comments

Comments
 (0)