@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/data-schema",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -51,7 +51,9 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@aws-amplify/data-schema-types": "*",
54
+ "@smithy/util-base64": "^3.0.0",
54
55
  "@types/aws-lambda": "^8.10.134",
56
+ "@types/json-schema": "^7.0.15",
55
57
  "rxjs": "^7.8.1"
56
58
  },
57
59
  "devDependencies": {
@@ -5,6 +5,8 @@ export interface ClientSchemaProperty {
5
5
  | 'customType'
6
6
  | 'customQuery'
7
7
  | 'customMutation'
8
- | 'customSubscription';
8
+ | 'customSubscription'
9
+ | 'customConversation'
10
+ | 'customGeneration';
9
11
  type: any;
10
12
  }
@@ -0,0 +1,15 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type {
5
+ Conversation,
6
+ ConversationMessage,
7
+ } from '../../ai/ConversationType';
8
+ import type { ClientSchemaProperty } from '../Core';
9
+
10
+ export interface ClientConversation
11
+ extends Pick<ClientSchemaProperty, '__entityType'> {
12
+ __entityType: 'customConversation';
13
+ type: Conversation;
14
+ messageType: ConversationMessage;
15
+ }
@@ -1,6 +1,7 @@
1
1
  import type { __modelMeta__ } from '../runtime/client';
2
2
  import type {
3
3
  BaseSchema,
4
+ ConversationType,
4
5
  CustomOperation,
5
6
  CustomType,
6
7
  EnumType,
@@ -21,6 +22,7 @@ import type {
21
22
  } from '../CombineSchema';
22
23
  import type { SchemaMetadata } from './utilities/SchemaMetadata';
23
24
  import type { Brand, Select, SpreadTuple } from '../util';
25
+ import { ClientConversation } from './ai/ClientConversation';
24
26
 
25
27
  export type ClientSchema<
26
28
  Schema extends GenericModelSchema<any> | CombinedModelSchema<any>,
@@ -65,11 +67,14 @@ type ClientSchemaProperty<
65
67
  | 'queryCustomOperation'
66
68
  | 'mutationCustomOperation'
67
69
  | 'subscriptionCustomOperation'
70
+ | 'generationCustomOperation'
68
71
  >
69
72
  ? RemapCustomOperation<T, Metadata, IsRDS, T[K]>
70
73
  : T[K] extends Brand<'modelType'>
71
74
  ? RemapModel<T, Metadata, IsRDS, T[K], K>
72
- : never;
75
+ : T[K] extends Brand<'conversationCustomOperation'>
76
+ ? RemapAIRoute<T, T[K]>
77
+ : never;
73
78
 
74
79
  type RemapEnum<_T extends ModelSchemaContents, E> =
75
80
  E extends EnumType<infer values> ? ClientEnum<values> : never;
@@ -111,6 +116,11 @@ type RemapModel<
111
116
  >
112
117
  : never;
113
118
 
119
+ type RemapAIRoute<
120
+ _T extends ModelSchemaContents,
121
+ E,
122
+ > = E extends ConversationType ? ClientConversation : never;
123
+
114
124
  type GetInternalClientSchema<Schema> =
115
125
  Schema extends GenericModelSchema<any> ? InternalClientSchema<Schema> : never;
116
126
 
@@ -146,6 +156,8 @@ export type ClientSchemaByEntityTypeBaseShape = {
146
156
  queries: Record<string, ClientCustomOperation<any, any>>;
147
157
  mutations: Record<string, ClientCustomOperation<any, any>>;
148
158
  subscriptions: Record<string, ClientCustomOperation<any, any>>;
159
+ conversations: Record<string, ClientConversation>;
160
+ generations: Record<string, ClientCustomOperation<any, any>>;
149
161
  };
150
162
 
151
163
  export type ClientSchemaByEntityType<T> = {
@@ -155,4 +167,6 @@ export type ClientSchemaByEntityType<T> = {
155
167
  queries: Select<T, { __entityType: 'customQuery' }>;
156
168
  mutations: Select<T, { __entityType: 'customMutation' }>;
157
169
  subscriptions: Select<T, { __entityType: 'customSubscription' }>;
170
+ conversations: Select<T, { __entityType: 'customConversation' }>;
171
+ generations: Select<T, { __entityType: 'customGeneration' }>;
158
172
  };
@@ -14,15 +14,18 @@ import type {
14
14
  FunctionHandler,
15
15
  HandlerType as Handler,
16
16
  } from './Handler';
17
+ import { AiModel, InferenceConfiguration } from './ai/ModelType';
17
18
 
18
19
  const queryBrand = 'queryCustomOperation';
19
20
  const mutationBrand = 'mutationCustomOperation';
20
21
  const subscriptionBrand = 'subscriptionCustomOperation';
22
+ const generationBrand = 'generationCustomOperation';
21
23
 
22
24
  type CustomOperationBrand =
23
25
  | typeof queryBrand
24
26
  | typeof mutationBrand
25
- | typeof subscriptionBrand;
27
+ | typeof subscriptionBrand
28
+ | typeof generationBrand;
26
29
 
27
30
  type CustomArguments = Record<string, BaseModelField | EnumType>;
28
31
 
@@ -38,6 +41,7 @@ export const CustomOperationNames = [
38
41
  'Query',
39
42
  'Mutation',
40
43
  'Subscription',
44
+ 'Generation',
41
45
  ] as const;
42
46
  type CustomOperationName = (typeof CustomOperationNames)[number];
43
47
 
@@ -48,6 +52,7 @@ type CustomData = {
48
52
  typeName: CustomOperationName;
49
53
  handlers: Handler[] | null;
50
54
  subscriptionSource: SubscriptionSource[];
55
+ input?: CustomOperationInput;
51
56
  };
52
57
 
53
58
  type InternalCustomData = CustomData & {
@@ -57,12 +62,15 @@ type InternalCustomData = CustomData & {
57
62
  authorization: Authorization<any, any, any>[];
58
63
  };
59
64
 
65
+ export type CustomOperationInput = GenerationInput;
66
+
60
67
  export type CustomOperationParamShape = {
61
68
  arguments: CustomArguments | null;
62
69
  returnType: CustomReturnType | null;
63
70
  authorization: Authorization<any, any, any>[];
64
71
  typeName: CustomOperationName;
65
72
  handlers: Handler | null;
73
+ input?: CustomOperationInput;
66
74
  };
67
75
 
68
76
  export type CustomOperation<
@@ -137,7 +145,7 @@ export type InternalCustom<B extends CustomOperationBrand = any> =
137
145
  function _custom<
138
146
  T extends CustomOperationParamShape,
139
147
  B extends CustomOperationBrand,
140
- >(typeName: CustomOperationName, brand: B) {
148
+ >(typeName: CustomOperationName, brand: B, input?: T['input']) {
141
149
  const data: CustomData = {
142
150
  arguments: {},
143
151
  returnType: null,
@@ -145,6 +153,7 @@ function _custom<
145
153
  typeName: typeName,
146
154
  handlers: null,
147
155
  subscriptionSource: [],
156
+ input,
148
157
  };
149
158
 
150
159
  const builder = brandedBuilder<T>(
@@ -210,7 +219,7 @@ export type QueryCustomOperation = CustomOperation<
210
219
  * .authorization(allow => [allow.publicApiKey()])
211
220
  * // 3. set the function has the handler
212
221
  * .handler(a.handler.function(echoHandler)),
213
- *
222
+ *
214
223
  * EchoResponse: a.customType({
215
224
  * content: a.string(),
216
225
  * executionDuration: a.float()
@@ -277,9 +286,9 @@ export type SubscriptionCustomOperation = CustomOperation<
277
286
  * // Subscribe to incoming messages
278
287
  * receive: a.subscription()
279
288
  * // subscribes to the 'publish' mutation
280
- * .for(a.ref('publish'))
289
+ * .for(a.ref('publish'))
281
290
  * // subscription handler to set custom filters
282
- * .handler(a.handler.custom({entry: './receive.js'}))
291
+ * .handler(a.handler.custom({entry: './receive.js'}))
283
292
  * // authorization rules as to who can subscribe to the data
284
293
  * .authorization(allow => [allow.publicApiKey()]),
285
294
  * @returns a custom subscription
@@ -297,3 +306,37 @@ export function subscription(): CustomOperation<
297
306
  > {
298
307
  return _custom('Subscription', subscriptionBrand);
299
308
  }
309
+
310
+ export interface GenerationInput {
311
+ aiModel: AiModel;
312
+ systemPrompt: string;
313
+ inferenceConfiguration?: InferenceConfiguration;
314
+ }
315
+
316
+ /**
317
+ * @experimental
318
+ *
319
+ * Define an AI generation route for single request-response interaction with specified AI model.
320
+ * @example
321
+ * makeRecipe: a.generation({
322
+ * aiModel: { resourcePath },
323
+ * systemPrompt: 'Please make a recipe from the provided ingredients',
324
+ * })
325
+ * .arguments({ ingredients: a.string().array() })
326
+ * .returns(a.ref("Recipe"))
327
+ * @returns a generation route definition
328
+ */
329
+ export function generation(input: GenerationInput): CustomOperation<
330
+ {
331
+ arguments: null;
332
+ returnType: null;
333
+ authorization: [];
334
+ typeName: 'Generation';
335
+ handlers: null;
336
+ input: GenerationInput;
337
+ },
338
+ 'for' | 'handler',
339
+ typeof generationBrand
340
+ > {
341
+ return _custom('Generation', generationBrand, input);
342
+ }
@@ -30,11 +30,13 @@ import {
30
30
  ModelRelationalField,
31
31
  ModelRelationalFieldParamShape,
32
32
  } from './ModelRelationalField';
33
+ import { ConversationType } from './ai/ConversationType';
33
34
 
34
35
  export { ModelType } from './ModelType';
35
36
  export { EnumType } from './EnumType';
36
37
  export { CustomType } from './CustomType';
37
38
  export { CustomOperation } from './CustomOperation';
39
+ export { ConversationType } from './ai/ConversationType';
38
40
 
39
41
  export const rdsSchemaBrandName = 'RDSSchema';
40
42
  export const rdsSchemaBrand = brand(rdsSchemaBrandName);
@@ -48,7 +50,8 @@ type SchemaContent =
48
50
  | BaseModelType
49
51
  | CustomType<CustomTypeParamShape>
50
52
  | EnumType
51
- | CustomOperation<CustomOperationParamShape, any>;
53
+ | CustomOperation<CustomOperationParamShape, any>
54
+ | ConversationType;
52
55
 
53
56
  // The SQL-only `addToSchema` accepts all top-level entities, excepts models
54
57
  type AddToSchemaContent = Exclude<SchemaContent, BaseModelType>;
@@ -1,4 +1,4 @@
1
- import { type CustomPathData, type InternalSchema } from './ModelSchema';
1
+ import type { CustomPathData, InternalSchema } from './ModelSchema';
2
2
  import {
3
3
  type ModelField,
4
4
  type InternalField,
@@ -30,17 +30,30 @@ import {
30
30
  import type { InternalRef, RefType } from './RefType';
31
31
  import type { EnumType } from './EnumType';
32
32
  import type { CustomType, CustomTypeParamShape } from './CustomType';
33
- import { type InternalCustom, CustomOperationNames } from './CustomOperation';
33
+ import {
34
+ type InternalCustom,
35
+ type CustomOperationInput,
36
+ type GenerationInput,
37
+ CustomOperationNames,
38
+ } from './CustomOperation';
34
39
  import { Brand, getBrand } from './util';
35
40
  import {
36
41
  getHandlerData,
37
42
  type HandlerType,
38
43
  type CustomHandler,
39
44
  type SqlReferenceHandler,
40
- FunctionHandler,
45
+ type FunctionHandler,
41
46
  } from './Handler';
42
47
  import * as os from 'os';
43
48
  import * as path from 'path';
49
+ import {
50
+ brandName as conversationBrandName,
51
+ type InternalConversationType,
52
+ } from './ai/ConversationType';
53
+ import {
54
+ conversationTypes,
55
+ createConversationField,
56
+ } from './ai/ConversationSchemaTypes';
44
57
 
45
58
  type ScalarFieldDef = Exclude<InternalField['data'], { fieldType: 'model' }>;
46
59
 
@@ -84,6 +97,16 @@ function isCustomType(
84
97
  return false;
85
98
  }
86
99
 
100
+ function isConversationRoute(type: any): type is InternalConversationType {
101
+ return getBrand(type) === conversationBrandName;
102
+ }
103
+
104
+ function isGenerationInput(
105
+ input?: CustomOperationInput,
106
+ ): input is GenerationInput {
107
+ return Boolean(input?.aiModel && input?.systemPrompt);
108
+ }
109
+
87
110
  function isCustomOperation(type: any): type is InternalCustom {
88
111
  if (CustomOperationNames.includes(type?.data?.typeName)) {
89
112
  return true;
@@ -469,7 +492,29 @@ function customOperationToGql(
469
492
  gqlHandlerContent += `@aws_subscribe(mutations: ["${subscriptionSources}"]) `;
470
493
  }
471
494
 
495
+ if (opType === 'Generation') {
496
+ if (!isGenerationInput(typeDef.data.input)) {
497
+ throw new Error(
498
+ `Invalid Generation Route definition. A Generation Route must include a valid input. ${typeName} has an invalid or no input defined.`,
499
+ );
500
+ }
501
+ const { aiModel, systemPrompt, inferenceConfiguration } =
502
+ typeDef.data.input;
503
+
504
+ const inferenceConfigurationEntries = Object.entries(
505
+ inferenceConfiguration ?? {},
506
+ );
507
+ const inferenceConfigurationGql =
508
+ inferenceConfigurationEntries.length > 0
509
+ ? `, inferenceConfiguration: { ${inferenceConfigurationEntries
510
+ .map(([key, value]) => `${key}: ${value}`)
511
+ .join(', ')} }`
512
+ : '';
513
+ gqlHandlerContent += `@generation(aiModel: "${aiModel.resourcePath}", systemPrompt: "${systemPrompt}"${inferenceConfigurationGql}) `;
514
+ }
515
+
472
516
  const gqlField = `${callSignature}: ${returnTypeName} ${gqlHandlerContent}${authString}`;
517
+
473
518
  return {
474
519
  gqlField,
475
520
  implicitTypes: implicitTypes,
@@ -1210,6 +1255,7 @@ const schemaPreprocessor = (
1210
1255
  const customQueries = [];
1211
1256
  const customMutations = [];
1212
1257
  const customSubscriptions = [];
1258
+ let shouldAddConversationTypes = false;
1213
1259
 
1214
1260
  // Dict of auth rules to be applied to custom types
1215
1261
  // Inherited from the auth configured on the custom operations that return these custom types
@@ -1296,6 +1342,8 @@ const schemaPreprocessor = (
1296
1342
  const model = `type ${typeName} ${customAuth}\n{\n ${joined}\n}`;
1297
1343
  gqlModels.push(model);
1298
1344
  } else if (isCustomOperation(typeDef)) {
1345
+ // TODO: add generation route logic.
1346
+
1299
1347
  const { typeName: opType } = typeDef.data;
1300
1348
 
1301
1349
  const {
@@ -1347,6 +1395,7 @@ const schemaPreprocessor = (
1347
1395
 
1348
1396
  switch (opType) {
1349
1397
  case 'Query':
1398
+ case 'Generation':
1350
1399
  customQueries.push(gqlField);
1351
1400
  break;
1352
1401
  case 'Mutation':
@@ -1358,6 +1407,10 @@ const schemaPreprocessor = (
1358
1407
  default:
1359
1408
  break;
1360
1409
  }
1410
+ } else if (isConversationRoute(typeDef)) {
1411
+ // TODO: add inferenceConfiguration values to directive.
1412
+ customMutations.push(createConversationField(typeDef, typeName));
1413
+ shouldAddConversationTypes = true;
1361
1414
  }
1362
1415
  } else if (staticSchema) {
1363
1416
  const fields = { ...typeDef.data.fields } as Record<
@@ -1473,6 +1526,9 @@ const schemaPreprocessor = (
1473
1526
  };
1474
1527
 
1475
1528
  gqlModels.push(...generateCustomOperationTypes(customOperations));
1529
+ if (shouldAddConversationTypes) {
1530
+ gqlModels.push(...conversationTypes);
1531
+ }
1476
1532
 
1477
1533
  const processedSchema = gqlModels.join('\n\n');
1478
1534
 
@@ -1497,8 +1553,9 @@ function validateCustomOperations(
1497
1553
  const authConfigured = authRules.length > 0;
1498
1554
 
1499
1555
  if (
1500
- (authConfigured && !handlerConfigured) ||
1501
- (handlerConfigured && !authConfigured)
1556
+ opType !== 'Generation' &&
1557
+ ((authConfigured && !handlerConfigured) ||
1558
+ (handlerConfigured && !authConfigured))
1502
1559
  ) {
1503
1560
  // Deploying a custom operation with auth and no handler reference OR
1504
1561
  // with a handler reference but no auth
@@ -1529,10 +1586,12 @@ function validateCustomOperations(
1529
1586
 
1530
1587
  if (
1531
1588
  typeDef.data.returnType === null &&
1532
- (opType === 'Query' || opType === 'Mutation')
1589
+ (opType === 'Query' || opType === 'Mutation' || opType === 'Generation')
1533
1590
  ) {
1591
+ const typeDescription =
1592
+ opType === 'Generation' ? 'Generation Route' : `Custom ${opType}`;
1534
1593
  throw new Error(
1535
- `Invalid Custom ${opType} definition. A Custom ${opType} must include a return type. ${typeName} has no return type specified.`,
1594
+ `Invalid ${typeDescription} definition. A ${typeDescription} must include a return type. ${typeName} has no return type specified.`,
1536
1595
  );
1537
1596
  }
1538
1597
 
@@ -1711,12 +1770,18 @@ function transformCustomOperations(
1711
1770
  getRefType: ReturnType<typeof getRefTypeForSchema>,
1712
1771
  ) {
1713
1772
  const { typeName: opType, handlers } = typeDef.data;
1773
+
1714
1774
  let jsFunctionForField: JsResolver | undefined = undefined;
1715
1775
 
1716
1776
  validateCustomOperations(typeDef, typeName, authRules, getRefType);
1717
1777
 
1718
1778
  if (isCustomHandler(handlers)) {
1719
- jsFunctionForField = handleCustom(handlers, opType, typeName);
1779
+ jsFunctionForField = handleCustom(
1780
+ handlers,
1781
+ // Generation routes should not have handlers
1782
+ opType as Exclude<typeof opType, 'Generation'>,
1783
+ typeName,
1784
+ );
1720
1785
  }
1721
1786
 
1722
1787
  const isCustom = Boolean(jsFunctionForField);
package/src/a.ts CHANGED
@@ -21,8 +21,14 @@ import { ref } from './RefType';
21
21
  import { hasOne, hasMany, belongsTo } from './ModelRelationalField';
22
22
  import { customType } from './CustomType';
23
23
  import { enumType } from './EnumType';
24
- import { query, mutation, subscription } from './CustomOperation';
24
+ import { query, mutation, subscription, generation } from './CustomOperation';
25
25
  import { handler } from './Handler';
26
+ import { conversation } from './ai/ConversationType';
27
+ import { model as aiModel } from './ai/ModelType';
28
+
29
+ const ai = {
30
+ model: aiModel,
31
+ };
26
32
 
27
33
  // We are re-exporting with this pattern to make the JSDoc happy.
28
34
  // Otherwise the JSDoc wouldn't consistently show up as a customer types
@@ -54,5 +60,8 @@ export {
54
60
  phone,
55
61
  url,
56
62
  ipAddress,
63
+ conversation,
64
+ generation,
65
+ ai,
57
66
  handler,
58
67
  };