@aws-amplify/data-schema 1.4.1 → 1.5.1
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.
- package/dist/cjs/ClientSchema/ai/ClientConversation.js +6 -0
- package/dist/cjs/ClientSchema/ai/ClientConversation.js.map +1 -0
- package/dist/cjs/CustomOperation.js +22 -2
- package/dist/cjs/CustomOperation.js.map +1 -1
- package/dist/cjs/SchemaProcessor.js +41 -5
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/a.js +9 -1
- package/dist/cjs/a.js.map +1 -1
- package/dist/cjs/ai/ConversationSchemaTypes.js +210 -0
- package/dist/cjs/ai/ConversationSchemaTypes.js.map +1 -0
- package/dist/cjs/ai/ConversationType.js +27 -0
- package/dist/cjs/ai/ConversationType.js.map +1 -0
- package/dist/cjs/ai/ModelType.js +37 -0
- package/dist/cjs/ai/ModelType.js.map +1 -0
- package/dist/cjs/ai/types/ConversationMessageContent.js +6 -0
- package/dist/cjs/ai/types/ConversationMessageContent.js.map +1 -0
- package/dist/cjs/ai/types/ToolConfiguration.js +6 -0
- package/dist/cjs/ai/types/ToolConfiguration.js.map +1 -0
- package/dist/cjs/ai/types/ToolResultContent.js +6 -0
- package/dist/cjs/ai/types/ToolResultContent.js.map +1 -0
- package/dist/cjs/ai/types/contentBlocks.js +6 -0
- package/dist/cjs/ai/types/contentBlocks.js.map +1 -0
- package/dist/cjs/runtime/addSchemaToClient.js +2 -0
- package/dist/cjs/runtime/addSchemaToClient.js.map +1 -1
- package/dist/cjs/runtime/internals/APIClient.js +3 -3
- package/dist/cjs/runtime/internals/APIClient.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/conversationMessageDeserializers.js +54 -0
- package/dist/cjs/runtime/internals/ai/conversationMessageDeserializers.js.map +1 -0
- package/dist/cjs/runtime/internals/ai/conversationMessageSerializers.js +58 -0
- package/dist/cjs/runtime/internals/ai/conversationMessageSerializers.js.map +1 -0
- package/dist/cjs/runtime/internals/ai/convertItemToConversation.js +22 -0
- package/dist/cjs/runtime/internals/ai/convertItemToConversation.js.map +1 -0
- package/dist/cjs/runtime/internals/ai/convertItemToConversationMessage.js +16 -0
- package/dist/cjs/runtime/internals/ai/convertItemToConversationMessage.js.map +1 -0
- package/dist/cjs/runtime/internals/ai/createCreateConversationFunction.js +18 -0
- package/dist/cjs/runtime/internals/ai/createCreateConversationFunction.js.map +1 -0
- package/dist/cjs/runtime/internals/ai/createGetConversationFunction.js +20 -0
- package/dist/cjs/runtime/internals/ai/createGetConversationFunction.js.map +1 -0
- package/dist/cjs/runtime/internals/ai/createListConversationsFunction.js +21 -0
- package/dist/cjs/runtime/internals/ai/createListConversationsFunction.js.map +1 -0
- package/dist/cjs/runtime/internals/ai/createListMessagesFunction.js +22 -0
- package/dist/cjs/runtime/internals/ai/createListMessagesFunction.js.map +1 -0
- package/dist/cjs/runtime/internals/ai/createOnMessageFunction.js +22 -0
- package/dist/cjs/runtime/internals/ai/createOnMessageFunction.js.map +1 -0
- package/dist/cjs/runtime/internals/ai/createSendMessageFunction.js +32 -0
- package/dist/cjs/runtime/internals/ai/createSendMessageFunction.js.map +1 -0
- package/dist/cjs/runtime/internals/index.js +5 -1
- package/dist/cjs/runtime/internals/index.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/custom.js +17 -10
- package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/subscription.js +11 -3
- package/dist/cjs/runtime/internals/operations/subscription.js.map +1 -1
- package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js +48 -0
- package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js.map +1 -0
- package/dist/cjs/runtime/internals/utils/clientProperties/generateGenerationsProperty.js +22 -0
- package/dist/cjs/runtime/internals/utils/clientProperties/generateGenerationsProperty.js.map +1 -0
- package/dist/esm/ClientSchema/Core/ClientSchemaProperty.d.ts +1 -1
- package/dist/esm/ClientSchema/ai/ClientConversation.d.ts +7 -0
- package/dist/esm/ClientSchema/ai/ClientConversation.mjs +2 -0
- package/dist/esm/ClientSchema/ai/ClientConversation.mjs.map +1 -0
- package/dist/esm/ClientSchema/index.d.ts +12 -2
- package/dist/esm/CustomOperation.d.ts +33 -2
- package/dist/esm/CustomOperation.mjs +21 -2
- package/dist/esm/CustomOperation.mjs.map +1 -1
- package/dist/esm/ModelSchema.d.ts +3 -1
- package/dist/esm/SchemaProcessor.d.ts +1 -1
- package/dist/esm/SchemaProcessor.mjs +41 -5
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/a.d.ts +7 -2
- package/dist/esm/a.mjs +9 -1
- package/dist/esm/a.mjs.map +1 -1
- package/dist/esm/ai/ConversationSchemaTypes.d.ts +3 -0
- package/dist/esm/ai/ConversationSchemaTypes.mjs +208 -0
- package/dist/esm/ai/ConversationSchemaTypes.mjs.map +1 -0
- package/dist/esm/ai/ConversationType.d.ts +102 -0
- package/dist/esm/ai/ConversationType.mjs +25 -0
- package/dist/esm/ai/ConversationType.mjs.map +1 -0
- package/dist/esm/ai/ModelType.d.ts +30 -0
- package/dist/esm/ai/ModelType.mjs +34 -0
- package/dist/esm/ai/ModelType.mjs.map +1 -0
- package/dist/esm/ai/types/ConversationMessageContent.d.ts +27 -0
- package/dist/esm/ai/types/ConversationMessageContent.mjs +2 -0
- package/dist/esm/ai/types/ConversationMessageContent.mjs.map +1 -0
- package/dist/esm/ai/types/ToolConfiguration.d.ts +18 -0
- package/dist/esm/ai/types/ToolConfiguration.mjs +2 -0
- package/dist/esm/ai/types/ToolConfiguration.mjs.map +1 -0
- package/dist/esm/ai/types/ToolResultContent.d.ts +18 -0
- package/dist/esm/ai/types/ToolResultContent.mjs +2 -0
- package/dist/esm/ai/types/ToolResultContent.mjs.map +1 -0
- package/dist/esm/ai/types/contentBlocks.d.ts +19 -0
- package/dist/esm/ai/types/contentBlocks.mjs +2 -0
- package/dist/esm/ai/types/contentBlocks.mjs.map +1 -0
- package/dist/esm/runtime/addSchemaToClient.mjs +4 -0
- package/dist/esm/runtime/addSchemaToClient.mjs.map +1 -1
- package/dist/esm/runtime/addSchemaToClientWithInstance.mjs +2 -1
- package/dist/esm/runtime/addSchemaToClientWithInstance.mjs.map +1 -1
- package/dist/esm/runtime/bridge-types.d.ts +29 -3
- package/dist/esm/runtime/client/index.d.ts +8 -1
- package/dist/esm/runtime/internals/APIClient.mjs +3 -3
- package/dist/esm/runtime/internals/APIClient.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.d.ts +2 -0
- package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.mjs +52 -0
- package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.mjs.map +1 -0
- package/dist/esm/runtime/internals/ai/conversationMessageSerializers.d.ts +37 -0
- package/dist/esm/runtime/internals/ai/conversationMessageSerializers.mjs +54 -0
- package/dist/esm/runtime/internals/ai/conversationMessageSerializers.mjs.map +1 -0
- package/dist/esm/runtime/internals/ai/convertItemToConversation.d.ts +3 -0
- package/dist/esm/runtime/internals/ai/convertItemToConversation.mjs +20 -0
- package/dist/esm/runtime/internals/ai/convertItemToConversation.mjs.map +1 -0
- package/dist/esm/runtime/internals/ai/convertItemToConversationMessage.d.ts +7 -0
- package/dist/esm/runtime/internals/ai/convertItemToConversationMessage.mjs +14 -0
- package/dist/esm/runtime/internals/ai/convertItemToConversationMessage.mjs.map +1 -0
- package/dist/esm/runtime/internals/ai/createCreateConversationFunction.d.ts +3 -0
- package/dist/esm/runtime/internals/ai/createCreateConversationFunction.mjs +16 -0
- package/dist/esm/runtime/internals/ai/createCreateConversationFunction.mjs.map +1 -0
- package/dist/esm/runtime/internals/ai/createGetConversationFunction.d.ts +3 -0
- package/dist/esm/runtime/internals/ai/createGetConversationFunction.mjs +18 -0
- package/dist/esm/runtime/internals/ai/createGetConversationFunction.mjs.map +1 -0
- package/dist/esm/runtime/internals/ai/createListConversationsFunction.d.ts +3 -0
- package/dist/esm/runtime/internals/ai/createListConversationsFunction.mjs +19 -0
- package/dist/esm/runtime/internals/ai/createListConversationsFunction.mjs.map +1 -0
- package/dist/esm/runtime/internals/ai/createListMessagesFunction.d.ts +3 -0
- package/dist/esm/runtime/internals/ai/createListMessagesFunction.mjs +20 -0
- package/dist/esm/runtime/internals/ai/createListMessagesFunction.mjs.map +1 -0
- package/dist/esm/runtime/internals/ai/createOnMessageFunction.d.ts +3 -0
- package/dist/esm/runtime/internals/ai/createOnMessageFunction.mjs +20 -0
- package/dist/esm/runtime/internals/ai/createOnMessageFunction.mjs.map +1 -0
- package/dist/esm/runtime/internals/ai/createSendMessageFunction.d.ts +3 -0
- package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs +30 -0
- package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs.map +1 -0
- package/dist/esm/runtime/internals/index.d.ts +2 -0
- package/dist/esm/runtime/internals/index.mjs +2 -0
- package/dist/esm/runtime/internals/index.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/custom.d.ts +1 -1
- package/dist/esm/runtime/internals/operations/custom.mjs +17 -10
- package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/subscription.mjs +12 -4
- package/dist/esm/runtime/internals/operations/subscription.mjs.map +1 -1
- package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.d.ts +3 -0
- package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs +46 -0
- package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs.map +1 -0
- package/dist/esm/runtime/internals/utils/clientProperties/generateGenerationsProperty.d.ts +3 -0
- package/dist/esm/runtime/internals/utils/clientProperties/generateGenerationsProperty.mjs +20 -0
- package/dist/esm/runtime/internals/utils/clientProperties/generateGenerationsProperty.mjs.map +1 -0
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +3 -1
- package/src/ClientSchema/Core/ClientSchemaProperty.ts +3 -1
- package/src/ClientSchema/ai/ClientConversation.ts +15 -0
- package/src/ClientSchema/index.ts +15 -1
- package/src/CustomOperation.ts +48 -5
- package/src/ModelSchema.ts +4 -1
- package/src/SchemaProcessor.ts +73 -8
- package/src/a.ts +10 -1
- package/src/ai/ConversationSchemaTypes.ts +253 -0
- package/src/ai/ConversationType.ts +135 -0
- package/src/ai/ModelType.ts +43 -0
- package/src/ai/types/ConversationMessageContent.ts +43 -0
- package/src/ai/types/ToolConfiguration.ts +24 -0
- package/src/ai/types/ToolResultContent.ts +28 -0
- package/src/ai/types/contentBlocks.ts +26 -0
- package/src/runtime/addSchemaToClient.ts +12 -0
- package/src/runtime/bridge-types.ts +41 -4
- package/src/runtime/client/index.ts +17 -1
- package/src/runtime/internals/APIClient.ts +3 -4
- package/src/runtime/internals/ai/conversationMessageDeserializers.ts +62 -0
- package/src/runtime/internals/ai/conversationMessageSerializers.ts +68 -0
- package/src/runtime/internals/ai/convertItemToConversation.ts +53 -0
- package/src/runtime/internals/ai/convertItemToConversationMessage.ts +18 -0
- package/src/runtime/internals/ai/createCreateConversationFunction.ts +44 -0
- package/src/runtime/internals/ai/createGetConversationFunction.ts +48 -0
- package/src/runtime/internals/ai/createListConversationsFunction.ts +46 -0
- package/src/runtime/internals/ai/createListMessagesFunction.ts +42 -0
- package/src/runtime/internals/ai/createOnMessageFunction.ts +41 -0
- package/src/runtime/internals/ai/createSendMessageFunction.ts +60 -0
- package/src/runtime/internals/index.ts +2 -0
- package/src/runtime/internals/operations/custom.ts +24 -12
- package/src/runtime/internals/operations/subscription.ts +18 -10
- package/src/runtime/internals/utils/clientProperties/generateConversationsProperty.ts +91 -0
- package/src/runtime/internals/utils/clientProperties/generateGenerationsProperty.ts +41 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientConversation.js","sources":["../../../../src/ClientSchema/ai/ClientConversation.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;;"}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.subscription = exports.mutation = exports.query = exports.CustomOperationNames = void 0;
|
|
4
|
+
exports.generation = exports.subscription = exports.mutation = exports.query = exports.CustomOperationNames = void 0;
|
|
5
5
|
const util_1 = require("./util");
|
|
6
6
|
const Authorization_1 = require("./Authorization");
|
|
7
7
|
const queryBrand = 'queryCustomOperation';
|
|
8
8
|
const mutationBrand = 'mutationCustomOperation';
|
|
9
9
|
const subscriptionBrand = 'subscriptionCustomOperation';
|
|
10
|
+
const generationBrand = 'generationCustomOperation';
|
|
10
11
|
exports.CustomOperationNames = [
|
|
11
12
|
'Query',
|
|
12
13
|
'Mutation',
|
|
13
14
|
'Subscription',
|
|
15
|
+
'Generation',
|
|
14
16
|
];
|
|
15
17
|
function brandedBuilder(builder, brandValue) {
|
|
16
18
|
return { ...builder, ...(0, util_1.brand)(brandValue) };
|
|
17
19
|
}
|
|
18
|
-
function _custom(typeName, brand) {
|
|
20
|
+
function _custom(typeName, brand, input) {
|
|
19
21
|
const data = {
|
|
20
22
|
arguments: {},
|
|
21
23
|
returnType: null,
|
|
@@ -23,6 +25,7 @@ function _custom(typeName, brand) {
|
|
|
23
25
|
typeName: typeName,
|
|
24
26
|
handlers: null,
|
|
25
27
|
subscriptionSource: [],
|
|
28
|
+
input,
|
|
26
29
|
};
|
|
27
30
|
const builder = brandedBuilder({
|
|
28
31
|
arguments(args) {
|
|
@@ -109,4 +112,21 @@ function subscription() {
|
|
|
109
112
|
return _custom('Subscription', subscriptionBrand);
|
|
110
113
|
}
|
|
111
114
|
exports.subscription = subscription;
|
|
115
|
+
/**
|
|
116
|
+
* @experimental
|
|
117
|
+
*
|
|
118
|
+
* Define an AI generation route for single request-response interaction with specified AI model.
|
|
119
|
+
* @example
|
|
120
|
+
* makeRecipe: a.generation({
|
|
121
|
+
* aiModel: { resourcePath },
|
|
122
|
+
* systemPrompt: 'Please make a recipe from the provided ingredients',
|
|
123
|
+
* })
|
|
124
|
+
* .arguments({ ingredients: a.string().array() })
|
|
125
|
+
* .returns(a.ref("Recipe"))
|
|
126
|
+
* @returns a generation route definition
|
|
127
|
+
*/
|
|
128
|
+
function generation(input) {
|
|
129
|
+
return _custom('Generation', generationBrand, input);
|
|
130
|
+
}
|
|
131
|
+
exports.generation = generation;
|
|
112
132
|
//# sourceMappingURL=CustomOperation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomOperation.js","sources":["../../src/CustomOperation.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.subscription = exports.mutation = exports.query = exports.CustomOperationNames = void 0;\nconst util_1 = require(\"./util\");\nconst Authorization_1 = require(\"./Authorization\");\nconst queryBrand = 'queryCustomOperation';\nconst mutationBrand = 'mutationCustomOperation';\nconst subscriptionBrand = 'subscriptionCustomOperation';\nexports.CustomOperationNames = [\n 'Query',\n 'Mutation',\n 'Subscription',\n];\nfunction brandedBuilder(builder, brandValue) {\n return { ...builder, ...(0, util_1.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(Authorization_1.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 */\nfunction query() {\n return _custom('Query', queryBrand);\n}\nexports.query = query;\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 */\nfunction mutation() {\n return _custom('Mutation', mutationBrand);\n}\nexports.mutation = mutation;\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 */\nfunction subscription() {\n return _custom('Subscription', subscriptionBrand);\n}\nexports.subscription = subscription;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"CustomOperation.js","sources":["../../src/CustomOperation.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generation = exports.subscription = exports.mutation = exports.query = exports.CustomOperationNames = void 0;\nconst util_1 = require(\"./util\");\nconst Authorization_1 = require(\"./Authorization\");\nconst queryBrand = 'queryCustomOperation';\nconst mutationBrand = 'mutationCustomOperation';\nconst subscriptionBrand = 'subscriptionCustomOperation';\nconst generationBrand = 'generationCustomOperation';\nexports.CustomOperationNames = [\n 'Query',\n 'Mutation',\n 'Subscription',\n 'Generation',\n];\nfunction brandedBuilder(builder, brandValue) {\n return { ...builder, ...(0, util_1.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(Authorization_1.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 */\nfunction query() {\n return _custom('Query', queryBrand);\n}\nexports.query = query;\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 */\nfunction mutation() {\n return _custom('Mutation', mutationBrand);\n}\nexports.mutation = mutation;\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 */\nfunction subscription() {\n return _custom('Subscription', subscriptionBrand);\n}\nexports.subscription = subscription;\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 */\nfunction generation(input) {\n return _custom('Generation', generationBrand, input);\n}\nexports.generation = generation;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAC,CAAC;AACrH,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,eAAe,GAAG,OAAO,CAAC,iBA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AC;AACD,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,UAAU,CAAC,KAAK,EAAE;AAC3B,IAAI,OAAO,OAAO,CAAC,YAAY,EAAE,eAAe,EAAE,KAAK,CAAC,CAAC;AACzD,CAAC;AACD,OAAO,CAAC,UAAU,GAAG,UAAU;;"}
|
|
@@ -11,6 +11,8 @@ const util_1 = require("./util");
|
|
|
11
11
|
const Handler_1 = require("./Handler");
|
|
12
12
|
const os = tslib_1.__importStar(require("os"));
|
|
13
13
|
const path = tslib_1.__importStar(require("path"));
|
|
14
|
+
const ConversationType_1 = require("./ai/ConversationType");
|
|
15
|
+
const ConversationSchemaTypes_1 = require("./ai/ConversationSchemaTypes");
|
|
14
16
|
function isInternalModel(model) {
|
|
15
17
|
if (model.data &&
|
|
16
18
|
!isCustomType(model) &&
|
|
@@ -31,6 +33,12 @@ function isCustomType(data) {
|
|
|
31
33
|
}
|
|
32
34
|
return false;
|
|
33
35
|
}
|
|
36
|
+
function isConversationRoute(type) {
|
|
37
|
+
return (0, util_1.getBrand)(type) === ConversationType_1.brandName;
|
|
38
|
+
}
|
|
39
|
+
function isGenerationInput(input) {
|
|
40
|
+
return Boolean(input?.aiModel && input?.systemPrompt);
|
|
41
|
+
}
|
|
34
42
|
function isCustomOperation(type) {
|
|
35
43
|
if (CustomOperation_1.CustomOperationNames.includes(type?.data?.typeName)) {
|
|
36
44
|
return true;
|
|
@@ -279,6 +287,19 @@ function customOperationToGql(typeName, typeDef, authorization, isCustom = false
|
|
|
279
287
|
.join('", "');
|
|
280
288
|
gqlHandlerContent += `@aws_subscribe(mutations: ["${subscriptionSources}"]) `;
|
|
281
289
|
}
|
|
290
|
+
if (opType === 'Generation') {
|
|
291
|
+
if (!isGenerationInput(typeDef.data.input)) {
|
|
292
|
+
throw new Error(`Invalid Generation Route definition. A Generation Route must include a valid input. ${typeName} has an invalid or no input defined.`);
|
|
293
|
+
}
|
|
294
|
+
const { aiModel, systemPrompt, inferenceConfiguration } = typeDef.data.input;
|
|
295
|
+
const inferenceConfigurationEntries = Object.entries(inferenceConfiguration ?? {});
|
|
296
|
+
const inferenceConfigurationGql = inferenceConfigurationEntries.length > 0
|
|
297
|
+
? `, inferenceConfiguration: { ${inferenceConfigurationEntries
|
|
298
|
+
.map(([key, value]) => `${key}: ${value}`)
|
|
299
|
+
.join(', ')} }`
|
|
300
|
+
: '';
|
|
301
|
+
gqlHandlerContent += `@generation(aiModel: "${aiModel.resourcePath}", systemPrompt: "${systemPrompt}"${inferenceConfigurationGql}) `;
|
|
302
|
+
}
|
|
282
303
|
const gqlField = `${callSignature}: ${returnTypeName} ${gqlHandlerContent}${authString}`;
|
|
283
304
|
return {
|
|
284
305
|
gqlField,
|
|
@@ -786,6 +807,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
786
807
|
const customQueries = [];
|
|
787
808
|
const customMutations = [];
|
|
788
809
|
const customSubscriptions = [];
|
|
810
|
+
let shouldAddConversationTypes = false;
|
|
789
811
|
// Dict of auth rules to be applied to custom types
|
|
790
812
|
// Inherited from the auth configured on the custom operations that return these custom types
|
|
791
813
|
const customTypeInheritedAuthRules = {};
|
|
@@ -829,6 +851,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
829
851
|
gqlModels.push(model);
|
|
830
852
|
}
|
|
831
853
|
else if (isCustomOperation(typeDef)) {
|
|
854
|
+
// TODO: add generation route logic.
|
|
832
855
|
const { typeName: opType } = typeDef.data;
|
|
833
856
|
const { gqlField, implicitTypes, customTypeAuthRules, jsFunctionForField, lambdaFunctionDefinition, customSqlDataSourceStrategy, } = transformCustomOperations(typeDef, typeName, mostRelevantAuthRules, databaseType, getRefType);
|
|
834
857
|
topLevelTypes.push(...implicitTypes);
|
|
@@ -851,6 +874,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
851
874
|
}
|
|
852
875
|
switch (opType) {
|
|
853
876
|
case 'Query':
|
|
877
|
+
case 'Generation':
|
|
854
878
|
customQueries.push(gqlField);
|
|
855
879
|
break;
|
|
856
880
|
case 'Mutation':
|
|
@@ -861,6 +885,11 @@ const schemaPreprocessor = (schema) => {
|
|
|
861
885
|
break;
|
|
862
886
|
}
|
|
863
887
|
}
|
|
888
|
+
else if (isConversationRoute(typeDef)) {
|
|
889
|
+
// TODO: add inferenceConfiguration values to directive.
|
|
890
|
+
customMutations.push((0, ConversationSchemaTypes_1.createConversationField)(typeDef, typeName));
|
|
891
|
+
shouldAddConversationTypes = true;
|
|
892
|
+
}
|
|
864
893
|
}
|
|
865
894
|
else if (staticSchema) {
|
|
866
895
|
const fields = { ...typeDef.data.fields };
|
|
@@ -919,6 +948,9 @@ const schemaPreprocessor = (schema) => {
|
|
|
919
948
|
subscriptions: customSubscriptions,
|
|
920
949
|
};
|
|
921
950
|
gqlModels.push(...generateCustomOperationTypes(customOperations));
|
|
951
|
+
if (shouldAddConversationTypes) {
|
|
952
|
+
gqlModels.push(...ConversationSchemaTypes_1.conversationTypes);
|
|
953
|
+
}
|
|
922
954
|
const processedSchema = gqlModels.join('\n\n');
|
|
923
955
|
return {
|
|
924
956
|
schema: processedSchema,
|
|
@@ -932,8 +964,9 @@ function validateCustomOperations(typeDef, typeName, authRules, getRefType) {
|
|
|
932
964
|
const { handlers, typeName: opType, subscriptionSource } = typeDef.data;
|
|
933
965
|
const handlerConfigured = handlers?.length;
|
|
934
966
|
const authConfigured = authRules.length > 0;
|
|
935
|
-
if (
|
|
936
|
-
(
|
|
967
|
+
if (opType !== 'Generation' &&
|
|
968
|
+
((authConfigured && !handlerConfigured) ||
|
|
969
|
+
(handlerConfigured && !authConfigured))) {
|
|
937
970
|
// Deploying a custom operation with auth and no handler reference OR
|
|
938
971
|
// with a handler reference but no auth
|
|
939
972
|
// causes the CFN stack to reach an unrecoverable state. Ideally, this should be fixed
|
|
@@ -952,8 +985,9 @@ function validateCustomOperations(typeDef, typeName, authRules, getRefType) {
|
|
|
952
985
|
}
|
|
953
986
|
}
|
|
954
987
|
if (typeDef.data.returnType === null &&
|
|
955
|
-
(opType === 'Query' || opType === 'Mutation')) {
|
|
956
|
-
|
|
988
|
+
(opType === 'Query' || opType === 'Mutation' || opType === 'Generation')) {
|
|
989
|
+
const typeDescription = opType === 'Generation' ? 'Generation Route' : `Custom ${opType}`;
|
|
990
|
+
throw new Error(`Invalid ${typeDescription} definition. A ${typeDescription} must include a return type. ${typeName} has no return type specified.`);
|
|
957
991
|
}
|
|
958
992
|
if (opType !== 'Subscription' && subscriptionSource.length > 0) {
|
|
959
993
|
throw new Error(`The .for() modifier function can only be used with a custom subscription. ${typeName} is not a custom subscription.`);
|
|
@@ -1067,7 +1101,9 @@ function transformCustomOperations(typeDef, typeName, authRules, databaseType, g
|
|
|
1067
1101
|
let jsFunctionForField = undefined;
|
|
1068
1102
|
validateCustomOperations(typeDef, typeName, authRules, getRefType);
|
|
1069
1103
|
if (isCustomHandler(handlers)) {
|
|
1070
|
-
jsFunctionForField = handleCustom(handlers,
|
|
1104
|
+
jsFunctionForField = handleCustom(handlers,
|
|
1105
|
+
// Generation routes should not have handlers
|
|
1106
|
+
opType, typeName);
|
|
1071
1107
|
}
|
|
1072
1108
|
const isCustom = Boolean(jsFunctionForField);
|
|
1073
1109
|
const { gqlField, implicitTypes, customTypeAuthRules, lambdaFunctionDefinition, customSqlDataSourceStrategy, } = customOperationToGql(typeName, typeDef, authRules, isCustom, databaseType, getRefType);
|