Skip to content

Commit 2b312c4

Browse files
committed
Merge branch 'main' into e2e/vigy/clear-env-issue
2 parents 4047803 + faacd1b commit 2b312c4

File tree

125 files changed

+5252
-1129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+5252
-1129
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/ai-constructs': patch
3+
---
4+
5+
Fix case where bedrock content blocks would be populated with 'null' instead of 'undefined.

.changeset/modern-toys-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/backend-deployer': patch
3+
---
4+
5+
detect more generic CFN deployment failure errors

.changeset/seven-rabbits-poke.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslint_dictionary.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"mysql",
104104
"namespace",
105105
"namespaces",
106+
"netstat",
106107
"nodejs",
107108
"nodenext",
108109
"nodir",

.prettierignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Ignore artifacts:
2+
.amplify
23
build
34
coverage
45
bin
@@ -10,6 +11,7 @@ verdaccio-cache
1011
expected-cdk-out
1112
.changeset/pre.json
1213
concurrent_workspace_script_cache.json
14+
packages/integration-tests/src/e2e-tests
1315
scripts/components/api-changes-validator/test-resources/working-directory
1416
/test-projects
15-
testDir
17+
testDir

package-lock.json

Lines changed: 814 additions & 284 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ai-constructs/API.md

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66

77
/// <reference types="node" />
88

9+
import { AIConversationOutput } from '@aws-amplify/backend-output-schemas';
10+
import { BackendOutputStorageStrategy } from '@aws-amplify/plugin-types';
911
import * as bedrock from '@aws-sdk/client-bedrock-runtime';
1012
import { Construct } from 'constructs';
1113
import { FunctionResources } from '@aws-amplify/plugin-types';
14+
import * as jsonSchemaToTypeScript from 'json-schema-to-ts';
1215
import { ResourceProvider } from '@aws-amplify/plugin-types';
13-
import * as smithy from '@smithy/types';
1416

1517
declare namespace __export__conversation {
1618
export {
1719
ConversationHandlerFunction,
18-
ConversationHandlerFunctionProps
20+
ConversationHandlerFunctionProps,
21+
ConversationTurnEventVersion
1922
}
2023
}
2124
export { __export__conversation }
@@ -25,10 +28,12 @@ declare namespace __export__conversation__runtime {
2528
ConversationMessage,
2629
ConversationMessageContentBlock,
2730
ConversationTurnEvent,
31+
createExecutableTool,
2832
ExecutableTool,
33+
FromJSONSchema,
34+
JSONSchema,
2935
handleConversationTurnEvent,
3036
ToolDefinition,
31-
ToolExecutionInput,
3237
ToolInputSchema,
3338
ToolResultContentBlock
3439
}
@@ -39,6 +44,8 @@ export { __export__conversation__runtime }
3944
class ConversationHandlerFunction extends Construct implements ResourceProvider<FunctionResources> {
4045
constructor(scope: Construct, id: string, props: ConversationHandlerFunctionProps);
4146
// (undocumented)
47+
static readonly eventVersion: ConversationTurnEventVersion;
48+
// (undocumented)
4249
resources: FunctionResources;
4350
}
4451

@@ -49,6 +56,7 @@ type ConversationHandlerFunctionProps = {
4956
modelId: string;
5057
region?: string;
5158
}>;
59+
outputStorageStrategy?: BackendOutputStorageStrategy<AIConversationOutput>;
5260
};
5361

5462
// @public (undocumented)
@@ -64,6 +72,12 @@ type ConversationMessageContentBlock = bedrock.ContentBlock | {
6472
bytes: string;
6573
};
6674
};
75+
text?: never;
76+
document?: never;
77+
toolUse?: never;
78+
toolResult?: never;
79+
guardContent?: never;
80+
$unknown?: never;
6781
};
6882

6983
// @public (undocumented)
@@ -87,11 +101,16 @@ type ConversationTurnEvent = {
87101
};
88102
};
89103
request: {
90-
headers: {
91-
authorization: string;
92-
};
104+
headers: Record<string, string>;
105+
};
106+
messages?: Array<ConversationMessage>;
107+
messageHistoryQuery: {
108+
getQueryName: string;
109+
getQueryInputTypeName: string;
110+
listQueryName: string;
111+
listQueryInputTypeName: string;
112+
listQueryLimit?: number;
93113
};
94-
messages: Array<ConversationMessage>;
95114
toolsConfiguration?: {
96115
dataTools?: Array<ToolDefinition & {
97116
graphqlRequestInputDescriptor: {
@@ -105,27 +124,38 @@ type ConversationTurnEvent = {
105124
};
106125

107126
// @public (undocumented)
108-
type ExecutableTool = ToolDefinition & {
109-
execute: (input: ToolExecutionInput | undefined) => Promise<ToolResultContentBlock>;
127+
type ConversationTurnEventVersion = `1.${number}`;
128+
129+
// @public
130+
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>;
131+
132+
// @public (undocumented)
133+
type ExecutableTool<TJSONSchema extends JSONSchema = JSONSchema, TToolInput = FromJSONSchema<TJSONSchema>> = ToolDefinition<TJSONSchema> & {
134+
execute: (input: TToolInput) => Promise<ToolResultContentBlock>;
110135
};
111136

137+
// @public (undocumented)
138+
type FromJSONSchema<TJSONSchema extends JSONSchema> = jsonSchemaToTypeScript.FromSchema<TJSONSchema>;
139+
112140
// @public
113141
const handleConversationTurnEvent: (event: ConversationTurnEvent, props?: {
114-
tools?: Array<ExecutableTool>;
142+
tools?: Array<ExecutableTool<JSONSchema, any>>;
115143
}) => Promise<void>;
116144

117145
// @public (undocumented)
118-
type ToolDefinition = {
146+
type JSONSchema = jsonSchemaToTypeScript.JSONSchema;
147+
148+
// @public (undocumented)
149+
type ToolDefinition<TJSONSchema extends JSONSchema = JSONSchema> = {
119150
name: string;
120151
description: string;
121-
inputSchema: ToolInputSchema;
152+
inputSchema: ToolInputSchema<TJSONSchema>;
122153
};
123154

124155
// @public (undocumented)
125-
type ToolExecutionInput = smithy.DocumentType;
126-
127-
// @public (undocumented)
128-
type ToolInputSchema = bedrock.ToolInputSchema;
156+
type ToolInputSchema<TJSONSchema extends JSONSchema> = {
157+
json: TJSONSchema;
158+
};
129159

130160
// @public (undocumented)
131161
type ToolResultContentBlock = bedrock.ToolResultContentBlock;

packages/ai-constructs/CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
# @aws-amplify/ai-constructs
22

3+
## 0.4.0
4+
5+
### Minor Changes
6+
7+
- 4781704: Add information about event version to conversation components
8+
- 3a29d43: Pass user agent in conversation handler lambda
9+
10+
### Patch Changes
11+
12+
- 6e4a62f: Fix multi tool usage in single turn.
13+
14+
## 0.3.0
15+
16+
### Minor Changes
17+
18+
- 300a72d: Infer executable tool input type from input schema
19+
- 0a5e51c: Stream conversation logs in sandbox
20+
21+
### Patch Changes
22+
23+
- Updated dependencies [0a5e51c]
24+
- @aws-amplify/backend-output-schemas@1.3.0
25+
26+
## 0.2.0
27+
28+
### Minor Changes
29+
30+
- d0a90b1: Use message history instead of event payload for conversational route
31+
332
## 0.1.4
433

534
### Patch Changes

packages/ai-constructs/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aws-amplify/ai-constructs",
3-
"version": "0.1.4",
3+
"version": "0.4.0",
44
"type": "commonjs",
55
"publishConfig": {
66
"access": "public"
@@ -26,9 +26,16 @@
2626
},
2727
"license": "Apache-2.0",
2828
"dependencies": {
29+
"@aws-amplify/backend-output-schemas": "^1.3.0",
30+
"@aws-amplify/platform-core": "^1.1.0",
2931
"@aws-amplify/plugin-types": "^1.0.1",
3032
"@aws-sdk/client-bedrock-runtime": "^3.622.0",
31-
"@smithy/types": "^3.3.0"
33+
"@smithy/types": "^3.3.0",
34+
"json-schema-to-ts": "^3.1.1"
35+
},
36+
"devDependencies": {
37+
"@aws-amplify/backend-output-storage": "^1.1.2",
38+
"typescript": "^5.0.0"
3239
},
3340
"peerDependencies": {
3441
"aws-cdk-lib": "^2.152.0",

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { App, Stack } from 'aws-cdk-lib';
44
import { ConversationHandlerFunction } from './conversation_handler_construct';
55
import { Template } from 'aws-cdk-lib/assertions';
66
import path from 'path';
7+
import { StackMetadataBackendOutputStorageStrategy } from '@aws-amplify/backend-output-storage';
78

89
void describe('Conversation Handler Function construct', () => {
910
void it('creates handler with log group with JWT token redacting policy', () => {
@@ -140,6 +141,56 @@ void describe('Conversation Handler Function construct', () => {
140141
});
141142
});
142143

144+
void it('does not store output if output strategy is absent', () => {
145+
const app = new App();
146+
const stack = new Stack(app);
147+
new ConversationHandlerFunction(stack, 'conversationHandler', {
148+
models: [
149+
{
150+
modelId: 'testModelId',
151+
},
152+
],
153+
outputStorageStrategy: undefined,
154+
});
155+
const template = Template.fromStack(stack);
156+
const output = template.findOutputs(
157+
'definedConversationHandlers'
158+
).definedConversationHandlers;
159+
assert.ok(!output);
160+
});
161+
162+
void it('stores output if output strategy is present', () => {
163+
const app = new App();
164+
const stack = new Stack(app);
165+
new ConversationHandlerFunction(stack, 'conversationHandler', {
166+
models: [
167+
{
168+
modelId: 'testModelId',
169+
},
170+
],
171+
outputStorageStrategy: new StackMetadataBackendOutputStorageStrategy(
172+
stack
173+
),
174+
});
175+
const template = Template.fromStack(stack);
176+
const outputValue = template.findOutputs('definedConversationHandlers')
177+
.definedConversationHandlers.Value;
178+
assert.deepStrictEqual(outputValue, {
179+
'Fn::Join': [
180+
'',
181+
[
182+
'["',
183+
{
184+
/* eslint-disable spellcheck/spell-checker */
185+
Ref: 'conversationHandlerconversationHandlerFunction45BC2E1F',
186+
/* eslint-enable spellcheck/spell-checker */
187+
},
188+
'"]',
189+
],
190+
],
191+
});
192+
});
193+
143194
void it('throws if entry is not absolute', () => {
144195
const app = new App();
145196
const stack = new Stack(app);

0 commit comments

Comments
 (0)