@aws-amplify/data-schema 1.13.2 → 1.13.3

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.
@@ -0,0 +1,190 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.CONVERSATION_SCHEMA_GRAPHQL_TYPES = void 0;
5
+ exports.CONVERSATION_SCHEMA_GRAPHQL_TYPES =
6
+ /* GraphQL */ `enum ConversationParticipantRole {
7
+ user
8
+ assistant
9
+ }
10
+
11
+ interface ConversationMessage {
12
+ id: ID!
13
+ conversationId: ID!
14
+ associatedUserMessageId: ID
15
+ role: ConversationParticipantRole
16
+ content: [ContentBlock]
17
+ aiContext: AWSJSON
18
+ toolConfiguration: ToolConfiguration
19
+ createdAt: AWSDateTime
20
+ updatedAt: AWSDateTime
21
+ owner: String
22
+ }
23
+
24
+ input DocumentBlockSourceInput {
25
+ bytes: String
26
+ }
27
+
28
+ input DocumentBlockInput {
29
+ format: String!
30
+ name: String!
31
+ source: DocumentBlockSourceInput!
32
+ }
33
+
34
+ input ImageBlockSourceInput {
35
+ bytes: String
36
+ }
37
+
38
+ input ImageBlockInput {
39
+ format: String!
40
+ source: ImageBlockSourceInput!
41
+ }
42
+
43
+ input ToolUseBlockInput {
44
+ toolUseId: String!
45
+ name: String!
46
+ input: AWSJSON!
47
+ }
48
+
49
+ input ToolResultContentBlockInput {
50
+ document: DocumentBlockInput
51
+ image: ImageBlockInput
52
+ json: AWSJSON
53
+ text: String
54
+ }
55
+
56
+ input ToolResultBlockInput {
57
+ content: [ToolResultContentBlockInput!]!
58
+ toolUseId: String!
59
+ status: String
60
+ }
61
+
62
+ type DocumentBlockSource {
63
+ bytes: String
64
+ }
65
+
66
+ type DocumentBlock {
67
+ format: String!
68
+ name: String!
69
+ source: DocumentBlockSource!
70
+ }
71
+
72
+ type ImageBlock {
73
+ format: String!
74
+ source: ImageBlockSource!
75
+ }
76
+
77
+ type ImageBlockSource {
78
+ bytes: String
79
+ }
80
+
81
+ type ToolUseBlock {
82
+ toolUseId: String!
83
+ name: String!
84
+ input: AWSJSON!
85
+ }
86
+
87
+ type ToolResultContentBlock {
88
+ document: DocumentBlock
89
+ image: ImageBlock
90
+ json: AWSJSON
91
+ text: String
92
+ }
93
+
94
+ type ToolResultBlock {
95
+ content: [ToolResultContentBlock!]!
96
+ toolUseId: String!
97
+ status: String
98
+ }
99
+
100
+ type ContentBlockText {
101
+ text: String
102
+ }
103
+
104
+ type ContentBlockImage {
105
+ image: ImageBlock
106
+ }
107
+
108
+ type ContentBlockDocument {
109
+ document: DocumentBlock
110
+ }
111
+
112
+ type ContentBlockToolUse {
113
+ toolUse: ToolUseBlock
114
+ }
115
+
116
+ type ContentBlockToolResult {
117
+ toolResult: ToolResultBlock
118
+ }
119
+
120
+ input ContentBlockInput {
121
+ text: String
122
+ document: DocumentBlockInput
123
+ image: ImageBlockInput
124
+ toolResult: ToolResultBlockInput
125
+ toolUse: ToolUseBlockInput
126
+ }
127
+
128
+ type ContentBlock {
129
+ text: String
130
+ document: DocumentBlock
131
+ image: ImageBlock
132
+ toolResult: ToolResultBlock
133
+ toolUse: ToolUseBlock
134
+ }
135
+
136
+ input ToolConfigurationInput {
137
+ tools: [ToolInput]
138
+ }
139
+
140
+ input ToolInput {
141
+ toolSpec: ToolSpecificationInput
142
+ }
143
+
144
+ input ToolSpecificationInput {
145
+ name: String!
146
+ description: String
147
+ inputSchema: ToolInputSchemaInput!
148
+ }
149
+
150
+ input ToolInputSchemaInput {
151
+ json: AWSJSON
152
+ }
153
+
154
+ type ToolConfiguration {
155
+ tools: [Tool]
156
+ }
157
+
158
+ type Tool {
159
+ toolSpec: ToolSpecification
160
+ }
161
+
162
+ type ToolSpecification {
163
+ name: String!
164
+ description: String
165
+ inputSchema: ToolInputSchema!
166
+ }
167
+
168
+ type ToolInputSchema {
169
+ json: AWSJSON
170
+ }
171
+
172
+ type ConversationMessageStreamPart @aws_cognito_user_pools {
173
+ id: ID!
174
+ owner: String
175
+ conversationId: ID!
176
+ associatedUserMessageId: ID!
177
+ contentBlockIndex: Int
178
+ contentBlockText: String
179
+ contentBlockDeltaIndex: Int
180
+ contentBlockToolUse: ToolUseBlock
181
+ contentBlockDoneAtIndex: Int
182
+ stopReason: String
183
+ errors: [ConversationTurnError]
184
+ }
185
+
186
+ type ConversationTurnError @aws_cognito_user_pools {
187
+ message: String!
188
+ errorType: String!
189
+ }`;
190
+ //# sourceMappingURL=ConversationSchemaGraphQLTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConversationSchemaGraphQLTypes.js","sources":["../../../src/ai/ConversationSchemaGraphQLTypes.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.CONVERSATION_SCHEMA_GRAPHQL_TYPES = void 0;\nexports.CONVERSATION_SCHEMA_GRAPHQL_TYPES = \n/* GraphQL */ `enum ConversationParticipantRole {\n user\n assistant\n}\n\ninterface ConversationMessage {\n id: ID!\n conversationId: ID!\n associatedUserMessageId: ID\n role: ConversationParticipantRole\n content: [ContentBlock]\n aiContext: AWSJSON\n toolConfiguration: ToolConfiguration\n createdAt: AWSDateTime\n updatedAt: AWSDateTime\n owner: String\n}\n\ninput DocumentBlockSourceInput {\n bytes: String\n}\n\ninput DocumentBlockInput {\n format: String!\n name: String!\n source: DocumentBlockSourceInput!\n}\n\ninput ImageBlockSourceInput {\n bytes: String\n}\n\ninput ImageBlockInput {\n format: String!\n source: ImageBlockSourceInput!\n}\n\ninput ToolUseBlockInput {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}\n\ninput ToolResultContentBlockInput {\n document: DocumentBlockInput\n image: ImageBlockInput\n json: AWSJSON\n text: String\n}\n\ninput ToolResultBlockInput {\n content: [ToolResultContentBlockInput!]!\n toolUseId: String!\n status: String\n}\n\ntype DocumentBlockSource {\n bytes: String\n}\n\ntype DocumentBlock {\n format: String!\n name: String!\n source: DocumentBlockSource!\n}\n\ntype ImageBlock {\n format: String!\n source: ImageBlockSource!\n}\n\ntype ImageBlockSource {\n bytes: String\n}\n\ntype ToolUseBlock {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}\n\ntype ToolResultContentBlock {\n document: DocumentBlock\n image: ImageBlock\n json: AWSJSON\n text: String\n}\n\ntype ToolResultBlock {\n content: [ToolResultContentBlock!]!\n toolUseId: String!\n status: String\n}\n\ntype ContentBlockText {\n text: String\n}\n\ntype ContentBlockImage {\n image: ImageBlock\n}\n\ntype ContentBlockDocument {\n document: DocumentBlock\n}\n\ntype ContentBlockToolUse {\n toolUse: ToolUseBlock\n}\n\ntype ContentBlockToolResult {\n toolResult: ToolResultBlock\n}\n\ninput ContentBlockInput {\n text: String\n document: DocumentBlockInput\n image: ImageBlockInput\n toolResult: ToolResultBlockInput\n toolUse: ToolUseBlockInput\n}\n\ntype ContentBlock {\n text: String\n document: DocumentBlock\n image: ImageBlock\n toolResult: ToolResultBlock\n toolUse: ToolUseBlock\n}\n\ninput ToolConfigurationInput {\n tools: [ToolInput]\n}\n\ninput ToolInput {\n toolSpec: ToolSpecificationInput\n}\n\ninput ToolSpecificationInput {\n name: String!\n description: String\n inputSchema: ToolInputSchemaInput!\n}\n\ninput ToolInputSchemaInput {\n json: AWSJSON\n}\n\ntype ToolConfiguration {\n tools: [Tool]\n}\n\ntype Tool {\n toolSpec: ToolSpecification\n}\n\ntype ToolSpecification {\n name: String!\n description: String\n inputSchema: ToolInputSchema!\n}\n\ntype ToolInputSchema {\n json: AWSJSON\n}\n\ntype ConversationMessageStreamPart @aws_cognito_user_pools {\n id: ID!\n owner: String\n conversationId: ID!\n associatedUserMessageId: ID!\n contentBlockIndex: Int\n contentBlockText: String\n contentBlockDeltaIndex: Int\n contentBlockToolUse: ToolUseBlock\n contentBlockDoneAtIndex: Int\n stopReason: String\n errors: [ConversationTurnError]\n}\n\ntype ConversationTurnError @aws_cognito_user_pools {\n message: String!\n errorType: String!\n}`;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,iCAAiC,GAAG,KAAK,CAAC,CAAC;AACnD,OAAO,CAAC,iCAAiC;AACzC,cAAc,CAAC;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC,CAAC;;"}
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createConversationField = void 0;
5
+ const utils_1 = require("../runtime/utils");
6
+ const createConversationField = (typeDef, typeName) => {
7
+ const { aiModel, systemPrompt, handler, tools } = typeDef;
8
+ const args = {
9
+ aiModel: aiModel.resourcePath,
10
+ // This is done to escape newlines in potentially multi-line system prompts
11
+ // e.g.
12
+ // realtorChat: a.conversation({
13
+ // aiModel: a.ai.model('Claude 3 Haiku'),
14
+ // systemPrompt: `You are a helpful real estate assistant
15
+ // Respond in the poetic form of haiku.`,
16
+ // }),
17
+ //
18
+ // It doesn't affect non multi-line string inputs for system prompts
19
+ systemPrompt: systemPrompt.replace(/\r?\n/g, '\\n'),
20
+ };
21
+ const argsString = Object.entries(args)
22
+ .map(([key, value]) => `${key}: "${value}"`)
23
+ .join(', ');
24
+ const functionHandler = {};
25
+ let handlerString = '';
26
+ if (handler) {
27
+ const functionName = `Fn${(0, utils_1.capitalize)(typeName)}`;
28
+ const eventVersion = handler.eventVersion;
29
+ handlerString = `, handler: { functionName: "${functionName}", eventVersion: "${eventVersion}" }`;
30
+ functionHandler[functionName] = handler;
31
+ }
32
+ const toolsString = tools?.length
33
+ ? `, tools: [${getConversationToolsString(tools)}]`
34
+ : '';
35
+ const conversationDirective = `@conversation(${argsString}${handlerString}${toolsString})`;
36
+ const field = `${typeName}(conversationId: ID!, content: [ContentBlockInput], aiContext: AWSJSON, toolConfiguration: ToolConfigurationInput): ConversationMessage ${conversationDirective} @aws_cognito_user_pools`;
37
+ return { field, functionHandler };
38
+ };
39
+ exports.createConversationField = createConversationField;
40
+ const isRef = (query) => query?.data?.type === 'ref';
41
+ const getConversationToolsString = (tools) => tools
42
+ .map((tool) => {
43
+ const { query, description } = tool;
44
+ if (!isRef(query)) {
45
+ throw new Error(`Unexpected query was found in tool ${tool}.`);
46
+ }
47
+ // TODO: add validation for query / auth (cup) / etc
48
+ const queryName = query.data.link;
49
+ return `{ name: "${queryName}", description: "${description}" }`;
50
+ })
51
+ .join(', ');
52
+ //# sourceMappingURL=ConversationSchemaProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConversationSchemaProcessor.js","sources":["../../../src/ai/ConversationSchemaProcessor.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createConversationField = void 0;\nconst utils_1 = require(\"../runtime/utils\");\nconst createConversationField = (typeDef, typeName) => {\n const { aiModel, systemPrompt, handler, tools } = typeDef;\n const args = {\n aiModel: aiModel.resourcePath,\n // This is done to escape newlines in potentially multi-line system prompts\n // e.g.\n // realtorChat: a.conversation({\n // aiModel: a.ai.model('Claude 3 Haiku'),\n // systemPrompt: `You are a helpful real estate assistant\n // Respond in the poetic form of haiku.`,\n // }),\n //\n // It doesn't affect non multi-line string inputs for system prompts\n systemPrompt: systemPrompt.replace(/\\r?\\n/g, '\\\\n'),\n };\n const argsString = Object.entries(args)\n .map(([key, value]) => `${key}: \"${value}\"`)\n .join(', ');\n const functionHandler = {};\n let handlerString = '';\n if (handler) {\n const functionName = `Fn${(0, utils_1.capitalize)(typeName)}`;\n const eventVersion = handler.eventVersion;\n handlerString = `, handler: { functionName: \"${functionName}\", eventVersion: \"${eventVersion}\" }`;\n functionHandler[functionName] = handler;\n }\n const toolsString = tools?.length\n ? `, tools: [${getConversationToolsString(tools)}]`\n : '';\n const conversationDirective = `@conversation(${argsString}${handlerString}${toolsString})`;\n const field = `${typeName}(conversationId: ID!, content: [ContentBlockInput], aiContext: AWSJSON, toolConfiguration: ToolConfigurationInput): ConversationMessage ${conversationDirective} @aws_cognito_user_pools`;\n return { field, functionHandler };\n};\nexports.createConversationField = createConversationField;\nconst isRef = (query) => query?.data?.type === 'ref';\nconst getConversationToolsString = (tools) => tools\n .map((tool) => {\n const { query, description } = tool;\n if (!isRef(query)) {\n throw new Error(`Unexpected query was found in tool ${tool}.`);\n }\n // TODO: add validation for query / auth (cup) / etc\n const queryName = query.data.link;\n return `{ name: \"${queryName}\", description: \"${description}\" }`;\n})\n .join(', ');\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAA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AAE,MAAM;AACrC,UAAU,CAAC,UAAU,EAAE,0BAA0B,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC3D,UAAU,EAAE,CAAC;AACb,IAAI,MAAM,qBAAqB,GAAG,CAAC,cAAc,EAAE,UAAU,CAAC,EAAE,aAAa,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;AAC/F,IAAI,MAAM,KAAK,GAAG,CAAC,EAAE,QAAQ,CAAC,wIAAwI,EAAE,qBAAqB,CAAC,wBAAwB,CAAC,CAAC;AACxN,IAAI,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC;AACtC,CAAC,CAAC;AACF,OAAO,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;AAC1D,MAAM,KAAK,GAAG,CAAC,KAAK,KAAK,KAAK,EAAE,IAAI,EAAE,IAAI,KAAK,KAAK,CAAC;AACrD,MAAM,0BAA0B,GAAG,CAAC,KAAK,KAAK,KAAK;AACnD,KAAK,GAAG,CAAC,CAAC,IAAI,KAAK;AACnB,IAAI,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;AACxC,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;AACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,mCAAmC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACvE,KAAK;AACL;AACA,IAAI,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;AACtC,IAAI,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,iBAAiB,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;AACrE,CAAC,CAAC;AACF,KAAK,IAAI,CAAC,IAAI,CAAC;;"}
@@ -7,7 +7,8 @@ import { getHandlerData } from './Handler.mjs';
7
7
  import * as os from 'os';
8
8
  import * as path from 'path';
9
9
  import { brandName } from './ai/ConversationType.mjs';
10
- import { createConversationField, conversationTypes } from './ai/ConversationSchemaTypes.mjs';
10
+ import { CONVERSATION_SCHEMA_GRAPHQL_TYPES } from './ai/ConversationSchemaGraphQLTypes.mjs';
11
+ import { createConversationField } from './ai/ConversationSchemaProcessor.mjs';
11
12
 
12
13
  function isInternalModel(model) {
13
14
  if (model.data &&
@@ -1014,7 +1015,7 @@ const schemaPreprocessor = (schema) => {
1014
1015
  };
1015
1016
  gqlModels.push(...generateCustomOperationTypes(customOperations));
1016
1017
  if (shouldAddConversationTypes) {
1017
- gqlModels.push(...conversationTypes);
1018
+ gqlModels.push(CONVERSATION_SCHEMA_GRAPHQL_TYPES);
1018
1019
  }
1019
1020
  const processedSchema = gqlModels.join('\n\n');
1020
1021
  return {