Skip to content

Commit

Permalink
feat: Add backend-function data config with runtime support
Browse files Browse the repository at this point in the history
  • Loading branch information
stocaaro committed Nov 15, 2024
1 parent f83d6d5 commit d1dec7f
Show file tree
Hide file tree
Showing 25 changed files with 480 additions and 154 deletions.
6 changes: 6 additions & 0 deletions .changeset/brave-cheetahs-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@aws-amplify/backend': patch
'@aws-amplify/backend-function': patch
---

feat: Add backend-function runtime behavior to get the data config
56 changes: 29 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions packages/ai-constructs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# @aws-amplify/ai-constructs

## 1.0.0

### Major Changes

- bbd6add: GA release of backend AI features

### Patch Changes

- fd8759d: Fix a case when Bedrock throws validation error if tool input is not persisted in history

## 0.8.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ai-constructs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-amplify/ai-constructs",
"version": "1.0.0",
"version": "0.8.2",
"type": "commonjs",
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,8 +901,8 @@ void describe('Bedrock converse adapter', () => {
assert.strictEqual(responseText, 'finalResponse');

assert.strictEqual(toolExecuteMock.mock.calls.length, 2);
assert.deepStrictEqual(toolExecuteMock.mock.calls[0].arguments[0], {});
assert.deepStrictEqual(toolExecuteMock.mock.calls[1].arguments[0], {});
assert.strictEqual(toolExecuteMock.mock.calls[0].arguments[0], undefined);
assert.strictEqual(toolExecuteMock.mock.calls[1].arguments[0], undefined);
});

void it('throws if tool is duplicated', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@ export class BedrockConverseAdapter {
if (toolUseBlock) {
if (toolUseInput) {
toolUseBlock.toolUse.input = JSON.parse(toolUseInput);
} else {
// Bedrock API requires tool input to be non-null in message history.
// Therefore, falling back to empty object.
toolUseBlock.toolUse.input = {};
}
accumulatedAssistantMessage.content?.push(toolUseBlock);
if (
Expand Down
12 changes: 0 additions & 12 deletions packages/backend-ai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
# @aws-amplify/backend-ai

## 1.0.0

### Major Changes

- bbd6add: GA release of backend AI features

### Patch Changes

- Updated dependencies [fd8759d]
- Updated dependencies [bbd6add]
- @aws-amplify/ai-constructs@1.0.0

## 0.3.5

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/backend-ai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-amplify/backend-ai",
"version": "1.0.0",
"version": "0.3.5",
"type": "module",
"publishConfig": {
"access": "public"
Expand All @@ -22,7 +22,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"@aws-amplify/ai-constructs": "^1.0.0",
"@aws-amplify/ai-constructs": "^0.8.0",
"@aws-amplify/backend-output-schemas": "^1.4.0",
"@aws-amplify/backend-output-storage": "^1.1.3",
"@aws-amplify/data-schema-types": "^1.2.0",
Expand Down
77 changes: 77 additions & 0 deletions packages/backend-function/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,23 @@ import { ConstructFactory } from '@aws-amplify/plugin-types';
import { FunctionResources } from '@aws-amplify/plugin-types';
import { ResourceAccessAcceptorFactory } from '@aws-amplify/plugin-types';
import { ResourceProvider } from '@aws-amplify/plugin-types';
import { S3Client } from '@aws-sdk/client-s3';
import { StackProvider } from '@aws-amplify/plugin-types';

declare namespace __export__runtime {
export {
getAmplifyDataClientConfig,
DataClientConfig,
DataClientEnv,
DataClientError,
DataClientReturn,
InvalidConfig,
LibraryOptions,
ResourceConfig
}
}
export { __export__runtime }

// @public (undocumented)
export type AddEnvironmentFactory = {
addEnvironment: (key: string, value: string | BackendSecret) => void;
Expand All @@ -19,6 +34,32 @@ export type AddEnvironmentFactory = {
// @public (undocumented)
export type CronSchedule = `${string} ${string} ${string} ${string} ${string}` | `${string} ${string} ${string} ${string} ${string} ${string}`;

// @public (undocumented)
type DataClientConfig = {
resourceConfig: ResourceConfig;
libraryOptions: LibraryOptions;
};

// @public (undocumented)
type DataClientEnv = {
AMPLIFY_DATA_GRAPHQL_ENDPOINT: string;
AMPLIFY_DATA_MODEL_INTROSPECTION_SCHEMA_BUCKET_NAME: string;
AMPLIFY_DATA_MODEL_INTROSPECTION_SCHEMA_KEY: string;
AWS_ACCESS_KEY_ID: string;
AWS_SECRET_ACCESS_KEY: string;
AWS_SESSION_TOKEN: string;
AWS_REGION: string;
};

// @public (undocumented)
type DataClientError = {
resourceConfig: InvalidConfig;
libraryOptions: InvalidConfig;
};

// @public (undocumented)
type DataClientReturn<T> = T extends DataClientEnv ? DataClientConfig : DataClientError;

// @public
export const defineFunction: (props?: FunctionProps) => ConstructFactory<ResourceProvider<FunctionResources> & ResourceAccessAcceptorFactory & AddEnvironmentFactory & StackProvider>;

Expand All @@ -43,9 +84,45 @@ export type FunctionProps = {
// @public (undocumented)
export type FunctionSchedule = TimeInterval | CronSchedule;

// @public
const getAmplifyDataClientConfig: <T>(env: T, s3Client?: S3Client) => Promise<DataClientReturn<T>>;

// @public (undocumented)
type InvalidConfig = unknown & {
invalidType: 'This function needs to be granted `authorization((allow) => [allow.resource(fcn)])` on the data schema.';
};

// @public (undocumented)
type LibraryOptions = {
Auth: {
credentialsProvider: {
getCredentialsAndIdentityId: () => Promise<{
credentials: {
accessKeyId: string;
secretAccessKey: string;
sessionToken: string;
};
}>;
clearCredentialsAndIdentityId: () => void;
};
};
};

// @public (undocumented)
export type NodeVersion = 16 | 18 | 20;

// @public (undocumented)
type ResourceConfig = {
API: {
GraphQL: {
endpoint: string;
region: string;
defaultAuthMode: string;
modelIntrospection: any;
};
};
};

// @public (undocumented)
export type TimeInterval = `every ${number}m` | `every ${number}h` | `every day` | `every week` | `every month` | `every year`;

Expand Down
3 changes: 2 additions & 1 deletion packages/backend-function/api-extractor.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "../../api-extractor.base.json"
"extends": "../../api-extractor.base.json",
"mainEntryPointFilePath": "<projectFolder>/lib/index.internal.d.ts"
}
Loading

0 comments on commit d1dec7f

Please sign in to comment.