Skip to content

Commit

Permalink
chore(ai): adding UA string for AIConversation (#5917)
Browse files Browse the repository at this point in the history

Co-authored-by: Jordan Van Ness <jordvn@amazon.com>
  • Loading branch information
dbanksdesign and jordanvn authored Oct 17, 2024
1 parent 6fea94b commit 3655af2
Show file tree
Hide file tree
Showing 24 changed files with 184 additions and 85 deletions.
20 changes: 20 additions & 0 deletions .changeset/rich-bags-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@aws-amplify/ui-angular": patch
"@aws-amplify/ui-react-ai": patch
"@aws-amplify/ui-react-auth": patch
"@aws-amplify/ui-react-core-auth": patch
"@aws-amplify/ui-react-core-notifications": patch
"@aws-amplify/ui-react-core": patch
"@aws-amplify/ui-react-geo": patch
"@aws-amplify/ui-react-liveness": patch
"@aws-amplify/ui-react-native-auth": patch
"@aws-amplify/ui-react-native": patch
"@aws-amplify/ui-react-notifications": patch
"@aws-amplify/ui-react-storage": patch
"@aws-amplify/ui-react": patch
"@aws-amplify/ui": patch
"@aws-amplify/ui-vue": patch
"@aws-amplify/ui-angular": patch
---

chore(ai): adding UA string for AIConversation
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"@types/jest": "^29.5.5",
"@types/react-test-renderer": "^18.0.2",
"@vitejs/plugin-vue": "^2.3.4",
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"esbuild-register": "^3.5.0",
"eslint": "^8.44.0",
"fs-extra": "^11.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/projects/ui-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"peerDependencies": {
"@angular/core": ">= 14.0.0",
"@angular/common": ">= 14.0.0",
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"rxjs": "^6.5.3 || ^7.4.0"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"peerDependencies": {
"@aws-amplify/api-graphql": "^4.3.0",
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { PromptList } from './views/default/PromptList';
import { AutoHidablePromptControl } from './views/Controls';
import { ComponentClassName } from '@aws-amplify/ui';
import { AIConversationProvider } from './AIConversationProvider';
import { useSetUserAgent } from '@aws-amplify/ui-react-core';
import { VERSION } from '../../version';

interface AIConversationBaseProps
extends AIConversationProps,
Expand All @@ -32,6 +34,11 @@ function AIConversationBase({
displayText,
allowAttachments,
}: AIConversationBaseProps): JSX.Element {
useSetUserAgent({
componentName: 'AIConversation',
packageName: 'react-ai',
version: VERSION,
});
const icons = useIcons('aiConversation');
const defaultAvatars: Avatars = {
ai: {
Expand Down
29 changes: 19 additions & 10 deletions packages/react-ai/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type ConversationRoute = V6Client<any>['conversations'][string];
export type Conversation = NonNullable<
Awaited<ReturnType<ConversationRoute['create']>>['data']
>;

export type ConversationMessage = NonNullable<
Awaited<ReturnType<Conversation['sendMessage']>>['data']
>;
Expand All @@ -14,20 +15,28 @@ export type TextContent = NonNullable<ConversationMessageContent['text']>;

export type ImageContent = NonNullable<ConversationMessageContent['image']>;

export type InputContent = Parameters<
Conversation['sendMessage']
>[0]['content'][number];
// Note: the conversation sendMessage function is an overload
// that accepts a string OR an object
export type InputContent = Exclude<
Parameters<Conversation['sendMessage']>[0],
string
>['content'][number];

export type SendMessageContent = Parameters<
Conversation['sendMessage']
>[0]['content'];
export type SendMessageContent = Exclude<
Parameters<Conversation['sendMessage']>[0],
string
>['content'];

export type SendMessageContext = Parameters<
Conversation['sendMessage']
>[0]['aiContext'];
export type SendMessageContext = Exclude<
Parameters<Conversation['sendMessage']>[0],
string
>['aiContext'];

export type ToolConfiguration = NonNullable<
Parameters<Conversation['sendMessage']>[0]['toolConfiguration']
Exclude<
Parameters<Conversation['sendMessage']>[0],
string
>['toolConfiguration']
>;

export interface SendMesageParameters {
Expand Down
1 change: 1 addition & 0 deletions packages/react-ai/src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const VERSION = '0.3.2';
2 changes: 1 addition & 1 deletion packages/react-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"tslib": "^2.5.2"
},
"peerDependencies": {
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"peerDependencies": {
"@aws-amplify/core": "*",
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "^16.14.0 || ^17.0 || ^18.0"
},
"sideEffects": false
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core-notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@aws-amplify/ui-react-core": "3.0.28"
},
"peerDependencies": {
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "^16.14.0 || ^17.0 || ^18.0"
},
"sideEffects": false
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"xstate": "^4.33.6"
},
"peerDependencies": {
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "^16.14.0 || ^17.0 || ^18.0"
},
"sideEffects": false
Expand Down
2 changes: 1 addition & 1 deletion packages/react-geo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"peerDependencies": {
"@aws-amplify/geo": "^3.0.47",
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-liveness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"peerDependencies": {
"@aws-amplify/core": "*",
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"qrcode": "1.5.0"
},
"peerDependencies": {
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "^18",
"react-native": "^0.70 || ^0.71 || ^0.72"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@aws-amplify/ui-react-core-notifications": "2.0.28"
},
"peerDependencies": {
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "*",
"react-native": "^0.70 || ^0.71 || ^0.72 || ^0.73 || ^0.74 || ^0.75",
"react-native-safe-area-context": "^4.2.5"
Expand Down
4 changes: 2 additions & 2 deletions packages/react-notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"tinycolor2": "1.4.2"
},
"peerDependencies": {
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
Expand All @@ -61,7 +61,7 @@
"name": "InAppMessaging",
"path": "dist/esm/index.mjs",
"import": "{ InAppMessagingProvider, InAppMessageDisplay }",
"limit": "22 kB"
"limit": "23 kB"
}
]
}
2 changes: 1 addition & 1 deletion packages/react-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"tslib": "^2.5.2"
},
"peerDependencies": {
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
"peerDependencies": {
"@aws-amplify/core": "*",
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"react": "^16.14.0 || ^17.0 || ^18.0",
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"peerDependencies": {
"@aws-amplify/core": "*",
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"xstate": "^4.33.6"
},
"peerDependenciesMeta": {
Expand Down
15 changes: 15 additions & 0 deletions packages/ui/src/utils/setUserAgent/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,23 @@ import {
InAppMessagingAction,
StorageAction,
Category,
AiAction,
AiUserAgentInput,
} from '@aws-amplify/core/internals/utils';

export const AI_INPUT_BASE: Omit<AiUserAgentInput, 'additionalDetails'> = {
category: Category.AI,
apis: [
AiAction.CreateConversation,
AiAction.DeleteConversation,
AiAction.ListConversations,
AiAction.UpdateConversation,
AiAction.OnMessage,
AiAction.SendMessage,
AiAction.Generation,
],
};

export const ACCOUNT_SETTINGS_INPUT_BASE: Omit<
AuthUserAgentInput,
'additionalDetails'
Expand Down
10 changes: 10 additions & 0 deletions packages/ui/src/utils/setUserAgent/setUserAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { setCustomUserAgent } from '@aws-amplify/core/internals/utils';

import {
ACCOUNT_SETTINGS_INPUT_BASE,
AI_INPUT_BASE,
AUTHENTICATOR_INPUT_BASE,
FILE_UPLOADER_BASE_INPUT,
IN_APP_MESSAGING_INPUT_BASE,
Expand All @@ -15,6 +16,7 @@ import { noop } from '../utils';
export type PackageName =
| 'angular'
| 'react'
| 'react-ai'
| 'react-auth'
| 'react-geo'
| 'react-liveness'
Expand All @@ -25,6 +27,7 @@ export type PackageName =
| 'vue';

export type ComponentName =
| 'AIConversation'
| 'Authenticator'
| 'ChangePassword'
| 'DeleteUser'
Expand Down Expand Up @@ -63,6 +66,13 @@ export const setUserAgent = ({
const packageData: [string, string] = [`ui-${packageName}`, version];

switch (componentName) {
case 'AIConversation': {
setCustomUserAgent({
...AI_INPUT_BASE,
additionalDetails: [[componentName], packageData],
});
break;
}
case 'Authenticator': {
setCustomUserAgent({
...AUTHENTICATOR_INPUT_BASE,
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
"peerDependencies": {
"@aws-amplify/core": "*",
"aws-amplify": "^6.6.0",
"aws-amplify": "^6.6.5",
"vue": "^3.0"
}
}
1 change: 1 addition & 0 deletions scripts/generateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const fs = require('fs-extra');
const packages = [
'packages/angular/projects/ui-angular',
'packages/react',
'packages/react-ai',
'packages/react-auth',
'packages/react-geo',
'packages/react-native',
Expand Down
Loading

0 comments on commit 3655af2

Please sign in to comment.