@aws-amplify/data-schema 1.6.3 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/dist/cjs/runtime/internals/ai/createDeleteConversationFunction.js +21 -0
  2. package/dist/cjs/runtime/internals/ai/createDeleteConversationFunction.js.map +1 -0
  3. package/dist/cjs/runtime/internals/ai/createSendMessageFunction.js +3 -1
  4. package/dist/cjs/runtime/internals/ai/createSendMessageFunction.js.map +1 -1
  5. package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js +5 -5
  6. package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js.map +1 -1
  7. package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js +2 -0
  8. package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js.map +1 -1
  9. package/dist/esm/ai/ConversationType.d.ts +11 -2
  10. package/dist/esm/runtime/internals/ai/createDeleteConversationFunction.d.ts +3 -0
  11. package/dist/esm/runtime/internals/ai/createDeleteConversationFunction.mjs +19 -0
  12. package/dist/esm/runtime/internals/ai/createDeleteConversationFunction.mjs.map +1 -0
  13. package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs +3 -1
  14. package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs.map +1 -1
  15. package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.d.ts +5 -5
  16. package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.mjs +5 -5
  17. package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.mjs.map +1 -1
  18. package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs +2 -0
  19. package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs.map +1 -1
  20. package/dist/meta/cjs.tsbuildinfo +1 -1
  21. package/package.json +1 -1
  22. package/src/ai/ConversationType.ts +14 -2
  23. package/src/runtime/internals/ai/createDeleteConversationFunction.ts +54 -0
  24. package/src/runtime/internals/ai/createSendMessageFunction.ts +8 -1
  25. package/src/runtime/internals/ai/getCustomUserAgentDetails.ts +5 -5
  26. package/src/runtime/internals/utils/clientProperties/generateConversationsProperty.ts +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/data-schema",
3
- "version": "1.6.3",
3
+ "version": "1.8.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,6 +29,10 @@ interface ConversationRouteGetInput {
29
29
  id: string;
30
30
  }
31
31
 
32
+ interface ConversationRouteDeleteInput {
33
+ id: string;
34
+ }
35
+
32
36
  interface ConversationRouteListInput {
33
37
  limit?: number;
34
38
  nextToken?: string | null;
@@ -47,6 +51,14 @@ export interface ConversationRoute {
47
51
  * Gets an existing {@link Conversation} based on ID.
48
52
  */
49
53
  get: (input: ConversationRouteGetInput) => SingularReturnValue<Conversation>;
54
+ /**
55
+ * @experimental
56
+ *
57
+ * Deletes an existing {@link Conversation} based on ID.
58
+ */
59
+ delete: (
60
+ input: ConversationRouteDeleteInput,
61
+ ) => SingularReturnValue<Conversation>;
50
62
  /**
51
63
  * @experimental
52
64
  *
@@ -56,7 +68,7 @@ export interface ConversationRoute {
56
68
  }
57
69
 
58
70
  // conversation types
59
- interface ConversationSendMessageInput {
71
+ export interface ConversationSendMessageInput {
60
72
  content: ConversationSendMessageInputContent[];
61
73
  aiContext?: string | Record<string, any>;
62
74
  toolConfiguration?: ToolConfiguration;
@@ -77,7 +89,7 @@ export interface Conversation {
77
89
  * Sends a message to the current conversation.
78
90
  */
79
91
  sendMessage: (
80
- input: ConversationSendMessageInput,
92
+ input: ConversationSendMessageInput | string,
81
93
  ) => SingularReturnValue<ConversationMessage>;
82
94
  /**
83
95
  * @experimental
@@ -0,0 +1,54 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { ConversationRoute } from '../../../ai/ConversationType';
5
+ import type { SingularReturnValue } from '../../../runtime/client';
6
+ import {
7
+ BaseClient,
8
+ ClientInternalsGetter,
9
+ ModelIntrospectionSchema,
10
+ SchemaModel,
11
+ } from '../../bridge-types';
12
+ import { getFactory } from '../operations/get';
13
+ import { convertItemToConversation } from './convertItemToConversation';
14
+ import {
15
+ AiAction,
16
+ getCustomUserAgentDetails,
17
+ } from './getCustomUserAgentDetails';
18
+
19
+ export const createDeleteConversationFunction =
20
+ (
21
+ client: BaseClient,
22
+ modelIntrospection: ModelIntrospectionSchema,
23
+ conversationRouteName: string,
24
+ conversationModel: SchemaModel,
25
+ conversationMessageModel: SchemaModel,
26
+ getInternals: ClientInternalsGetter,
27
+ ): ConversationRoute['delete'] =>
28
+ async ({ id }) => {
29
+ const deleteOperation = getFactory(
30
+ client,
31
+ modelIntrospection,
32
+ conversationModel,
33
+ 'DELETE',
34
+ getInternals,
35
+ false,
36
+ getCustomUserAgentDetails(AiAction.DeleteConversation),
37
+ ) as (
38
+ args?: Record<string, any>,
39
+ ) => SingularReturnValue<Record<string, any>>;
40
+ const { data, errors } = await deleteOperation({ id });
41
+ return {
42
+ data: data
43
+ ? convertItemToConversation(
44
+ client,
45
+ modelIntrospection,
46
+ data?.id,
47
+ conversationRouteName,
48
+ conversationMessageModel,
49
+ getInternals,
50
+ )
51
+ : data,
52
+ errors,
53
+ };
54
+ };
@@ -5,6 +5,7 @@ import { SingularReturnValue } from '../..';
5
5
  import type {
6
6
  Conversation,
7
7
  ConversationMessage,
8
+ ConversationSendMessageInput,
8
9
  } from '../../../ai/ConversationType';
9
10
  import {
10
11
  BaseClient,
@@ -31,13 +32,19 @@ export const createSendMessageFunction =
31
32
  conversationRouteName: string,
32
33
  getInternals: ClientInternalsGetter,
33
34
  ): Conversation['sendMessage'] =>
34
- async ({ aiContext, content, toolConfiguration }) => {
35
+ async (input: ConversationSendMessageInput | string) => {
35
36
  const { conversations } = modelIntrospection;
36
37
 
37
38
  // Safe guard for standalone function. When called as part of client generation, this should never be falsy.
38
39
  if (!conversations) {
39
40
  return {} as SingularReturnValue<ConversationMessage>;
40
41
  }
42
+
43
+ const processedInput: ConversationSendMessageInput =
44
+ typeof input === 'string' ? { content: [{ text: input }] } : input;
45
+
46
+ const { content, aiContext, toolConfiguration } = processedInput;
47
+
41
48
  const sendSchema = conversations[conversationRouteName].message.send;
42
49
  const sendOperation = customOpFactory(
43
50
  client,
@@ -21,11 +21,11 @@ export enum AiAction {
21
21
  CreateConversation = '1',
22
22
  GetConversation = '2',
23
23
  ListConversations = '3',
24
- SendMessage = '4',
25
- ListMessages = '5',
26
- OnMessage = '6',
27
- Generation = '7',
28
- Delete = '8',
24
+ DeleteConversation = '4',
25
+ SendMessage = '5',
26
+ ListMessages = '6',
27
+ OnMessage = '7',
28
+ Generation = '8',
29
29
  }
30
30
 
31
31
  export const getCustomUserAgentDetails = (
@@ -11,6 +11,7 @@ import {
11
11
  import { createCreateConversationFunction } from '../../ai/createCreateConversationFunction';
12
12
  import { createGetConversationFunction } from '../../ai/createGetConversationFunction';
13
13
  import { createListConversationsFunction } from '../../ai/createListConversationsFunction';
14
+ import { createDeleteConversationFunction } from '../../ai/createDeleteConversationFunction';
14
15
 
15
16
  export function generateConversationsProperty(
16
17
  client: BaseClient,
@@ -76,6 +77,14 @@ export function generateConversationsProperty(
76
77
  conversationMessageModel,
77
78
  getInternals,
78
79
  ),
80
+ delete: createDeleteConversationFunction(
81
+ client,
82
+ conversationModelIntrospection,
83
+ name,
84
+ conversationModel,
85
+ conversationMessageModel,
86
+ getInternals,
87
+ ),
79
88
  list: createListConversationsFunction(
80
89
  client,
81
90
  conversationModelIntrospection,