@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.
- 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/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 +35 -19
- 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/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 +82 -23
- 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/utils/clientProperties/generateConversationsProperty.ts +91 -0
- 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.
|
|
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": {
|
|
@@ -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
|
-
:
|
|
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
|
};
|
package/src/CustomOperation.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/ModelSchema.ts
CHANGED
|
@@ -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>;
|
package/src/SchemaProcessor.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
1501
|
-
(
|
|
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
|
|
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(
|
|
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
|
};
|