@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.
@@ -1,237 +0,0 @@
1
- import { capitalize } from '../runtime/utils/stringTransformation.mjs';
2
-
3
- const createConversationField = (typeDef, typeName) => {
4
- const { aiModel, systemPrompt, handler, tools } = typeDef;
5
- const args = {
6
- aiModel: aiModel.resourcePath,
7
- // This is done to escape newlines in potentially multi-line system prompts
8
- // e.g.
9
- // realtorChat: a.conversation({
10
- // aiModel: a.ai.model('Claude 3 Haiku'),
11
- // systemPrompt: `You are a helpful real estate assistant
12
- // Respond in the poetic form of haiku.`,
13
- // }),
14
- //
15
- // It doesn't affect non multi-line string inputs for system prompts
16
- systemPrompt: systemPrompt.replace(/\r?\n/g, '\\n'),
17
- };
18
- const argsString = Object.entries(args)
19
- .map(([key, value]) => `${key}: "${value}"`)
20
- .join(', ');
21
- const functionHandler = {};
22
- let handlerString = '';
23
- if (handler) {
24
- const functionName = `Fn${capitalize(typeName)}`;
25
- const eventVersion = handler.eventVersion;
26
- handlerString = `, handler: { functionName: "${functionName}", eventVersion: "${eventVersion}" }`;
27
- functionHandler[functionName] = handler;
28
- }
29
- const toolsString = tools?.length
30
- ? `, tools: [${getConversationToolsString(tools)}]`
31
- : '';
32
- const conversationDirective = `@conversation(${argsString}${handlerString}${toolsString})`;
33
- const field = `${typeName}(conversationId: ID!, content: [ContentBlockInput], aiContext: AWSJSON, toolConfiguration: ToolConfigurationInput): ConversationMessage ${conversationDirective} @aws_cognito_user_pools`;
34
- return { field, functionHandler };
35
- };
36
- const isRef = (query) => query?.data?.type === 'ref';
37
- const getConversationToolsString = (tools) => tools
38
- .map((tool) => {
39
- const { query, description } = tool;
40
- if (!isRef(query)) {
41
- throw new Error(`Unexpected query was found in tool ${tool}.`);
42
- }
43
- // TODO: add validation for query / auth (cup) / etc
44
- const queryName = query.data.link;
45
- return `{ name: "${queryName}", description: "${description}" }`;
46
- })
47
- .join(', ');
48
- const ConversationParticipantRole = `enum ConversationParticipantRole {
49
- user
50
- assistant
51
- }`;
52
- const ConversationMessage = `interface ConversationMessage {
53
- id: ID!
54
- conversationId: ID!
55
- role: ConversationParticipantRole
56
- content: [ContentBlock]
57
- aiContext: AWSJSON
58
- toolConfiguration: ToolConfiguration
59
- createdAt: AWSDateTime
60
- updatedAt: AWSDateTime
61
- owner: String
62
- }`;
63
- const DocumentBlockSourceInput = `input DocumentBlockSourceInput {
64
- bytes: String
65
- }`;
66
- const DocumentBlockInput = `input DocumentBlockInput {
67
- format: String!
68
- name: String!
69
- source: DocumentBlockSourceInput!
70
- }`;
71
- const ImageBlockSourceInput = `input ImageBlockSourceInput {
72
- bytes: String
73
- }`;
74
- const ImageBlockInput = `input ImageBlockInput {
75
- format: String!
76
- source: ImageBlockSourceInput!
77
- }`;
78
- const ToolResultContentBlockInput = `input ToolResultContentBlockInput {
79
- document: DocumentBlockInput
80
- image: ImageBlockInput
81
- json: AWSJSON
82
- text: String
83
- }`;
84
- const ToolResultBlockInput = `input ToolResultBlockInput {
85
- content: [ToolResultContentBlockInput!]!
86
- toolUseId: String!
87
- status: String
88
- }`;
89
- const DocumentBlockSource = `type DocumentBlockSource {
90
- bytes: String
91
- }
92
- `;
93
- const DocumentBlock = `type DocumentBlock {
94
- format: String!
95
- name: String!
96
- source: DocumentBlockSource!
97
- }`;
98
- const ImageBlock = `type ImageBlock {
99
- format: String!
100
- source: ImageBlockSource!
101
- }`;
102
- const ImageBlockSource = `type ImageBlockSource {
103
- bytes: String
104
- }`;
105
- const ToolUseBlockInput = `input ToolUseBlockInput {
106
- toolUseId: String!
107
- name: String!
108
- input: AWSJSON!
109
- }`;
110
- const ToolUseBlock = `type ToolUseBlock {
111
- toolUseId: String!
112
- name: String!
113
- input: AWSJSON!
114
- }`;
115
- const ToolResultContentBlock = `type ToolResultContentBlock {
116
- document: DocumentBlock
117
- image: ImageBlock
118
- json: AWSJSON
119
- text: String
120
- }`;
121
- const ToolResultBlock = `type ToolResultBlock {
122
- content: [ToolResultContentBlock!]!
123
- toolUseId: String!
124
- status: String
125
- }`;
126
- const ContentBlockText = `type ContentBlockText {
127
- text: String
128
- }`;
129
- const ContentBlockImage = `type ContentBlockImage {
130
- image: ImageBlock
131
- }`;
132
- const ContentBlockDocument = `type ContentBlockDocument {
133
- document: DocumentBlock
134
- }`;
135
- const ContentBlockToolUse = `type ContentBlockToolUse {
136
- toolUse: ToolUseBlock
137
- }`;
138
- const ContentBlockToolResult = `type ContentBlockToolResult {
139
- toolResult: ToolResultBlock
140
- }`;
141
- const ContentBlockInput = `input ContentBlockInput {
142
- text: String
143
- document: DocumentBlockInput
144
- image: ImageBlockInput
145
- toolResult: ToolResultBlockInput
146
- toolUse: ToolUseBlockInput
147
- }`;
148
- const ContentBlock = `type ContentBlock {
149
- text: String
150
- document: DocumentBlock
151
- image: ImageBlock
152
- toolResult: ToolResultBlock
153
- toolUse: ToolUseBlock
154
- }`;
155
- const ToolConfigurationInput = `input ToolConfigurationInput {
156
- tools: [ToolInput]
157
- }`;
158
- const ToolInput = `input ToolInput {
159
- toolSpec: ToolSpecificationInput
160
- }`;
161
- const ToolSpecificationInput = `input ToolSpecificationInput {
162
- name: String!
163
- description: String
164
- inputSchema: ToolInputSchemaInput!
165
- }`;
166
- const ToolInputSchemaInput = `input ToolInputSchemaInput {
167
- json: AWSJSON
168
- }`;
169
- const ToolConfiguration = `type ToolConfiguration {
170
- tools: [Tool]
171
- }`;
172
- const Tool = `type Tool {
173
- toolSpec: ToolSpecification
174
- }`;
175
- const ToolSpecification = `type ToolSpecification {
176
- name: String!
177
- description: String
178
- inputSchema: ToolInputSchema!
179
- }`;
180
- const ToolInputSchema = `type ToolInputSchema {
181
- json: AWSJSON
182
- }`;
183
- const ConversationMessageStreamEvent = `type ConversationMessageStreamPart @aws_cognito_user_pools {
184
- id: ID!
185
- owner: String
186
- conversationId: ID!
187
- associatedUserMessageId: ID!
188
- contentBlockIndex: Int
189
- contentBlockText: String
190
- contentBlockDeltaIndex: Int
191
- contentBlockToolUse: ToolUseBlock
192
- contentBlockDoneAtIndex: Int
193
- stopReason: String
194
- errors: [ConversationTurnError]
195
- }`;
196
- const ConversationTurnError = `type ConversationTurnError @aws_cognito_user_pools {
197
- message: String!
198
- errorType: String!
199
- }`;
200
- const conversationTypes = [
201
- ConversationParticipantRole,
202
- ConversationMessage,
203
- DocumentBlockSourceInput,
204
- DocumentBlockInput,
205
- ImageBlockSourceInput,
206
- ImageBlockInput,
207
- ToolUseBlockInput,
208
- ToolResultContentBlockInput,
209
- ToolResultBlockInput,
210
- DocumentBlockSource,
211
- DocumentBlock,
212
- ImageBlock,
213
- ImageBlockSource,
214
- ToolUseBlock,
215
- ToolResultContentBlock,
216
- ToolResultBlock,
217
- ContentBlockText,
218
- ContentBlockImage,
219
- ContentBlockDocument,
220
- ContentBlockToolUse,
221
- ContentBlockToolResult,
222
- ContentBlockInput,
223
- ContentBlock,
224
- ToolConfigurationInput,
225
- ToolInput,
226
- ToolSpecificationInput,
227
- ToolInputSchemaInput,
228
- ToolConfiguration,
229
- Tool,
230
- ToolSpecification,
231
- ToolInputSchema,
232
- ConversationMessageStreamEvent,
233
- ConversationTurnError,
234
- ];
235
-
236
- export { conversationTypes, createConversationField };
237
- //# sourceMappingURL=ConversationSchemaTypes.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConversationSchemaTypes.mjs","sources":["../../../src/ai/ConversationSchemaTypes.ts"],"sourcesContent":["import { capitalize } from '../runtime/utils';\nexport const 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${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};\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(', ');\nconst ConversationParticipantRole = `enum ConversationParticipantRole {\n user\n assistant\n}`;\nconst ConversationMessage = `interface ConversationMessage {\n id: ID!\n conversationId: ID!\n role: ConversationParticipantRole\n content: [ContentBlock]\n aiContext: AWSJSON\n toolConfiguration: ToolConfiguration\n createdAt: AWSDateTime\n updatedAt: AWSDateTime\n owner: String\n}`;\nconst DocumentBlockSourceInput = `input DocumentBlockSourceInput {\n bytes: String\n}`;\nconst DocumentBlockInput = `input DocumentBlockInput {\n format: String!\n name: String!\n source: DocumentBlockSourceInput!\n}`;\nconst ImageBlockSourceInput = `input ImageBlockSourceInput {\n bytes: String\n}`;\nconst ImageBlockInput = `input ImageBlockInput {\n format: String!\n source: ImageBlockSourceInput!\n}`;\nconst ToolResultContentBlockInput = `input ToolResultContentBlockInput {\n document: DocumentBlockInput\n image: ImageBlockInput\n json: AWSJSON\n text: String\n}`;\nconst ToolResultBlockInput = `input ToolResultBlockInput {\n content: [ToolResultContentBlockInput!]!\n toolUseId: String!\n status: String\n}`;\nconst DocumentBlockSource = `type DocumentBlockSource {\n bytes: String\n}\n`;\nconst DocumentBlock = `type DocumentBlock {\n format: String!\n name: String!\n source: DocumentBlockSource!\n}`;\nconst ImageBlock = `type ImageBlock {\n format: String!\n source: ImageBlockSource!\n}`;\nconst ImageBlockSource = `type ImageBlockSource {\n bytes: String\n}`;\nconst ToolUseBlockInput = `input ToolUseBlockInput {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}`;\nconst ToolUseBlock = `type ToolUseBlock {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}`;\nconst ToolResultContentBlock = `type ToolResultContentBlock {\n document: DocumentBlock\n image: ImageBlock\n json: AWSJSON\n text: String\n}`;\nconst ToolResultBlock = `type ToolResultBlock {\n content: [ToolResultContentBlock!]!\n toolUseId: String!\n status: String\n}`;\nconst ContentBlockText = `type ContentBlockText {\n text: String\n}`;\nconst ContentBlockImage = `type ContentBlockImage {\n image: ImageBlock\n}`;\nconst ContentBlockDocument = `type ContentBlockDocument {\n document: DocumentBlock\n}`;\nconst ContentBlockToolUse = `type ContentBlockToolUse {\n toolUse: ToolUseBlock\n}`;\nconst ContentBlockToolResult = `type ContentBlockToolResult {\n toolResult: ToolResultBlock\n}`;\nconst ContentBlockInput = `input ContentBlockInput {\n text: String\n document: DocumentBlockInput\n image: ImageBlockInput\n toolResult: ToolResultBlockInput\n toolUse: ToolUseBlockInput\n}`;\nconst ContentBlock = `type ContentBlock {\n text: String\n document: DocumentBlock\n image: ImageBlock\n toolResult: ToolResultBlock\n toolUse: ToolUseBlock\n}`;\nconst ToolConfigurationInput = `input ToolConfigurationInput {\n tools: [ToolInput]\n}`;\nconst ToolInput = `input ToolInput {\n toolSpec: ToolSpecificationInput\n}`;\nconst ToolSpecificationInput = `input ToolSpecificationInput {\n name: String!\n description: String\n inputSchema: ToolInputSchemaInput!\n}`;\nconst ToolInputSchemaInput = `input ToolInputSchemaInput {\n json: AWSJSON\n}`;\nconst ToolConfiguration = `type ToolConfiguration {\n tools: [Tool]\n}`;\nconst Tool = `type Tool {\n toolSpec: ToolSpecification\n}`;\nconst ToolSpecification = `type ToolSpecification {\n name: String!\n description: String\n inputSchema: ToolInputSchema!\n}`;\nconst ToolInputSchema = `type ToolInputSchema {\n json: AWSJSON\n}`;\nconst ConversationMessageStreamEvent = `type 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}`;\nconst ConversationTurnError = `type ConversationTurnError @aws_cognito_user_pools {\n message: String!\n errorType: String!\n}`;\nexport const conversationTypes = [\n ConversationParticipantRole,\n ConversationMessage,\n DocumentBlockSourceInput,\n DocumentBlockInput,\n ImageBlockSourceInput,\n ImageBlockInput,\n ToolUseBlockInput,\n ToolResultContentBlockInput,\n ToolResultBlockInput,\n DocumentBlockSource,\n DocumentBlock,\n ImageBlock,\n ImageBlockSource,\n ToolUseBlock,\n ToolResultContentBlock,\n ToolResultBlock,\n ContentBlockText,\n ContentBlockImage,\n ContentBlockDocument,\n ContentBlockToolUse,\n ContentBlockToolResult,\n ContentBlockInput,\n ContentBlock,\n ToolConfigurationInput,\n ToolInput,\n ToolSpecificationInput,\n ToolInputSchemaInput,\n ToolConfiguration,\n Tool,\n ToolSpecification,\n ToolInputSchema,\n ConversationMessageStreamEvent,\n ConversationTurnError,\n];\n"],"names":[],"mappings":";;AACY,MAAC,uBAAuB,GAAG,CAAC,OAAO,EAAE,QAAQ,KAAK;AAC9D,IAAI,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;AAC9D,IAAI,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
2
- import { InternalRef } from '../RefType';
3
- import { capitalize } from '../runtime/utils';
4
- import type {
5
- InternalConversationType,
6
- ToolDefinition,
7
- } from './ConversationType';
8
-
9
- export const createConversationField = (
10
- typeDef: InternalConversationType,
11
- typeName: string,
12
- ): { field: string, functionHandler: LambdaFunctionDefinition } => {
13
- const { aiModel, systemPrompt, handler, tools } = typeDef;
14
-
15
- const args: Record<string, string> = {
16
- aiModel: aiModel.resourcePath,
17
- // This is done to escape newlines in potentially multi-line system prompts
18
- // e.g.
19
- // realtorChat: a.conversation({
20
- // aiModel: a.ai.model('Claude 3 Haiku'),
21
- // systemPrompt: `You are a helpful real estate assistant
22
- // Respond in the poetic form of haiku.`,
23
- // }),
24
- //
25
- // It doesn't affect non multi-line string inputs for system prompts
26
- systemPrompt: systemPrompt.replace(/\r?\n/g, '\\n'),
27
- };
28
-
29
- const argsString = Object.entries(args)
30
- .map(([key, value]) => `${key}: "${value}"`)
31
- .join(', ');
32
-
33
- const functionHandler: LambdaFunctionDefinition = {};
34
- let handlerString = '';
35
- if (handler) {
36
- const functionName = `Fn${capitalize(typeName)}`;
37
- const eventVersion = handler.eventVersion;
38
- handlerString = `, handler: { functionName: "${functionName}", eventVersion: "${eventVersion}" }`;
39
- functionHandler[functionName] = handler;
40
- }
41
-
42
- const toolsString = tools?.length
43
- ? `, tools: [${getConversationToolsString(tools)}]`
44
- : '';
45
-
46
- const conversationDirective = `@conversation(${argsString}${handlerString}${toolsString})`;
47
-
48
- const field = `${typeName}(conversationId: ID!, content: [ContentBlockInput], aiContext: AWSJSON, toolConfiguration: ToolConfigurationInput): ConversationMessage ${conversationDirective} @aws_cognito_user_pools`;
49
- return { field, functionHandler };
50
- };
51
-
52
- const isRef = (query: unknown): query is { data: InternalRef['data'] } =>
53
- (query as any)?.data?.type === 'ref';
54
-
55
- const getConversationToolsString = (tools: ToolDefinition[]) =>
56
- tools
57
- .map((tool) => {
58
- const { query, description } = tool;
59
- if (!isRef(query)) {
60
- throw new Error(`Unexpected query was found in tool ${tool}.`);
61
- }
62
- // TODO: add validation for query / auth (cup) / etc
63
- const queryName = query.data.link;
64
- return `{ name: "${queryName}", description: "${description}" }`;
65
- })
66
- .join(', ');
67
-
68
- const ConversationParticipantRole = `enum ConversationParticipantRole {
69
- user
70
- assistant
71
- }`;
72
-
73
- const ConversationMessage = `interface ConversationMessage {
74
- id: ID!
75
- conversationId: ID!
76
- role: ConversationParticipantRole
77
- content: [ContentBlock]
78
- aiContext: AWSJSON
79
- toolConfiguration: ToolConfiguration
80
- createdAt: AWSDateTime
81
- updatedAt: AWSDateTime
82
- owner: String
83
- }`;
84
-
85
- const DocumentBlockSourceInput = `input DocumentBlockSourceInput {
86
- bytes: String
87
- }`;
88
-
89
- const DocumentBlockInput = `input DocumentBlockInput {
90
- format: String!
91
- name: String!
92
- source: DocumentBlockSourceInput!
93
- }`;
94
-
95
- const ImageBlockSourceInput = `input ImageBlockSourceInput {
96
- bytes: String
97
- }`;
98
-
99
- const ImageBlockInput = `input ImageBlockInput {
100
- format: String!
101
- source: ImageBlockSourceInput!
102
- }`;
103
-
104
- const ToolResultContentBlockInput = `input ToolResultContentBlockInput {
105
- document: DocumentBlockInput
106
- image: ImageBlockInput
107
- json: AWSJSON
108
- text: String
109
- }`;
110
-
111
- const ToolResultBlockInput = `input ToolResultBlockInput {
112
- content: [ToolResultContentBlockInput!]!
113
- toolUseId: String!
114
- status: String
115
- }`;
116
-
117
- const DocumentBlockSource = `type DocumentBlockSource {
118
- bytes: String
119
- }
120
- `;
121
- const DocumentBlock = `type DocumentBlock {
122
- format: String!
123
- name: String!
124
- source: DocumentBlockSource!
125
- }`;
126
-
127
- const ImageBlock = `type ImageBlock {
128
- format: String!
129
- source: ImageBlockSource!
130
- }`;
131
-
132
- const ImageBlockSource = `type ImageBlockSource {
133
- bytes: String
134
- }`;
135
-
136
- const ToolUseBlockInput = `input ToolUseBlockInput {
137
- toolUseId: String!
138
- name: String!
139
- input: AWSJSON!
140
- }`;
141
-
142
- const ToolUseBlock = `type ToolUseBlock {
143
- toolUseId: String!
144
- name: String!
145
- input: AWSJSON!
146
- }`;
147
-
148
- const ToolResultContentBlock = `type ToolResultContentBlock {
149
- document: DocumentBlock
150
- image: ImageBlock
151
- json: AWSJSON
152
- text: String
153
- }`;
154
-
155
- const ToolResultBlock = `type ToolResultBlock {
156
- content: [ToolResultContentBlock!]!
157
- toolUseId: String!
158
- status: String
159
- }`;
160
-
161
- const ContentBlockText = `type ContentBlockText {
162
- text: String
163
- }`;
164
-
165
- const ContentBlockImage = `type ContentBlockImage {
166
- image: ImageBlock
167
- }`;
168
-
169
- const ContentBlockDocument = `type ContentBlockDocument {
170
- document: DocumentBlock
171
- }`;
172
-
173
- const ContentBlockToolUse = `type ContentBlockToolUse {
174
- toolUse: ToolUseBlock
175
- }`;
176
-
177
- const ContentBlockToolResult = `type ContentBlockToolResult {
178
- toolResult: ToolResultBlock
179
- }`;
180
-
181
- const ContentBlockInput = `input ContentBlockInput {
182
- text: String
183
- document: DocumentBlockInput
184
- image: ImageBlockInput
185
- toolResult: ToolResultBlockInput
186
- toolUse: ToolUseBlockInput
187
- }`;
188
-
189
- const ContentBlock = `type ContentBlock {
190
- text: String
191
- document: DocumentBlock
192
- image: ImageBlock
193
- toolResult: ToolResultBlock
194
- toolUse: ToolUseBlock
195
- }`;
196
-
197
- const ToolConfigurationInput = `input ToolConfigurationInput {
198
- tools: [ToolInput]
199
- }`;
200
-
201
- const ToolInput = `input ToolInput {
202
- toolSpec: ToolSpecificationInput
203
- }`;
204
-
205
- const ToolSpecificationInput = `input ToolSpecificationInput {
206
- name: String!
207
- description: String
208
- inputSchema: ToolInputSchemaInput!
209
- }`;
210
-
211
- const ToolInputSchemaInput = `input ToolInputSchemaInput {
212
- json: AWSJSON
213
- }`;
214
-
215
- const ToolConfiguration = `type ToolConfiguration {
216
- tools: [Tool]
217
- }`;
218
-
219
- const Tool = `type Tool {
220
- toolSpec: ToolSpecification
221
- }`;
222
-
223
- const ToolSpecification = `type ToolSpecification {
224
- name: String!
225
- description: String
226
- inputSchema: ToolInputSchema!
227
- }`;
228
-
229
- const ToolInputSchema = `type ToolInputSchema {
230
- json: AWSJSON
231
- }`;
232
-
233
- const ConversationMessageStreamEvent = `type ConversationMessageStreamPart @aws_cognito_user_pools {
234
- id: ID!
235
- owner: String
236
- conversationId: ID!
237
- associatedUserMessageId: ID!
238
- contentBlockIndex: Int
239
- contentBlockText: String
240
- contentBlockDeltaIndex: Int
241
- contentBlockToolUse: ToolUseBlock
242
- contentBlockDoneAtIndex: Int
243
- stopReason: String
244
- errors: [ConversationTurnError]
245
- }`;
246
-
247
- const ConversationTurnError = `type ConversationTurnError @aws_cognito_user_pools {
248
- message: String!
249
- errorType: String!
250
- }`;
251
-
252
- export const conversationTypes: string[] = [
253
- ConversationParticipantRole,
254
- ConversationMessage,
255
- DocumentBlockSourceInput,
256
- DocumentBlockInput,
257
- ImageBlockSourceInput,
258
- ImageBlockInput,
259
- ToolUseBlockInput,
260
- ToolResultContentBlockInput,
261
- ToolResultBlockInput,
262
- DocumentBlockSource,
263
- DocumentBlock,
264
- ImageBlock,
265
- ImageBlockSource,
266
- ToolUseBlock,
267
- ToolResultContentBlock,
268
- ToolResultBlock,
269
- ContentBlockText,
270
- ContentBlockImage,
271
- ContentBlockDocument,
272
- ContentBlockToolUse,
273
- ContentBlockToolResult,
274
- ContentBlockInput,
275
- ContentBlock,
276
- ToolConfigurationInput,
277
- ToolInput,
278
- ToolSpecificationInput,
279
- ToolInputSchemaInput,
280
- ToolConfiguration,
281
- Tool,
282
- ToolSpecification,
283
- ToolInputSchema,
284
- ConversationMessageStreamEvent,
285
- ConversationTurnError,
286
- ];