@aws-amplify/data-schema 1.4.0 → 1.5.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 (174) hide show
  1. package/dist/cjs/ClientSchema/ai/ClientConversation.js +6 -0
  2. package/dist/cjs/ClientSchema/ai/ClientConversation.js.map +1 -0
  3. package/dist/cjs/CustomOperation.js +22 -2
  4. package/dist/cjs/CustomOperation.js.map +1 -1
  5. package/dist/cjs/SchemaProcessor.js +41 -5
  6. package/dist/cjs/SchemaProcessor.js.map +1 -1
  7. package/dist/cjs/a.js +9 -1
  8. package/dist/cjs/a.js.map +1 -1
  9. package/dist/cjs/ai/ConversationSchemaTypes.js +210 -0
  10. package/dist/cjs/ai/ConversationSchemaTypes.js.map +1 -0
  11. package/dist/cjs/ai/ConversationType.js +27 -0
  12. package/dist/cjs/ai/ConversationType.js.map +1 -0
  13. package/dist/cjs/ai/ModelType.js +37 -0
  14. package/dist/cjs/ai/ModelType.js.map +1 -0
  15. package/dist/cjs/ai/types/ConversationMessageContent.js +6 -0
  16. package/dist/cjs/ai/types/ConversationMessageContent.js.map +1 -0
  17. package/dist/cjs/ai/types/ToolConfiguration.js +6 -0
  18. package/dist/cjs/ai/types/ToolConfiguration.js.map +1 -0
  19. package/dist/cjs/ai/types/ToolResultContent.js +6 -0
  20. package/dist/cjs/ai/types/ToolResultContent.js.map +1 -0
  21. package/dist/cjs/ai/types/contentBlocks.js +6 -0
  22. package/dist/cjs/ai/types/contentBlocks.js.map +1 -0
  23. package/dist/cjs/runtime/addSchemaToClient.js +2 -0
  24. package/dist/cjs/runtime/addSchemaToClient.js.map +1 -1
  25. package/dist/cjs/runtime/internals/APIClient.js +3 -3
  26. package/dist/cjs/runtime/internals/APIClient.js.map +1 -1
  27. package/dist/cjs/runtime/internals/ai/conversationMessageDeserializers.js +54 -0
  28. package/dist/cjs/runtime/internals/ai/conversationMessageDeserializers.js.map +1 -0
  29. package/dist/cjs/runtime/internals/ai/conversationMessageSerializers.js +58 -0
  30. package/dist/cjs/runtime/internals/ai/conversationMessageSerializers.js.map +1 -0
  31. package/dist/cjs/runtime/internals/ai/convertItemToConversation.js +22 -0
  32. package/dist/cjs/runtime/internals/ai/convertItemToConversation.js.map +1 -0
  33. package/dist/cjs/runtime/internals/ai/convertItemToConversationMessage.js +16 -0
  34. package/dist/cjs/runtime/internals/ai/convertItemToConversationMessage.js.map +1 -0
  35. package/dist/cjs/runtime/internals/ai/createCreateConversationFunction.js +18 -0
  36. package/dist/cjs/runtime/internals/ai/createCreateConversationFunction.js.map +1 -0
  37. package/dist/cjs/runtime/internals/ai/createGetConversationFunction.js +20 -0
  38. package/dist/cjs/runtime/internals/ai/createGetConversationFunction.js.map +1 -0
  39. package/dist/cjs/runtime/internals/ai/createListConversationsFunction.js +21 -0
  40. package/dist/cjs/runtime/internals/ai/createListConversationsFunction.js.map +1 -0
  41. package/dist/cjs/runtime/internals/ai/createListMessagesFunction.js +22 -0
  42. package/dist/cjs/runtime/internals/ai/createListMessagesFunction.js.map +1 -0
  43. package/dist/cjs/runtime/internals/ai/createOnMessageFunction.js +22 -0
  44. package/dist/cjs/runtime/internals/ai/createOnMessageFunction.js.map +1 -0
  45. package/dist/cjs/runtime/internals/ai/createSendMessageFunction.js +32 -0
  46. package/dist/cjs/runtime/internals/ai/createSendMessageFunction.js.map +1 -0
  47. package/dist/cjs/runtime/internals/index.js +5 -1
  48. package/dist/cjs/runtime/internals/index.js.map +1 -1
  49. package/dist/cjs/runtime/internals/operations/custom.js +17 -10
  50. package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
  51. package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js +48 -0
  52. package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js.map +1 -0
  53. package/dist/cjs/runtime/internals/utils/clientProperties/generateGenerationsProperty.js +22 -0
  54. package/dist/cjs/runtime/internals/utils/clientProperties/generateGenerationsProperty.js.map +1 -0
  55. package/dist/esm/ClientSchema/Core/ClientSchemaProperty.d.ts +1 -1
  56. package/dist/esm/ClientSchema/ai/ClientConversation.d.ts +7 -0
  57. package/dist/esm/ClientSchema/ai/ClientConversation.mjs +2 -0
  58. package/dist/esm/ClientSchema/ai/ClientConversation.mjs.map +1 -0
  59. package/dist/esm/ClientSchema/index.d.ts +12 -2
  60. package/dist/esm/CustomOperation.d.ts +33 -2
  61. package/dist/esm/CustomOperation.mjs +21 -2
  62. package/dist/esm/CustomOperation.mjs.map +1 -1
  63. package/dist/esm/ModelSchema.d.ts +3 -1
  64. package/dist/esm/SchemaProcessor.d.ts +1 -1
  65. package/dist/esm/SchemaProcessor.mjs +41 -5
  66. package/dist/esm/SchemaProcessor.mjs.map +1 -1
  67. package/dist/esm/a.d.ts +7 -2
  68. package/dist/esm/a.mjs +9 -1
  69. package/dist/esm/a.mjs.map +1 -1
  70. package/dist/esm/ai/ConversationSchemaTypes.d.ts +3 -0
  71. package/dist/esm/ai/ConversationSchemaTypes.mjs +208 -0
  72. package/dist/esm/ai/ConversationSchemaTypes.mjs.map +1 -0
  73. package/dist/esm/ai/ConversationType.d.ts +102 -0
  74. package/dist/esm/ai/ConversationType.mjs +25 -0
  75. package/dist/esm/ai/ConversationType.mjs.map +1 -0
  76. package/dist/esm/ai/ModelType.d.ts +30 -0
  77. package/dist/esm/ai/ModelType.mjs +34 -0
  78. package/dist/esm/ai/ModelType.mjs.map +1 -0
  79. package/dist/esm/ai/types/ConversationMessageContent.d.ts +27 -0
  80. package/dist/esm/ai/types/ConversationMessageContent.mjs +2 -0
  81. package/dist/esm/ai/types/ConversationMessageContent.mjs.map +1 -0
  82. package/dist/esm/ai/types/ToolConfiguration.d.ts +18 -0
  83. package/dist/esm/ai/types/ToolConfiguration.mjs +2 -0
  84. package/dist/esm/ai/types/ToolConfiguration.mjs.map +1 -0
  85. package/dist/esm/ai/types/ToolResultContent.d.ts +18 -0
  86. package/dist/esm/ai/types/ToolResultContent.mjs +2 -0
  87. package/dist/esm/ai/types/ToolResultContent.mjs.map +1 -0
  88. package/dist/esm/ai/types/contentBlocks.d.ts +19 -0
  89. package/dist/esm/ai/types/contentBlocks.mjs +2 -0
  90. package/dist/esm/ai/types/contentBlocks.mjs.map +1 -0
  91. package/dist/esm/runtime/addSchemaToClient.mjs +4 -0
  92. package/dist/esm/runtime/addSchemaToClient.mjs.map +1 -1
  93. package/dist/esm/runtime/addSchemaToClientWithInstance.mjs +2 -1
  94. package/dist/esm/runtime/addSchemaToClientWithInstance.mjs.map +1 -1
  95. package/dist/esm/runtime/bridge-types.d.ts +29 -3
  96. package/dist/esm/runtime/client/index.d.ts +35 -19
  97. package/dist/esm/runtime/internals/APIClient.mjs +3 -3
  98. package/dist/esm/runtime/internals/APIClient.mjs.map +1 -1
  99. package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.d.ts +2 -0
  100. package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.mjs +52 -0
  101. package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.mjs.map +1 -0
  102. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.d.ts +37 -0
  103. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.mjs +54 -0
  104. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.mjs.map +1 -0
  105. package/dist/esm/runtime/internals/ai/convertItemToConversation.d.ts +3 -0
  106. package/dist/esm/runtime/internals/ai/convertItemToConversation.mjs +20 -0
  107. package/dist/esm/runtime/internals/ai/convertItemToConversation.mjs.map +1 -0
  108. package/dist/esm/runtime/internals/ai/convertItemToConversationMessage.d.ts +7 -0
  109. package/dist/esm/runtime/internals/ai/convertItemToConversationMessage.mjs +14 -0
  110. package/dist/esm/runtime/internals/ai/convertItemToConversationMessage.mjs.map +1 -0
  111. package/dist/esm/runtime/internals/ai/createCreateConversationFunction.d.ts +3 -0
  112. package/dist/esm/runtime/internals/ai/createCreateConversationFunction.mjs +16 -0
  113. package/dist/esm/runtime/internals/ai/createCreateConversationFunction.mjs.map +1 -0
  114. package/dist/esm/runtime/internals/ai/createGetConversationFunction.d.ts +3 -0
  115. package/dist/esm/runtime/internals/ai/createGetConversationFunction.mjs +18 -0
  116. package/dist/esm/runtime/internals/ai/createGetConversationFunction.mjs.map +1 -0
  117. package/dist/esm/runtime/internals/ai/createListConversationsFunction.d.ts +3 -0
  118. package/dist/esm/runtime/internals/ai/createListConversationsFunction.mjs +19 -0
  119. package/dist/esm/runtime/internals/ai/createListConversationsFunction.mjs.map +1 -0
  120. package/dist/esm/runtime/internals/ai/createListMessagesFunction.d.ts +3 -0
  121. package/dist/esm/runtime/internals/ai/createListMessagesFunction.mjs +20 -0
  122. package/dist/esm/runtime/internals/ai/createListMessagesFunction.mjs.map +1 -0
  123. package/dist/esm/runtime/internals/ai/createOnMessageFunction.d.ts +3 -0
  124. package/dist/esm/runtime/internals/ai/createOnMessageFunction.mjs +20 -0
  125. package/dist/esm/runtime/internals/ai/createOnMessageFunction.mjs.map +1 -0
  126. package/dist/esm/runtime/internals/ai/createSendMessageFunction.d.ts +3 -0
  127. package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs +30 -0
  128. package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs.map +1 -0
  129. package/dist/esm/runtime/internals/index.d.ts +2 -0
  130. package/dist/esm/runtime/internals/index.mjs +2 -0
  131. package/dist/esm/runtime/internals/index.mjs.map +1 -1
  132. package/dist/esm/runtime/internals/operations/custom.d.ts +1 -1
  133. package/dist/esm/runtime/internals/operations/custom.mjs +17 -10
  134. package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
  135. package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.d.ts +3 -0
  136. package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs +46 -0
  137. package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs.map +1 -0
  138. package/dist/esm/runtime/internals/utils/clientProperties/generateGenerationsProperty.d.ts +3 -0
  139. package/dist/esm/runtime/internals/utils/clientProperties/generateGenerationsProperty.mjs +20 -0
  140. package/dist/esm/runtime/internals/utils/clientProperties/generateGenerationsProperty.mjs.map +1 -0
  141. package/dist/meta/cjs.tsbuildinfo +1 -1
  142. package/package.json +3 -1
  143. package/src/ClientSchema/Core/ClientSchemaProperty.ts +3 -1
  144. package/src/ClientSchema/ai/ClientConversation.ts +15 -0
  145. package/src/ClientSchema/index.ts +15 -1
  146. package/src/CustomOperation.ts +48 -5
  147. package/src/ModelSchema.ts +4 -1
  148. package/src/SchemaProcessor.ts +73 -8
  149. package/src/a.ts +10 -1
  150. package/src/ai/ConversationSchemaTypes.ts +253 -0
  151. package/src/ai/ConversationType.ts +135 -0
  152. package/src/ai/ModelType.ts +43 -0
  153. package/src/ai/types/ConversationMessageContent.ts +43 -0
  154. package/src/ai/types/ToolConfiguration.ts +24 -0
  155. package/src/ai/types/ToolResultContent.ts +28 -0
  156. package/src/ai/types/contentBlocks.ts +26 -0
  157. package/src/runtime/addSchemaToClient.ts +12 -0
  158. package/src/runtime/bridge-types.ts +41 -4
  159. package/src/runtime/client/index.ts +82 -23
  160. package/src/runtime/internals/APIClient.ts +3 -4
  161. package/src/runtime/internals/ai/conversationMessageDeserializers.ts +62 -0
  162. package/src/runtime/internals/ai/conversationMessageSerializers.ts +68 -0
  163. package/src/runtime/internals/ai/convertItemToConversation.ts +53 -0
  164. package/src/runtime/internals/ai/convertItemToConversationMessage.ts +18 -0
  165. package/src/runtime/internals/ai/createCreateConversationFunction.ts +44 -0
  166. package/src/runtime/internals/ai/createGetConversationFunction.ts +48 -0
  167. package/src/runtime/internals/ai/createListConversationsFunction.ts +46 -0
  168. package/src/runtime/internals/ai/createListMessagesFunction.ts +42 -0
  169. package/src/runtime/internals/ai/createOnMessageFunction.ts +41 -0
  170. package/src/runtime/internals/ai/createSendMessageFunction.ts +60 -0
  171. package/src/runtime/internals/index.ts +2 -0
  172. package/src/runtime/internals/operations/custom.ts +24 -12
  173. package/src/runtime/internals/utils/clientProperties/generateConversationsProperty.ts +91 -0
  174. package/src/runtime/internals/utils/clientProperties/generateGenerationsProperty.ts +41 -0
@@ -0,0 +1,253 @@
1
+ import { InternalRef } from '../RefType';
2
+ import { capitalize } from '../runtime/utils';
3
+ import type {
4
+ InternalConversationType,
5
+ ToolDefinition,
6
+ } from './ConversationType';
7
+
8
+ export const createConversationField = (
9
+ typeDef: InternalConversationType,
10
+ typeName: string,
11
+ ): string => {
12
+ const { aiModel, systemPrompt, handler, tools } = typeDef;
13
+
14
+ const args: Record<string, string> = {
15
+ aiModel: aiModel.resourcePath,
16
+ systemPrompt,
17
+ };
18
+
19
+ if (handler) {
20
+ if (typeof handler === 'string') {
21
+ args['functionName'] = handler;
22
+ } else if (typeof handler.getInstance === 'function') {
23
+ args['functionName'] = `Fn${capitalize(typeName)}`;
24
+ }
25
+ }
26
+
27
+ const argsString = Object.entries(args)
28
+ .map(([key, value]) => `${key}: "${value}"`)
29
+ .join(', ');
30
+
31
+ const toolsString = tools?.length
32
+ ? `, tools: [${getConversationToolsString(tools)}]`
33
+ : '';
34
+
35
+ const conversationDirective = `@conversation(${argsString}${toolsString})`;
36
+
37
+ return `${typeName}(conversationId: ID!, content: [ContentBlockInput], aiContext: AWSJSON, toolConfiguration: ToolConfigurationInput): ConversationMessage ${conversationDirective} @aws_cognito_user_pools`;
38
+ };
39
+
40
+ const isRef = (query: unknown): query is { data: InternalRef['data'] } =>
41
+ (query as any)?.data?.type === 'ref';
42
+
43
+ const getConversationToolsString = (tools: ToolDefinition[]) =>
44
+ tools
45
+ .map((tool) => {
46
+ const { query, description } = tool;
47
+ if (!isRef(query)) {
48
+ throw new Error(`Unexpected query was found in tool ${tool}.`);
49
+ }
50
+ // TODO: add validation for query / auth (cup) / etc
51
+ const queryName = query.data.link;
52
+ return `{ name: "${queryName}", description: "${description}" }`;
53
+ })
54
+ .join(', ');
55
+
56
+ const ConversationParticipantRole = `enum ConversationParticipantRole {
57
+ user
58
+ assistant
59
+ }`;
60
+
61
+ const ConversationMessage = `interface ConversationMessage {
62
+ id: ID!
63
+ conversationId: ID!
64
+ role: ConversationParticipantRole
65
+ content: [ContentBlock]
66
+ aiContext: AWSJSON
67
+ toolConfiguration: ToolConfiguration
68
+ createdAt: AWSDateTime
69
+ updatedAt: AWSDateTime
70
+ owner: String
71
+ }`;
72
+
73
+ const DocumentBlockSourceInput = `input DocumentBlockSourceInput {
74
+ bytes: String
75
+ }`;
76
+
77
+ const DocumentBlockInput = `input DocumentBlockInput {
78
+ format: String!
79
+ name: String!
80
+ source: DocumentBlockSourceInput!
81
+ }`;
82
+
83
+ const ImageBlockSourceInput = `input ImageBlockSourceInput {
84
+ bytes: String
85
+ }`;
86
+
87
+ const ImageBlockInput = `input ImageBlockInput {
88
+ format: String!
89
+ source: ImageBlockSourceInput!
90
+ }`;
91
+
92
+ const ToolResultContentBlockInput = `input ToolResultContentBlockInput {
93
+ document: DocumentBlockInput
94
+ image: ImageBlockInput
95
+ json: AWSJSON
96
+ text: String
97
+ }`;
98
+
99
+ const ToolResultBlockInput = `input ToolResultBlockInput {
100
+ content: [ToolResultContentBlockInput!]!
101
+ toolUseId: String!
102
+ status: String
103
+ }`;
104
+
105
+ const DocumentBlockSource = `type DocumentBlockSource {
106
+ bytes: String
107
+ }
108
+ `;
109
+ const DocumentBlock = `type DocumentBlock {
110
+ format: String!
111
+ name: String!
112
+ source: DocumentBlockSource!
113
+ }`;
114
+
115
+ const ImageBlock = `type ImageBlock {
116
+ format: String!
117
+ source: ImageBlockSource!
118
+ }`;
119
+
120
+ const ImageBlockSource = `type ImageBlockSource {
121
+ bytes: String
122
+ }`;
123
+
124
+ const ToolUseBlockInput = `input ToolUseBlockInput {
125
+ toolUseId: String!
126
+ name: String!
127
+ input: AWSJSON!
128
+ }`;
129
+
130
+ const ToolUseBlock = `type ToolUseBlock {
131
+ toolUseId: String!
132
+ name: String!
133
+ input: AWSJSON!
134
+ }`;
135
+
136
+ const ToolResultContentBlock = `type ToolResultContentBlock {
137
+ document: DocumentBlock
138
+ image: ImageBlock
139
+ json: AWSJSON
140
+ text: String
141
+ }`;
142
+
143
+ const ToolResultBlock = `type ToolResultBlock {
144
+ content: [ToolResultContentBlock!]!
145
+ toolUseId: String!
146
+ status: String
147
+ }`;
148
+
149
+ const ContentBlockText = `type ContentBlockText {
150
+ text: String
151
+ }`;
152
+
153
+ const ContentBlockImage = `type ContentBlockImage {
154
+ image: ImageBlock
155
+ }`;
156
+
157
+ const ContentBlockDocument = `type ContentBlockDocument {
158
+ document: DocumentBlock
159
+ }`;
160
+
161
+ const ContentBlockToolUse = `type ContentBlockToolUse {
162
+ toolUse: ToolUseBlock
163
+ }`;
164
+
165
+ const ContentBlockToolResult = `type ContentBlockToolResult {
166
+ toolResult: ToolResultBlock
167
+ }`;
168
+
169
+ const ContentBlockInput = `input ContentBlockInput {
170
+ text: String
171
+ document: DocumentBlockInput
172
+ image: ImageBlockInput
173
+ toolResult: ToolResultBlockInput
174
+ toolUse: ToolUseBlockInput
175
+ }`;
176
+
177
+ const ContentBlock = `type ContentBlock {
178
+ text: String
179
+ document: DocumentBlock
180
+ image: ImageBlock
181
+ toolResult: ToolResultBlock
182
+ toolUse: ToolUseBlock
183
+ }`;
184
+
185
+ const ToolConfigurationInput = `input ToolConfigurationInput {
186
+ tools: [ToolInput]
187
+ }`;
188
+
189
+ const ToolInput = `input ToolInput {
190
+ toolSpec: ToolSpecificationInput
191
+ }`;
192
+
193
+ const ToolSpecificationInput = `input ToolSpecificationInput {
194
+ name: String!
195
+ description: String
196
+ inputSchema: ToolInputSchemaInput!
197
+ }`;
198
+
199
+ const ToolInputSchemaInput = `input ToolInputSchemaInput {
200
+ json: AWSJSON
201
+ }`;
202
+
203
+ const ToolConfiguration = `type ToolConfiguration {
204
+ tools: [Tool]
205
+ }`;
206
+
207
+ const Tool = `type Tool {
208
+ toolSpec: ToolSpecification
209
+ }`;
210
+
211
+ const ToolSpecification = `type ToolSpecification {
212
+ name: String!
213
+ description: String
214
+ inputSchema: ToolInputSchema!
215
+ }`;
216
+
217
+ const ToolInputSchema = `type ToolInputSchema {
218
+ json: AWSJSON
219
+ }`;
220
+
221
+ export const conversationTypes: string[] = [
222
+ ConversationParticipantRole,
223
+ ConversationMessage,
224
+ DocumentBlockSourceInput,
225
+ DocumentBlockInput,
226
+ ImageBlockSourceInput,
227
+ ImageBlockInput,
228
+ ToolUseBlockInput,
229
+ ToolResultContentBlockInput,
230
+ ToolResultBlockInput,
231
+ DocumentBlockSource,
232
+ DocumentBlock,
233
+ ImageBlock,
234
+ ImageBlockSource,
235
+ ToolUseBlock,
236
+ ToolResultContentBlock,
237
+ ToolResultBlock,
238
+ ContentBlockText,
239
+ ContentBlockImage,
240
+ ContentBlockDocument,
241
+ ContentBlockToolUse,
242
+ ContentBlockToolResult,
243
+ ContentBlockInput,
244
+ ContentBlock,
245
+ ToolConfigurationInput,
246
+ ToolInput,
247
+ ToolSpecificationInput,
248
+ ToolInputSchemaInput,
249
+ ToolConfiguration,
250
+ Tool,
251
+ ToolSpecification,
252
+ ToolInputSchema,
253
+ ];
@@ -0,0 +1,135 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Subscription } from 'rxjs';
5
+ import type { DefineFunction } from '@aws-amplify/data-schema-types';
6
+ import type { ListReturnValue, SingularReturnValue } from '../runtime/client';
7
+ import { type Brand, brand } from '../util';
8
+ import type { RefType } from '../RefType';
9
+ import { AiModel, InferenceConfiguration } from './ModelType';
10
+ import {
11
+ ConversationMessageContent,
12
+ ConversationSendMessageInputContent,
13
+ } from './types/ConversationMessageContent';
14
+ import { ToolConfiguration } from './types/ToolConfiguration';
15
+
16
+ export const brandName = 'conversationCustomOperation';
17
+
18
+ // conversation message types
19
+ export interface ConversationMessage {
20
+ content: ConversationMessageContent[];
21
+ conversationId: string;
22
+ createdAt: string;
23
+ id: string;
24
+ role: 'user' | 'assistant';
25
+ }
26
+
27
+ // conversation route types
28
+ interface ConversationRouteGetInput {
29
+ id: string;
30
+ }
31
+
32
+ interface ConversationRouteListInput {
33
+ limit?: number;
34
+ nextToken?: string | null;
35
+ }
36
+
37
+ export interface ConversationRoute {
38
+ /**
39
+ * @experimental
40
+ *
41
+ * Creates a {@link Conversation} from the current conversation route.
42
+ */
43
+ create: () => SingularReturnValue<Conversation>;
44
+ /**
45
+ * @experimental
46
+ *
47
+ * Gets an existing {@link Conversation} based on ID.
48
+ */
49
+ get: (input: ConversationRouteGetInput) => SingularReturnValue<Conversation>;
50
+ /**
51
+ * @experimental
52
+ *
53
+ * Lists all existing {@link Conversation}s on the current conversation route.
54
+ */
55
+ list: (input?: ConversationRouteListInput) => ListReturnValue<Conversation>;
56
+ }
57
+
58
+ // conversation types
59
+ interface ConversationSendMessageInput {
60
+ content: ConversationSendMessageInputContent[];
61
+ aiContext?: string | Record<string, any>;
62
+ toolConfiguration?: ToolConfiguration;
63
+ }
64
+
65
+ interface ConversationListMessagesInput {
66
+ limit?: number;
67
+ nextToken?: string | null;
68
+ }
69
+
70
+ type ConversationOnMessageHandler = (message: ConversationMessage) => void;
71
+
72
+ export interface Conversation {
73
+ id: string;
74
+ /**
75
+ * @experimental
76
+ *
77
+ * Sends a message to the current conversation.
78
+ */
79
+ sendMessage: (
80
+ input: ConversationSendMessageInput,
81
+ ) => SingularReturnValue<ConversationMessage>;
82
+ /**
83
+ * @experimental
84
+ *
85
+ * Lists all existing messages for the current conversation.
86
+ */
87
+ listMessages: (
88
+ input?: ConversationListMessagesInput,
89
+ ) => ListReturnValue<ConversationMessage>;
90
+ /**
91
+ * @experimental
92
+ *
93
+ * Subscribes to new messages on the current conversation.
94
+ */
95
+ onMessage: (handler: ConversationOnMessageHandler) => Subscription;
96
+ }
97
+
98
+ // schema definition input
99
+ export interface ToolDefinition {
100
+ query: RefType<any>;
101
+ description: string;
102
+ }
103
+
104
+ export interface ConversationInput {
105
+ aiModel: AiModel;
106
+ systemPrompt: string;
107
+ inferenceConfiguration?: InferenceConfiguration;
108
+ tools?: ToolDefinition[];
109
+ handler?: DefineFunction | string;
110
+ }
111
+
112
+ export interface InternalConversationType
113
+ extends ConversationType,
114
+ ConversationInput {}
115
+
116
+ export interface ConversationType extends Brand<typeof brandName> {}
117
+
118
+ function _conversation(input: ConversationInput): ConversationType {
119
+ return { ...brand(brandName), ...input };
120
+ }
121
+
122
+ /**
123
+ * @experimental
124
+ *
125
+ * Define an AI conversation route which enables multi-turn conversation APIs for interacting with specified AI model.
126
+ * @example
127
+ * realtorChat: a.conversation({
128
+ * aiModel: { resourcePath },
129
+ * systemPrompt: 'You are a helpful real estate assistant',
130
+ * })
131
+ * @returns a conversation route definition
132
+ */
133
+ export function conversation(input: ConversationInput): ConversationType {
134
+ return _conversation(input);
135
+ }
@@ -0,0 +1,43 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ const supportedModelsLookup = {
5
+ // Anthropic models
6
+ 'Claude 3 Haiku': 'anthropic.claude-3-haiku-20240307-v1:0',
7
+ 'Claude 3 Opus': 'anthropic.claude-3-opus-20240229-v1:0',
8
+ 'Claude 3 Sonnet': 'anthropic.claude-3-sonnet-20240229-v1:0',
9
+ 'Claude 3.5 Sonnet': 'anthropic.claude-3-5-sonnet-20240620-v1:0',
10
+ // Cohere models
11
+ 'Cohere Command R': 'cohere.command-r-v1:0',
12
+ 'Cohere Command R+': 'cohere.command-r-plus-v1:0',
13
+ // Meta models
14
+ 'Llama 3.1 8B Instruct': 'meta.llama3-1-8b-instruct-v1:0',
15
+ 'Llama 3.1 70B Instruct': 'meta.llama3-1-70b-instruct-v1:0',
16
+ 'Llama 3.1 405B Instruct': 'meta.llama3-1-405b-instruct-v1:0',
17
+ // Mistral AI models
18
+ 'Mistral Large': 'mistral.mistral-large-2402-v1:0',
19
+ 'Mistral Large 2': 'mistral.mistral-large-2407-v1:0',
20
+ 'Mistral Small': 'mistral.mistral-small-2402-v1:0',
21
+ } as const;
22
+
23
+ export interface AiModel {
24
+ resourcePath: string;
25
+ }
26
+
27
+ export interface InferenceConfiguration {
28
+ topP?: number;
29
+ temperature?: number;
30
+ maxTokens?: number;
31
+ }
32
+
33
+ /**
34
+ * @experimental
35
+ *
36
+ * Bedrock models currently supporting Converse API and Tool use
37
+ * @see {@link https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html#conversation-inference-supported-models-features}
38
+ */
39
+ export function model(modelName: keyof typeof supportedModelsLookup): AiModel {
40
+ return {
41
+ resourcePath: supportedModelsLookup[modelName],
42
+ };
43
+ }
@@ -0,0 +1,43 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ImageBlock, ToolResultBlock, ToolUseBlock } from './contentBlocks';
5
+
6
+ export interface ConversationMessageTextContent {
7
+ text: string;
8
+ image?: never;
9
+ toolUse?: never;
10
+ toolResult?: never;
11
+ }
12
+
13
+ export interface ConversationMessageImageContent {
14
+ text?: never;
15
+ image: ImageBlock;
16
+ toolUse?: never;
17
+ toolResult?: never;
18
+ }
19
+
20
+ export interface ConversationMessageToolUseContent {
21
+ text?: never;
22
+ image?: never;
23
+ toolUse: ToolUseBlock;
24
+ toolResult?: never;
25
+ }
26
+
27
+ export interface ConversationMessageToolResultContent {
28
+ text?: never;
29
+ image?: never;
30
+ toolUse?: never;
31
+ toolResult: ToolResultBlock;
32
+ }
33
+
34
+ export type ConversationMessageContent =
35
+ | ConversationMessageTextContent
36
+ | ConversationMessageImageContent
37
+ | ConversationMessageToolUseContent
38
+ | ConversationMessageToolResultContent;
39
+
40
+ export type ConversationSendMessageInputContent =
41
+ | Omit<ConversationMessageTextContent, 'toolUse'>
42
+ | Omit<ConversationMessageImageContent, 'toolUse'>
43
+ | Omit<ConversationMessageToolResultContent, 'toolUse'>;
@@ -0,0 +1,24 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { JSONSchema4 } from 'json-schema';
5
+
6
+ interface ObjectTypedJSONSchema4 extends JSONSchema4 {
7
+ type: 'object';
8
+ }
9
+
10
+ interface ToolJsonInputSchema {
11
+ /**
12
+ * The schema for the tool. The top level schema type must be object.
13
+ */
14
+ json: ObjectTypedJSONSchema4;
15
+ }
16
+
17
+ export interface Tool {
18
+ inputSchema: ToolJsonInputSchema;
19
+ description?: string;
20
+ }
21
+
22
+ export interface ToolConfiguration {
23
+ tools: Record<string, Tool>;
24
+ }
@@ -0,0 +1,28 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { DocumentType } from '../../runtime/bridge-types';
5
+ import { ImageBlock } from './contentBlocks';
6
+
7
+ export interface ToolResultTextContent {
8
+ text: string;
9
+ image?: never;
10
+ json?: never;
11
+ }
12
+
13
+ export interface ToolResultImageContent {
14
+ text?: never;
15
+ image: ImageBlock;
16
+ json?: never;
17
+ }
18
+
19
+ export interface ToolResultJsonContent {
20
+ text?: never;
21
+ image?: never;
22
+ json: DocumentType;
23
+ }
24
+
25
+ export type ToolResultContent =
26
+ | ToolResultTextContent
27
+ | ToolResultImageContent
28
+ | ToolResultJsonContent;
@@ -0,0 +1,26 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { DocumentType } from '../../runtime/bridge-types';
5
+ import type { ToolResultContent } from './ToolResultContent';
6
+
7
+ interface BytesImageSource {
8
+ bytes: Uint8Array;
9
+ }
10
+
11
+ // common content blocks
12
+ export interface ImageBlock {
13
+ format: 'gif' | 'jpeg' | 'png' | 'webp';
14
+ source: BytesImageSource;
15
+ }
16
+
17
+ export interface ToolUseBlock {
18
+ toolUseId: string;
19
+ name: string;
20
+ input: DocumentType;
21
+ }
22
+
23
+ export interface ToolResultBlock {
24
+ toolUseId: string;
25
+ content: ToolResultContent[];
26
+ }
@@ -3,10 +3,12 @@
3
3
 
4
4
  import { ClientExtensions } from './client';
5
5
  import {
6
+ generateConversationsProperty,
6
7
  generateCustomQueriesProperty,
7
8
  generateCustomMutationsProperty,
8
9
  generateCustomSubscriptionsProperty,
9
10
  generateEnumsProperty,
11
+ generateGenerationsProperty,
10
12
  generateModelsProperty,
11
13
  upgradeClientCancellation,
12
14
  } from './internals';
@@ -43,5 +45,15 @@ export function addSchemaToClient<T extends Record<any, any> = never>(
43
45
  apiGraphqlConfig,
44
46
  getInternals,
45
47
  );
48
+ (client as any).conversations = generateConversationsProperty(
49
+ client as any,
50
+ apiGraphqlConfig,
51
+ getInternals,
52
+ );
53
+ (client as any).generations = generateGenerationsProperty(
54
+ client as any,
55
+ apiGraphqlConfig,
56
+ getInternals,
57
+ );
46
58
  return client as any;
47
59
  }
@@ -87,6 +87,8 @@ export interface ModelIntrospectionSchema {
87
87
  queries?: CustomOperations;
88
88
  mutations?: CustomOperations;
89
89
  subscriptions?: CustomOperations;
90
+ conversations?: SchemaConversationRoutes;
91
+ generations?: SchemaGenerationRoutes;
90
92
  }
91
93
 
92
94
  /**
@@ -96,6 +98,27 @@ export type SchemaModels = Record<string, SchemaModel>;
96
98
  export type SchemaNonModels = Record<string, SchemaNonModel>;
97
99
  export type SchemaEnums = Record<string, SchemaEnum>;
98
100
  export type CustomOperations = Record<string, CustomOperation>;
101
+ export type SchemaConversationRoutes = Record<string, SchemaConversationRoute>;
102
+ export type SchemaGenerationRoutes = Record<string, CustomOperation>;
103
+
104
+ export type SchemaConversationRoute = {
105
+ name: string;
106
+ models: SchemaModels;
107
+ nonModels: SchemaNonModels;
108
+ enums: SchemaEnums;
109
+ conversation: SchemaConversation;
110
+ message: SchemaConversationMessage;
111
+ };
112
+
113
+ export type SchemaConversation = {
114
+ modelName: string;
115
+ };
116
+
117
+ export type SchemaConversationMessage = {
118
+ modelName: string;
119
+ subscribe: CustomOperation;
120
+ send: CustomOperation;
121
+ };
99
122
 
100
123
  export interface SchemaModel {
101
124
  name: string;
@@ -140,7 +163,7 @@ export type CustomOperationArguments = Record<string, CustomOperationArgument>;
140
163
 
141
164
  export interface CustomOperationArgument {
142
165
  name: string;
143
- type: FieldType;
166
+ type: InputFieldType;
144
167
  isArray: boolean;
145
168
  isRequired: boolean;
146
169
  isArrayNullable?: boolean;
@@ -185,7 +208,15 @@ export interface NonModelFieldType {
185
208
  nonModel: string;
186
209
  }
187
210
 
188
- export type FieldType =
211
+ export interface EnumType {
212
+ enum: string;
213
+ }
214
+
215
+ export interface InputType {
216
+ input: string;
217
+ }
218
+
219
+ type ScalarType =
189
220
  | 'ID'
190
221
  | 'String'
191
222
  | 'Int'
@@ -199,10 +230,16 @@ export type FieldType =
199
230
  | 'AWSIPAddress'
200
231
  | 'Boolean'
201
232
  | 'AWSJSON'
202
- | 'AWSPhone'
203
- | { enum: string }
233
+ | 'AWSPhone';
234
+
235
+ export type FieldType =
236
+ | ScalarType
237
+ | EnumType
204
238
  | ModelFieldType
205
239
  | NonModelFieldType;
240
+
241
+ export type InputFieldType = ScalarType | EnumType | InputType;
242
+
206
243
  export type FieldAttribute = ModelAttribute;
207
244
 
208
245
  /**