@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
@@ -4,15 +4,17 @@ import { allowForCustomOperations } from './Authorization.mjs';
4
4
  const queryBrand = 'queryCustomOperation';
5
5
  const mutationBrand = 'mutationCustomOperation';
6
6
  const subscriptionBrand = 'subscriptionCustomOperation';
7
+ const generationBrand = 'generationCustomOperation';
7
8
  const CustomOperationNames = [
8
9
  'Query',
9
10
  'Mutation',
10
11
  'Subscription',
12
+ 'Generation',
11
13
  ];
12
14
  function brandedBuilder(builder, brandValue) {
13
15
  return { ...builder, ...brand(brandValue) };
14
16
  }
15
- function _custom(typeName, brand) {
17
+ function _custom(typeName, brand, input) {
16
18
  const data = {
17
19
  arguments: {},
18
20
  returnType: null,
@@ -20,6 +22,7 @@ function _custom(typeName, brand) {
20
22
  typeName: typeName,
21
23
  handlers: null,
22
24
  subscriptionSource: [],
25
+ input,
23
26
  };
24
27
  const builder = brandedBuilder({
25
28
  arguments(args) {
@@ -103,6 +106,22 @@ function mutation() {
103
106
  function subscription() {
104
107
  return _custom('Subscription', subscriptionBrand);
105
108
  }
109
+ /**
110
+ * @experimental
111
+ *
112
+ * Define an AI generation route for single request-response interaction with specified AI model.
113
+ * @example
114
+ * makeRecipe: a.generation({
115
+ * aiModel: { resourcePath },
116
+ * systemPrompt: 'Please make a recipe from the provided ingredients',
117
+ * })
118
+ * .arguments({ ingredients: a.string().array() })
119
+ * .returns(a.ref("Recipe"))
120
+ * @returns a generation route definition
121
+ */
122
+ function generation(input) {
123
+ return _custom('Generation', generationBrand, input);
124
+ }
106
125
 
107
- export { CustomOperationNames, mutation, query, subscription };
126
+ export { CustomOperationNames, generation, mutation, query, subscription };
108
127
  //# sourceMappingURL=CustomOperation.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"CustomOperation.mjs","sources":["../../src/CustomOperation.ts"],"sourcesContent":["import { brand } from './util';\nimport { allowForCustomOperations, } from './Authorization';\nconst queryBrand = 'queryCustomOperation';\nconst mutationBrand = 'mutationCustomOperation';\nconst subscriptionBrand = 'subscriptionCustomOperation';\nexport const CustomOperationNames = [\n 'Query',\n 'Mutation',\n 'Subscription',\n];\nfunction brandedBuilder(builder, brandValue) {\n return { ...builder, ...brand(brandValue) };\n}\nfunction _custom(typeName, brand) {\n const data = {\n arguments: {},\n returnType: null,\n authorization: [],\n typeName: typeName,\n handlers: null,\n subscriptionSource: [],\n };\n const builder = brandedBuilder({\n arguments(args) {\n data.arguments = args;\n return this;\n },\n returns(returnType) {\n data.returnType = returnType;\n return this;\n },\n authorization(callback) {\n const rules = callback(allowForCustomOperations);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n handler(handlers) {\n data.handlers = Array.isArray(handlers)\n ? handlers\n : [handlers];\n return this;\n },\n for(source) {\n data.subscriptionSource = Array.isArray(source) ? source : [source];\n return this;\n },\n }, brand);\n return { ...builder, data };\n}\n/**\n * Use a custom query to define an API request that will retrieve backend data.\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}\n * @example\n * const schema = a.schema({\n * echo: a\n * .query()\n * .arguments({ content: a.string() })\n * .returns(a.ref('EchoResponse'))\n * .authorization(allow => [allow.publicApiKey()])\n * // 3. set the function has the handler\n * .handler(a.handler.function(echoHandler)),\n *\n * EchoResponse: a.customType({\n * content: a.string(),\n * executionDuration: a.float()\n * }),\n * });\n * @returns a custom query\n */\nexport function query() {\n return _custom('Query', queryBrand);\n}\n/**\n * Use a custom mutation to define an API request that will modify backend data or trigger a subscription event.\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}\n * @example\n * likePost: a\n * .mutation()\n * .arguments({ postId: a.string() })\n * .returns(a.ref('Post'))\n * .authorization(allow => [allow.publicApiKey()])\n * .handler(a.handler.function(echoHandler))\n * @returns a custom mutation\n */\nexport function mutation() {\n return _custom('Mutation', mutationBrand);\n}\n/**\n * Define a custom subscription to receive an event when a mutation is triggered\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-subscription/}\n * @example\n * // Subscribe to incoming messages\n * receive: a.subscription()\n * // subscribes to the 'publish' mutation\n * .for(a.ref('publish'))\n * // subscription handler to set custom filters\n * .handler(a.handler.custom({entry: './receive.js'}))\n * // authorization rules as to who can subscribe to the data\n * .authorization(allow => [allow.publicApiKey()]),\n * @returns a custom subscription\n */\nexport function subscription() {\n return _custom('Subscription', subscriptionBrand);\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAC1C,MAAM,aAAa,GAAG,yBAAyB,CAAC;AAChD,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AAC5C,MAAC,oBAAoB,GAAG;AACpC,IAAI,OAAO;AACX,IAAI,UAAU;AACd,IAAI,cAAc;AAClB,EAAE;AACF,SAAS,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE;AAC7C,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;AAChD,CAAC;AACD,SAAS,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE;AAClC,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,SAAS,EAAE,EAAE;AACrB,QAAQ,UAAU,EAAE,IAAI;AACxB,QAAQ,aAAa,EAAE,EAAE;AACzB,QAAQ,QAAQ,EAAE,QAAQ;AAC1B,QAAQ,QAAQ,EAAE,IAAI;AACtB,QAAQ,kBAAkB,EAAE,EAAE;AAC9B,KAAK,CAAC;AACN,IAAI,MAAM,OAAO,GAAG,cAAc,CAAC;AACnC,QAAQ,SAAS,CAAC,IAAI,EAAE;AACxB,YAAY,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;AAClC,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,OAAO,CAAC,UAAU,EAAE;AAC5B,YAAY,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;AACzC,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,aAAa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AAc,EAAE,iBAAiB,CAAC,CAAC;AACtD;;;;"}
1
+ {"version":3,"file":"CustomOperation.mjs","sources":["../../src/CustomOperation.ts"],"sourcesContent":["import { brand } from './util';\nimport { allowForCustomOperations, } from './Authorization';\nconst queryBrand = 'queryCustomOperation';\nconst mutationBrand = 'mutationCustomOperation';\nconst subscriptionBrand = 'subscriptionCustomOperation';\nconst generationBrand = 'generationCustomOperation';\nexport const CustomOperationNames = [\n 'Query',\n 'Mutation',\n 'Subscription',\n 'Generation',\n];\nfunction brandedBuilder(builder, brandValue) {\n return { ...builder, ...brand(brandValue) };\n}\nfunction _custom(typeName, brand, input) {\n const data = {\n arguments: {},\n returnType: null,\n authorization: [],\n typeName: typeName,\n handlers: null,\n subscriptionSource: [],\n input,\n };\n const builder = brandedBuilder({\n arguments(args) {\n data.arguments = args;\n return this;\n },\n returns(returnType) {\n data.returnType = returnType;\n return this;\n },\n authorization(callback) {\n const rules = callback(allowForCustomOperations);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n handler(handlers) {\n data.handlers = Array.isArray(handlers)\n ? handlers\n : [handlers];\n return this;\n },\n for(source) {\n data.subscriptionSource = Array.isArray(source) ? source : [source];\n return this;\n },\n }, brand);\n return { ...builder, data };\n}\n/**\n * Use a custom query to define an API request that will retrieve backend data.\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}\n * @example\n * const schema = a.schema({\n * echo: a\n * .query()\n * .arguments({ content: a.string() })\n * .returns(a.ref('EchoResponse'))\n * .authorization(allow => [allow.publicApiKey()])\n * // 3. set the function has the handler\n * .handler(a.handler.function(echoHandler)),\n *\n * EchoResponse: a.customType({\n * content: a.string(),\n * executionDuration: a.float()\n * }),\n * });\n * @returns a custom query\n */\nexport function query() {\n return _custom('Query', queryBrand);\n}\n/**\n * Use a custom mutation to define an API request that will modify backend data or trigger a subscription event.\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}\n * @example\n * likePost: a\n * .mutation()\n * .arguments({ postId: a.string() })\n * .returns(a.ref('Post'))\n * .authorization(allow => [allow.publicApiKey()])\n * .handler(a.handler.function(echoHandler))\n * @returns a custom mutation\n */\nexport function mutation() {\n return _custom('Mutation', mutationBrand);\n}\n/**\n * Define a custom subscription to receive an event when a mutation is triggered\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-subscription/}\n * @example\n * // Subscribe to incoming messages\n * receive: a.subscription()\n * // subscribes to the 'publish' mutation\n * .for(a.ref('publish'))\n * // subscription handler to set custom filters\n * .handler(a.handler.custom({entry: './receive.js'}))\n * // authorization rules as to who can subscribe to the data\n * .authorization(allow => [allow.publicApiKey()]),\n * @returns a custom subscription\n */\nexport function subscription() {\n return _custom('Subscription', subscriptionBrand);\n}\n/**\n * @experimental\n *\n * Define an AI generation route for single request-response interaction with specified AI model.\n * @example\n * makeRecipe: a.generation({\n * aiModel: { resourcePath },\n * systemPrompt: 'Please make a recipe from the provided ingredients',\n * })\n * .arguments({ ingredients: a.string().array() })\n * .returns(a.ref(\"Recipe\"))\n * @returns a generation route definition\n */\nexport function generation(input) {\n return _custom('Generation', generationBrand, input);\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAC1C,MAAM,aAAa,GAAG,yBAAyB,CAAC;AAChD,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AACxD,MAAM,eAAe,GAAG,2BAA2B,CAAC;AACxC,MAAC,oBAAoB,GAAG;AACpC,IAAI,OAAO;AACX,IAAI,UAAU;AACd,IAAI,cAAc;AAClB,IAAI,YAAY;AAChB,EAAE;AACF,SAAS,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE;AAC7C,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;AAChD,CAAC;AACD,SAAS,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE;AACzC,IAAI,MAAM,IAAI,GAAG;A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C;AACd,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,GAAG;AACxB,IAAI,OAAO,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACxC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,QAAQ,GAAG;AAC3B,IAAI,OAAO,OAAO,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAC9C,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,YAAY,GAAG;AAC/B,IAAI,OAAO,OAAO,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;AACtD,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,UAAU,CAAC,KAAK,EAAE;AAClC,IAAI,OAAO,OAAO,CAAC,YAAY,EAAE,eAAe,EAAE,KAAK,CAAC,CAAC;AACzD;;;;"}
@@ -6,16 +6,18 @@ import type { CustomOperation, CustomOperationParamShape, InternalCustom, Mutati
6
6
  import { AllowModifier, SchemaAuthorization } from './Authorization';
7
7
  import { Brand, RenameUsingTuples } from './util';
8
8
  import { ModelRelationalField, ModelRelationalFieldParamShape } from './ModelRelationalField';
9
+ import { ConversationType } from './ai/ConversationType';
9
10
  export { ModelType } from './ModelType';
10
11
  export { EnumType } from './EnumType';
11
12
  export { CustomType } from './CustomType';
12
13
  export { CustomOperation } from './CustomOperation';
14
+ export { ConversationType } from './ai/ConversationType';
13
15
  export declare const rdsSchemaBrandName = "RDSSchema";
14
16
  export declare const rdsSchemaBrand: Brand<"RDSSchema">;
15
17
  export type RDSSchemaBrand = Brand<typeof rdsSchemaBrandName>;
16
18
  export declare const ddbSchemaBrandName = "DDBSchema";
17
19
  export type DDBSchemaBrand = Brand<typeof ddbSchemaBrandName>;
18
- type SchemaContent = BaseModelType | CustomType<CustomTypeParamShape> | EnumType | CustomOperation<CustomOperationParamShape, any>;
20
+ type SchemaContent = BaseModelType | CustomType<CustomTypeParamShape> | EnumType | CustomOperation<CustomOperationParamShape, any> | ConversationType;
19
21
  type AddToSchemaContent = Exclude<SchemaContent, BaseModelType>;
20
22
  type AddToSchemaContents = Record<string, AddToSchemaContent>;
21
23
  type NonEmpty<T> = keyof T extends never ? never : T;
@@ -1,4 +1,4 @@
1
- import { type InternalSchema } from './ModelSchema';
1
+ import type { InternalSchema } from './ModelSchema';
2
2
  import { DerivedApiDefinition } from '@aws-amplify/data-schema-types';
3
3
  /**
4
4
  * Returns API definition from ModelSchema or string schema
@@ -6,6 +6,8 @@ import { getBrand } from './util/Brand.mjs';
6
6
  import { getHandlerData } from './Handler.mjs';
7
7
  import * as os from 'os';
8
8
  import * as path from 'path';
9
+ import { brandName } from './ai/ConversationType.mjs';
10
+ import { createConversationField, conversationTypes } from './ai/ConversationSchemaTypes.mjs';
9
11
 
10
12
  function isInternalModel(model) {
11
13
  if (model.data &&
@@ -27,6 +29,12 @@ function isCustomType(data) {
27
29
  }
28
30
  return false;
29
31
  }
32
+ function isConversationRoute(type) {
33
+ return getBrand(type) === brandName;
34
+ }
35
+ function isGenerationInput(input) {
36
+ return Boolean(input?.aiModel && input?.systemPrompt);
37
+ }
30
38
  function isCustomOperation(type) {
31
39
  if (CustomOperationNames.includes(type?.data?.typeName)) {
32
40
  return true;
@@ -275,6 +283,19 @@ function customOperationToGql(typeName, typeDef, authorization, isCustom = false
275
283
  .join('", "');
276
284
  gqlHandlerContent += `@aws_subscribe(mutations: ["${subscriptionSources}"]) `;
277
285
  }
286
+ if (opType === 'Generation') {
287
+ if (!isGenerationInput(typeDef.data.input)) {
288
+ throw new Error(`Invalid Generation Route definition. A Generation Route must include a valid input. ${typeName} has an invalid or no input defined.`);
289
+ }
290
+ const { aiModel, systemPrompt, inferenceConfiguration } = typeDef.data.input;
291
+ const inferenceConfigurationEntries = Object.entries(inferenceConfiguration ?? {});
292
+ const inferenceConfigurationGql = inferenceConfigurationEntries.length > 0
293
+ ? `, inferenceConfiguration: { ${inferenceConfigurationEntries
294
+ .map(([key, value]) => `${key}: ${value}`)
295
+ .join(', ')} }`
296
+ : '';
297
+ gqlHandlerContent += `@generation(aiModel: "${aiModel.resourcePath}", systemPrompt: "${systemPrompt}"${inferenceConfigurationGql}) `;
298
+ }
278
299
  const gqlField = `${callSignature}: ${returnTypeName} ${gqlHandlerContent}${authString}`;
279
300
  return {
280
301
  gqlField,
@@ -782,6 +803,7 @@ const schemaPreprocessor = (schema) => {
782
803
  const customQueries = [];
783
804
  const customMutations = [];
784
805
  const customSubscriptions = [];
806
+ let shouldAddConversationTypes = false;
785
807
  // Dict of auth rules to be applied to custom types
786
808
  // Inherited from the auth configured on the custom operations that return these custom types
787
809
  const customTypeInheritedAuthRules = {};
@@ -825,6 +847,7 @@ const schemaPreprocessor = (schema) => {
825
847
  gqlModels.push(model);
826
848
  }
827
849
  else if (isCustomOperation(typeDef)) {
850
+ // TODO: add generation route logic.
828
851
  const { typeName: opType } = typeDef.data;
829
852
  const { gqlField, implicitTypes, customTypeAuthRules, jsFunctionForField, lambdaFunctionDefinition, customSqlDataSourceStrategy, } = transformCustomOperations(typeDef, typeName, mostRelevantAuthRules, databaseType, getRefType);
830
853
  topLevelTypes.push(...implicitTypes);
@@ -847,6 +870,7 @@ const schemaPreprocessor = (schema) => {
847
870
  }
848
871
  switch (opType) {
849
872
  case 'Query':
873
+ case 'Generation':
850
874
  customQueries.push(gqlField);
851
875
  break;
852
876
  case 'Mutation':
@@ -857,6 +881,11 @@ const schemaPreprocessor = (schema) => {
857
881
  break;
858
882
  }
859
883
  }
884
+ else if (isConversationRoute(typeDef)) {
885
+ // TODO: add inferenceConfiguration values to directive.
886
+ customMutations.push(createConversationField(typeDef, typeName));
887
+ shouldAddConversationTypes = true;
888
+ }
860
889
  }
861
890
  else if (staticSchema) {
862
891
  const fields = { ...typeDef.data.fields };
@@ -915,6 +944,9 @@ const schemaPreprocessor = (schema) => {
915
944
  subscriptions: customSubscriptions,
916
945
  };
917
946
  gqlModels.push(...generateCustomOperationTypes(customOperations));
947
+ if (shouldAddConversationTypes) {
948
+ gqlModels.push(...conversationTypes);
949
+ }
918
950
  const processedSchema = gqlModels.join('\n\n');
919
951
  return {
920
952
  schema: processedSchema,
@@ -928,8 +960,9 @@ function validateCustomOperations(typeDef, typeName, authRules, getRefType) {
928
960
  const { handlers, typeName: opType, subscriptionSource } = typeDef.data;
929
961
  const handlerConfigured = handlers?.length;
930
962
  const authConfigured = authRules.length > 0;
931
- if ((authConfigured && !handlerConfigured) ||
932
- (handlerConfigured && !authConfigured)) {
963
+ if (opType !== 'Generation' &&
964
+ ((authConfigured && !handlerConfigured) ||
965
+ (handlerConfigured && !authConfigured))) {
933
966
  // Deploying a custom operation with auth and no handler reference OR
934
967
  // with a handler reference but no auth
935
968
  // causes the CFN stack to reach an unrecoverable state. Ideally, this should be fixed
@@ -948,8 +981,9 @@ function validateCustomOperations(typeDef, typeName, authRules, getRefType) {
948
981
  }
949
982
  }
950
983
  if (typeDef.data.returnType === null &&
951
- (opType === 'Query' || opType === 'Mutation')) {
952
- throw new Error(`Invalid Custom ${opType} definition. A Custom ${opType} must include a return type. ${typeName} has no return type specified.`);
984
+ (opType === 'Query' || opType === 'Mutation' || opType === 'Generation')) {
985
+ const typeDescription = opType === 'Generation' ? 'Generation Route' : `Custom ${opType}`;
986
+ throw new Error(`Invalid ${typeDescription} definition. A ${typeDescription} must include a return type. ${typeName} has no return type specified.`);
953
987
  }
954
988
  if (opType !== 'Subscription' && subscriptionSource.length > 0) {
955
989
  throw new Error(`The .for() modifier function can only be used with a custom subscription. ${typeName} is not a custom subscription.`);
@@ -1063,7 +1097,9 @@ function transformCustomOperations(typeDef, typeName, authRules, databaseType, g
1063
1097
  let jsFunctionForField = undefined;
1064
1098
  validateCustomOperations(typeDef, typeName, authRules, getRefType);
1065
1099
  if (isCustomHandler(handlers)) {
1066
- jsFunctionForField = handleCustom(handlers, opType, typeName);
1100
+ jsFunctionForField = handleCustom(handlers,
1101
+ // Generation routes should not have handlers
1102
+ opType, typeName);
1067
1103
  }
1068
1104
  const isCustom = Boolean(jsFunctionForField);
1069
1105
  const { gqlField, implicitTypes, customTypeAuthRules, lambdaFunctionDefinition, customSqlDataSourceStrategy, } = customOperationToGql(typeName, typeDef, authRules, isCustom, databaseType, getRefType);