Skip to content

Commit 4781704

Browse files
authored
Add information about event version to conversation components (#2089)
1 parent f5d0ab4 commit 4781704

File tree

8 files changed

+57
-7
lines changed

8 files changed

+57
-7
lines changed

.changeset/sixty-cycles-happen.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@aws-amplify/ai-constructs': minor
3+
'@aws-amplify/backend-ai': minor
4+
---
5+
6+
Add information about event version to conversation components

packages/ai-constructs/API.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { ResourceProvider } from '@aws-amplify/plugin-types';
1717
declare namespace __export__conversation {
1818
export {
1919
ConversationHandlerFunction,
20-
ConversationHandlerFunctionProps
20+
ConversationHandlerFunctionProps,
21+
ConversationTurnEventVersion
2122
}
2223
}
2324
export { __export__conversation }
@@ -43,6 +44,8 @@ export { __export__conversation__runtime }
4344
class ConversationHandlerFunction extends Construct implements ResourceProvider<FunctionResources> {
4445
constructor(scope: Construct, id: string, props: ConversationHandlerFunctionProps);
4546
// (undocumented)
47+
static readonly eventVersion: ConversationTurnEventVersion;
48+
// (undocumented)
4649
resources: FunctionResources;
4750
}
4851

@@ -114,6 +117,9 @@ type ConversationTurnEvent = {
114117
};
115118
};
116119

120+
// @public (undocumented)
121+
type ConversationTurnEventVersion = `1.${number}`;
122+
117123
// @public
118124
const createExecutableTool: <TJSONSchema extends JSONSchema = JSONSchema, TToolInput = FromJSONSchema<TJSONSchema>>(name: string, description: string, inputSchema: ToolInputSchema<TJSONSchema>, handler: (input: TToolInput) => Promise<bedrock.ToolResultContentBlock>) => ExecutableTool<TJSONSchema, TToolInput>;
119125

packages/ai-constructs/src/conversation/conversation_handler_construct.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export type ConversationHandlerFunctionProps = {
4040
outputStorageStrategy?: BackendOutputStorageStrategy<AIConversationOutput>;
4141
};
4242

43+
// Event is a protocol between AppSync and Lambda handler. Therefore, X.Y subset of semver is enough.
44+
// Typing this as 1.X so that major version changes are caught by compiler if consumer of this construct inspects
45+
// event version.
46+
export type ConversationTurnEventVersion = `1.${number}`;
47+
4348
/**
4449
* Conversation Handler Function CDK construct.
4550
* This construct deploys resources that integrate conversation routes
@@ -54,6 +59,7 @@ export class ConversationHandlerFunction
5459
extends Construct
5560
implements ResourceProvider<FunctionResources>
5661
{
62+
static readonly eventVersion: ConversationTurnEventVersion = '1.0';
5763
resources: FunctionResources;
5864

5965
/**
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import {
22
ConversationHandlerFunction,
33
ConversationHandlerFunctionProps,
4+
ConversationTurnEventVersion,
45
} from './conversation_handler_construct.js';
56

6-
export { ConversationHandlerFunction, ConversationHandlerFunctionProps };
7+
export {
8+
ConversationHandlerFunction,
9+
ConversationHandlerFunctionProps,
10+
ConversationTurnEventVersion,
11+
};

packages/backend-ai/API.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
```ts
66

77
import { ConstructFactory } from '@aws-amplify/plugin-types';
8+
import { ConversationTurnEventVersion } from '@aws-amplify/ai-constructs/conversation';
89
import { FunctionResources } from '@aws-amplify/plugin-types';
910
import { ResourceProvider } from '@aws-amplify/plugin-types';
1011
import * as runtime from '@aws-amplify/ai-constructs/conversation/runtime';
1112

1213
declare namespace __export__conversation {
1314
export {
15+
ConversationHandlerFunctionFactory,
1416
DefineConversationHandlerFunctionProps,
1517
defineConversationHandlerFunction
1618
}
@@ -28,14 +30,19 @@ declare namespace __export__conversation__runtime {
2830
}
2931
export { __export__conversation__runtime }
3032

33+
// @public (undocumented)
34+
type ConversationHandlerFunctionFactory = ConstructFactory<ResourceProvider<FunctionResources>> & {
35+
readonly eventVersion: ConversationTurnEventVersion;
36+
};
37+
3138
// @public (undocumented)
3239
type ConversationTurnEvent = runtime.ConversationTurnEvent;
3340

3441
// @public (undocumented)
3542
const createExecutableTool: <TJSONSchema extends runtime.JSONSchema = runtime.JSONSchema, TToolInput = runtime.FromJSONSchema<TJSONSchema>>(name: string, description: string, inputSchema: runtime.ToolInputSchema<TJSONSchema>, handler: (input: TToolInput) => Promise<ToolResultContentBlock>) => ExecutableTool<TJSONSchema, TToolInput>;
3643

3744
// @public
38-
const defineConversationHandlerFunction: (props: DefineConversationHandlerFunctionProps) => ConstructFactory<ResourceProvider<FunctionResources>>;
45+
const defineConversationHandlerFunction: (props: DefineConversationHandlerFunctionProps) => ConversationHandlerFunctionFactory;
3946

4047
// @public (undocumented)
4148
type DefineConversationHandlerFunctionProps = {

packages/backend-ai/src/conversation/factory.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { defaultEntryHandler } from './test-assets/with-default-entry/resource.j
1515
import { customEntryHandler } from './test-assets/with-custom-entry/resource.js';
1616
import { Template } from 'aws-cdk-lib/assertions';
1717
import { defineConversationHandlerFunction } from './factory.js';
18+
import { ConversationHandlerFunction } from '@aws-amplify/ai-constructs/conversation';
1819

1920
const createStackAndSetContext = (): Stack => {
2021
const app = new App();
@@ -57,6 +58,14 @@ void describe('ConversationHandlerFactory', () => {
5758
assert.strictEqual(instance1, instance2);
5859
});
5960

61+
void it('has event version corresponding to construct', () => {
62+
const factory = defaultEntryHandler;
63+
assert.strictEqual(
64+
factory.eventVersion,
65+
ConversationHandlerFunction.eventVersion
66+
);
67+
});
68+
6069
void it('resolves default entry when not specified', () => {
6170
const factory = defaultEntryHandler;
6271
const lambda = factory.getInstance(getInstanceProps);

packages/backend-ai/src/conversation/factory.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import {
1212
ConversationHandlerFunction,
1313
ConversationHandlerFunctionProps,
14+
ConversationTurnEventVersion,
1415
} from '@aws-amplify/ai-constructs/conversation';
1516
import path from 'path';
1617
import { CallerDirectoryExtractor } from '@aws-amplify/platform-core';
@@ -51,9 +52,17 @@ class ConversationHandlerFunctionGenerator
5152
};
5253
}
5354

54-
class ConversationHandlerFunctionFactory
55-
implements ConstructFactory<ConversationHandlerFunction>
55+
export type ConversationHandlerFunctionFactory = ConstructFactory<
56+
ResourceProvider<FunctionResources>
57+
> & {
58+
readonly eventVersion: ConversationTurnEventVersion;
59+
};
60+
61+
class DefaultConversationHandlerFunctionFactory
62+
implements ConversationHandlerFunctionFactory
5663
{
64+
readonly eventVersion: ConversationTurnEventVersion =
65+
ConversationHandlerFunction.eventVersion;
5766
private generator: ConstructContainerEntryGenerator;
5867

5968
constructor(
@@ -121,6 +130,6 @@ export type DefineConversationHandlerFunctionProps = {
121130
*/
122131
export const defineConversationHandlerFunction = (
123132
props: DefineConversationHandlerFunctionProps
124-
): ConstructFactory<ResourceProvider<FunctionResources>> =>
133+
): ConversationHandlerFunctionFactory =>
125134
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
126-
new ConversationHandlerFunctionFactory(props, new Error().stack);
135+
new DefaultConversationHandlerFunctionFactory(props, new Error().stack);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {
2+
ConversationHandlerFunctionFactory,
23
DefineConversationHandlerFunctionProps,
34
defineConversationHandlerFunction,
45
} from './factory.js';
56

67
export {
8+
ConversationHandlerFunctionFactory,
79
DefineConversationHandlerFunctionProps,
810
defineConversationHandlerFunction,
911
};

0 commit comments

Comments
 (0)